The Java Developer's Guide to EclipseThe Java Developer's Guide to Eclipse

Chapter 18 showed you how to create views. The view provided in the com.ibm.jdg2e.view.simplemodel project demonstrates many of the implementation options that exist, including techniques for integrating the view with other Eclipse capabilities such as the common Properties dialog.

You may also wish to review these other view-related example plug-ins:

These are located in the com.ibm.jdg2e.view.basic, com.ibm.jdg2e.view.files, and com.ibm.jdg2e.view.marker projects, respectively.

Running the Example

  1. Make sure that dependent plug-in project com.ibm.jdg2e.simplemodel is in your workspace.
  2. Launch and run a runtime workbench (Run > Run As > Eclipse Application).
  3. Find and open the JDG2E > RoadTrip Locations view.
    RoadTrip Locations view

You are now ready to explore the function provided in this view. This includes a demonstration of many of the capabilities of Eclipse for viewers, dialogs, action contributions and view interaction.

Properties View Interaction

  1. Open the standard Eclipse Properties view
  2. Select a location entry in the RoadTrip Locations View and note how the data for the selected entry is displayed in the Properties view.

  3. property view
  4. Modify some of the displayed content using the properties view and note how the RoadTrip Locations view reflects the change (Political Unit values trigger an image change).
Note: This support is provided as part of the Simple Model (RoadTrip Locations) plug-in, defined in the com.ibm.jdg2e.simplemodel project. The adapter factory and IPropertySource implementation are reviewed there.

Properties Dialog Interaction

  1. Select a location entry and double-click (or use the context menu) to open the Properties dialog. A single property page is available.

  2. property page
  3. Use this page to modify some of the location attributes.

The Eclipse Properties Dialog is opened with a reference to the viewer, this allows the dialog to ask if there are any properties pages defined (by extension) for the object selected in the viewer. The plug-in manifest file for this project defines such a page.

New Location Wizard

  1. A wizard to create a new location instance (JDG2E: Road Trip Location) can be opened using either the standard wizard menu File > New > Other... or the Add action available view's toolbar, pull-down, and context menu.

  2. wizard
  3. Use this wizard to add a new location.
Note: The changes to the Simple Model are visible in this view and the Locations (Basic View). Each view is listening to changes on the same model.

View Actions

  1. Use the toolbar actions to filter filter action and sort sort action the model conent. (Yes, the icons are not gorgeous, we just reused images from Eclipse.)
  2. Use the delete action sort action to remove locations; if you remove them all you can use the Reset Locations List action on the pull-down meun to bring back the default location list.

View/Viewer Context Menu Actions

The actions on the ILocation Object Contribution menu are of interest here.


RoadTrip Locations view menu
  1. Select a state location element, such as Alaska, and then check the context menu actions. Two should be visible and enabled.
  2. Select a country location element, such as Brazil, and then check the context menu actions. Two should be visible but only one is enabled. The disabled action is only enabled when the w/political_type of State rule is met.
  3. Select a county location element, such as Cork (a county in Ireland), and then check the context menu actions. Three should be visible and two are enabled. The new action is only visible when the w/Visibility based on Political type of County rule is met.

These actions are contributed as popup menu object contributions. The plug-in manifest file can be reviewed to see how the rules were defined. This is possible because the target ILocation object implements the IActionFilter interface. This support is reviewed as part of the Simple Model (RoadTrip Locations) plug-in project.

Roadmap of the Example

The Simple Model View (RoadTrip Locations) plug-in includes contributions and API demonstrations that help you understand how a view using a viewer to display content can be integrated with many of the reusable components in Eclipse. The implementation of this function can be found in the plug-in manifest file and one or more of the classes included in this plug-in.

The plug-in manifest file defines the extension definition for the Locations (Basic View) and an extension to the Eclipse Resource perspective to have the view opened up on top of the Tasks view. Extensions for the Location object contributions (actions), New Location wizard and Location property page are also included. The table below shows the key classes from the com.ibm.jdg2e.view.simplemodel package that are used to implement the view part and its associated JFace viewer user interface.

Class (All) Description
LocationsView This class implements the view's user interface and function. This includes the logic required to open the Properties dialog.
LocationsContentProvider Used to obtain model content for the JFace viewer used in the view's user interface.
LocationsTableLabelProvider Used to display content for the ILocation objects shown in the JFace table viewer used in the view.
PoliticalFilter Controls the display of content in the viewer.
PoliticalSorter Allows the viewer content to be sorted by political type and then location name.
LocationPropertyPage Used to display content for the ILocation object in the Properties dialog.
LocationsObjectAction Action contribution that is available in the view. The plug-in manifest file action contribution definitions target ILocation objects with specific attributes.
LocationPropertyPage Property page that is shown when the common Properties dialog is opened for an ILocation object.
NewLocation Wizard used to create new location model instances. Available on the File > New menu and directly by an action in the view.

© Copyright International Business Machines Corporation, 2003, 2004, 2006. All Rights Reserved.
Code or samples provided herein are provided without warranty of any kind.