Eclipse Plugin


TonyQ



About me

QNAP Senior Engineer
Run-Jetty-Run Eclipse plugin maintainer


JavaScript.tw Community creator
JavaScript Developer Conference




Why this talk


  • Eclipse Plugin is easy.
  • Eclipse plugin FAQ/cheatsheet for beginners .


Outline

  • Introduction
  • Eclipse View
  • Eclipse Plugin Concept
  • Eclipse Extension point
  • Eclipse Resource
  • Eclipse Plugin Resource/Storage
  • Eclipse Plugin Preference
  • Eclipse plugin deploy


Eclipse RoadMap

2001 /11 ~ now

  • Europa  3.3 2007/6/26
  • Ganymede 3.4 2008/6/27
  • Galileo 3.5 2009/6/24
  • Helios 3.6 2010/6/23
  • Indigo 3.7 2011/6/22
  • Juno 4.2 2012/6/27
  • Kepler 4.3 2013/6/26


Support languages


  • Java
  • JavaEE
  • Android (ADT)
  • PHP (PDT)
  • Web (Aptana)
.
.
.


Eclipse View 



Eclipse view



Eclipse plugin


Eclipse View Review



Plugin File Structure


  • src/org.myplugin.Activator.java

  • plugin.xml

  • build.properties

  • META-INF/MANIFEST.MF


That's it ? ? ?


yes



How to add items 
in existing view ?

* Follow defined rule.




Extension point 

Interfaces and contracts between plugins.


Extension point


  • Provided by other existing plugins

  • Use XML to define elements and datas

  • Usually include items below:

    • Description (ex. name)

    • Mapping Class 

    • Configuration





Sample  1 : Launch


Sample Detail

<extension point="org.eclipse.debug.ui.launchShortcuts">
  <shortcut class="mypackage.RunJettyRunLaunchShortcut"    icon="icons/jetty.gif"&nbsp; id="runjettyrun.runJettyShortcut"     label="Run Jetty " modes="run, debug">
     <!-- ... -->
  </shortcut>
</extension>

Sample 2  : Key binding 

In this case used two extension point .

<extension point="org.eclipse.ui.bindings">
   <key commandId="runjettyrun.runJettyShortcut.debug"
     contextId="org.eclipse.ui.contexts.window"
     schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
     sequence="Alt+Z">
   </key>
</extension>
<extension point="org.eclipse.ui.commands">   <command name="Debug Jetty Web Application"
      description="Debug Jetty Web app"
      categoryId="runjettyrun.commands"
      id="runjettyrun.runJettyShortcut.debug">
   </command>
   <category
         id="runjettyrun.commands"
         name="Run Jetty Run">
   </category>
</extension>



Plugin development

All started from extension points.



new Wizard


  • org.eclipse.ui.newWizards
  • org.eclipse.ui.importWizards
  • org.eclipse.ui.exportWizards


new Key

  • org.eclipse.ui.bindings
  • org.eclipse.ui.commands


new View

  • org.eclipse.ui.views
  • org.eclipse.ui.editors
  • org.eclipse.ui.navigator.viewer
.
.
.


new Perspective

org.eclipse.ui.perspectives


new Builder

org.eclipse.core.resources.builders
org.eclipse.core.resources.natures


new Launch type


  • org.eclipse.debug.core.launchConfigurationTypes
  • org.eclipse.debug.ui.launchConfigurationTypeImages
  • org.eclipse.debug.ui.launchShortcuts



Question 


How could I find the correct extension point?


Here's official extension list




It seldom work

 (for me)


Learn from 

existing plugin


Magic SPY method

The most important two method you should know.


Plugin Selection Spy
Alt + Shift + F1  (Shift + Option + F1  on Mac)

Plugin Menu Spy
Alt + Shift + F2  (Shift + Option + F2  on Mac)


Plugin Selection Spy


Plugin menu spy

 

Plugin menu spy



Plugin menu spy 



Use Eclipse Standard


Not all Eclipse packages contains plugin source ,
but it's a good reference when you developing a plugin.

Import Plugins




Import Package




Import packages


Import Plugins


Import Plugins


Resource Type Tree



Plugin Resource


Bundle bundle = Activator.getDefault().   getBundle("my.example.plugin");
URL fileURL = bundle.getEntry("files/test.txt"); 
InputStream inputStream = fileURL.openConnection().getInputStream();/* Do what you need. */


Plugin Resource

Bundle bundle = Activator.getDefault().   getBundle("my.example.plugin");
URL resourceURL = bundle.getEntry("files/test.txt"); URL fileURL = FileLocator.toFileURL(resourceURL);
/* Do what you need. */



Plugin Storage

IPath path = Activator.getDefault().getStateLocation().  append("my.text");File f = path.toFile();
/* Do what you need*/		 


Plugin Storage


Stored in workspace meta



Preference


Activator.getDefault().getPreferenceStore()


  getBoolean(name)

 setValue(name, value)


Support:  int,long,float,double,boolean,String.


Debug


  • Run in another Eclipse , 
breakpoint supported.

  • Choose selected plugin to import.




Release

  • Update Site
    Easy install/update for users .

  • Feature
    Group multiple plugins.

  • Plugin



Q & A



This is a web slide, slide url:
https://slid.es/tonyq/javatwo-eclipse-talk

Shorted url :  http://goo.gl/Mj0jIz

Contact me: tonylovejava@gmail.com  
                            (I guess that's why I am here.)

JavaTwo-eclipse-talk

By TonyQ Wang

JavaTwo-eclipse-talk

  • 6,993