blob: 297733c7d3eaa2822a9a31899156b699c8f799fb [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
<HEAD>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="../book.css" CHARSET="ISO-8859-1" TYPE="text/css">
<TITLE>
Setting a global action handler
</TITLE>
<link rel="stylesheet" type="text/css" HREF="../book.css">
</HEAD>
<BODY BGCOLOR="#ffffff">
<h3>Setting a global action handler</h3>
<p>A plug-in contributes a <a href="wrkAdv_retarget.htm">retargetable action</a>
for a view or editor part by implementing an <a href="../reference/api/org/eclipse/jface/action/IAction.html"><b>IAction</b></a>
and registering it as a global action handler with the part's action bars.&nbsp;
In views, this is usually done at the time that the part creates its actions and
controls. For editors see <a href="wrkAdv_retarget_contribute_editors.htm">Retargetable editor actions</a>.
The name of the retargeted action (as defined in <a href="../reference/api/org/eclipse/ui/IWorkbenchActionConstants.html"><b>IWorkbenchActionConstants</b></a>)
is used to specify which action the handler is intended for.&nbsp; The following
shows how the workbench task list view registers its handler for the <b>PROPERTIES</b>
action.</p>
<pre>public void createPartControl(Composite parent) {
...
<b>makeActions();</b>
...
// Add global action handlers.
...
getViewSite().getActionBars().<b>setGlobalActionHandler(
IWorkbenchActionConstants.PROPERTIES,
propertiesAction);</b>
...</pre>
<p>The properties action is created in the local method <b>makeActions</b>:</p>
<pre>void makeActions() {
...
// properties
propertiesAction = new TaskPropertiesAction(this, &quot;properties&quot;);
propertiesAction.setText(TaskListMessages.getString(&quot;Properties.text&quot;));
propertiesAction.setToolTipText(TaskListMessages.getString(&quot;Properties.tooltip&quot;));
propertiesAction.setEnabled(false);
}</pre>
<p>That's all that is needed.&nbsp; Your action will be run when the user
chooses the action from the workbench menu bar or tool bar and your view or
editor is active.&nbsp; The workbench handles the details of ensuring that the
retargeted action is always associated with the currently active view. The
same applies to editor actions supplied through the EditorActionBarContributor.
</p>
</BODY>
</HTML>