Eclipse resources and Managers

From Bioclipse
Jump to: navigation, search
Working page
Involved users:Ola, jonalv, Goglepox
Bioclipse version:N/A
Last updated:2009-10-10

Getting the resources

Managers should provide two methods for passing a file to them either as IFile or as a String. The string can be of tree types:

  • a path relative to the workspace (e.g. /myProject/myfile.cml). You can get this by calling IResource.getFullPath().toPortableString();
  • an URI pointing to a resource in the workspace (e.g. file:/myProject/myfile.cml, memory:/myProject/myfile.cml). This can be created by IResource.getLocationURI().toString();
  • a path to any file in the filesystem (e.g. c:\myProject\myfile.cml). A temporary resource will be created and linked to the specified file.

Getting the IFile from the string is done through a helper class. Like this:

 IFile file = ResourcePathTransformer.getInstance().transform( filePathString );


Apart from the general support for long-runnig operations, Eclipse UI provides additional support for operations in WorkspaceModifyOperation. This class simplifies the implementation of long-running operations that modify the workspace. It maps between IRunnableWithProgress and IWorkspaceRunnable.

The WorkspaceModifyOperation should be used for any operation which potentially makes changes to the workspace. All resource modification should be performed using this operation. The primary consequence of using this operation is that events which typically occur as a result of workspace changes (such as the firing of resource deltas, performance of autobuilds, etc.) are deferred until the outermost operation has successfully completed. Example:

       WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
           protected void execute(IProgressMonitor monitor) throws CoreException {

If a scheduling rule is provided, the operation will obtain that scheduling rule for the duration of its execute method. If no scheduling rule is provided, the operation will obtain a scheduling rule that locks the entire workspace for the duration of the operation. All operations working with resources should be wrapped in workspace operations and take advantage of Eclipse system for locking resources.

Responding to resource changes

One important feature is to be able to react upon the fact that some function altered the current resource that you base your model upon. This is done by having your view/editor/dialog etc implement IResourceChangeListener, see for more information.