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
Answertopia.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

Retargetable actions

It is common for a plug-in's views and editors to implement actions that are semantically similar to existing workbench actions, such as clipboard cut/copy/paste, view refresh, or properties.  The popup menu for views and editors can become quite cluttered if every view or editor has to define unique actions for these operations and include them in their menus. 

To solve this problem, the workbench defines retargetable (also called global) actions that can be handled by any view or editor.  When a view or editor is active, its handler will be run when the user chooses the action from the workbench menu or toolbar.  This allows views and editors to share workbench menu space for semantically similar actions.

IWorkbenchActionConstants documents all of the workbench actions and denotes retargetable actions as global.  For example, here is the definition of the Properties action.

public static final String PROPERTIES = "properties"; // Global action. 

The following table summarizes some of the more common retargetable actions that are implemented by views and editors:

  File menu Edit menu Navigate menu Project menu
views move
rename
refresh
properties
  go into
go to resource
sync with editor
back
forward
up
next
previous
open
close
build
rebuild
editors revert
print
find    
views and editors   cut
copy
paste
delete
select all
undo
redo
   

Retargetable actions are created using RetargetAction .  The following snippet is from WorkbenchActionBuilder.

 propertiesAction = createGlobalAction(IWorkbenchActionConstants.PROPERTIES, "file", false); 

The createGlobalAction method shows us exactly how to make a RetargetAction .

private RetargetAction createGlobalAction(String id, String actionDefPrefix, boolean labelRetarget) {
	RetargetAction action;
	if (labelRetarget) {
		action = new LabelRetargetAction(id, WorkbenchMessages.getString("Workbench." + id)); 
	}
	else {
		action = new RetargetAction(id, WorkbenchMessages.getString("Workbench." + id)); 
	}
	...
	return action;
}

When creating a retargetable action, the workbench assigns the id for the action and the default label.  Note that there are two styles of retarget actions.  RetargetAction simply allows a view or editor to reimplement an action.  LabelRetargetAction also allows views and editors to reset the label of the action.   This is useful for making the menu label more specific, such as relabeling an Undo action as Undo Typing.  

Now we know how the retarget actions are defined by the workbench.  Let's look next at how your view or editor can provide an implementation for a retargetable action.  This is done by setting a global actionhandler.


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