A.Richard
A.Richard

Reputation: 45

How to display the label of an item on the drop-down menu

In Eclipse RCP application I have a custom view and a drop-down command contributed into that view's toolbar:

 <menuContribution
            allPopups="false"
            locationURI="toolbar:test.ui.views.MyView">
         <command
               commandId="test.ui.commands.Command1"
               id="test.ui.commands.Command1.dropdown"
               label="Command 1"
               style="pulldown">
         </command>
      </menuContribution>

Then, I have a couple of other commands contributed into the Command1 drop-down menu like this:

  <menuContribution
        allPopups="false"
        locationURI="menu:test.ui.commands.Command1.dropdown">
     <command
           commandId="test.ui.commands.Command2"
           label="Command 2"
           style="push">
     </command>
     <command
           commandId="test.ui.commands.Command3"
           label="Command 3"
           style="push">
     </command>
  </menuContribution>

Until now everything works fine, I can see the Command1 label on the view's toolbar and when I click the drop-down symbol next to it, the menu shows up with the Command2 and Command3 commands - as expected.

Problem:

What I would like to achieve now, when I click the Command2 item, is to display the label of the Command2 in the drop-down menu instead of the drop-down Command1 label.

Thanks in advance for any help!

Upvotes: 1

Views: 308

Answers (1)

Paul Webster
Paul Webster

Reputation: 10654

You should be able to have your handler for Command 1 implement org.eclipse.ui.commands.IElementUpdater and at the appropriate time, call org.eclipse.ui.commands.ICommandService.refreshElements(String, Map).

In your IElementUpdater you have a chance to set the label for the UIElement (the main tool item).

Upvotes: 2

Related Questions