![]() | The Java Developer's Guide to Eclipse |
In Chapter 24, Managing Resources with Natures and Builders and Chapter 25, Resource Tagging Using Markers,
you learned how to extend the capability of the workspace by defining extensions. These workspace extensions
add behaviors to projects (natures and builders) and define new types of markers than can
tag resources with additional information.
The com.ibm.jdg2e.resources.extensions project demonstrates the
resource extensions, and how they can be used to enhance the capabilities of
a project and other workspace resources.
This project includes a series of examples. Each demonstrates
what can be done using one or more of the resource extension types. This typically involves the use
of the resource programming API. See the Resource Programming plug-in,
defined in project com.ibm.jdg2e.resources.programming
for additional examples.
To begin, launch a runtime workbench (Run > Run As > Eclipse Application). From here we'll follow a natural exploration of the function provided in this plug-in.
New marker types can be defined to
record information about a resource. For example, a marker might
be used to denote a resource's location like a bookmark, or add information
related to the resource, like a task to be completed.
The example's plug-in manifest file defines a marker extension with an
id of com.ibm.jdg2e.resources.extensions.recentEdits. This marker is used
to tag files that have been recently edited (modified).
org.eclipse.ui.startup extension point. This requests that the
Workbench activate the plug-in and call its implementor of IEarlyStartup once the main window opens;
this also activates the plug-in. In the plug-in's start method the resource change listener is added to
the workspace.
You can tell the plug-in starts early if you review the Workbench > Startup and Shutdown preference page. The JDG2E: Resource Extensions plug-in is listed.

Review the JDG2E: Recent Edits preferences page; adjust any control options you want, but keep Track Recent File Edits checked for the moment.
org.eclipse.core.resources.taskmarker,
org.eclipse.core.resources.bookmark, and org.eclipse.core.resources.textmarker,
the new marker will show up in both
the Tasks and Bookmarks views and can interact with text editors.
If the recent edit markers are not visible you may
need to adjust the view filters to include the recent edits marker type.

Note: The Marker View plug-in,
defined in the com.ibm.jdg2e.view.marker
project, includes a view that is designed to find and display only recent edit markers.

If you modify a file after selecting the exclude option, a marker will not be created.
org.eclipse.ui.popupMenus
extension point. The action targets all markers whose
message property (Description column) starts with "aRE". This action shows up for
recent edit markers regardless of the view in which they are shown; the pop-up menu action can be found
in the Tasks and Problem views from Eclipse as well as the
Recent Edit Markers view
provided as part of the com.ibm.jdg2e.view.marker project.

Quick fix support and contextual help can be defined for a marker. In addition, markers are often related to builder processing. These capabilities and relationships will be covered in the next section.
To create a nature or builder, you first define them as extensions in your plug-in, provide an implementation for these extensions, and then either create a project that includes the nature or add the nature to an existing project. Builders can be used without a nature, but the expected usage pattern in Eclipse is to have a nature that customizes a project by adding any builders that are required.
The example's plug-in manifest file defines extensions for a nature, nature image,
and builder. When added to a project, the nature will decorate the project with a nature image if it is
the first nature known to the project that has an image.
The provided implementation for the nature is limited to adding the readme builder. The readme builder will process
.readme files found in a readme folder and create an .html
file with the content of the readme wrapped by some HTML markup.
The readme builder also tracks deletions to .readme files. The builder does not
delete the matching .html file, but instead creates a marker to identify the orphan.
The marker includes help to tell you what to do and a suggested
Quick Fix to correct the problem.
This will add a new project to the workspace. The CustomNature and its associated
image (
) will be associated with the project. The nature will add the builder.
This is recorded in the .project file for the project.
.readme file (such as abc.readme) to
the proejct. If you have the
com.ibm.jdg2e.resources.programming
project loaded, you can use one of the Setup Project Structure actions to create
the folder and file.
Once the .readme file has been created the builder will be invoked (unless you
turned off the automatic build process). If the .html file is not created, verify the
Project > Build automatically menu choice is checked.
.readme file leaving an orphan .html file. The builder
notices this and complains by adding a problem marker to the .html file. This marker
should be visible in the Problems view. Help has been defined for this marker;
select it in the Problems view and press F1.


When you choose the fix you are prompted to either delete the .html file
or change it so it is not marked as derived (a resource API call).
Note: There are some additional actions included in the plug-in located
in the pop-up menu for a project (JDG2E: Resource Demos > ...). These actions
are available only in the Navigator view and can be used to
directly add a nature to a project, list builders for a project, and even add or remove the readme builder.
The nature and builder have a defined relationship via the
of the org.eclipse.core.resources.natures and
org.eclipse.core.resources.builders
extensions, so if you want to directly add the builder
you will have to modify the extension definitions to remove this relationship.
The Resource Extensions plug-in is designed to help you understand not only the basics of extending the capabilities of the workspace, but also how markers, natures, and builders function.
The plug-in manifest file defines the extension definitions
for the different actions, markers, natures, builders, and other marker related processing such
as help an quick fix support.
These are the key classes from the com.ibm.jdg2e.resources.extensions
package that are used to implement the examples just discussed.
| Class (All) | Description |
RecentEditsRCL |
This class tracks file changes and creates recent edit markers. This process is assisted by
RecentEdits.
The preference and property pages that can be used to control this process are implemented by
The preference values used are initialized by a preference initializer extension (
|
CustomNature |
Implements the nature extension. The nature will add the
ReadmeBuilder
to the project as a builder.
This builder uses a
When the builder detects an orphan |
© Copyright International Business Machines Corporation, 2003, 2004, 2006. All Rights Reserved.
Code or samples provided herein are provided without warranty of any kind.