Writing an Eclipse Plug-in (Part 17): Custom Project: Customizing the Perspective Menus Using Customize Perspective
Almost time to add submenus!
But not today. I said almost.
Today, I want to take a look at the Customize Perspective dialog, what we got for free and what we still have to do to get that final finished look.
Back in Part 15 I mentioned that we should update three things when we add a New Wizard:
- Main menu File menu
- Toolbar
- Customize Perspective window
In Part 15 we updated the File menu, in part 16 we updated the toolbar and now we will take a look at what needs to be done to allow us to customize the custom perspective’s version of the File menu and the toolbar.
Before we do that let’s take a look at what Eclipse gave us for free and review how a user might customize a perspective.
Start the runtime workbench, switch to the Custom Perspective and open the Customize Perspective window by doing the following:
- Window –> Open Perspective –> Other –> Custom Plug-in Perspective –> OK
- Window –> Customize Perspective
Click on the Menu Visibility tab.
From the Menu Structure list we can see that our three New Wizard types are already listed. If a user were to decide that they did not want to see one or more of the custom wizards they could simply uncheck the undesired types. Simply adding the items to perspectiveExtensions as newWizardShortcuts added them to the File –> New main menu, the toolbar New button and this user configuration window.
Clicking on the Command Groups Availability tab does not show us anything related to our current task.
Click on the Shortcuts tab.
The Submenus choice of New has our Custom Wizards all selected. Anything checked/unchecked here will have the same impact as the Menu Visibility tab; things will appear or disappear from the main menu File –> New submenu and from the toolbar New drop down button.
The Submenus choice of Open Perspective will display the checked item under the main menu Window –> Open Perspective submenu. Since none of the items are check none of them appear when the user selects Window –> Open Perspective (they see the ubiquitous Other).
The Submenus choice of Show View will display the checked item under the main menu Window –> Show View. Again, none are chosen so Other will be seen instead.
Click on the Tool Bar Visibility tab. Be prepared to cover your eyes; it could get ugly.
The Tool Bar Structure list shows the second entry as existing, having three entries, but no label. What happened?
Way back in the history of Eclipse, say the 3.5 release, the Platform Command Framework was introduced. It deprecated the use of the actionSets extension to both make adding commands simpler and more flexible. The recommended way of doing what we did was the way we did it: use the org.eclipse.ui.menus extension. There is only one problem: the actionSets extension is still useful and is the missing part of today’s puzzle.
Today’s puzzle: how do we give our toolbar group a label?
I’m glad you asked.
How (are we doing it?)
Let’s walk the steps to give our custom wizard toolbar commands a label.
- plugin.xml –>Extensions –> Add
- Select org.eclipse.ui.actionSets and click Finish
- Change label (actionSet) to:
- id: customplugin.toolbar
- label: Hidden Clause Toolbar Commands
- Save plugin.xml
- Start the runtime workbench
- Change to the Custom Perspective and go to Window –> Customize Perspective
Woo hoo! Yes, success tastes sweet.
Now use the Externalize Strings Wizard to move the string Hidden Clause Toolbar Commands to our properties file.
Why (did we do it that way?)
As you may have already guessed, not using the actionSets extension had 0 impact on the behavior of the buttons we added. None. Nada. Zilch.
That didn’t stop me from spending a few hours to track down the proper configuration to make sure that I had a respectable label for my new toolbar buttons. Why bother spending the time? Because it matters to the user even if that user is me or my most hated enemy (well, maybe not my most hated enemy).
In this case, the use of the actionSets extension just got us our label and burned part of my Saturday afternoon. The use of actionSets continues the configuration-only streak I like so much.
Hey, if I can’t burn a few hours to help spread the good word about Eclipse then what can I do?
The cat is alive and has company.
What Just Happened?
With a simple addition to plugin.xml we were able to complete a successful addition of New Wizard functionality to the main menu, the toolbar and the Customize Perspective window. I’m happy. I hope you are too (but that doesn’t matter to me so much).
Thanks
Thanks to Michael Scharf at the Eclipse and Java Blog for just the example I was looking for on how to give the Customize Perspective Tool Bar Visibility toolbar group a label using just configuration.
Reference
Every pixel counts! The new eclipse fullscreen plugin…
Code
No code! Again!
plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension
point="org.eclipse.ui.newWizards">
<category
id="customplugin.category.wizards"
name="%category.name">
</category>
<wizard
category="customplugin.category.wizards"
class="customplugin.wizards.CustomProjectNewWizard"
finalPerspective="customplugin.perspective"
icon="icons/project-folder.png"
id="customplugin.wizard.new.custom"
name="%wizard.name">
</wizard>
<wizard
category="customplugin.category.wizards"
class="customplugin.wizards.CustomProjectNewSchemaFile"
descriptionImage="icons/schema-file_32x32.png"
icon="icons/schema-file_16x16.png"
id="customplugin.wizard.file.schema"
name="%wizard.name.schema">
</wizard>
<wizard
category="customplugin.category.wizards"
class="customplugin.wizards.CustomProjectNewDeploymentFile"
descriptionImage="icons/deployment-file_32x32.png"
icon="icons/deployment-file_16x16.png"
id="customplugin.wizard.file.deployment"
name="%wizard.name.deployment">
</wizard>
</extension>
<extension
point="org.eclipse.ui.perspectives">
<perspective
class="customplugin.perspectives.Perspective"
icon="icons/perspective.png"
id="customplugin.perspective"
name="%perspective.name">
</perspective>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="customplugin.perspective">
<view
id="customnavigator.navigator"
minimized="false"
ratio=".25"
relationship="left"
relative="org.eclipse.ui.editorss">
</view>
</perspectiveExtension>
</extension>
<extension
id="customplugin.projectNature"
point="org.eclipse.core.resources.natures">
<runtime>
<run
class="customplugin.natures.ProjectNature">
</run>
</runtime>
</extension>
<extension
point="org.eclipse.ui.ide.projectNatureImages">
<image
icon="icons/project-folder.png"
id="customplugin.natureImage"
natureId="customplugin.projectNature">
</image>
</extension>
<extension
id="customplugin.contenttype"
point="org.eclipse.core.contenttype.contentTypes">
<content-type
base-type="org.eclipse.core.runtime.xml"
file-extensions="xml"
id="customplugin.contenttype.schema"
name="%content-type.name.schema"
priority="normal">
<describer
class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber2">
<parameter
name="element"
value="hc-schema">
</parameter>
</describer>
</content-type>
<content-type
base-type="org.eclipse.core.runtime.xml"
file-extensions="xml"
id="customplugin.contenttype.deployment"
name="%content-type.name.deployment"
priority="normal">
<describer
class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber2">
<parameter
name="element"
value="hc-deployment">
</parameter>
</describer>
</content-type>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="customplugin.perspective">
<newWizardShortcut
id="customplugin.wizard.new.custom">
</newWizardShortcut>
<newWizardShortcut
id="customplugin.wizard.file.schema">
</newWizardShortcut>
<newWizardShortcut
id="customplugin.wizard.file.deployment">
</newWizardShortcut>
</perspectiveExtension>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="customplugin.toolbar">
<command
commandId="org.eclipse.ui.newWizard"
icon="icons/project-folder.png"
label="%customproject.label"
style="push"
tooltip="%customproject.tooltip">
<parameter
name="newWizardId"
value="customplugin.wizard.new.custom">
</parameter>
<visibleWhen
checkEnabled="false">
<with
variable="activeWorkbenchWindow.activePerspective">
<equals
value="customplugin.perspective">
</equals>
</with>
</visibleWhen>
</command>
<command
commandId="org.eclipse.ui.newWizard"
icon="icons/schema-file_16x16.png"
label="%schema.label"
style="push"
tooltip="%schema.tooltip">
<parameter
name="newWizardId"
value="customplugin.wizard.file.schema">
</parameter>
<visibleWhen
checkEnabled="false">
<with
variable="activeWorkbenchWindow.activePerspective">
<equals
value="customplugin.perspective">
</equals>
</with>
</visibleWhen>
</command>
<command
commandId="org.eclipse.ui.newWizard"
icon="icons/deployment-file_16x16.png"
label="%deployment.label"
style="push"
tooltip="%deployment.tooltip">
<parameter
name="newWizardId"
value="customplugin.wizard.file.deployment">
</parameter>
<visibleWhen
checkEnabled="false">
<with
variable="activeWorkbenchWindow.activePerspective">
<equals
value="customplugin.perspective">
</equals>
</with>
</visibleWhen>
</command>
</toolbar>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.actionSets">
<actionSet
id="customplugin.toolbar"
label="Hidden Clause Toolbar Commands">
</actionSet>
</extension>
</plugin>
bundle.properties
#Properties file for customplugin Bundle-Name = Customplugin Plug-in category.name = Custom Wizards wizard.name = Custom Project perspective.name = Custom Plug-in Perspective content-type.name.schema = Hidden Clause Schema Definition content-type.name.deployment = Hidden Clause Deployment Definition wizard.name.schema = Schema File wizard.name.deployment = Deployment File customproject.label = New Custom Project customproject.tooltip = New Custom Project schema.label = New Schema File schema.tooltip = New Schema File deployment.label = New Deployment File deployment.tooltip = New Deployment File toolbar.actionSet.label = Hidden Clause Toolbar Commands
Share this:
Leave a Reply Cancel reply
Top Posts
- Kubuntu 11.10: Mapping the Windows Key to Activate KMenu
- Writing an Eclipse Plug-in (Part 4): Create a Custom Project in Eclipse - New Project Wizard: the Behavior
- Writing an Eclipse Plug-in (Part 2): Creating a custom project in Eclipse - Adding to the New Project Wizard
- Writing an Eclipse Plug-in (Part 7): Creating a Custom Navigator
- Writing an Eclipse Plug-in (Part 1)- What I'm going to do
Archives
- January 2012 (1)
- February 2011 (1)
- January 2011 (1)
- August 2010 (2)
- June 2010 (1)
- May 2010 (2)
- April 2010 (1)
- March 2010 (1)
- February 2010 (4)
- January 2010 (2)
- December 2009 (5)
- November 2009 (2)
- October 2009 (6)
- September 2009 (6)
- August 2009 (4)
- July 2009 (6)
- April 2009 (2)
- February 2009 (2)
- December 2008 (1)
- October 2008 (2)
- September 2008 (2)
- August 2008 (1)
Top Rated
Blog Stats
- 262,328 hits






Hi Carlos!:)
Hi,
I am not sure if you have covered this in later tutorials but the part where you add an action set to give a label to the toolbar visibility section in Customize Perspective…, is not necessary anymore in Eclipse 3.6 (Helios).
When you add the toolbar in the menucontribution under org.eclipse.ui.menus, then there are two properties to fill, id and label.
Where id is, as you say in your tutorial, ‘customplugin.toolbar’ and label is ‘Hidden Clause Toolbar Commands’. I have tested it and the label shows fine in the Customize Perspective… menu.