### Eclipse Workspace Patch 1.0 #P org.eclipse.platform.doc.isv Index: guide/workbench_actionfilters.htm =================================================================== RCS file: guide/workbench_actionfilters.htm diff -N guide/workbench_actionfilters.htm --- guide/workbench_actionfilters.htm 24 Mar 2009 13:59:43 -0000 1.27 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,242 +0,0 @@ - - - - - - - - - - -Boolean expressions and action filters - - - - - -

-Boolean expressions and action filters

-

-When a plug-in contributes an action to the workbench UI using one of the menu -extension points, it can specify the conditions under which the menu item is -visible and/or enabled in the menu. In addition to supplying simple enabling -conditions, such as selection counts and selection classes, plug-ins can use boolean -expressions for more flexibility in determining when an action should be visible or enabled.

- - -

Boolean enablement expressions

-

Boolean expressions can contain the boolean operators (NOT, AND, OR) combined with a predefined syntax -for evaluating certain conditions. Many of these conditions test a particular object. The identity of the -"object in focus" (the object being tested) depends upon the specific context of the enablement expression: -

- -

-When specifying a value to be tested against any of these expressions, the value is assumed to be a string except for when -the following conversions are successful: -

- -

A complete definition of enablement XML syntax can be found in the extension point reference documentation for any -extension that defines an enablement element, such as - org.eclipse.ui.popupMenus. -

-

Prior to R3.0, these generalized boolean expressions were not available. The following predefined expressions were used to -evaluate certain conditions without building a general expression. Note that any of these expressions could now be expressed with -the more generalized syntax. The predefined expressions can still be used as follows:

- -

For example, the following snippets represent enablement - expressions that could be used on a hypothetical action in an action set:

-
<action id="org.eclipse.examples.actionEnablement.class" 
-       label="Red Element" 
-       menubarPath="additions" 
-       class="org.eclipse.examples.actionEnablement.ObjectTestAction"> 
-       <enablement> 
-	 <and>
-	   <objectClass name="org.eclipse.examples.actionEnablement.TestElement"/> 
-           <objectState name="name" value="red"/> 
-	 </and>
-       </enablement> 
-</action>
-
<action id="org.eclipse.examples.actionEnablement.property" 
-       label="Property" 
-       menubarPath="additions" 
-       class="org.eclipse.examples.actionEnablement.PropertyTestAction"> 
-       <enablement> 
-           <systemProperty name="MyTestProperty" value="puppy"/> 
-       </enablement> 
-</action> 
-
<action id="org.eclipse.examples.actionEnablement.pluginState" 
-       label="Installed" 
-       menubarPath="additions" 
-       class="org.eclipse.examples.actionEnablement.PluginTestAction"> 
-       <enablement> 
-           <pluginState id="x.y.z.anotherPlugin" value="installed"/> 
-       </enablement> 
-</action> 
-

See the reference documentation of the extension points -for more elaborate samples of these expressions and a complete description of -the XML.

- - -

-The following table lists extension points that contribute actions and -summarizes how XML markup attributes and boolean expressions can be used to -affect enablement.

- - - - - - - - - - - - - - - - - - -
-

-Extension point name

-
-

-Attributes affecting enablement

-
-

-Boolean expressions

-
-

- - -viewActions,

-

editorActions,

-

actionSets

-
-

-enablesFor - specifies the selection count that must be met for the -action to be enabled

-

-selection class - the class that the selected objects must -subclass or implement in order for the action to be enabled

-

-selection name - a wild card filter that can be applied to the -objects in the selection.

-
-

-visibility - a boolean expression.  Controls whether the menu item -is visible in the menu.

-

-enablement - a boolean expression.  Controls whether the menu item -is enabled in the menu.  The enablesFor attribute and the selection class -and name, and must be -satisfied before applying the enablement expression.

-
-

- - -popupMenus

-
-

-(For object contributions only.)

-

-objectClass - specifies the class that objects in the selection must -subclass or implement

-

-(For both object and viewer contributions)

-

-enablesFor - specifies the selection count that must be met for the -action to be enabled

-

-selection class - the class that the selected objects must -subclass or implement to enable the action

-

-selection name - a wild card filter that can be applied to the -objects in the selection.

-

-
-

-(For both object and viewer contributions)

-

-visibility - a boolean expression.  Controls whether the menu item -is visible in the menu.

-

enablement - a boolean expression.  Controls -whether the menu item is enabled in the menu.  -The enablesFor attribute and the selection class and name, and must be -satisfied before applying the enablement expression.

-
- -

Using objectState with content types

-

The ability to define content types (see Content types) can be combined -with boolean expressions to define very specific enablement or visibility conditions based on -the content type of a resource. For example, the following snippet makes a popup menu item visible only if the -selected file's content matches the plug-in's specialized content types. -

-
-<extension point="org.eclipse.ui.popupMenus">
-   <objectContribution
-      id="com.example.objectContributions"
-      objectClass="org.eclipse.core.resources.IFile"
-      nameFilter="*.xml">
-         <visibility>
-            <or>
-               <objectState
-                  name="contentTypeId"
-                  value="com.example.employeeRecordContentType"/>
-               <objectState
-                  name="contentTypeId"
-                  value="com.example.customerRecordContentType"/>
-            </or>
-         </visibility>
-         <action id="com.example.action1"
-         ...
-
-The contentTypeId attribute can be used in an objectState expression to check the content type of -the selected xml file. This allows a plug-in to apply very specific content checking before enabling or showing -menu actions related to specific types of files. See Content types for more detail -about the content type extension. - - - - - Index: guide/workbench_basicext.htm =================================================================== RCS file: guide/workbench_basicext.htm diff -N guide/workbench_basicext.htm --- guide/workbench_basicext.htm 24 Mar 2009 13:59:54 -0000 1.27 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,55 +0,0 @@ - - - - - - - - - - -Basic workbench extension points - - - - - -

-Basic workbench extension points using actions

-

-The workbench defines extension points that allow plug-ins to contribute -behaviors to existing views and editors or to provide implementations for -new views and editors. Using commands is covered in the Basic workbench extension points using commands section. Here we are - going to take a look at the -contributions to these extension points from one of the workbench sample applications, the readme tool.

-

-The readme tool is a plug-in that provides custom editing and navigation for a specific resource -, a - .readme file. The example shows many typical (but simplified) ways that extensions can be used to provide specialized tools.

-

-The readme tool contributes to the menus of the navigator view, adds editor related actions to the workbench menus and -tool bar, defines a custom view and content outliner, and defines markers -and marker resolutions. The figure below shows some of the -customized features added to the workbench by the readme tool.

-

-Workbench with readme tool contributing action sets, view and editor actions, custom editors and views, and outliner

-

-The readme tool also contributes preference and properties pages to the workbench. Later we'll also look -at some wizard contributions in - Dialogs and wizards.

-

-The readme tool is located in the org.eclipse.ui.examples.readmetool package. The - readmetool.jar and plugin.xml can be found in the - org.eclipse.ui.examples.readmetool directory underneath the - plugins directory. To follow along, you will need to make sure that -you have installed the platform examples.  (See the Examples -Guide for more information.) 

-

-The readme -tool implements many different workbench extensions.  We will start -with one of the simplest workbench extension points, a view.  We'll -continue by looking at additional readme tool extensions.

- - - Index: guide/workbench_basicext_actionSetPartAssociations.htm =================================================================== RCS file: guide/workbench_basicext_actionSetPartAssociations.htm diff -N guide/workbench_basicext_actionSetPartAssociations.htm --- guide/workbench_basicext_actionSetPartAssociations.htm 2 Jun 2011 15:20:56 -0000 1.18.6.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,72 +0,0 @@ - - - - - - - - - - -Action set part associations - - - - -

-Action set part associations

- -

-Once your plug-in defines an action -set, it can use the - org.eclipse.ui.actionSetPartAssociations -extension point to specify that an action set should be made visible when a -particular view or editor is active.  

- -

- Ultimately, the user controls the -appearance of action sets using - - -command link -Window > Customize Perspectives... - -in -the workbench menu. If the user marks an action set visible, it will always be visible when the -perspective is active, regardless of -the active view or editor.  Likewise, if the user marks the action set as hidden, it will always be hidden when the perspective is active.  If the user does not change the state of -an action set in this dialog, then the action set part associations are used to -determine the visibility of the action set.

- - -

-The markup for an action set part association is straightforward.  The -following example comes from the Java development tools (JDT) UI plug-in.

-
-   <extension point="org.eclipse.ui.actionSetPartAssociations">
-	<actionSetPartAssociation 
-		targetID="org.eclipse.jdt.ui.CodingActionSet">
-		<part id="org.eclipse.jdt.ui.PackageExplorer"/>
-		<part id="org.eclipse.jdt.ui.TypeHierarchy" />
-		<part id="org.eclipse.jdt.ui.CompilationUnitEditor"/>
-		<part id="org.eclipse.jdt.ui.ClassFileEditor"/>
-		<part id="org.eclipse.jdt.ui.ProjectsView"/>
-		<part id="org.eclipse.jdt.ui.PackagesView"/>
-		<part id="org.eclipse.jdt.ui.TypesView"/>
-		<part id="org.eclipse.jdt.ui.MembersView"/>
-	</actionSetPartAssociation>
-</extension>
-
-

The targetID specifies the action set.  (The CodingActionSet was -previously defined in the JDT plug-in manifest.)  One or more part -attributes can be specified to indicate which views and editors will cause the -action set to become visible in the menus and toolbar.  The effect of this extension -contribution is that the actions associated with writing Java code will only be -visible when one of the specified views is active.

- - - - - - - Index: guide/workbench_basicext_actionSets.htm =================================================================== RCS file: guide/workbench_basicext_actionSets.htm diff -N guide/workbench_basicext_actionSets.htm --- guide/workbench_basicext_actionSets.htm 2 Jun 2011 15:20:56 -0000 1.32.6.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,158 +0,0 @@ - - - - - - - - - - -org.eclipse.ui.actionSets - - - - -

-org.eclipse.ui.actionSets

- -

-Your plug-in can contribute menus, menu items, and tool bar items to the workbench menus and toolbar -by using the - org.eclipse.ui.actionSets -extension point. In order to reduce the clutter that would be caused by having every plug-in's menu contributions shown at once, the contributions are grouped into action sets which can be made visible by user preference.

-

-You can see which action sets have been contributed to your workbench by choosing - - -command link -Window > Customize Perspective... - -from the workbench menu. This option will show you a dialog that lists -action sets as groups of commands. A checkmark by a command group means that the menu and tool bar actions are visible in the workbench. -You can select the name of the command group to see the list of available menu and toolbar actions to the right. The figure below shows the -list of command groups available in our workbench.  (Your workbench may look different depending on which plug-ins you have -installed and which perspective is active.)

- -Customize Perspective dialog with action set list - - -

-The readme tool uses an action set to contribute several different "Open Readme -Browser" actions to the workbench menu.  (We contributed a similar -action to the popup menu of the resource navigator.)  The markup follows:

-
-<extension point = "org.eclipse.ui.actionSets">
-	   <actionSet id="org_eclipse_ui_examples_readmetool_actionSet"
-		   label="%ActionSet.name"
-		   visible="true">
-		   <menu id="org_eclipse_ui_examples_readmetool"
-			   label="%ActionSet.menu"
-			   path="window/additions"> 
-			   <separator name="slot1"/>
-			   <separator name="slot2"/>
-			   <separator name="slot3"/>
-		   </menu>
-		   <action id="org.eclipse.ui.examples.readmetool.readmeAction"
-			   menubarPath="window/org_eclipse_ui_examples_readmetool/slot1"
-			   toolbarPath="readme"
-			   label="%ReadmeAction.label"
-			   tooltip="%ReadmeAction.tooltip"
-			   helpContextId="org.eclipse.ui.examples.readmetool.open_browser_action_context"
-			   icon="icons/ctool16/openbrwsr.png"
-			   class="org.eclipse.ui.examples.readmetool.WindowActionDelegate"
-			   definitionId="org.eclipse.ui.examples.readmetool.readmeAction"
-			   enablesFor="1">
-			   <selection class="org.eclipse.core.resources.IFile"
-					name="*.readme">
-			   </selection>
-		   </action>
-		   ...
-	   </actionSet>
-   </extension>
-

-Wow, there's a lot going on here!  Let's take it a step at a time, looking -only at the first action for now.  

-

-First, the action set is declared and given a label.  -The label "ReadMe Actions" (defined for %ActionSet.name key in the plug-in's -properties file) is used to display the action set in the -dialog shown above.  Since we set visible to true, the workbench will initially have the action set -checked in the action set list and the actions will be visible.

-

-The rest of the action set declaration is concerned with defining the menu in -which the actions appears and the actions themselves.

-

-We define a menu whose label appears in the workbench menus.  The menu's path -tells the workbench to place the new menu in the additions -slot of the window menu.  (For a discussion -of menu paths and slots, see Menu and toolbar paths.)  -We also define some slots in our new menu so that actions can be inserted at specific locations in our menu.

-

-This markup alone is enough to cause the menu to appear in the workbench Window -menu.

-

-Workbench Window menu with Readme File Editor entry

-

-Next, we define the actions themselves.  

-

-The action definition (id, -label, icon, class) is -similar to the other actions we've seen in views, editors, and popups.  -We'll focus here on what's different:  where does the action go?  We -use  menubarPath and toolbarPath -to indicate its location.  First, we define the menubarPath to add the -action to a slot in the menu -that we just defined ( "window/org_eclipse_ui_examples_readmetool/slot1").

-

-Readme File Editor menu with menu items

-

-Then, we define a new toolbarPath to insert our actions in the workbench tool -bar.  Since we've defined a new tool path, "readme", the workbench will decide where it goes -relative to other plug-in's toolbar contributions.

-

-Workbench tool bar with readme action

-

-What happens when the action is selected by the user?  The action is -implemented by the class specified in the class -attribute.  The action class must implement - IWorkbenchWindowActionDelegate, -or - IWorkbenchWindowPulldownDelegate -if the action will be shown as a pull-down tool item in the tool bar.  Since we are not -creating a pull-down tool item, we provide WindowActionDelegate.  -This class is similar to ObjectActionDelegate.  -It launches the readme sections dialog when the user chooses the action.  (We'll -discuss the sections dialog in Application -dialogs.)

- - -

-The action also supplies enabling conditions for its menu item and tool bar -item.  The menu and tool bar items will only be enabled when a single (enablesFor="1") -readme file (selectionClass ="org.eclipse.core.resources.IFile" -name="*.readme") is selected.  This action's menu and toolbar -item appear and are enabled by virtue of the markup -in the plugin.xml file.  None of the -plug-in code will execute until the user chooses the action and the workbench -runs the action class.

- -

The definitionId allows the action to be linked to a command created by the -org.eclipse.ui.commands -extension, which can be used for keybindings. All actions in an actionSets -should be linked to a command, either existing commands provided by the workbench or -commands created by the contributing plugin. -See Associating actions to commands -and org.eclipse.ui.commands for -defining commands.

- -

-We'll look at the other two actions later in the context of retargetable -actions.

- - - - - - - Index: guide/workbench_basicext_editorActions.htm =================================================================== RCS file: guide/workbench_basicext_editorActions.htm diff -N guide/workbench_basicext_editorActions.htm --- guide/workbench_basicext_editorActions.htm 24 Mar 2009 13:59:43 -0000 1.27 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,77 +0,0 @@ - - - - - - - - - -org.eclipse.ui.editorActions - - - - -

-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")); 
-}
- - - - - Index: guide/workbench_basicext_editors.htm =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.platform.doc.isv/guide/workbench_basicext_editors.htm,v retrieving revision 1.30 diff -u -r1.30 workbench_basicext_editors.htm --- guide/workbench_basicext_editors.htm 24 Mar 2009 13:59:55 -0000 1.30 +++ guide/workbench_basicext_editors.htm 9 Jun 2011 12:43:45 -0000 @@ -1,7 +1,7 @@ - + @@ -28,7 +28,8 @@ editor on the same file from a different workbench window or perspective).  Unlike views, however, the same editor type, such as a text editor, may be open many times -within one workbench page for different inputs.

+within one workbench page for different inputs. The editor input can also be a path +to an in memory model, as in the InfoEditor example.

The workbench extension point org.eclipse.ui.editors is used by plug-ins to add editors to the workbench. Plug-ins that contribute an editor must register the editor @@ -36,8 +37,9 @@ for the editor. Some of the editor information, such as the implementation class and the name and the icon to be used in the workbench menus and -labels, is similar to the view information. In addition, editor extensions specify the file extensions or file name patterns of the file types that the editor understands. Editors can also define a - contributorClass, which is a class that adds actions to workbench menus and tool bars when the editor is active.

+labels, is similar to the view information. In addition, editor extensions specify the file extensions or file name patterns of the file types that the editor understands. +Editors also use org.eclipse.ui.commands and org.eclipse.ui.menus +to contribute to the workbench menus and toolbars when that editor is active.

The interface for editors is defined in IEditorPart, but plug-ins can choose to extend the @@ -50,110 +52,56 @@ are implemented using IEditorPart.

-The readme tool provides a custom editor primarily for the purpose of contributing its own content outliner page to the +The editor can contribute its own content outliner page to the workbench outline view.  

The configuration for the editor extension is defined as follows.

 <extension
     point = "org.eclipse.ui.editors">
-	<editor
-  	   id = "org.eclipse.ui.examples.readmetool.ReadmeEditor"
-  	   name="%Editors.ReadmeEditor"
-      	   icon="icons/obj16/editor.png"
-      	   class="org.eclipse.ui.examples.readmetool.ReadmeEditor"
-	   extensions="readme"
-           contributorClass="org.eclipse.ui.examples.readmetool.ReadmeEditorActionBarContributor">
-	</editor>
+      <editor
+            class="org.eclipse.ui.examples.contributions.editor.InfoEditor"
+            icon="icons/editor.gif"
+            id="org.eclipse.ui.examples.contributions.editor"
+            name="%contributions.editor.name">
+      </editor>
 </extension>

We see the familiar configuration markup for id, name, -icon, and class.   The extensions attribute -describes the file types that the editor understands.  (You could also +icon (which must be specified when specifying class), +and class.   You could use the extensions attribute +describes the file types that the editor understands, like extensions="person", +although this example doesn't need it. +(You could also specify filenames if you need to be more specific.)  The class -implements the editor, and the contributorClass is responsible for -providing editor-related actions. The contributor is not normally used to -contribute commands or handlers to the workbench menu or toolbar, that's done -via org.eclipse.ui.menus. -Let's look at the contributor that's used for actions in more -detail.

+implements the editor.

-

-Editor action contributors

-

-The contributor class adds editor-related actions to the workbench menu and toolbar. It must implement the - IEditorActionBarContributor interface. The contributor is -separate from the editor itself since any given workbench page can have multiple editors of the same type. -A single contributor is shared by all the editors of a specific type, rather than -having each instance of an editor create actions and images. 

-

-In ReadmeEditorActionBarContributor, we contribute three actions, -"Editor Action1," "Editor Action2," and "Editor Action3."   -These are set up in the constructor.

-
-   public ReadmeEditorActionBarContributor() {
-      	...
-	action1 = new EditorAction(MessageUtil.getString("Editor_Action1")); 
-	action1.setToolTipText(MessageUtil.getString("Readme_Editor_Action1")); 
-	action1.setDisabledImageDescriptor(ReadmeImages.EDITOR_ACTION1_IMAGE_DISABLE);
-	action1.setImageDescriptor(ReadmeImages.EDITOR_ACTION1_IMAGE_ENABLE);
-	...	
-	action2 = new RetargetAction(IReadmeConstants.RETARGET2, MessageUtil.getString("Editor_Action2")); 
-	action2.setToolTipText(MessageUtil.getString("Readme_Editor_Action2")); 
-	action2.setDisabledImageDescriptor(ReadmeImages.EDITOR_ACTION2_IMAGE_DISABLE);
-	action2.setImageDescriptor(ReadmeImages.EDITOR_ACTION2_IMAGE_ENABLE);
-	...
-	action3 = new LabelRetargetAction(IReadmeConstants.LABELRETARGET3, MessageUtil.getString("Editor_Action3"));
-	action3.setDisabledImageDescriptor(ReadmeImages.EDITOR_ACTION3_IMAGE_DISABLE);
-	action3.setImageDescriptor(ReadmeImages.EDITOR_ACTION3_IMAGE_ENABLE);
-	...   
-   }
-
-

-The names and icons for the actions are set up in the code rather than in the plugin.xml.  -(We'll ignore the differences in the action classes for now until we look at retargetable -actions.)  

-

Note how similar the action information is to the - viewActions information we saw in the markup -for the view action.  The actions are set up in code since we have to -manage the sharing of the actions among different instances of the same editor.  -When the actions are created in the constructor, they are independent of any -particular instance of the editor.

- When an editor becomes active and it has actions that need to be installed in the workbench menus and tool bar, the setActiveEditor -message is sent to the contributor.  The contributor connects the editor actions to a specific editor.  

+Editor menus and editor toolbars are placed in the main menu and main toolbar. See +org.eclipse.ui.menus for how to use the +locationURI to place the commands correctly.

+Showing a global menu additions +

+These menu and tool bar items can be shown only when the editor is active using core expressions. +To define a re-usable core expression for your editor, use +org.eclipse.core.expressions.definitions

-   public void setActiveEditor(IEditorPart editor) {
-      ...
-      action1.setActiveEditor(editor);
-      ...
-   }
-
-

-As you can see, the actions show up in the workbench menu and tool bar when a readme editor is active.

- -Readme entry in workbench menu bar with three editor actions - - - -

Workbench toolbar with three readme actions

-

-These menu and tool bar items are only shown when the editor is active. The location for the menu and tool bar items can be specified as described in -Menu and toolbar paths.

- - +<extension + point = "org.eclipse.core.expressions.definitions"> + <definition id="org.eclipse.ui.examples.contributions.view.activeEditor"> + <with variable="activeEditorId"> + <equals value="org.eclipse.ui.examples.contributions.editor"/> + </with> + </definition> +</extension>

Editors and content outliners

-The readme editor itself, ReadmeEditor, is not very complicated. It extends the - TextEditor class so that it can contribute a customized content outliner page -to the outline view when a readme file is being edited. It does not change any behavior inside the text editor.

-

-

-Editors often have corresponding content outliners that provide a structured +Although the Info Editor does not, editors often have corresponding content outliners +that provide a structured view of the editor's contents and assist the user in navigating through the contents of the editor.  See Content outliners for more detail.

@@ -164,8 +112,5 @@ editors and platform text.

- - - Index: guide/workbench_basicext_popupMenus.htm =================================================================== RCS file: guide/workbench_basicext_popupMenus.htm diff -N guide/workbench_basicext_popupMenus.htm --- guide/workbench_basicext_popupMenus.htm 14 Apr 2010 19:11:30 -0000 1.28 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,138 +0,0 @@ - - - - - - - - - -org.eclipse.ui.popupMenus - - - - -

-org.eclipse.ui.popupMenus

- -

-The org.eclipse.ui.popupMenus extension -point allows a plug-in to contribute to the popup menus of other -views and editors.

-

-You can contribute an action to a specific popup menu by its id (viewerContribution), or -by associating it with a particular object type (objectContribution). 

- -

-You can add commands to context menus for a similar result, see the -Contributing to popup menus section in -org.eclipse.ui.menus. -

-

-The readme tool defines both. Let's look at the object contribution -first.  

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

- Object contribution -

-

-The action "Show Readme Action" is contributed for the object class IFile. This means that any view containing -IFile -objects will show the contribution if IFile -objects are selected. We see that the selection criteria is restricted further with a name filter -(nameFilter="*.readme") and for single selections (enablesFor="1"). 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.

-

-When the menu item is selected, the workbench will run the specified class.  -Since the popup is declared as an objectContribution, -the supplied class must implement IObjectActionDelegate

-

-The action is implemented in PopupMenuActionDelegate.  

-
-   public void run(IAction action) {
-      MessageDialog.openInformation(
-         this.part.getSite().getShell(),
-         "Readme Example",
-         "Popup Menu Action executed");
-   }
-
-

-We can see the popup menu contribution when we select a readme file from the resource navigator.

- - -

Viewer contribution

-

-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:

-
      ...
-      <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>
-
-Note:  The name viewerContribution is somewhat misleading, as it does not relate to JFace viewers. A better name would -be popupMenuContribution.
-

-When the extension is a viewerContribution, the -supplied class must implement the - IEditorActionDelegate or - IViewActionDelegate interface, depending on whether the -action is contributed to an editor's or view's popup menu. 

- - -

-The targetID specifies the popup menu that will be altered.  If not specified -in the call to getSite().registerContextMenu(*) the popup menu's ID will default to the view or editor ID.  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 id, -definitionId, label, and icon of the action, and -the path within the popup for our contribution.  The action will be -shown only in the readme outline view's popup menu.

- - -

-

- - - The interfaces required to contribute a viewerContribution -to the popupMenus extension -point are the same as those required by the viewActions and editorActions 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. - - - - - - - Index: guide/workbench_basicext_viewActions.htm =================================================================== RCS file: guide/workbench_basicext_viewActions.htm diff -N guide/workbench_basicext_viewActions.htm --- guide/workbench_basicext_viewActions.htm 24 Mar 2009 13:59:39 -0000 1.28 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,99 +0,0 @@ - - - - - - - - - -org.eclipse.ui.viewActions - - - - -

-org.eclipse.ui.viewActions

- -

-It is common for plug-ins to contribute behavior to views that already exist in the workbench. This is done through the - org.eclipse.ui.viewActions -extension point. This extension point allows plug-ins to contribute menu items, submenus and tool bar entries to an -existing view's local -pull-down menu and local tool bar.

-

-Contributing menu items to views is also done using the -org.eclipse.ui.menus -extension point. This allows command targeted at a view to be contributed to -an existing view's local pull-down menu and local tool bar, as in the Contribution location section -covering the Info View of org.eclipse.ui.menus. -

-

-You may have noticed an item in the project explorer's local tool bar that becomes -enabled whenever a readme file is selected. This item also appears in the -project explorer's local -pull-down menu. These actions appear because the readme tool plug-in contributes -them using the - viewActions extension.

- - -

-The relevant plugin.xml contribution is below.

-
-<extension
-    point = "org.eclipse.ui.viewActions">
-      <viewContribution 
-         id="org.eclipse.ui.examples.readmetool.vc1" 
-         targetID="org.eclipse.ui.navigator.ProjectExplorer">        
-	   <action id="org.eclipse.ui.examples.readmetool.va1" 
-              label="%PopupMenu.ResourceNav.label" 
-	      menubarPath="additions"
-              toolbarPath="additions" 
-              icon="icons/obj16/editor.png" 
-              tooltip="%PopupMenu.ResourceNav.tooltip" 
-   	      helpContextId="org.eclipse.ui.examples.readmetool.view_action_context"
-              class="org.eclipse.ui.examples.readmetool.ViewActionDelegate" 
-              enablesFor="1"> 
-		<selection class="org.eclipse.core.resources.IFile" name="*.readme"/> 
-	   </action>
-      </viewContribution>
- </extension>
-
-

-A view contribution with a unique id is specified. The view to which we are adding -the action is specified in the - targetID. We are contributing to the Project -Explorer's menu.  We specify the label and the menu bar and -tool bar locations for the new action.  (For a complete discussion of menu and toolbar locations, see - Menu and toolbar paths).

-

-We also specify the conditions under which the action should be enabled. You can see that this action will be enabled when there is one selection -(enablesFor="1") of type -IFile -(class="org.eclipse.core.resources.IFile"), whose name has -".readme" in the file extension (name="*.readme"). Sure enough, that's exactly what happens when you click around in the Project Explorer.  

-

-The information in the plugin.xml is all that's needed to add items to menus and tool -bars since plug-in code will only run when the action is actually selected from the menu or toolbar. -To provide the action behavior, the implementation class specified in the - plugin.xml must implement the IViewActionDelegate interface.

-

-In this example, the readme plug-in supplies ViewActionDelegate to implement the action. If you browse this class you will see that it includes methods for -remembering its view, handling selection changes, and invoking its action.  -When invoked the action itself simply launches a dialog that announces it was executed.

-
-public void run(org.eclipse.jface.action.IAction action) {
-	MessageDialog.openInformation(view.getSite().getShell(),
-		MessageUtil.getString("Readme_Editor"),  
-		MessageUtil.getString("View_Action_executed")); 
-}
-

-Although this action is simple, we can imagine how using selections and more -functional dialogs could make this action do something more interesting.

- - - - - - - Index: guide/workbench_basicext_views.htm =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.platform.doc.isv/guide/workbench_basicext_views.htm,v retrieving revision 1.27.6.1 diff -u -r1.27.6.1 workbench_basicext_views.htm --- guide/workbench_basicext_views.htm 2 Jun 2011 15:20:57 -0000 1.27.6.1 +++ guide/workbench_basicext_views.htm 9 Jun 2011 12:43:45 -0000 @@ -27,7 +27,7 @@

The extension point org.eclipse.ui.views allows plug-ins to add views to the workbench. Plug-ins that contribute a view must register the view in their - plugin.xml file and provide  configuration information about the view, such as its implementation class, the category (or group) of views to which it belongs, and the name and icon that should be used to describe the view in menus and labels.

+ plugin.xml file and provide configuration information about the view, such as its implementation class, the category (or group) of views to which it belongs, and the name and icon that should be used to describe the view in menus and labels.

The interface for views is defined in IViewPart, but plug-ins can choose to extend the @@ -39,27 +39,25 @@ let's take a look at the declaration of the extension in the plugin.xml.

<extension 
    point="org.eclipse.ui.views">
-	<category 
-	   id="org.eclipse.ui.examples.readmetool"
-	   name="%Views.category">
-	</category>
-	<view
- 	   id="org.eclipse.ui.examples.readmetool.views.SectionsView"
-	   name="%Views.ReadmeSections"
-	   icon="icons/view16/sections.png"
-	   category="org.eclipse.ui.examples.readmetool"
-	   class="org.eclipse.ui.examples.readmetool.ReadmeSectionsView">
-	</view>
+      <category
+            id="org.eclipse.ui.examples.contributions.viewCategory"
+            name="%contributions.viewCategory.name">
+      </category>
+      <view
+            category="org.eclipse.ui.examples.contributions.viewCategory"
+            class="org.eclipse.ui.examples.contributions.view.InfoView"
+            id="org.eclipse.ui.examples.contributions.view"
+            name="%contributions.view.name">
+      </view>
 </extension>
 

-This should look pretty familiar. We see that a new view, ReadmeSectionsView, is contributed to the workbench. The +This should look pretty familiar. We see that a new view, InfoView, is contributed to the workbench. The view id, name, and - category are specified as we've seen before. An icon is also provided -for the view, using a path relative to the plug-in's installation directory.

+ category are specified as we've seen before.

-Let's look at the ReadmeSectionsView. You can show any view in the +Let's look at the InfoView. You can show any view in the workbench by choosing @@ -68,14 +66,10 @@ and selecting the view from the Show View list.

-When we show the ReadmeSectionsView, a view with a list in it pops up. -The list is empty unless we click on a file with an extension of .readme, in which case -the list is populated with sections from the readme file.

+When we show the InfoView, a view with a list in it pops up. +The list is pre-populated with some data.

- -

-How does the plug-in recognize the readme file and how did it know about selection changes? If we can track down -the answers to these questions, we are well on our way to understanding how to build integrated workbench plug-ins.

+Picture of the workbench, showing the contributions

We'll start with the familiar createPartControl method.  As we saw in the Hello World example, this is where the widgets @@ -84,74 +78,37 @@

    public void createPartControl(Composite parent) {
       viewer = new ListViewer(parent);
+      viewer.setContentProvider(new ContentProvider());
+      viewer.setLabelProvider(new LabelProvider());
+      viewer.addDoubleClickListener(new IDoubleClickListener() {
+         public void doubleClick(DoubleClickEvent event) {
+            editSelection();
+         }
+      });
+      // A service will be providing our input
+      IPersonService service = (IPersonService) getSite().getService(
+         IPersonService.class);
+      viewerInput = new ArrayList(service.getPeople());
+      viewer.setInput(viewerInput);
       ...
-      // add myself as a global selection listener
-      getSite().getPage().addSelectionListener(this);
-
-      // prime the selection
-      selectionChanged(null, getSite().getPage().getSelection());
+      // register myself as a selection provider for this view
+      getSite().setSelectionProvider(viewer);
    }
 

-The view creates and stores a ListViewer and registers itself as a selection listener -on its page. It obtains the page from an +The view creates and stores a ListViewer and sets the content and label provides. +It also registers itself as the selection +provider for this view. +(The concept of selection provider, label provider, and content provider come + from JFace viewers.) +It obtains the service from its IViewSite, which contains information about the view's context, such as its workbench window, -its containing page, its local services, and its plug-in. When we are notified of a selection change, what happens?  -The following code is executed:

-
-   public void selectionChanged(IWorkbenchPart part, ISelection sel) {
-      //if the selection is a readme file, get its sections.
-      AdaptableList input = ReadmeModelFactory.getInstance().getSections(sel);
-      viewer.setInput(input);
-   }
-
-

-It looks like the ReadmeModelFactory class is responsible for turning the selection into readme -sections and these sections are input for -the viewer that we created in the createPartControl -method.

-

-But how did the viewer populate its list widgets?  For now, let's assume that once the viewer was told its input element, it knew how to populate -its list widget with the information - it is a ListViewer, after all.  If you must know right now what this viewer is all about, go to Viewers

-

-We still do not know how readme files are detected or where the file's section -information comes from.  A quick look at the - ReadmeModelFactory sheds some light.

-
-   public AdaptableList getSections(ISelection sel) {
-      // If sel is not a structured selection just return.
-      if (!(sel instanceof IStructuredSelection))
-         return null;
-      IStructuredSelection structured = (IStructuredSelection)sel;
-
-      //if the selection is a readme file, get its sections.
-      Object object = structured.getFirstElement();
-      if (object instanceof IFile) {
-         IFile file = (IFile) object;
-         String extension = file.getFileExtension();
-         if (extension != null && extension.equals(IReadmeConstants.EXTENSION)) {
-            return getSections(file);
-         }
-      }
-
-      //the selected object is not a readme file
-      return null;
-   }
-
-

We check the selection to see if it is a structured (multiple) -selection.  (The concept of a structured selection comes from JFace viewers.)  -For the first object in the selection, we check to see whether it is a file (IFile) -resource.  If it is, we check its extension to see if it matches the ".readme" -extension.  Once we know we have a readme file, we can use other methods to -parse the sections.   You can browse the rest of ReadmeModelFactory,  -MarkElement, and DefaultSectionsParser for the -details about the file parsing.

+its containing page, its local services, and its plug-in.

+

+

We've covered a lot of common workbench concepts by studying this extension. Now we'll move on to some other workbench extensions and examine how your plug-in can further contribute to the workbench UI.

- - - Index: guide/workbench_cmd.htm =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.platform.doc.isv/guide/workbench_cmd.htm,v retrieving revision 1.7.2.1 diff -u -r1.7.2.1 workbench_cmd.htm --- guide/workbench_cmd.htm 2 Jun 2011 15:20:59 -0000 1.7.2.1 +++ guide/workbench_cmd.htm 9 Jun 2011 12:43:45 -0000 @@ -22,15 +22,16 @@ of the Command Framework became mature. In 3.3 the menu contributions portion of the Command Framework became available.

+

+The workbench defines extension points that allow plug-ins to contribute +behaviors to existing views and editors or to provide implementations for +new views and editors. We'll use the Info example from the +contributions plugin. It provides a view that lists people and an +editor for updating their names.

We are going to take a look at how commands, handlers, menu contributions, and keybindings can be used to contribute behaviour to the workbench, -to views, and to editors. We'll use the Info example from the -contributions plugin. It provides a view that lists people and an -editor for updating their names. Much of the contribution of editors -and views has already been covered in the readme example in -Basic workbench extension points using actions. +to views, and to editors.

Picture of the workbench, showing the contributions Index: guide/workbench_cmd_commands.htm =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.platform.doc.isv/guide/workbench_cmd_commands.htm,v retrieving revision 1.3 diff -u -r1.3 workbench_cmd_commands.htm --- guide/workbench_cmd_commands.htm 24 Mar 2009 13:59:41 -0000 1.3 +++ guide/workbench_cmd_commands.htm 9 Jun 2011 12:43:45 -0000 @@ -19,20 +19,16 @@

A command is the declaration of a behaviour by id. Commands are used to declare semantic behaviour so that action implementations defined -elsewhere by handlers, or linked to the action extension points (see -Basic workbench extension points using actions) -can associate themselves with a particular semantic -command. The separation of the command from the action -implementation allows multiple plug-ins to define actions that implement the +elsewhere by handlers. The separation of the command from the behaviour +implementation allows multiple plug-ins to define implementations that implement the same semantic command. The command is what gets associated with a particular key binding.

The workbench defines many common commands in its plugin.xml -file, and plug-ins are encouraged to associate their own actions with these +file, and plug-ins are encouraged to associate their own implementations with these commands where it makes sense. In this way, semantically similar -actions implemented in different plug-ins may share the same key binding.

+behaviour implemented in different plug-ins may share the same key binding.

Defining a command

@@ -57,7 +53,7 @@

The command definition specifies a name, description, and id for -the action. It also specifies the id of a category for the command, which is +the behaviour. It also specifies the id of a category for the command, which is used to group commands in the preferences dialog.  The categories are also defined in the org.eclipse.ui.commands Index: guide/workbench_cmd_expressions.htm =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.platform.doc.isv/guide/workbench_cmd_expressions.htm,v retrieving revision 1.6.6.1 diff -u -r1.6.6.1 workbench_cmd_expressions.htm --- guide/workbench_cmd_expressions.htm 2 Jun 2011 15:20:55 -0000 1.6.6.1 +++ guide/workbench_cmd_expressions.htm 9 Jun 2011 12:43:46 -0000 @@ -235,7 +235,7 @@

ActionSets and Contexts

-

As of 3.3 all org.eclipse.ui.actionSets +

As of 3.3 all org.eclipse.ui.actionSets (Deprecated) generate a context with a parent of org.eclipse.ui.contexts.actionSet. Contexts with this parent are filtered from the Index: guide/workbench_cmd_menus.htm =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.platform.doc.isv/guide/workbench_cmd_menus.htm,v retrieving revision 1.14.2.1 diff -u -r1.14.2.1 workbench_cmd_menus.htm --- guide/workbench_cmd_menus.htm 2 Jun 2011 15:20:54 -0000 1.14.2.1 +++ guide/workbench_cmd_menus.htm 9 Jun 2011 12:43:46 -0000 @@ -253,7 +253,7 @@

-You can add menu contributions that work similar to org.eclipse.ui.editorActions. +You can add menu contributions that work similar to org.eclipse.ui.editorActions (Deprecated). First you define your editor command and handler, like Reset. Then you can add them in an editor menu like "Info" to the main menu:

Index: guide/workbench_menupaths.htm
===================================================================
RCS file: guide/workbench_menupaths.htm
diff -N guide/workbench_menupaths.htm
--- guide/workbench_menupaths.htm	24 Mar 2009 13:59:47 -0000	1.24
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,338 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-Menu and toolbar paths
-
-
-
-
-
-
-

-Menu and toolbar paths

-

-We've seen many action contributions that specify the path for the location of their action. Let's take a close look at what these paths mean.  

- -

-Menu paths

- -

-We'll look at menu paths first by looking at the workbench Help menu.

- -

-Named groups in the workbench

-

-The locations for inserting new menus and menu items are defined using named groups. You can think of -a named group as a slot or placeholder that allows you to insert your menu items -at certain points in a menu bar or pulldown menu.

-

-The workbench defines all of its group slot names in the classes IWorkbenchActionConstants -and IIDEActionConstants. -(Two different classes are used since resource-related menu items are factored out of the generic workbench). -For each workbench menu, named groups are placed in the menu at locations where it is expected that -plug-ins will insert new actions.

-

-The following description of the help menu is adapted from the IWorkbenchActionConstants -class definition.

-
-   Standard Help menu actions
-   Start group - HELP_START - "start"
-   End group - HELP_END - "end"
-
-

-The standard workbench help menu defines a named group called "start," followed by a named group called "end,". -Defining two groups gives plug-ins a little more control over where their contributed -items will be positioned within the help menu.  When you define a menu, you can define as many slots as you like. Adding more slots gives -other plug-ins more control over where their contributions appear relative to existing contributions.

-

-Plug-ins that add a menu item to the help menu can use these group names to decide where their -menu item will go. For example, the cheatsheet plug-in adds an action -set containing the "Cheat Sheets..." menu to the workbench.  Here's -the markup from the org.eclipse.ui.cheatsheets plug-in's -plugin.xml.

-
-<extension
-	point="org.eclipse.ui.actionSets">
-	<actionSet
-		label="%CHEAT_SHEETS"
-		visible="true"
-		id="org.eclipse.ui.cheatsheets.actionSet">
-		<action
-			label="%CHEAT_SHEETS_MENU"
-			class="org.eclipse.ui.internal.cheatsheets.actions.CheatSheetHelpMenuAction"
-			menubarPath="help/helpStart"
-			id="org.eclipse.ui.cheatsheets.actions.CheatSheetHelpMenuAction">
-		</action>
-	</actionSet>
-</extension>
-
-

-The new help action will be placed in the help menu, inside the helpStart group.

- - -

-Fully qualified menu paths

-

- A complete menu path is simply "menu name/group - name."  Most menu names for the workbench are defined in -IWorkbenchActionConstants. -(Resource-related menu names are defined in IIDEActionConstants.) -If we look for the name of the help menu in this class, we'll find -that the fully qualified path name for our help action is - "help/helpEnd."

-

-Some menus have nested submenus. This is where longer paths come into play. If the help menu had defined a submenu -called "submenu" with a named group called "submenuStart," -then the fully qualified menu path for an action in the new submenu would be -"help/submenu/submenuStart."

- - -

- -Externalizing UI labels

-

The example above demonstrates a technique for externalizing strings -that appear in the UI.  Externalized strings are used to make translating the plug-in's UI to -other languages simpler.  We can externalize the strings in our plugin.xml -files by replacing the string with a key (%CHEAT_SHEETS_MENU) and creating entries in the plugin.properties -file of the form:

-
-	CHEAT_SHEETS_MENU = Cheat Sheets...
-
-

-The plugin.properties file can be -translated for different languages and the plugin.xml -will not need to be modified.

- - -

-Adding new menus and groups

-

-In many of the examples we've seen so far, the actions contributed by the sample plug-ins have been added to existing named groups within menus.

-

-The menus extension point -allows you to contribute to your menus using an alternative placement syntax, menu ids. -The actionSets, -viewActions, -editorActions, and - popupMenus extension points also allow you to define new menus and groups within your contribution. This means that you can define new submenus or new -pull-down menus and contribute your actions to these new menus. In this case, the path for your new action will contain the name of your newly defined menu.

-

-We saw this technique when the readme tool defined a new menu for its action -set.  Let's look at the markup one more time now that we've looked at menu -paths in more detail.

-
-   <extension point = "org.eclipse.ui.actionSets">
-   <actionSet id="org_eclipse_ui_examples_readmetool_actionSet"
-	   label="%ActionSet.name"
-	   visible="true">
-	   <menu id="org_eclipse_ui_examples_readmetool"
-		   label="%ActionSet.menu"
-		   path="window/additions"> 
-		   <separator name="slot1"/>
-		   <separator name="slot2"/>
-		   <separator name="slot3"/>
-	   </menu>
-	   <action id="org_eclipse_ui_examples_readmetool_readmeAction"
-		   menubarPath="window/org_eclipse_ui_examples_readmetool/slot1"
-		   toolbarPath="readme"
-		   label="%ReadmeAction.label"
-		   tooltip="%ReadmeAction.tooltip"
-		   helpContextId="org.eclipse.ui.examples.readmetool.open_browser_action_context"
-		   icon="icons/ctool16/openbrwsr.png"
-		   class="org.eclipse.ui.examples.readmetool.WindowActionDelegate"
-		   enablesFor="1">
-		   <selection class="org.eclipse.core.resources.IFile"
-				name="*.readme">
-		   </selection>
-	   </action>
-	   ...
-
-

We added a new menu called  "org_eclipse_ui_examples_readmetool" -whose label is defined in by the key "%ActionSet.name" in the -properties file. Within this menu, we define three named -groups:  "slot1," "slot2," -and "slot3."  We add this new -menu to the path "window/additions."

-

If we go back to IWorkbenchActionConstants, -we see this definition of the window menu in the javadoc:

-
-    * <h3>Standard Window menu actions</h3>
-    * <ul>
-    * <li>Extra Window-like action group (<code>WINDOW_EXT</code>)</li> 
-
-

-If we look further at the class definition, we will see these related -definitions:

- - -
-   public static final String MENU_PREFIX = "";
-   ...
-   public static final String M_WINDOW = MENU_PREFIX+"window";
-   ...
-   public static final String MB_ADDITIONS = "additions";  // Group.
-   ...
-   public static final String WINDOW_EXT = MB_ADDITIONS;   // Group.
-
- - -

-From this information, we can piece together the path for adding something to -the workbench "Window" menu.  The menu itself is called "window" -and it defines one slot called "additions."  -We use the path "window/additions" to -add our new menu.

- - -

-In the action set declaration, we add an action to our newly defined menu, using -the path "window/org_eclipse_ui_examples_readmetool/slot1."

- - -

-

- - -

Other plug-ins could add to our menu by using this same path (or perhaps one -of the other slots) to add one of their own menus.  

- - -

In the readme tool example, we use the separator attribute to -identify the group names.  This will cause a separator line to appear -between these groups when they contain items.  We could instead use the groupMarker -attribute if we want to define a named group without showing any separators in -the menu to distinguish between the groups.

- - -

Tool bar paths

- - -

Tool bar paths work similarly to menu paths.  

- - -

Named tool bars in the workbench

- - -

The workbench tool bar is composed of -tool bars contributed by different plug-ins, including the workbench -itself.  Within any particular tool bar, there are named groups or slots that can be used for inserting new tool bar items. -   

-

-The following description of the workbench tool bars is adapted from the IWorkbenchActionConstants -class definition.

-
// Workbench toolbar ids
-public static final String TOOLBAR_FILE = "org.eclipse.ui.workbench.file"
-public static final String TOOLBAR_NAVIGATE = "org.eclipse.ui.workbench.navigate"; 
-
-// Workbench toolbar group ids.  To add an item at the beginning of the group, 
-// use the GROUP id.  To add an item at the end of the group, use the EXT id.
-public static final String PIN_GROUP = "pin.group"; 
-public static final String HISTORY_GROUP = "history.group"; 
-public static final String NEW_GROUP = "new.group"; 
-public static final String SAVE_GROUP = "save.group"; 
-public static final String BUILD_GROUP = "build.group"; 
-

In the simplest case, a plug-in can contribute a tool bar item in its own -tool bar.  For example, the readme tool actions contributed to the menu are -also given a tool bar path:

-
-<action id="org_eclipse_ui_examples_readmetool_readmeAction"  
-   menubarPath="window/org_eclipse_ui_examples_readmetool/slot1"
-   toolbarPath="readme"
-...
-

Since there is no reference to the workbench tool bar paths or groups, the -readme actions appear in their own group on the tool bar.  Specifying the -following path would instead place the item in the file tool bar in the save -group:

-
...
-<action id="org_eclipse_ui_examples_readmetool_readmeAction"  
-   menubarPath="window/org_eclipse_ui_examples_readmetool/slot1"
-   toolbarPath="org.eclipse.ui.workbench.file/save.group"
-...
-

The paths defined in IWorkbenchActionConstants - may be referenced in the tool bar paths of other plug-ins.

-

Adding to action sets of another plug-in

-

Suppose a plug-in wants its tool bar items better integrated with actions -from a different plug-in?  Let's look at how the external -tools plug-in (org.eclipse.ui.externaltools) integrates its action with the debugger tool bar.  The -debugger (org.eclipse.debug.ui) defines its tool bar actions like this:

-
<extension
-      point="org.eclipse.ui.actionSets">
-   <actionSet
-         label="%LaunchActionSet.label"
-         visible="false"
-         id="org.eclipse.debug.ui.launchActionSet">
-   ...
-   <action
-         toolbarPath="debug"
-         id="org.eclipse.debug.internal.ui.actions.RunDropDownAction"
-         hoverIcon="icons/full/ctool16/run_exc.png"
-         class="org.eclipse.debug.internal.ui.actions.RunToolbarAction"
-         disabledIcon="icons/full/dtool16/run_exc.png"
-         icon="icons/full/etool16/run_exc.png"
-         helpContextId="run_action_context"
-         label="%RunDropDownAction.label"
-         pulldown="true">
-   </action>
-   ...
-

Just like the readme tool, the debugger plug-in defines its own tool bar -path, which means its tool bar items will be inside their own tool bar on the -workbench.  What does the external tools plug-in do?

-
<extension point="org.eclipse.ui.actionSets">
-	<actionSet
-		id="org.eclipse.ui.externaltools.ExternalToolsSet"
-		label="%ActionSet.externalTools"
-		visible="true">
-		...
-		<action
-			id="org.eclipse.ui.externaltools.ExternalToolMenuDelegateToolbar"
-			definitionId= "org.eclipse.ui.externaltools.ExternalToolMenuDelegateToolbar"
-			label="%Action.externalTools"
-			toolbarPath="org.eclipse.debug.ui.launchActionSet/debug"
-			disabledIcon="icons/full/dtool16/external_tools.png"
-			icon="icons/full/etool16/external_tools.png"
-			hoverIcon="icons/full/ctool16/external_tools.png"
-			tooltip="%Action.externalToolsTip"
-			pulldown="true"
-			class="org.eclipse.ui.externaltools.internal.menu.ExternalToolMenuDelegate">
-		</action>
-	</actionSet>
-</extension>

Note the use of the action set ID of the -debugger in the tool bar path.  Using an action set ID in the path denotes -that the tool bar item should be placed in the tool bar used by the referenced -action set.  Within a toolbar group, items are ordered by action set id, so -for our example, the external tools action will appear after the debugger actions. 

-

When adding to an action set's tool bar, new groups can also be defined.  -If the external tools plug-in defined its toolbarpath as -"org.eclipse.debug.ui.launchActionSet/external" a new group would be created -for the action on the tool bar.  As with menus, tool bar groups are delineated by separators. 

-

Using paths from another plug-in

- - -

In general, it's not good practice to contribute to another plug-in's menu -or tool bar by deriving the path name from the plugin.xml unless it has -been marked specifically as being available for clients.  It's possible that a future version of the plug-in could change the names of the -paths.  Two common ways to mark your plug-in's action set ids and paths as -fair game are:

- - - - - - - - - - Index: guide/workbench_menus.htm =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.platform.doc.isv/guide/workbench_menus.htm,v retrieving revision 1.21 diff -u -r1.21 workbench_menus.htm --- guide/workbench_menus.htm 24 Mar 2009 13:59:46 -0000 1.21 +++ guide/workbench_menus.htm 9 Jun 2011 12:43:46 -0000 @@ -37,100 +37,14 @@

-viewActions

- - -

-Actions appear in a specific view's local toolbar and local pulldown menu.

- - -

-Contribute an action class that implements IViewActionDelegate. Specify the id of the contribution and the id of the target view that should show the action. The label and image -dictate the appearance of the action in the UI. The path specifies the location relative to the view's menu and toolbar items.

- - - - -

editorActions

- - -

-Actions are associated with an editor and appear in the workbench menu and/or tool bar.

- - -

-Contribute an action class that implements IEditorActionDelegate. Specify the id of the contribution and the id of the target editor that causes the action to be shown. The label and image specify the appearance of the action in the UI. Separate menu and toolbar paths specify the existence and location of the contribution in the workbench menu and toolbar.

- - - - -

- -popupMenus

- - -

-Actions appear in the popup menu of an editor or view. Actions associated with an object type show up in all popups of views -and editors that show the object type. Actions associated with a specific popup menu appear only in that popup menu.

- - -

- -Object contributions specify the type of object for which the action should appear in a popup menu. The action will be shown in all view -and editor popups -that contain the object type.  Provide an action class that implements IObjectActionDelegate
- -Viewer contributions specify the id of the target popup menu in which the menu item should appear.  -Provide an action class that implements IEditorActionDelegate -or IViewActionDelegate

- - - - -

- -actionSets

- - -

-Actions appear in the workbench main menus and toolbar. Actions are grouped into action sets. All actions in an action set will show up in the workbench menus and toolbars according to the user's selection of action sets -and the current perspective shown in the workbench.  May be influenced by -actionSetPartAssociations (below).

- - -

-Contribute an action class that implements IWorkbenchWindowActionDelegate or -IWorkbenchWindowPulldownDelegate. Specify the - name and id of the action set. Enumerate all of the actions that are defined for that action set. For each action, separate menu and toolbar paths specify the existence and location of the contribution in the workbench menu and toolbar.

- - - - -

- -actionSetPartAssociations

- - -

Actions sets are shown only when the specified views or -editors are active.  This is ignored if the user has customized the current -perspective.

- - -

-Specify an action set by id and followed by one or more parts (by id) -that must be active in the current perspective in order to show the action set.

- - - - -

- menus

-Commands can be placed in all of the locations covered by the 4 main action -extension points, plus other trim areas. +Commands can be placed in the main menu and toolbar. Command can be placed in +part context menus, as well as view menus and view toolbars. The placement +is controlled by the locationURI and the visibility is controlled by +the visibleWhen core expression.

@@ -143,7 +57,11 @@ - +

This replaces the old action extension points, actionSets, editorActions, +viewActions, +popupMenus, +and actionSetPartAssociations. +

Index: guide/workbench_plugin.htm =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.platform.doc.isv/guide/workbench_plugin.htm,v retrieving revision 1.26 diff -u -r1.26 workbench_plugin.htm --- guide/workbench_plugin.htm 24 Mar 2009 13:59:39 -0000 1.26 +++ guide/workbench_plugin.htm 9 Jun 2011 12:43:46 -0000 @@ -17,8 +17,8 @@

The plug-in class

-So far, we've been looking at the different extensions that are provided by the readme tool. Let's look at the general -definition of the readme tool plug-in.

+So far, we've been looking at the different extensions that are provided by the contributions plug-in. Let's look at the general +definition of the contributions plug-in.

Plug-in definition

@@ -27,51 +27,43 @@
 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
-Bundle-Name: %Plugin.name
-Bundle-SymbolicName: org.eclipse.ui.examples.readmetool; singleton:=true
-Bundle-Version: 3.3.0.qualifier
-Bundle-ClassPath: readmetool.jar
-Bundle-Activator: org.eclipse.ui.examples.readmetool.ReadmePlugin
-Bundle-Vendor: %Plugin.providerName
-Bundle-Localization: plugin
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.resources,
+Bundle-Name: %contributions.Activator.name
+Bundle-SymbolicName: org.eclipse.ui.examples.contributions; singleton:=true
+Bundle-Version: 3.3.100.qualifier
+Bundle-Activator: org.eclipse.ui.examples.contributions.Activator
+Require-Bundle: org.eclipse.ui;bundle-version="[3.3.0,4.0.0)",
  org.eclipse.core.runtime,
- org.eclipse.ui.views,
- org.eclipse.ui.ide,
- org.eclipse.jface.text,
- org.eclipse.text,
- org.eclipse.ui.workbench.texteditor,
- org.eclipse.ui.editors
-Eclipse-AutoStart: true
-Eclipse-AutoStart-comment: Use Eclipse-AutoStart instead of Eclipse-LazyStart because the readme example should run against 3.1 as well as 3.2.
+ org.eclipse.core.expressions;bundle-version="[3.3.0,4.0.0)"
+Bundle-Vendor: %contributions.Activator.providerName
+Bundle-Localization: plugin
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
+Bundle-ActivationPolicy: lazy
 

The plug-in definition includes the Bundle-Name, Bundle-SymbolicName (plug-in id), Bundle-Version, and Bundle-Vendor of the plug-in. We -saw most of these parameters before in our hello world plug-in. The readme tool also defines a specialized plug-in class, -ReadmePlugin.

-

-The name of the jar file is also provided. File names specified in Bundle-ClassPath are relative to the -plug-in's directory, so the readme tool's jar file should be located directly in the plug-in's directory.

+saw most of these parameters before in our hello world plug-in. The contribution plug-in +also defines a specialized plug-in class, +org.eclipse.ui.examples.contributions.Activator.

-The Require-Bundle element informs the platform of the readme tool's dependencies. -The workbench UI plug-ins are listed as required plug-ins, along with the various core, jface, and text plug-ins.

+The Require-Bundle element informs the platform of the contribution plug-in's dependencies. +The workbench UI plug-ins are listed as required plug-ins, along with the various core and expression plug-ins.

AbstractUIPlugin

-The ReadmePlugin class represents the readme -tool plug-in and manages the life cycle of the plug-in.  As we saw in the +The Activator class represents the contribution plug-in +and manages the life cycle of the plug-in.  As we saw in the Hello World example, you don't have to specify a plug-in class.  The platform will provide one for you.  In this case, our plug-in needs to -initialize UI related data when it starts up.  The platform class AbstractUIPlugin +initialize UI related data when it starts up.  +The platform class AbstractUIPlugin provides a structure for managing UI resources and is extended by -ReadmePlugin.

+Activator.

AbstractUIPlugin uses the generic startup and shutdown methods to manage images, dialog settings, and a preference store during the lifetime of the plug-in.  -We'll look at the specifics of the ReadmePlugin class when we work with dialogs and preferences.

+

Index: guide/wrkAdv_keyBindings_actionDef.htm =================================================================== RCS file: guide/wrkAdv_keyBindings_actionDef.htm diff -N guide/wrkAdv_keyBindings_actionDef.htm --- guide/wrkAdv_keyBindings_actionDef.htm 24 Mar 2009 13:59:39 -0000 1.25 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,89 +0,0 @@ - - - - - - - - - - -Commands - - - - - -

Commands

- -

See the org.eclipse.ui.commands -section for defining command definitions. -

- -

Associating an action with a command

- - -

Actions can be associated with a command in code or in the plugin.xml -for action sets.  -Your choice depends on where the action is defined.

- - -

Actions that are instantiated in code can also be associated with an action -definition using IAction -protocol.  This is typically done when the action is created.  The SaveAction -uses this technique when it initializes itself.

- - -
-public SaveAction(IWorkbenchWindow window) {
-	...
-	setText...
-	setToolTipText...
-	setImageDescriptor...
-	setActionDefinitionId("org.eclipse.ui.file.save"); 
-}
-
- -

(Note:  The method name setActionDefinitionID could more -appropriately be named setCommandID.  The method name reflects the -original implementation of key bindings and uses outdated terminology.)

- - -

By invoking setActionDefinitionID, the implementation action (SaveAction) is associated with -the command id that was used in the command definition markup. It is good practice to define constants for your action definitions so that -they are easily referenced in code.

- -

If you define an -action in an action set, then you typically do not need to -instantiate an action yourself.  The workbench will do it for you when the user -invokes your action from a menu or the keyboard.  In this case, you can -associate your action with a command ID in your  XML markup.  The -following shows a hypothetical markup for an action set:

- -
-<extension point = "org.eclipse.ui.actionSets">
-	   <actionSet id="com.example.actions.actionSet"
-		   label="Example Actions"
-		   visible="true">
-		   <action id="com.example.actions.action1"
-			   menubarPath="additions"
-			   label="Example Save Action"
-			   class="org.example.actions.ExampleActionDelegate"
-			   definitionId="org.eclipse.ui.file.save">
-		   </action>
-		   ...
-	   </actionSet>
-   </extension>
-

The definitionId attribute is used to declare a command ID for the action.

- - -

Using either technique, associating your action with a command ID causes any key bindings that get defined for the -command org.eclipse.ui.file.save -to invoke your action when appropriate. 

- - -

Now let's look at how these key bindings get defined.

- - - - Index: guide/wrkAdv_retarget.htm =================================================================== RCS file: guide/wrkAdv_retarget.htm diff -N guide/wrkAdv_retarget.htm --- guide/wrkAdv_retarget.htm 24 Mar 2009 13:59:40 -0000 1.19 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,132 +0,0 @@ - - - - - - - - - - -Retargetable actions - - - - - -

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 menuEdit menuNavigate menuProject menu
viewsmove
- rename
- refresh
- properties
 go into
- go to resource
- sync with editor
- back
- forward
- up
- next
- previous
open
- close
- build
- rebuild
editorsrevert
- 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 action -handler.

- - - - - Index: guide/wrkAdv_retarget_contribute.htm =================================================================== RCS file: guide/wrkAdv_retarget_contribute.htm diff -N guide/wrkAdv_retarget_contribute.htm --- guide/wrkAdv_retarget_contribute.htm 24 Mar 2009 13:59:47 -0000 1.13 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,40 +0,0 @@ - - - - - - - - - - -Contributing new retargetable actions - - - - - -

Contributing new retargetable actions

-

The workbench is not the only plug-in that can create retargetable -actions.  Your plug-in can define its own retargetable action, so that -views and editors within your plug-in can share the same menu actions.  -There are two ways to contribute retargetable actions from your plug-in:

- -

This mechanism is useful for providing tight integration between editors and -related views.  For example, a content outline view can implement a handler -for an action defined by its associated editor.  

-

The readme -tool example demonstrates both of these techniques.

- - - - - Index: guide/wrkAdv_retarget_contribute_actionsets.htm =================================================================== RCS file: guide/wrkAdv_retarget_contribute_actionsets.htm diff -N guide/wrkAdv_retarget_contribute_actionsets.htm --- guide/wrkAdv_retarget_contribute_actionsets.htm 24 Mar 2009 13:59:52 -0000 1.19 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,119 +0,0 @@ - - - - - - - - - - -Retargetable action set actions - - - - - -

Retargetable action set actions

-

The readme -tool action set also defines retargetable actions.  The action remains -visible as long as the readme action set is visible, but it is only enabled when -a view or editor that implements the action is active.  When using action -sets to define retargetable actions, the actions are created in the action set -markup rather than in code.  The following is from the readme tool's action -set definition:

-
<extension point = "org.eclipse.ui.actionSets">
-	   <actionSet id="org_eclipse_ui_examples_readmetool_actionSet"
-		   label="%ActionSet.name"
-		   visible="true">
-...
-<action id="org_eclipse_ui_examples_readmetool_readmeRetargetAction"
-   menubarPath="window/org_eclipse_ui_examples_readmetool/slot1"
-   toolbarPath="readme"
-   label="%ReadmeRetargetAction.label"
-   tooltip="%ReadmeRetargetAction.tooltip"
-   helpContextId="org.eclipse.ui.examples.readmetool.open_browser_action_context"
-   icon="icons/ctool16/openbrwsr.png"
-   retarget="true">
-</action>
-<action id="org_eclipse_ui_examples_readmetool_readmeRelabelRetargetAction"
-   menubarPath="window/org_eclipse_ui_examples_readmetool/slot1"
-   toolbarPath="readme"
-   label="%ReadmeRelabelRetargetAction.label"
-   tooltip="%ReadmeRelabelRetargetAction.tooltip"
-   helpContextId="org.eclipse.ui.examples.readmetool.open_browser_action_context"
-   icon="icons/ctool16/openbrwsr.png"
-   retarget="true"	
-   allowLabelUpdate="true">
-</action>
-...
-

Retargeted actions are specified by using the retarget="true" -attribute.  This will cause a RetargetAction -to be created in the action set.  Note that the retargetable actions do not specify an implementing -class since it is up to each view or editor in the plug-in to set up a -handler that implements each action.  If the allowLabelUpdate is -true, then a LabelRetargetAction -will be created instead.

-

The retargeted actions will be visible in the window menu when the readme -action set is visible.  However, they will not be enabled if the readme -tool's editor or outline view are not active.

-

Readme File Editor menu with two grayed items and one enabled item

-

 

-

What do the editor and view have to do?  Again, the client side is -similar to registering a handler for the workbench or an editor's retargetable -action.  The action id specified in the markup must be used when -registering a global action handler.

-

The ReadmeEditorActionBarContributor takes care of this for the -editor.  First, it defines the handlers for the actions.

-
public ReadmeEditorActionBarContributor() {
-	...
-	handler4 = new EditorAction(MessageUtil.getString("Editor_Action4")); 
-	handler5 = new EditorAction(MessageUtil.getString("Editor_Action5")); 
-	handler5.setToolTipText(MessageUtil.getString("Readme_Editor_Action5"));
-	...
-}
-

The handlers are registered at the same time that the handlers for the editor -retargetable actions were registered.

-
public void init(IActionBars bars, IWorkbenchPage page) {
-	...
-	bars.setGlobalActionHandler(IReadmeConstants.ACTION_SET_RETARGET4, handler4);
-	bars.setGlobalActionHandler(IReadmeConstants.ACTION_SET_LABELRETARGET5, handler5);
-	...
-}
-

Recall that action bar contributors are shared among different instances of -the same editor.  This means the handlers must be notified if the active -editor for the ReadmeEditorActionBarContributor changes.

-
public void setActiveEditor(IEditorPart editor) {
-	...
-	handler4.setActiveEditor(editor);
-	handler5.setActiveEditor(editor);
-	...
-}
-

That's it for the editor.  We should see these actions enable when the -editor is activated.

-

Readme File Editor menu with actions enabled 

-

Note that the label for the first retargetable action ("Editor Action -4") was not used since the action set XML markup did not set allowLabelUpdate.

-

The ReadmeContentOutlinePage - defines its handlers in the same place it defined handlers for the editor's -retargetable actions:

-
public void createControl(Composite parent) {
-	...
-	action = new OutlineAction(MessageUtil.getString("Outline_Action4")); 
-	getSite().getActionBars().setGlobalActionHandler(
-		IReadmeConstants.ACTION_SET_RETARGET4, 
-		action);  
-	action = new OutlineAction(MessageUtil.getString("Outline_Action5")); 
-	action.setToolTipText(MessageUtil.getString("Readme_Outline_Action5")); 
-	getSite().getActionBars().setGlobalActionHandler(
-		IReadmeConstants.ACTION_SET_LABELRETARGET5, 
-		action);  
-}
-

We should see its relabeled action when the content outliner is active.

-

Readme File Editor menu with renamed action

-

 

- - - - - Index: guide/wrkAdv_retarget_contribute_editors.htm =================================================================== RCS file: guide/wrkAdv_retarget_contribute_editors.htm diff -N guide/wrkAdv_retarget_contribute_editors.htm --- guide/wrkAdv_retarget_contribute_editors.htm 24 Mar 2009 13:59:39 -0000 1.17 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,132 +0,0 @@ - - - - - - - - - - -Retargetable editor actions - - - - - -

Retargetable editor actions

-

Recall that the readme -tool defines its own editor which contributes actions -to the workbench menu bar using its ReadmeEditorActionBarContributor.  

-
<extension
-    point = "org.eclipse.ui.editors">
-	<editor
-  	   id = "org.eclipse.ui.examples.readmetool.ReadmeEditor"
-  	   name="%Editors.ReadmeEditor"
-      	   icon="icons/obj16/editor.png"
-      	   class="org.eclipse.ui.examples.readmetool.ReadmeEditor"
-	   extensions="readme"
-           contributorClass="org.eclipse.ui.examples.readmetool.ReadmeEditorActionBarContributor">
-	</editor>
-</extension>
-

Let's look closer at what happens in the contributor class.

-
public ReadmeEditorActionBarContributor() {
-	...
-	action2 = new RetargetAction(IReadmeConstants.RETARGET2, MessageUtil.getString("Editor_Action2"));
-	action2.setToolTipText(MessageUtil.getString("Readme_Editor_Action2"));
-	action2.setDisabledImageDescriptor(ReadmeImages.EDITOR_ACTION2_IMAGE_DISABLE);
-	action2.setImageDescriptor(ReadmeImages.EDITOR_ACTION2_IMAGE_ENABLE);
-	...
-	action3 = new LabelRetargetAction(IReadmeConstants.LABELRETARGET3, MessageUtil.getString("Editor_Action3"));
-	action3.setDisabledImageDescriptor(ReadmeImages.EDITOR_ACTION3_IMAGE_DISABLE);
-	action3.setImageDescriptor(ReadmeImages.EDITOR_ACTION3_IMAGE_ENABLE);
-	...  
-	handler2 = new EditorAction(MessageUtil.getString("Editor_Action2")); 
-	...
-	handler3 = new EditorAction(MessageUtil.getString("Editor_Action3")); 
-	...
-

When the contributor is created, it creates two retargetable actions (one -that allows label update and one that does not).  Creation of the actions -uses the same technique that the workbench uses.  It also creates two -handlers that will be used for the actions when the editor is the active -part.  

-

But where are the handlers for the actions registered?  Setting the -global handlers is done a little differently when your editor defines the -retargeted actions.  Why?  Because your contributor is in charge of -tracking the active view and hooking different handlers as different views or -the editor itself becomes active.  (The workbench does this for you when -you set a handler for one of its global actions).  Here's how the ReadmeEditorActionBarContributor -sets things up:

-
public void init(IActionBars bars, IWorkbenchPage page) {
-	super.init(bars, page);
-	bars.setGlobalActionHandler(IReadmeConstants.RETARGET2, handler2);
-	bars.setGlobalActionHandler(IReadmeConstants.LABELRETARGET3, handler3);
-	...
-

First, the contributor registers its handlers for the retargeted -actions.  This ensures that the contributor's actions will be run when the -editor itself is active.  The next step is to register each RetargetAction -as a part listener on the page.

-
	...
-	// Hook retarget actions as page listeners
-	page.addPartListener(action2);
-	page.addPartListener(action3);
-	IWorkbenchPart activePart = page.getActivePart();
-	if (activePart != null) {
-		action2.partActivated(activePart);
-		action3.partActivated(activePart);
-	}
-}
-

Adding each RetargetAction -as a part listener means that it will be notified when the active part -changes.  The action can get the correct global handler from the newly -activated part.  (See the implementation of RetargetAction -for all the details.)   Note that to start, the action is seeded -with the currently active part.

-

When the editor contributor is disposed, it should unhook the retargetable -actions as page listeners.

-
public void dispose() {
-	// Remove retarget actions as page listeners
-	getPage().removePartListener(action2);
-	getPage().removePartListener(action3);
-}
-

Finally, recall that action bar contributors are shared among instances of -the same editor class.  For this reason, the handlers must be notified when -the active editor changes so that they can connect to the proper editor -instance.

-
public void setActiveEditor(IEditorPart editor) {
-	...
-	handler2.setActiveEditor(editor);
-	handler3.setActiveEditor(editor);
-	...
-}
-

That completes the setup on the editor side.  When the editor is open -and active, the handlers (and their labels) as defined by the ReadmeEditorActionBarContributor -will appear in the workbench menu bar.

-

Readme menu with three editor actions in workbench menu bar

-

Now that the editor's contributions are in place, what does a view do to register a handler?  The code on the client side -is similar to registering a handler for a workbench action, except that the -action id is the one defined by the plug-in's editor.  The ReadmeContentOutlinePage -registers a handler for these actions.

-
public void createControl(Composite parent) {
-	super.createControl(parent);
-	...
-	getSite().getActionBars().setGlobalActionHandler(
-		IReadmeConstants.RETARGET2, 
-		new OutlineAction(MessageUtil.getString("Outline_Action2")));  
-
-	OutlineAction action = new OutlineAction(MessageUtil.getString("Outline_Action3")); 
-	action.setToolTipText(MessageUtil.getString("Readme_Outline_Action3")); 
-	getSite().getActionBars().setGlobalActionHandler(
-		IReadmeConstants.LABELRETARGET3, 
-		action);  
-	...
-

Note that the outliner sets tool tip text and a label on the second action, -since it allows relabeling.  When the readme outliner view is made active, -its handlers (and their labels) will now appear in the workbench menu bar.

-

Readme menu with one renamed editor action

-

Note that the relabeled action shows the new label.

- - - - - Index: guide/wrkAdv_retarget_setting.htm =================================================================== RCS file: guide/wrkAdv_retarget_setting.htm diff -N guide/wrkAdv_retarget_setting.htm --- guide/wrkAdv_retarget_setting.htm 24 Mar 2009 13:59:48 -0000 1.17 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,57 +0,0 @@ - - - - - - - - - - -Setting a global action handler - - - - - -

Setting a global action handler

-

A plug-in contributes a retargetable action -for a view or editor part by implementing an IAction -and registering it as a global action handler with the part's action bars.  -In views, this is usually done at the time that the part creates its actions and -controls. For editors see Retargetable editor actions. -The name of the retargeted action (as defined in IWorkbenchActionConstants) -is used to specify which action the handler is intended for.  The following -shows how the workbench task list view registers its handler for the PROPERTIES -action.

-
public void createPartControl(Composite parent) {
-	...
-	makeActions();
-	...
-
-	// Add global action handlers.
-	...	
-	getViewSite().getActionBars().setGlobalActionHandler(
-		IWorkbenchActionConstants.PROPERTIES,
-		propertiesAction);
-	...
-

The properties action is created in the local method makeActions:

-
void makeActions() {
-	...
-	// properties
-	propertiesAction = new TaskPropertiesAction(this, "properties"); 
-	propertiesAction.setText(TaskListMessages.getString("Properties.text")); 
-	propertiesAction.setToolTipText(TaskListMessages.getString("Properties.tooltip")); 
-	propertiesAction.setEnabled(false);
-}
-

That's all that is needed.  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.  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. -

- - - - - Index: topics_Guide.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.platform.doc.isv/topics_Guide.xml,v retrieving revision 1.210 diff -u -r1.210 topics_Guide.xml --- topics_Guide.xml 10 May 2011 09:28:51 -0000 1.210 +++ topics_Guide.xml 9 Jun 2011 12:43:45 -0000 @@ -62,15 +62,9 @@ - + - - - - - - @@ -201,16 +195,6 @@ - - - - - - - - - - @@ -220,7 +204,6 @@ -