| <!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>org.eclipse.ui.popupMenus</TITLE> |
| |
| <link rel="stylesheet" type="text/css" HREF="../book.css"> |
| </HEAD> |
| <BODY BGCOLOR="#ffffff"> |
| <H3> |
| org.eclipse.ui.popupMenus</H3> |
| |
| <P > |
| The <b><a href="../reference/extension-points/org_eclipse_ui_popupMenus.html"> org.eclipse.ui.popupMenus</a></b> extension |
| point allows a plug-in to contribute to the popup menus of other |
| views and editors.</P> |
| <P > |
| You can contribute an action to a specific popup menu by its id (<b>viewerContribution</b>), or |
| by associating it with a particular object type (<b>objectContribution</b>). </P> |
| <ul> |
| <li>An <b>objectContribution</b> will cause the menu |
| item to appear in popup menus for views or editors where objects of |
| the specified type are selected.</li> |
| <li>A <b>viewerContribution</b> will cause the menu |
| item to appear in the popup menu of a view or editor specified by id in the |
| markup. </li> |
| </ul> |
| <p> |
| You can add commands to context menus for a similar result, see the |
| <b>Contributing to popup menus</b> section in |
| <a href="workbench_cmd_menus.htm" class="XRef">org.eclipse.ui.menus</a>. |
| </p> |
| <P > |
| The readme tool defines both. Let's look at the object contribution |
| first. </P> |
| <pre> |
| <extension point = "org.eclipse.ui.popupMenus"> |
| <objectContribution |
| id="org.eclipse.ui.examples.readmetool" |
| objectClass="org.eclipse.core.resources.IFile" |
| nameFilter="*.readme"> |
| <action id="org.eclipse.ui.examples.readmetool.action1" |
| label="%PopupMenus.action" |
| icon="icons/ctool16/openbrwsr.png" |
| menubarPath="additions" |
| helpContextId="org.eclipse.ui.examples.readmetool.open_browser_action_context" |
| class="org.eclipse.ui.examples.readmetool.PopupMenuActionDelegate" |
| definitionId="org.eclipse.ui.examples.readmetool.action1" |
| enablesFor="1"> |
| </action> |
| </objectContribution> |
| ... |
| </pre><h4> |
| Object contribution |
| </h4> |
| <P > |
| The action "Show Readme Action" is contributed for the object class <a href="../reference/api/org/eclipse/core/resources/IFile.html"><b>IFile</b></a>. This means that any view containing |
| <a href="../reference/api/org/eclipse/core/resources/IFile.html"><b>IFile</b></a> |
| objects will show the contribution if <a href="../reference/api/org/eclipse/core/resources/IFile.html"><b>IFile</b></a> |
| objects are selected. We see that the selection criteria is restricted further with a name filter |
| (<b>nameFilter="*.readme"</b>) and for single selections (<b>enablesFor="1"</b>). As we've discussed before, the registration of this menu does not run any code from our plug-in until the menu item is actually selected. </P> |
| <P > |
| When the menu item is selected, the workbench will run the specified class. |
| Since the popup is declared as an <b>objectContribution</b>, |
| the supplied class must implement <b><a href="../reference/api/org/eclipse/ui/IObjectActionDelegate.html">IObjectActionDelegate</a></b>. </P> |
| <P > |
| The action is implemented in <b>PopupMenuActionDelegate</b>. </P> |
| <pre> |
| public void run(IAction action) { |
| MessageDialog.openInformation( |
| this.part.getSite().getShell(), |
| "Readme Example", |
| "Popup Menu Action executed"); |
| } |
| </pre> |
| <P > |
| We can see the popup menu contribution when we select a readme file from the resource navigator.</P> |
| |
| <img src="images/readmepopupmenu.png" alt="" border="0"> |
| <h4>Viewer contribution</h4> |
| <p> |
| A viewer contribution is used to contribute to a specific view or editor's popup menu |
| by using its id. |
| Here is the readme tool's viewer contribution:</p> |
| <pre> ... |
| <viewerContribution |
| id="org.eclipse.ui.examples.readmetool2" |
| targetID="org.eclipse.ui.examples.readmetool.outline"> |
| <action id="org.eclipse.ui.examples.readmetool.action1" |
| label="%PopupMenus.action" |
| icon="icons/ctool16/openbrwsr.png" |
| menubarPath="additions" |
| helpContextId="org.eclipse.ui.examples.readmetool.open_browser_action_context" |
| definitionId="org.eclipse.ui.examples.readmetool.action1" |
| class="org.eclipse.ui.examples.readmetool.ViewActionDelegate"> |
| </action> |
| </viewerContribution> |
| </extension></pre> |
| <blockquote><i> |
| Note: The name <b> viewerContribution</b> is somewhat misleading, as it does not relate to JFace viewers. A better name would |
| be <b>popupMenuContribution</b>.</i></blockquote> |
| <P > |
| When the extension is a <b>viewerContribution</b>, the |
| supplied class must implement the |
| <b><a href="../reference/api/org/eclipse/ui/IEditorActionDelegate.html"> IEditorActionDelegate</a></b> or |
| <b><a href="../reference/api/org/eclipse/ui/IViewActionDelegate.html"> IViewActionDelegate</a></b> interface, depending on whether the |
| action is contributed to an editor's or view's popup menu. </P> |
| |
| |
| <P > |
| The <b>targetID</b> specifies the view whose popup menu will be altered. In this |
| case, we are adding an action to one of the readme tool views, the |
| outliner. The action itself is similar to others that we've seen. We specify the <b>id</b>, |
| <b>definitionId</b>, <b>label</b>, and <b>icon</b> of the action, and |
| the <b>path</b> within the popup for our contribution. The action will be |
| shown only in the readme outline view's popup menu.</P> |
| |
| |
| <P > |
| <img src="images/readmeoutlinerpopup.png" alt="" border="0"></P> |
| |
| |
| The interfaces required to contribute a <b>viewerContribution</b> |
| to the <b> popupMenus</b> extension |
| point are the same as those required by the <b> viewActions</b> and <b> editorActions</b> extension points. If you want to contribute the same action to the popup menu and the local menu of a view or editor, you can use the same class for both extensions. |
| |
| |
| |
| |
| |
| </BODY> |
| </HTML> |