www espirity com Plugin Development Dwight Deugo dwightespirity

  • Slides: 36
Download presentation
www. espirity. com Plug-in Development Dwight Deugo (dwight@espirity. com) Nesa Matic (nesa@espirity. com)

www. espirity. com Plug-in Development Dwight Deugo (dwight@espirity. com) Nesa Matic (nesa@espirity. com)

Additional Contributors n None as of September, 2005 2 © 2003 -2005, Espirity Inc.

Additional Contributors n None as of September, 2005 2 © 2003 -2005, Espirity Inc.

Module Overview 1. Extending Workbench 3 © 2003 -2005, Espirity Inc.

Module Overview 1. Extending Workbench 3 © 2003 -2005, Espirity Inc.

Module Road Map 1. Extending Workbench § § § § Contributing Actions Action set

Module Road Map 1. Extending Workbench § § § § Contributing Actions Action set Adding toolbar and menu items to the Workbench Developing plug-in Installing plug-in Running plug-in Plug-in registry 4 © 2003 -2005, Espirity Inc.

Integration Between Plug-ins n Supported through ability to contribute actions to existing plug-ins q

Integration Between Plug-ins n Supported through ability to contribute actions to existing plug-ins q q n New plug-in contributes an action to existing plug-in Allows for tight integration between plug-ins There are many areas where actions can be contributed: q q Context menus of views and editors Local toolbar and pull-down menu of a view Toolbar and menu of an editor – appears on the Workbench when editor opens Main toolbar and menu for the Workbench 5 © 2003 -2005, Espirity Inc.

Extending Views n n Changes made to a view are specific to that view

Extending Views n n Changes made to a view are specific to that view Changes can be made to view’s: Context menu q Menu and toolbar q 6 © 2003 -2005, Espirity Inc.

Extending Editors n When extending an editor changes could be made to: q q

Extending Editors n When extending an editor changes could be made to: q q Editor’s context menu Editor’s menu and toolbar ; n The changes appear in the Workbench menu and toolbar only when editor opens Actions defined are shared by all instances of the same editor type q q Editors stay open across multiple perspectives, so their actions stay same When new workspace is open, or workbench is open in a new window, new instance of editor can be created 7 © 2003 -2005, Espirity Inc.

Action Set n Allows extension of the Workbench that is generic q q n

Action Set n Allows extension of the Workbench that is generic q q n Should be used for adding non-editor, or non-view specific actions to the Workbench Actions defined are available for all views and editors Allows customization of the Workbench that includes defining: q q q Menus Menu items Toolbar Action Set 8 Hover Help for the Toolbar Item © 2003 -2005, Espirity Inc.

Choosing What to Extend n Eclipse has a set of predefined extension points q

Choosing What to Extend n Eclipse has a set of predefined extension points q Called Platform Extension Points Comprehensive set of extension points ; Detailed in the on-line help ; n It is possible to create new extension points Requires id, name, and schema to be defined q Done through Plug-in Development Environment (PDE) q 9 © 2003 -2005, Espirity Inc.

Some Common Extension Points n Popup Menus for editors and views q n Menu

Some Common Extension Points n Popup Menus for editors and views q n Menu and toolbar for views q n org. eclipse. ui. editor. Actions Menu and toolbar for the Workbench q n org. eclipse. ui. view. Actions Menu and toolbars for editors q n org. eclipse. ui. popup. Menus org. eclipse. ui. action. Sets Complete set of extension points located in Eclipse help, including definitions q Search on “Platform Extension Points” 10 © 2003 -2005, Espirity Inc.

How to Extend the Workbench? n Steps for adding a plug-in: q Write the

How to Extend the Workbench? n Steps for adding a plug-in: q Write the plug-in code Define Java project ; Create Java class ; Add appropriate protocols to the class ; Package the class q Create plugin. xml and manifest. mf q Test the plug-in q Deploy the plug-in q 11 © 2003 -2005, Espirity Inc.

Creating Java Project n n Project will contain source code for the plug-in Classes

Creating Java Project n n Project will contain source code for the plug-in Classes will be defined in the package: q org. eclipse. demo. plugins. workbench 12 © 2003 -2005, Espirity Inc.

Updating Project’s Build Path n To make classes required for the plug-in visible for

Updating Project’s Build Path n To make classes required for the plug-in visible for the project, update its path q j. Face. jar, swt. jar runtime, and workbench. jar files must be added to project’s build path 13 © 2003 -2005, Espirity Inc.

Creating a Class n For menu actions, define a class that: q q Subclasses

Creating a Class n For menu actions, define a class that: q q Subclasses client delegate class Implements interface that contributes action to the Workbench 14 © 2003 -2005, Espirity Inc.

Interface IWorkbench. Window. Action. Delegate n Extend IAction. Delegate and define methods: init(IWorkbech. Window)

Interface IWorkbench. Window. Action. Delegate n Extend IAction. Delegate and define methods: init(IWorkbech. Window) – Initialization method that connects action delegate to the workbench window q dispose() - Disposes action delegate, the implementer should unhook any references to itself so that garbage collection can occur q n Interface is for an action that is contributed into the workbench window menu or tool bar 15 © 2003 -2005, Espirity Inc.

Class Action. Delegate n n Abstract base implementation for a client delegate action (defines

Class Action. Delegate n n Abstract base implementation for a client delegate action (defines same methods as interface) In addition it also defines: q run. With. Event(IAction, Event) ; ; ; q run(IAction) ; q Does the actual work when action is triggered Parameters represent the action proxy that handles the presentation portion of the action and the SWT event which triggered this action being run Default implementation redirects to run() method Inherited method, does the actual work as it’s called when action is triggered selection. Changed(IAction, ISelection) ; Inherited method, notifies action delegate that the selection in the workbench has changed 16 © 2003 -2005, Espirity Inc.

Action Delegate Code public class My. First. Action. Delegate extends Action. Delegate implements IWorkbench.

Action Delegate Code public class My. First. Action. Delegate extends Action. Delegate implements IWorkbench. Window. Action. Delegate{ IWorkbench. Window active. Window = null; public void run(IAction action){ // used for defining what is done when action executes System. out. println("Hello from the action delegate run() method!"); } public void selection. Changed(IAction proxy. Action, ISelection selection){ // used if action is dependent on the selection } public void init(IWorkbench. Window window){ // used for initialization active. Window = window; } 17 © 2003 -2005, Espirity Inc.

Defining Manifest n n Manifest. mf file Located in the META-INF directory Plug-in specifics

Defining Manifest n n Manifest. mf file Located in the META-INF directory Plug-in specifics Manifest-Version: 1. 0 Bundle-Manifest. Version: 2 Bundle-Name: Code Rally Extension Bundle-Symbolic. Name: org. eclipse. plugins. labs. coderally; singleton: =true Bundle-Version: 1. 0. 0 Bundle-Vendor: Espirity Bundle-Localization: plugin Require-Bundle: com. ibm. coderally, org. eclipse. ui. workbench, org. eclipse. swt, org. eclipse. jface, org. eclipse. ui Eclipse-Auto. Start: true Other plug-ins required by the plug-in 18 © 2003 -2005, Espirity Inc.

Defining plugin. xml… Extension point for action set Label that will appear in Preferences

Defining plugin. xml… Extension point for action set Label that will appear in Preferences window <? xml version="1. 0" encoding="UTF-8"? > <? eclipse version="3. 0"? > <plugin> <extension point="org. eclipse. ui. action. Sets"> <action. Set label="Espirity Action Set" visible="true" id="com. espirity. course. plugins. action. Set"> <menu label="Espirity Menu" id="espirity. Menu"> <separator name="Espirity. Group"/> </menu> … more on next page 19 © 2003 -2005, Espirity Inc.

…Defining plugin. xml… <action label="Espirity Test Action" icon="icons/espirity. jpg" class="org. eclipse. plugins. labs. coderally.

…Defining plugin. xml… <action label="Espirity Test Action" icon="icons/espirity. jpg" class="org. eclipse. plugins. labs. coderally. actions. Test. Action" tooltip="Espirity Test Tooltip" menubar. Path="espirity. Menu/Espirity. Group" toolbar. Path="Espirity. Group" id=" org. eclipse. plugins. labs. coderally. actions. Test. Action"> </action. Set> </extension> </plugin> Icon that will appear in the toolbar Class that will handle action 20 © 2003 -2005, Espirity Inc.

…Defining plugin. xml n n n Pre OSGI/Manifest. mf The library element can specify

…Defining plugin. xml n n n Pre OSGI/Manifest. mf The library element can specify which portion of the library should be exported. By default the library is considered to be private. If you plan to make your plug-in’s library (e. g. , launch. Plugin. jar) classes available for others to use, update your plugin. xml file with the following: <runtime> <library name="launch. Plugin. jar"> <export name="*"/> </library> </runtime> 21 © 2003 -2005, Espirity Inc.

Testing Plug-in from the Workbench n Available through opening new Workbench instance by choosing

Testing Plug-in from the Workbench n Available through opening new Workbench instance by choosing Run As Eclipse Application n Used when developing plug-in with-in the platform q n Mostly used for the plug-in development Project’s output folder must be /bin/ directory For example My. First. Plugin. Project/bin q Can be set in project’s properties window q 22 © 2003 -2005, Espirity Inc.

Testing Requirements n Plug-in manifest file and all other resources required by the plug-in

Testing Requirements n Plug-in manifest file and all other resources required by the plug-in must be part of the project Required by the plug-in 23 © 2003 -2005, Espirity Inc.

Setting the Perspective n n Eclipse must be restarted (runtime workspace) to pick up

Setting the Perspective n n Eclipse must be restarted (runtime workspace) to pick up new plug-in that we have defined Customize opened perspective to show plug-in 24 © 2003 -2005, Espirity Inc.

Running the Plug-in Added toolbar item Added menubar item 25 © 2003 -2005, Espirity

Running the Plug-in Added toolbar item Added menubar item 25 © 2003 -2005, Espirity Inc.

Getting Ready to Export Plug-in n Create a build. properties file in your project

Getting Ready to Export Plug-in n Create a build. properties file in your project with the following contents: source. . = src/ output. . = bin/ bin. includes = plugin. xml, META-INF/, . , icons/ 26 © 2003 -2005, Espirity Inc.

Export Deployable Plug-ins and Fragments… 27 © 2003 -2005, Espirity Inc.

Export Deployable Plug-ins and Fragments… 27 © 2003 -2005, Espirity Inc.

…Export Deployable Plug-ins and Fragments n n n Export the code as a Archive

…Export Deployable Plug-ins and Fragments n n n Export the code as a Archive file The plug-in will have a zip extension Your plug-in is in the zip file and has the jar extension 28 © 2003 -2005, Espirity Inc.

Plug-in ZIP and JAR files n The Plug-in ZIP file has: q n Your

Plug-in ZIP and JAR files n The Plug-in ZIP file has: q n Your Plug-in’s JAR file Unzip contents into plugins directory 29 © 2003 -2005, Espirity Inc.

Installing Plug-in n Make sure the new plug-in. jar file is in Eclipse’s plugin

Installing Plug-in n Make sure the new plug-in. jar file is in Eclipse’s plugin directory. Restart Eclipse Warning Try your new plug-in in a fresh/nondevelopment Eclipse install q You don’t want to have problems in your development install q 30 © 2003 -2005, Espirity Inc.

Adding Submenu … <menu id="my_actions. menu" 1 label="My First Menu" path="additions"> <separator name="menu_group"/> </menu>

Adding Submenu … <menu id="my_actions. menu" 1 label="My First Menu" path="additions"> <separator name="menu_group"/> </menu> <menu id="my_actions. submenu" 2 label="My First Submenu" path="my_actions. menu/menu_group"> <separator name="submenu_group"/> </menu> … Text that will appear in the submenu Indicator where menu will be placed 1 31 + "/" + 2 © 2003 -2005, Espirity Inc.

Adding Action to the Menu … <menu id="my_actions. menu" label="My First Menu" path="additions"> <separator

Adding Action to the Menu … <menu id="my_actions. menu" label="My First Menu" path="additions"> <separator name="menu_group"/> </menu> <menu id="my_actions. submenu" label="My First Submenu" path="my_actions. menu/menu_group"> <separator name="submenu_group"/> </menu> <action id="my_actions. menu. action" label="My First Submenu Action" icon="icons/eclipse. gif" tooltip="My First Submenu Action Tooltip" menubar. Path="my_actions. menu/my_actions. submenu/submenu_group" class="com. espirity. course. plugins. workbench. My. First. Menu. Action. Delegate"> </action> … Action menu bar path includes menu id + submenu group 32 © 2003 -2005, Espirity Inc.

Workbench Changes Added top level menu Added action 33 © 2003 -2005, Espirity Inc.

Workbench Changes Added top level menu Added action 33 © 2003 -2005, Espirity Inc.

Plug-in Registry n To see what plug-ins are registered within the Workbench select: Window

Plug-in Registry n To see what plug-ins are registered within the Workbench select: Window Show View Other… 34 © 2003 -2005, Espirity Inc.

Summary n You have learned: How to contribute actions to views and editors q

Summary n You have learned: How to contribute actions to views and editors q How to define action set q How to add toolbar and menu items to the Workbench q How to develop basic plug-in q How to install plug-in q How to run plug-in q How to view plug-in registry q 35 © 2003 -2005, Espirity Inc.

Labs! Lab: Adding Menus to the Workbench 36 © 2003 -2005, Espirity Inc.

Labs! Lab: Adding Menus to the Workbench 36 © 2003 -2005, Espirity Inc.