Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse Plug-in Developer Guide
Previous Page Home Next Page

org.eclipse.ui.editorActions

We've just seen how editors can contribute their own actions to the workbench menus and tool bar when they become active.  The org.eclipse.ui.editorActions extension point allows a plug-in to add to the workbench menus and tool bar when another plug-in's editor becomes active.

In the readme example, the plug-in uses the editorActions extension point to contribute additional actions to the menu contributed by the readme editor. The definition in our plugin.xml should look pretty familiar by now.

<extension
    point = "org.eclipse.ui.editorActions">
      <editorContribution 
         id="org.eclipse.ui.examples.readmetool.ec1" 
         targetID="org.eclipse.ui.examples.readmetool.ReadmeEditor">        
	   <action id="org.eclipse.ui.examples.readmetool.ea1" 
              label="%Editors.Action.label" 
              toolbarPath="ReadmeEditor" 
              icon="icons/obj16/editor.png" 
              tooltip="%Editors.Action.tooltip" 
              class="org.eclipse.ui.examples.readmetool.EditorActionDelegate"
              definitionId="org.eclipse.ui.examples.readmetool.ea1"
              /> 
      </editorContribution>
 </extension>

Similar to a view action, the extension must specify the targetID of the editor to which it is contributing actions.  The action itself is very similar to a view action (id, label, icon, toolbarPath, ...), except that the specified class must implement IEditorActionDelegate and a definitionId can be specified to link this action to a Command specified by the org.eclipse.ui.commands extension, which is important for keybinding. See Associating actions to commands and org.eclipse.ui.commands for defining commands.

Note that a menu bar path is not specified in this markup.  Therefore, the action will appear in the workbench tool bar when the editor is active, but not in the workbench menu bar.  (See Menu and toolbar paths for a discussion of toolbar and menu paths.)

Sure enough, when the editor is active, we see our editor action on the tool bar next to the actions that were contributed by the editor itself.

Editor action appears next to original editor contributions in workbench toolbar

The readme tool supplies EditorActionDelegate to implement the action.  This class is very similar to the view action delegate we saw earlier.

public void run(IAction action) {
	MessageDialog.openInformation(editor.getSite().getShell(),
		MessageUtil.getString("Readme_Editor"),  
		MessageUtil.getString("Editor_Action_executed")); 
}

 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire