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

In Chapter 18, Views, you learned how to create views and we have provided you with several examples to help you understand the basics. This view is different; it attempts to implement a tool that you may find useful when working with Eclipse. We like it because it helps us find similar files across many folders, but we'll let you make your own decision; and since the source for it is in the com.ibm.jdg2e.view.files project, you can make any improvements you desire. That said, this view still demonstrates some of the implementation strategies for views that you should consider in your development work. These include structure, use of viewer sorter and filter components, reuse of Eclipse actions, and the use of mutiple types of jobs to manage content access and delivery.

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

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

Running the Example

  1. Launch and run a runtime workbench (Run > Run As > Run-time Workbench).
  2. Find and select the JDG2E > File Resources view.
    Files View
  3. Multiple instances of this view can be opened using the JDG2E: Open File Resources View popup menu action. This action is available in both the Navigator and Package Explorer views; anywhere the selection is adaptable to IContainer. This includes opening the view on a working set when they are the top level elements displayed in the Package Explorer view.
  4. While multiple view instances may not be appropriate in a single perspective, we'll show you in a minute that it can be managed. The technique to open another view instance is often useful if you use the view in two different perspectives. The second instance has its own File name criteria input field, individual control over other options, and can even manage a unique column width arrangement.

Basic Control Options

By default the view uses any currently selected resource or working set as its input and the view title changes to match. This selection triggers the process of finding the files and determining which should be displayed. While jobs are used to find and add content to the viewer, a very large resource tree can sometimes overwhelm the find and display processing. But, if you change your mind before it has finished finding all the files, the view cancels the active and waiting jobs and starts over on the new input.

The view drop down menu and action bar provide options to control view behavior.
File View Options

  1. The Use Selection As Input drop down toggle or toolbar toggle action can be used to allow the view to see the whole workspace instead of restricting the input to the current selection.
  2. The Hide .class Files option is a drop down or toolbar toggle action that filters out .class files.
  3. The Sticky Selection Input drop down toggle action can tell the view to keep the current input and ignore selection changes. This allows for the use of two instances of the view in one perspective, where each has a different input.
  4. The Use Input as View Name drop down menu toggle option determines if the view will have a fixed name or use one based on the current selection.
  5. The Use Enter to Apply Name Filter drop down menu toggle option determines if the filter field will react to typing or only after you press enter.
  6. The Sort using file system timestamps drop down menu toggle option determines if view logic will query the file system or just the workspace model for timestamp data; this data is read during timestamp sorting and the initial gathering of file information. Not using file system timestamps improves performance but files that have not been refreshed in the workspace will not sort true as their timestamp values will be old until they are refreshed.

Displayed File Control and Feedback

The view displays files, but you have some control over which and what information is presented as part of the standard display. All of the points discussed below are visible in the view image shown above.

  1. File name criteria: This input field allows you to enter file name patterns (* and ?) which are used to control the files that are included in the viewer. Multiple patterns can be entered, separate them with a | without spaces. The name filter is applied when you press enter, but you can use the drop down menu to have a new filter recognized just by typing. The drop down control saves the last few filters that were entered so you can reuse previous values. This list of values can be cleared using mouse button 2 on the control and the Clear menu option. You can press F1 with the cursor in this field to get a some help on what the field can do.
  2. Modification Timespan: The drop down control allows you to select a timeframe for special color highlighting of files that have been modified within that range. The default color is blue, but you have control. Simply open up the Workbench > Colors and Fonts preference page and select the JDG2E: File Resources View - Modification Highlight entry. Your choice of colors is honored the next time the viewer is updated. This also has F1 help content.
    action
  3. The last form of feedback is automatic and subtle. If the resource is not synchronized with the workspace, its entry is shown in a bold italic font. It may be both in the bold italic font and color coded based on the modification timestamp range chosen. The Refresh option is available on the context menu to correct the synchronization problem.

Content Interaction

The view includes several context menu options, and as the context menu is registered with the workbench, any other contribution that targets IResource or IFile objects will also be shown. Sorting is also supported.

  1. Column Sorting: Sort by any column using the column header. The active sort column is marked with a * as part of the column name.
  2. View Specific Actions: The context menu includes Open, Refresh, and Delete. These actions were reused by example from the Navigator view.
  3. Show In Target Part: The view supports the Show In workbench part navigation option. The reusable menu action Show in Navigator was added to reflect this capability. In addition, if you press Alt+Shift+W you can get the Show In popup menu if there are targets in the perspective. Depending on your perspective you will see targets such as the Navigator or Package Explorer view. This navigation works in reverse as well, the File Resources view can be the target of Show In part navigation from other views in the Resources Java, and Plug-in Development perspectives. Selection of the target resource will only occur if it has not been filtered out of the viewer.

Note: The view will not react to selection when it is behind other views or not in the active perspective. This was by design as it prevents unnecessary processing. Minimizing the view is not enough, it must actually be behind another view (which may be minimized).

Roadmap of the Example

The File Resources View plug-in is structurally the same as the other view examples. There are just a few more viewer helpers in the form of sorters and filters.

The view has a user interface, actions in the toolbar and pull-down menu, as well as the context menu for the viewer used in the user interface. This is the limit of its function.

The plug-in manifest file defines the extension definition for the view, the popup menu to open additional instances, the perspective extensions to add Show In Part support, help contexts for F1 help, and a UI theme for the color customization. The table below contains the key classes from the com.ibm.jdg2e.view.files package that are used to implement the view part and its associated JFace viewer user interface.

Class (All) Description
OpenFileView Used to open additional instances of the File Resources view.
FileView This class implements the view's user interface and function. This includes the NameFilter used to determine which files are included in the display.
FileContentProvider Accesses workspace resources using a resource proxy visitor to find files. The visitor is run as part of a FileFinder job. The results of the visit are actually sent to the viewer asynchronously using an AddToViewer workbench job.
FileLabelProvider Create the column content for the viewer.
Viewer Filter and Sorters A filter and various sorters are used to control the display.

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