Eclipse Design Patterns – Composite in Workspace

Composite in Workspace

Composite pattern defines a tree hierarchy which lets clients treat objects in the hierarchy uniformly.

In Eclipse Workspace, IWorkspace is the root interface and it is a Composite of IContainers and IFiles. Here is the interface hierarchy diagram.

IResourceHierarchy

Code Example

Here is an example to show how to get projects under Workspace.

IWorkspace workspace=ResourcesPlugin.getWorkspace();
  IProject[] projects=workspace.getRoot().getProjects();
  for (int i=0; i < projects.length; i++) {
    IProject project=projects[i];
    System.err.println(projectSelectionTable.getData(project.getName()));
    if ((project.isOpen()) && (projectSelectionTable.getData(project.getName()) == null)) {
      projectSelectionTable.add(project);
    }
  }

Leave a Comment