Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to display the command's drop-down menu after the command icon is clicked?
How to display the command's drop-down menu after the command icon is clicked? [message #1062907] Tue, 11 June 2013 06:56 Go to next message
Eclipse UserFriend
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"
           icon="icons/Command1.png"
           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 icon 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 is to show the drop-down menu not only after the user clicks the drop-down symbol next to the Command1 icon, but also after the user clicks the Command1 icon itself.

(for example, this is how the Open Console command works in the Console view's toolbar in Eclipse)

I guess I need to programmatically trigger displaying the Command1 drop-down menu from within the Command1 handler but I couldn't find any examples on how to do that.

Thanks in advance for any help!

Re: How to display the command's drop-down menu after the command icon is clicked? [message #1062942 is a reply to message #1062907] Tue, 11 June 2013 09:47 Go to previous messageGo to next message
Eclipse UserFriend
We had to do the same thing on our project, and it's pretty simple. All you have to do is add a handler to your pulldown command. Our execute method looks like this:

// Sanity check.
if ( null == event ) {
    return null;
}

// Class check.
if ( ! ( event.getTrigger() instanceof Event ) ) {
    return null;
}

Event eventWidget = (Event)event.getTrigger();

// Makes sure event came from a ToolItem.
if ( ! ( eventWidget.widget instanceof ToolItem ) ) {
    return null;
}

ToolItem toolItem = (ToolItem)eventWidget.widget;

// Creates fake selection event.
Event newEvent = new Event();
newEvent.button = 1;
newEvent.widget = toolItem;
newEvent.detail = SWT.ARROW;
newEvent.x = toolItem.getBounds().x;
newEvent.y = toolItem.getBounds().y + toolItem.getBounds().height;

// Dispatches the event.
toolItem.notifyListeners( SWT.Selection, newEvent );

return null;	

[Updated on: Tue, 11 June 2013 09:47] by Moderator

Re: How to display the command's drop-down menu after the command icon is clicked? [message #1063045 is a reply to message #1062942] Tue, 11 June 2013 17:21 Go to previous message
Eclipse UserFriend
that's exactly the trick I was looking for - works like a charm, thanks!

Previous Topic:If I create clones of a perspective, can I make them independent of each other?
Next Topic:Eclipse RCP APPlication
Goto Forum:
  


Current Time: Sun Mar 16 19:27:30 EDT 2025

Powered by FUDForum. Page generated in 0.25335 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top