10.2. Enhancing an Existing PerspectiveIn addition to creating a new perspective, you can also extend an existing perspective by adding new views, placeholders, shortcuts, and action sets. To illustrate this, you can add several extensions to the standard Resource perspective. To extend an existing perspective, open the Favorites plug-in manifest editor, select the Extensions tab, and click the Add button to open the New Extension wizard. Select the org.eclipse.ui.perspectiveExtensions extension point from the list of available extension points (see Figure 10-6). Figure 10-6. The New Extension wizard showing the org.eclipse.ui.perspectiveExtensions extension point selected.
On the Extensions page of the plug-in manifest editor, right-click on the org.eclipse.ui.perspectiveExtensions extension and select New > perspectiveExtension. This immediately adds a perspective extension named com.qualityeclipse.favorites.perspectiveExtension1 to the plug-in manifest. Click on this new perspective extension to display its properties and change the targetID field to "org.eclipse.ui.resourcePerspective" (see Figure 10-7). This will change the name of the perspective extension as seen on the Extensions page. Figure 10-7. The extension element details showing the perspective extension's attributes.
When the perspective extension has been created, a number of different extension types can be added, including views, placeholders, action sets, as well as shortcuts for views, perspectives, and the new wizards. 10.2.1. Adding views and placeholdersA view can be either directly added to an existing perspective or a placeholder can be added so that when the user opens the view it appears in the correct place. As an example, add the Favorites view to the standard Resource perspective. On the Extensions page, click on the newly created org.eclipse.ui.resourcePerspective extension and select New > view. This immediately adds a perspective view extension named com.quality-eclipse.favorites.view1 to the plug-in manifest. Clicking on this new extension shows its properties, which should be modified as follows (see Figure 10-8). Figure 10-8. The extension element details showing the perspective view extension's attributes.
The name of the perspective view extension as seen on the Extensions page will change to reflect the id entered. In addition to being stacked in a folder relative to another view, the added view could be placed at the left, right, above, or below the view specified in the relative field, or added as a fast view in the left toolbar. If the new view is added at the left, right, above, or below, the ratio of space that the new view takes from the old view can also be specified. If the visible field is specified as true, the new view will open when the perspective is opened. If it is set to false, the view will not open automatically. Rather, a placeholder will be established that defines the initial location of the view, if it is ever opened by a user. Switching to the plugin.xml page of the plug-in manifest editor, you will see the following new section of XML defining the new perspective extension. <extension point="org.eclipse.ui.perspectiveExtensions"> <perspectiveExtension targetID="org.eclipse.ui.resourcePerspective"> <view id="com.qualityeclipse.favorites.views.FavoritesView"> relationship="stack" relative="org.eclipse.ui.views.TaskList" visible="true" </view> </perspectiveExtension> </extension> When the Resource perspective is opened, the Favorites view will appear stacked relative to the Tasks view (see Figure 10-9). Figure 10-9. The Resource perspective showing the Favorites view.10.2.2. Adding shortcutsShortcuts for quickly accessing related views, perspectives, and new wizards can also be added to a perspective. As an example, add shortcuts for accessing the Favorites view and perspective to the Resources perspective. Start by adding a view shortcut for accessing the Favorites view from the Resource perspective. On the Extensions page, right-click on the org.eclipse.ui.resourcePerspective extension and select New > viewShortcut. This adds a view shortcut extension named com.quality-eclipse.favorites.viewShortcut1 to the plug-in manifest. Click on it to show its properties and then change the id field to "com.quality-eclipse.favorites.views.FavoritesView" (see Figure 10-10). This will change the name of the view shortcut extension as seen on the Extensions page. Figure 10-10. The extension element details showing the view shortcut extension's attributes.
When the Resource perspective is opened, this will add a shortcut to the Favorites view on the Window > Show View menu (see Figure 10-11). Figure 10-11. The Show View menu showing the Favorites shortcut.
Next, add a perspective shortcut for accessing the Favorites perspective from the Resource perspective. On the Extensions page, right-click on the org.eclipse.ui.resourcePerspective extension and select New > perspectiveShortcut. This adds a perspective shortcut extension named com.qualityeclipse.favorites.perspectiveShortcut1 to the plug-in manifest. Click on it to show its properties and then change the id field to "com.qualityeclipse.favorites.FavoritesPerspective" (see Figure 10-12). This will change the name of the perspective shortcut extension as seen on the Extensions page. Figure 10-12. The extension element details showing the perspective shortcut extension's attributes.
When the Resource perspective is opened, this will add a shortcut to the Favorites view on the Window > Open Perspective menu (see Figure 10-13). Figure 10-13. The Open Perspective menu showing the Favorites shortcut.
If you switch to the plug-in manifest editor's plugin.xml page, you will see this added section of XML defining the new view and perspective shortcuts: <extension point="org.eclipse.ui.perspectiveExtensions"> <perspectiveExtension targetID="org.eclipse.ui.resourcePerspective"> ... <viewShortcut id="com.qualityeclipse.favorites.views.FavoritesView"/> <perspectiveShortcut id="com.qualityeclipse.favorites.FavoritesPerspective"/> </perspectiveExtension> </extension> 10.2.3. Adding action setsGroups of commands (menu items and toolbar buttons) defined in action sets can also be added to a perspective (see Chapter 6, Actions, for more about adding actions). As an example, add the Favorites action set to the Resources perspective. On the Extensions page, right-click on the org.eclipse.ui.resourcePerspective extension and select New > actionSet. This adds an action set extension, com.qualityeclipse.favorites.actionSet1, to the plug-in manifest. Click on this action set to reveal its properties and change the id field to "com.qualityeclipse.favorites.workbenchActionSet" (see Figure 10-14). This will change the action set extension's name as seen on the Extensions page. Figure 10-14. The extension element details showing the action set extension's attributes.
If you switch to the plugin.xml page of the plug-in manifest editor, you will see the following added section of XML defining the new action set extension. <extension point="org.eclipse.ui.perspectiveExtensions"> <perspectiveExtension targetID="org.eclipse.ui.resourcePerspective"> ... <actionSet id="com.qualityeclipse.favorites.workbenchActionSet"/> </perspectiveExtension> </extension> With the above enhancements in place, the new perspective and perspective extensions will now be visible on the Extensions page (see Figure 10-15). Figure 10-15. The Extensions page showing the new perspective and perspective extensions. |