Jurgen Vinju
Jurgen Vinju

Reputation: 6696

how to add working sets to eclipse common navigator?

I would love to add support for Working Sets for my Eclipse plugin that used the Common Navigator framework.

I do not know where to start even since there is no extension point for it, and the Working Set implementation classes are all "internal". I have a very basic navigator setup showing default project resources and some additional IFileSystem stuff implementing ITreeContentProvider.

Upvotes: 3

Views: 316

Answers (2)

Jurgen Vinju
Jurgen Vinju

Reputation: 6696

In retrospect the following is a better solution. Instead of implementing ITreeContentProvider and traversing the working sets ourselves, we can reuse existing standard providers for the same content, which might work better.

You can use them like so:

 <extension
     point="org.eclipse.ui.navigator.viewer">
   <viewerContentBinding 
        viewerId="rascal.navigator">
      <includes>
         <contentExtension pattern="org.eclipse.ui.navigator.resourceContent" />                      
         <contentExtension pattern="org.eclipse.ui.navigator.resources.filters.*"/>
         <contentExtension pattern="org.eclipse.ui.navigator.resources.linkHelper"/>
         <contentExtension pattern="org.eclipse.ui.navigator.resources.workingSets"/>
      </includes>
   </viewerContentBinding>

In particular the org.eclipse.ui.navigator.resources.workingSets is what adds working sets capabilities to your navigator.

Adding your own content then becomes an issue of adding another content provider which ignores workingsets and projects and other kinds of resources which are already taken care of, e.g. like so:

 <extension
         point="org.eclipse.ui.navigator.navigatorContent">
      <navigatorContent
            activeByDefault="true"
            contentProvider="org.rascalmpl.eclipse.navigator.NavigatorContentProvider"
            id="org.rascalmpl.navigator.searchPathContent"
            labelProvider="org.rascalmpl.eclipse.navigator.NavigatorContentLabelProvider"
            name="Rascal search path"
            priority="normal">
         <triggerPoints>
          <or>
                 <instanceof value="org.eclipse.core.resources.IResource"/>
          </or>
         </triggerPoints>
         <possibleChildren>
            <or>
               <instanceof value="java.lang.Object"/> 
            </or>
         </possibleChildren>
         <actionProvider
               class="org.rascalmpl.eclipse.navigator.NavigatorActionProvider"
               id="org.rascalmpl.navigator.actions">
         </actionProvider>
         <commonSorter
               class="org.rascalmpl.eclipse.navigator.Sorter">
         </commonSorter>

      </navigatorContent>
      <commonWizard
            type="new"
            wizardId="rascal_eclipse.wizards.NewRascalFile">
         <enablement></enablement>
      </commonWizard>
      <commonWizard
            type="new"
            wizardId="rascal_eclipse.projectwizard">
         <enablement></enablement>
      </commonWizard>
   </extension>

and in the NavigatorContentProvider class we implement getElements and getChildren but only for our own additional content.

Upvotes: 1

greg-449
greg-449

Reputation: 111142

You can get the working set manager using:

IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();

and from that get the visible working sets with:

IWorkingSet [] workingSets = manager.getWorkingSets();

the members of a working set can be accessed with:

IAdaptable [] elements = workingSet.getElements();

so you could use the working sets list as the input for the tree viewer and adjust your tree content provider to deal with this.

Upvotes: 3

Related Questions