![]() |
Most plug-ins that provided function in Eclipse will need to use some
portion of the Workspace API. This example contains Workspace programming logic to create
resources, create resource listeners, and manipulate resource paths. These functions are exposed as view actions
and pop-up menu choices for project and other resources in the Navigator view .
The plugin.xml
defines these action extensions and the code
is provided in the
com.ibm.lab.soln.resources
package.
To run the example, launch the run-time instance of Eclipse (Run > Run As > Run-time Workbench).
This example demonstrates several of the Workspace APIs
using view actions and pop-up menu choices that have been contributed to the Navigator
view.
ActionProcessResourceTree
class by the showProjectDetails()
method.ActionProcessResourceTree
class by the pathPlay()
method.-debug
command line option. The following is an example of the trace statements when a bin
directory with content was deleted:RCL_Rpt: 1 RCL_Rpt: 1 -> Event triggered... RCL_Rpt: 1 -> Auto build about to run. RCL_Rpt: 2 RCL_Rpt: 2 -> Event triggered... RCL_Rpt: 2 -> Auto build complete. RCL_Rpt: 3 RCL_Rpt: 3 -> Event triggered... RCL_Rpt: 3 -> Resource has been changed. RCL_Rpt: 3 -> Lets visit the delta... RCL_Rpt: 3 -> DeltaPrinter: Resource / has changed. RCL_Rpt: 3 -> DeltaPrinter: Resource /a.CustomProject has changed. RCL_Rpt: 3 -> DeltaPrinter: Resource /a.CustomProject/bin has changed. RCL_Rpt: 3 -> DeltaPrinter: --> Content Replaced RCL_Rpt: 3 -> DeltaPrinter: Resource /a.CustomProject/bin/a was removed. RCL_Rpt: 3 -> DeltaPrinter: Resource /a.CustomProject/bin/a/b was removed. RCL_Rpt: 3 -> DeltaPrinter: Resource /a.CustomProject/bin/a/b/Mainline.class was removed.
Select the Soln: Remove Tracing RCL Navigator view drop-down menu choice to remove the listener and stop the tracing.
Note: The marker example makes productive use of a resource change listener by using one to create markers in response to file modifications.
The listener add and remove actions are implemented in the ActionManageTraceRCLs
class. The listener is implemented by the ResourceChangeReporter
class.
RCL_Rpt: 4 RCL_Rpt: 4 -> Event triggered... RCL_Rpt: 4 -> Auto build about to run. RCL_Rpt: 5 RCL_Rpt: 5 -> Event triggered... RCL_Rpt: 5 -> Auto build complete. RCL_Rpt: 6 RCL_Rpt: 6 -> Event triggered... RCL_Rpt: 6 -> Resource has been changed. RCL_Rpt: 6 -> Lets visit the delta... RCL_Rpt: 6 -> DeltaPrinter: Resource / has changed. RCL_Rpt: 6 -> DeltaPrinter: Resource /a.CustomProject has changed. RCL_Rpt: 6 -> DeltaPrinter: Resource /a.CustomProject/images was added. . . . RCL_Rpt: 18 RCL_Rpt: 18 -> Event triggered... RCL_Rpt: 18 -> Resource has been changed. RCL_Rpt: 18 -> Lets visit the delta... RCL_Rpt: 18 -> DeltaPrinter: Resource / has changed. RCL_Rpt: 18 -> DeltaPrinter: Resource /a.CustomProject has changed. RCL_Rpt: 18 -> DeltaPrinter: Resource /a.CustomProject/images has changed. RCL_Rpt: 18 -> DeltaPrinter: Resource /a.CustomProject/images/image_list.txt has changed. RCL_Rpt: 18 -> DeltaPrinter: --------------------> Marker Change RCL_Rpt: 18 -> DeltaPrinter: -------------------->lets test for marker changes: RCL_Rpt: 18 -> DeltaPrinter: Marker delta kind: 4 RCL_Rpt: 18 -> DeltaPrinter: Marker itself: org.eclipse.core.internal.resources.Marker@3e623a94 RCL_Rpt: 18 -> DeltaPrinter: Marker type: org.eclipse.core.resources.bookmark RCL_Rpt: 18 -> DeltaPrinter: Marker content: [153] RCL_Rpt: 18 -> DeltaPrinter: <-------------------- . . . RCL_Rpt: 27 RCL_Rpt: 27 -> Event triggered... RCL_Rpt: 27 -> Resource has been changed. RCL_Rpt: 27 -> Lets visit the delta... RCL_Rpt: 27 -> DeltaPrinter: Resource / has changed. RCL_Rpt: 27 -> DeltaPrinter: Resource /a.CustomProject has changed. RCL_Rpt: 27 -> DeltaPrinter: Resource /a.CustomProject/readme was added.
IResourceDelta
that includes all the changes made (Note: the images and
readme folders created in the previous step were deleted before running the action again): RCL_Rpt: 31 RCL_Rpt: 31 -> Event triggered... RCL_Rpt: 31 -> Auto build about to run. RCL_Rpt: 32 RCL_Rpt: 32 -> Event triggered... RCL_Rpt: 32 -> Auto build complete. RCL_Rpt: 33 RCL_Rpt: 33 -> Event triggered... RCL_Rpt: 33 -> Resource has been changed. RCL_Rpt: 33 -> Lets visit the delta... RCL_Rpt: 33 -> DeltaPrinter: Resource / has changed. RCL_Rpt: 33 -> DeltaPrinter: Resource /a.CustomProject has changed. RCL_Rpt: 33 -> DeltaPrinter: Resource /a.CustomProject/images was added. RCL_Rpt: 33 -> DeltaPrinter: Resource /a.CustomProject/images/getstart_b.GIF was added. RCL_Rpt: 33 -> DeltaPrinter: Resource /a.CustomProject/images/image_list.txt was added. RCL_Rpt: 33 -> DeltaPrinter: --------------------> Marker Change RCL_Rpt: 33 -> DeltaPrinter: -------------------->lets test for marker changes: RCL_Rpt: 33 -> DeltaPrinter: Marker delta kind: 1 RCL_Rpt: 33 -> DeltaPrinter: Marker itself: org.eclipse.core.internal.resources.Marker@3e623a95 RCL_Rpt: 33 -> DeltaPrinter: Marker type: org.eclipse.core.resources.bookmark RCL_Rpt: 33 -> DeltaPrinter: Marker content: [New image_list.txt added, 153, 154] RCL_Rpt: 33 -> DeltaPrinter: <-------------------- RCL_Rpt: 33 -> DeltaPrinter: Resource /a.CustomProject/readme was added.This demonstrates the importance of using a runnable to control visibility to your workspace modification actions. With any number of tools adding resource change listeners, you do not want every minor modification to trigger an unknown amount of event related processing. A Workspace runnable can reduce a series of notifications to a single notification.
ActionProcessResourceTree
class using the run()
and createFolderFile()
methods.EDUResources
plug-in also includes logic that adds a workspace save participant when the plug-in is started (see the startup()
method). The saved state that can be returned when adding a save
participant is processed in the addMy_SaveP
method using the ResourceChangeReporter
class. The save participant is implemented by the WorkspaceSaveParticipant
class. -debug
parameter),
you will see trace output for the IResourceDelta passed back as part of
the saved state and when the save participant logic is triggered. For
example, opening up a new project will trigger a workspace save event
which is processed by the WorkspaceSaveParticipant
class.EDUResources
plug-in and
allow the save participant to start later.WkSavePart ->: 0 *----------> MyWorkSpaceSaveParticipant created. WkSavePart ->: Event: 1 WkSavePart ->: Event: 1 -> Event triggered... WkSavePart ->: Event: 1 -> Auto build complete. WkSavePart ->: Event: 1 -> Lets visit the delta... WkSavePart ->: Event: 1 -> DeltaPrinter: Resource / has changed. WkSavePart ->: Event: 1 -> DeltaPrinter: Resource /a.custom has changed. WkSavePart ->: Event: 1 -> DeltaPrinter: Resource /a.custom/abc was added. WkSavePart ->: Event: 1 -> DeltaPrinter: Resource /a.custom/abc.txt was added.The changes that occurred before the plug-in was started are available to the save participant. Note that the add and then removal of the folder qrs is not reported. The two events cancel each other out.
This example includes both pop-up and view action contributions that demonstrate the use of the Workspace API. The extension definitions for the actions can be found in the plugin.xml. The available actions, with the class that implements the function, are shown below.
Action (view or pop-up) Extension |
Implementation |
---|---|
Navigator view: Soln: List Project Locations |
Implemented by the showProjectDetails()
method in the ActionProcessResourceTree
class. |
Navigator view: Soln: Add Tracing RCL |
The add and remove actions are
implemented in the ActionManageTraceRCLs
class. |
Navigator view: Soln: Remove Tracing RCL |
|
Soln: Resources > Soln: List Path Values |
Implemented the pathPlay()
method in the ActionProcessResourceTree
class. |
Soln: Resources > Soln: Setup Project Structure |
The project structure actions are
implemented by the ActionProcessResourceTree
class using the run()
and createFolderFile()
methods. |
Soln: Resources > Soln: Setup Project Structure using Runnable |
This plug-in includes a plug-in class that adds a workspace save
participant during startup, a resource change listener added by an
action contribution, and a resource delta visitor that is used to report
on the content of a resource delta. The plug-in is implemented by the
EDUResourcesPlugin
class. WorkspaceSaveParticipant
implements the workspace save participant.
Object | Implementation |
---|---|
Plug-in | Implemented by the EDUResourcesPlugin
class. |
Resource Change Listener | Implemented by the ResourceChangeReporter
class. |
Workspace Save Participant | Implemented by the WorkspaceSaveParticipant
class. |
Resource Delta Visitor | Implemented by the ResourceDeltaPrinter
class. This class is used by both the ResourceChangeReporter
and the WorkspaceSaveParticipant . |
© Copyright International Business Machines Corporation, 2003.
All rights reserved.