Browse DevX
Sign up for e-mail newsletters from DevX


Divided Loyalty, Part 2: Creating Views and Deploying Plugins in Eclipse and NetBeans

Views are an important aspect of any IDE but Eclipse and NetBeans users can write their own custom views and deploy them using each product's unique plugin architecture. Find out how to integrate a single view into either Eclipse, NetBeans, or both.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

view is a great UI concept for IDEs that enables developers to encapsulate a set of functionality. It is typically used in a "non-model" fashion, meaning the functionality is visible and active without interfering with your workflow. An example of a view is when an IDE's workspace explorer gives you a "Tree View" of the files in your workspace or a "Console View," which provides output for your IDE when building debug applications. These types of views are the same in both of the major open source Java IDEs: Eclipse and NetBeans.

In my last article, "Divided Loyalty: Create Plugins that Work in Eclipse and NetBeans," I explained how to integrate large pieces of functionality into both Eclipse and NetBeans frameworks and how to integrate actions and menus into both IDEs. This laid the groundwork for understanding the differences in plugin description files and APIs. In this follow-up article, I'll explain:
  1. How to integrate a view into each platform.
  2. The differences in plugin deployment structures and how to access resources, such as images and template files.
What You Need: This article is for code that is written in Eclipse 3.0 and NetBeans 3.6

Integrate a View into Eclipse
There are two steps that need to be taken for Eclipse to correctly activate and display a view. The first step is to notify the framework that the plugin contains a view. This is achieved by adding an extension tag to the plugin.xml. The extension tag then notifies Eclipse that you are implementing a defined functionality that the IDE recognizes. The "point" attribute of the extension tag notifies Eclipse of the type of functionality you're implementing—in this case I am adding a view designated by "org.eclipse.ui.views." You will also need to provide the category that your view will be listed in. However, if you have already defined a category or wish to use a standard category this step isn't necessary.

The second step is to define your view by providing the view tag with the display properties, the class to be instantiated, and the category the view is associated with.

<extension point="org.eclipse.ui.views"> <category name="Nexaweb" id="com.nexaweb.designer.views"/> <view name="Layout" icon="/icons/layoutview.gif" category="com.nexaweb.designer.views" class="com.nexaweb.designer.views.NexawebLayoutView" id="com.nexaweb.designer.views.NexawebLayoutView"> </view> </extension>

Defining the View in plugin.xml
Now that Eclipse knows your plugin will contain a view when the end user activates it, the class provided as the "class" attribute of the view tag will be instantiated. In order for your view to work, you must implement the IViewPart interface. Eclipse provides a base implementation of the interface in the ViewPart class. As seen in the code below, my NexawebLayoutView class extends the ViewPart class and it has all the base functionality needed to implement a view.

Lastly, you will need to implement the createPartControl method, which is called during the creation of the view to give the class the opportunity to create the view's UI.

public class NexawebLayoutView extends ViewPart Tree _tree = null; public void createPartControl(Composite parent) { _tree = new Tree(parent, SWT.NONE); //This should initialize the display. initializeTree(); } … }

Implementing the View Source Code
Now that I have implemented my view via the NexawebLayoutView and notified Eclipse that my plugin contains a view, Eclipse will display my view when the end user clicks the "Window -> Show View -> Other…" menu item. Eclipse also lists views in the "Window -> Show View" menu—if you want the view to be listed there you can create your own "perspective" and tell the perspective that you want the view displayed as a shortcut.

For the plugin shown below, I wanted to have the layout view be listed when the "Debug" perspective is active. Therefore in the plugin.xml, I added the extension tag with a point attribute of org.eclipse.ui.perspectiveExtensions. I also needed to notify Eclipse that I am extending the ID of the view for the shortcut I have created.

<extension point="org.eclipse.ui.perspectiveExtensions"> <perspectiveExtension targetID="org.eclipse.debug.ui.DebugPerspective"> <viewShortcut id="com.nexaweb.designer.views.NexawebLayoutView"/> </perspectiveExtension> </extension>

Comment and Contribute






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



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