Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Divided Loyalty: Create Plugins that Work in Eclipse and NetBeans : Page 2

One of the benefits of today's open source IDEs is that anyone can design a tool that plugs in to the IDE using an API, but Eclipse and NetBeans each uses a different API. This article will show you how to make your tool plug in to both environments with the least amount of coding work.


advertisement
Integrate the Action into Eclipse
First, I'll show you how to integrate the action into Eclipse and how to notify Eclipse that your plugin contains an action. If you don't notify Eclipse that your plugin contains an action the framework will not know where and how to display your action. In the plugin.xml file you need to add an extension tag and tell Eclipse that its extension is a popup menu. To do this, set the point attribute of the extension tag to org.eclipse.ui.popupMenus. Inside the extension tag, add an action tag. The action tag defines the display properties of the action and also the class to be called when the action is executed. The following is an example:

<extension point="org.eclipse.ui.popupMenus"> <action label="Preview" icon="icons/preview.gif" tooltip="Preview the current View" class="com.nexaweb.actions.PreviewAction" toolbarPath="nexawebDesignerMenu" id="com.nexaweb.actions.Preview"> </action> </extension>

Now that Eclipse knows about the action, you need to implement the code to perform that action. IActionDelegate interface is a base interface that this action is required to implement in Eclipse. You will need to implement two methods: run and selectionChanged. The run method is called when the user performs the action. This is where you need to connect the plugin code to the underlying business logic.

public class PreviewAction implements IActionDelegate{ //Called to perform the action public void run(IAction action) { currentFile.preview(); } //Called to notify the action that the selection has changed public void selectionChanged(IAction action, ISelection selection){ } }

That completes the integration of your action into Eclipse. You defined your action in plugin.xml and then implemented the code to perform the action.



Integrate the Action in to NetBeans
To integrate the action into NetBeans, you first need to define your action in the module's manifest file by adding a folder tag with a value of "Menu" for the name attribute. The "Menu" value notifies NetBeans that you are defining an action. Next, define the location of the action by using the folder tag with the name of the menu (to define the location of the menu in relation to other top-level menus use the attr tag). The value of the name attribute specifies that the menu is to be placed after the View menu.

Unlike Eclipse, specifying the display properties of your action is not done in the manifest file, but instead in a class that implements that action.

<folder name="Menu"> <attr name="View/Designer Tools" boolvalue="true" /> <folder name="Designer Tools"> <file name="com-nexaweb-actions-PreviewAction.instance"/> </folder> </folder>

You implement the action by extending the CallableSystemAction class. In your action class you'll need to implement the performAction method, which will be called when the user selects the menu item for this action. Now, implement the methods that supply NetBeans with the display properties for your action. To do this, implement the iconResource method and return the location of the image for the action, then the getName method that returns the display name for the action.

public class PreviewAction extends CallableSystemAction { //Called to perform the action public void performAction() { currentFile.preview(); } //Get the action's display icon protected String iconResource() { return "/icons/preview.gif"; } //Get the action's display name public String getName() { return "Preview"; } }

Other pieces of functionality required by your tool such as views, options, wizards, and editors are executed in the same manner as the action.
Author's Note: You will need to notify the IDE that your tool will be providing some set of functionality and then implement the code that is needed for that piece of functionality.


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date