Perspective ExtensionsPlug-ins can add action sets, views, and various shortcuts to existing perspectives by contributing to the org.jlense.uiworks.perspectiveExtensions extension point. That is, perspectiveExtensions are the mechanism for controlling what GUI components are made visible to the user when a particular perspective is active. For instance, if you want a particular set of menus and tool bar buttons (a.k.a. an action set) to appear when a particular perspective is active then add the menus to the perspective by creating an extension to the org.jlense.uiworks.perspectiveExtensions extension point. Views are also added to perspectives by creating an extension to the org.jlense.uiworks.perspectiveExtensions extension point. The contributions that can be defined for new perspectives (action sets, wizard entries, view layout, and view shortcuts) can also be supplied for an existing perspective. One important difference is that contributions to existing perspectives are specified in the plugin.xml markup instead of configuring them into an IPageLayout. The following markup shows how the JLedger application adds action sets and views to the JLedger Account perspective. <extension point="org.jlense.uiworks.perspectiveExtensions"> <perspectiveExtension targetID="org.jledger.ui.accounts"> <view id="org.jledger.ui.accounts.AccountsView" /> <!-- Add company actions to the workbench perspective --> <actionSet id="org.jledger.ui.CompanyActions"/> <newWizardShortcut id="org.jledger.ui.accounts.AccountWizard"/> <newWizardShortcut id="org.jledger.ui.gj.TransactionWizard"/> </perspectiveExtension> </extension>
Let's review the what the above perspective contributions mean with regard to the JLense Workbench.
<view id="org.jledger.ui.accounts.AccountsView" /> This perspective extension adds the Accounts View to the Accounts perspective. The Accounts view displays a list of all accounts in the active chart of accounts. <!-- Add company actions to the workbench perspective --> <actionSet id="org.jledger.ui.CompanyActions"/> This perspective extension adds an action set to the Accounts view. The CompanyActions action set contains actions for opening Charts of Accounts. These actions will be displayed on the main menu bar when the Accounts Perspective is active. If another perspective that doesn't include the CompanyActions action set becomes active then the CompanyActions menu item will disappear from the menu bar. <newWizardShortcut id="org.jledger.ui.accounts.AccountWizard"/> <newWizardShortcut id="org.jledger.ui.gj.TransactionWizard"/> These perspective extensions add shortcuts to the File | New menu for creating new Accounts and Transactions. So, when the Accounts perspective is the active perspective then shortcuts for creating new Accounts and transaction are displayed directly on the File | New menu. When a perspective that does not include these extensions is active then the File | New menu will not display these shortcuts. Contributing ViewsContributing a view to a perspective is a little more involved, since the perspective page layout information must be declared. Consider the following example: <extension point="org.eclipse.ui.perspectiveExtensions"> <perspectiveExtension targetID="org.eclipse.debug.ui.DebugPerspective"> <actionSet id="org.eclipse.jdt.debug.ui.JDTDebugActionSet"/> <view id="org.eclipse.jdt.debug.ui.DisplayView" relative="org.eclipse.debug.ui.ExpressionView" relationship="stack"/> </perspectiveExtension> </extension> The visible attribute controls whether the contributed view is initially visible when the perspective is opened. In addition to supplying the id of the contributed view, the id of a view that already exists in the perspective ( a relative view) must be specified as a reference point for placing the new view. The relationship parameter specifies the layout relationship between the new view and the relative view.
|