Search code examples
eclipsewizardproject-explorer

How to programmatically define the project types that the project explorer in a WizardNewFileCreationPage will display


I am working on an Eclipse plugin project that implements an Import file wizard, designed for files that pertain to a custom project type. One of the wizard's pages is a WizardNewFileCreationPage page, where a project explorer is automatically (as far as I can see) displayed. This project explorer displays all projects available in the workspace. However, since, as I said, the files the wizard deals with are useful to one particular project type, I want to restrict the explorer and only display projects of that custom type.

I know how to select projects of a custom type:

  List<IProject> projectList = new LinkedList<IProject>();
  try {
     IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
     IProject[] projects = workspaceRoot.getProjects();
     for(int i = 0; i < projects.length; i++) {
        IProject project = projects[i];
        if(project.hasNature("com.example.www.myNature")) {
           projectList.add(project);
        }
     }
  }
  catch(CoreException ce) {
     ce.printStackTrace();
  }

found at this link: Get a list of all java projects open in an Eclipse workspace

I am assuming that the WizardNewFileCreationPage class includes, behind the scenes, a TreeViewer or something similar. In any case, how can I filter the contents of the project explorer in this wizard page? I took a look at the following question: How to programmatically change the selection within package explorer, but in my case the activePart variable is of type

org.eclipse.ui.navigator.resources.ProjectExplorer

which does not have a getTreeViewer() method. It has a createPartControl() method:

public void createPartControl(Composite aParent);

Could this be useful for what I want? Or is it a case of using extension points?

Thank you in advance for your answers.


Solution

  • There is no way to do this.

    Although the tree shown in WizardNewFileCreationPage looks similar to project explorer it is not based on that code.

    The code used to show the tree is org.eclipse.ui.internal.ide.misc.ContainerSelectionGroup which is itself contained in org.eclipse.ui.internal.ide.misc.ResourceAndContainerGroup. These classes don't support much customization and in any case aren't accessible outside of WizardNewFileCreationPage.