Content and Action Binding

The sections below define the set of steps for usage of resource content and definition of own content for the CNF-based viewer. Finally, the steps needed for Action Binding are described. As described previously, in order to render content the viewer selects the corresponding NCEs based on the evaluation of the expressions on the selected objects.

Usage of Resource Content

One of the use cases of usage of the Common Navigator is the manipulation of the workspace resources. The resources-related content is defined by the org.eclipse.ui.navigator.resources plugin. The example of the resource usage of CNF can be found in org.eclipse.ui.examples.navigator.resources.

  1. Perform the general steps described in Creation of Common Navigator Viewer
  2. Add the following as dependent plug-ins:
  3. Add a org.eclipse.ui.navigator.viewer extension that has:
       <extension
             point="org.eclipse.ui.navigator.viewer">
           <viewerContentBinding 
                viewerId="example.view">
              <includes>
           	     <contentExtension pattern="org.eclipse.ui.navigator.resourceContent" />		       	      
    	     <contentExtension pattern="org.eclipse.ui.navigator.resources.filters.*"/>
              </includes>
           </viewerContentBinding>
       </extension>
       

Please note, that using CNF inside of your own RCP requires three additional steps.

  1. Add the org.eclipse.ui.ide as dependent plug-in
  2. To get the resource workspace root (IWorkspaceRoot) as default page input, override the WorkbenchAdvisor.getDefaultPageInput() method in your WorkbenchAdvisor:
    	public IAdaptable getDefaultPageInput() 
    	{
    		return ResourcesPlugin.getWorkspace().getRoot();
    	}
    
  3. Hook the workbench adapters correctly before they are used, so add this code to the WorkbenchAdvisor.initialize(IWorkbenchConfigurer) method:
    	public void initialize(IWorkbenchConfigurer configurer) 
    	{
    		IDE.registerAdapters();
    	}
    

Own Content Definition

Along with resource content provided by the org.eclipse.ui.navigator.resources plugin, application-specific content can be defined and presented in the CNF-based viewer. In order to define and use application specific you need to:

  1. Use extension org.eclipse.ui.navigator.navigatorContent and declare the NCE, with it providers and trigger conditions for the content:
      <extension
             point="org.eclipse.ui.navigator.navigatorContent">
          <navigatorContent 
                id="org.eclipse.ui.examples.navigator.propertiesContent" 
                name="Properties File Contents"
                contentProvider="org.eclipse.ui.examples.navigator.PropertiesContentProvider"
                labelProvider="org.eclipse.ui.examples.navigator.PropertiesLabelProvider" 
                activeByDefault="true"
                icon="icons/prop_ps.gif"
                priority="normal" >
             <triggerPoints>
             	<or>
    	            <and>
    	               <instanceof value="org.eclipse.core.resources.IResource"/>
    	               <test
    	                     forcePluginActivation="true"
    	                     property="org.eclipse.core.resources.extension"
    	                     value="properties"/>
    	            </and>
    				<instanceof value="org.eclipse.ui.examples.navigator.PropertiesTreeData"/>
    			</or>
             </triggerPoints>
             <possibleChildren>
                <or>
                   <instanceof value="org.eclipse.ui.examples.navigator.PropertiesTreeData"/> 
                </or>
             </possibleChildren>
          </navigatorContent>
       </extension>
    
    For more details, please consult the CNF Configuration and Operational Topics.
  2. Bind the content to the viewer using the org.eclipse.ui.navigator.viewer extension.
       <extension
             point="org.eclipse.ui.navigator.viewer">
          <viewerContentBinding viewerId="example.view">
             <includes>
                <contentExtension pattern="org.eclipse.ui.examples.navigator.propertiesContent"/>
             </includes>
          </viewerContentBinding>
       </extension>
    
    Note, that instead of using the exact Id of the content, the usage of the regular expression is allowed in the pattern attribute, so org.eclipse.ui.examples.navigator.* would also work.

Action Binding

The usage of actions in the viewer follows the same pattern as the content binding. For usage of existing actions on resources defined in the org.eclipse.ui.navigator.resources plugin:

  1. Add the following as dependent plug-ins:
  2. Add a org.eclipse.ui.navigator.viewer extension that has:
       <extension
             point="org.eclipse.ui.navigator.viewer">
           <viewerActionBinding 
                viewerId="example.view">
              <includes>
           	     <actionExtension pattern="org.eclipse.ui.navigator.resources.*" />		       	      
              </includes>
           </viewerActionBinding>
       </extension>