Home > Eclipse development, Linux, Software Development > Writing an Eclipse Plug-in (Part 17): Custom Project: Customizing the Perspective Menus Using Customize Perspective

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:

  1. Main menu File menu
  2. Toolbar
  3. 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.

  1. plugin.xml –>Extensions –> Add
  2. Select org.eclipse.ui.actionSets and click Finish
  3. Change label (actionSet) to:
    • id: customplugin.toolbar
    • label: Hidden Clause Toolbar Commands
  4. Save plugin.xml
  5. Start the runtime workbench
  6. 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
Advertisements
  1. January 16, 2010 at 5:30 pm

    Hi Carlos!:)

  2. nm
    November 22, 2010 at 8:56 am

    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.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: