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.


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];
    if ((project.isOpen()) && (projectSelectionTable.getData(project.getName()) == null)) {
Category >> Architecture & Design >> Design Patterns Stories  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";