Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » DROP_DOWN_MENU not always displaying menu(AS_DROP_DOWN_MENU only displays menu when you click on 'arrow' area, not the regular button area)
DROP_DOWN_MENU not always displaying menu [message #753754] Fri, 28 October 2011 11:20 Go to next message
kfbecker is currently offline kfbecker
Messages: 2
Registered: October 2011
Junior Member
I've added some actions to my view in the form:

Action someToolAction = new Action("My Action",Action.AS_DROP_DOWN_MENU) {
...
}
MyMenuCreator myCreator = new MyMenuCreator();
someToolAction.setMenuCreator(myCreator);
IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager();
mgr.add(someToolAction);


This works fine as long as I select the drop down button by pressing on the down arrow, but when I press on the body of the button to the left of the arrow, I don't get the menu to display.

I see that I can separately catch this event using the run() or runWithEvent() methods in my Action definition. I can even get the menu to then pop up using something like:

Action someToolAction = new Action("My Action",Action.AS_DROP_DOWN_MENU) {
public void run() {
IMenuCreator imenu = this.getMenuCreator();
Menu menu = imenu.getMenu(parent);
menu.setVisible(true);
}

But that places the menu relative where my mouse was when I selected the button.

My question is this -- is there someway that I am missing to configure the drop down to do the same thing when I select the button body as when I select the button drop down arrow? If not, how do I get the location of the generated button so that I can properly place the popup?

Re: DROP_DOWN_MENU not always displaying menu [message #753782 is a reply to message #753754] Fri, 28 October 2011 13:34 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

No, that's working as designed. Dropdown tool items execute when you click the button, and open the dropdown menu when you click the little arrow.

PW


Re: DROP_DOWN_MENU not always displaying menu [message #753784 is a reply to message #753782] Fri, 28 October 2011 13:46 Go to previous messageGo to next message
kfbecker is currently offline kfbecker
Messages: 2
Registered: October 2011
Junior Member
so maybe I misunderstand the standard use of this button. For what you're describing, it sounds like the drop down should modify what happens when you press the button.

I was trying to make the drop down function like the 'File' menu button (similar to the open console button shown with the console tab in the eclipse gui). The arrow just made it more obvious that it was there to distinguish it from the

How about the secondary question, as to how to get it to work the way I want?
Is the standard approach for that to make it a push button and add a popup to display the menu? I assume it is easier to determine the location of the push button (something that didn't appear to be available when using the drop down option)
Re: DROP_DOWN_MENU not always displaying menu [message #872730 is a reply to message #753784] Wed, 16 May 2012 13:58 Go to previous message
John C is currently offline John C
Messages: 1
Registered: May 2012
Junior Member
I know this is an old thread, but the question - how do you get the pop down menu to open when the user clicks on the non latch part of a drop down button - was never answered.

I had the same question. This thread was the only relevant google hit I could find. It got me half way towards the solution. The handleWidgetSelection method in the ActionContributionItem class got me to the full solution.

The eventual method I used is below. I am the farthest thing from an eclipse rcp expert, so please feel free to suggest better alternatives.

    @Override
    public void runWithEvent(Event e) 
    {
        Widget item = e.widget;
        if (item != null) 
        {
            int style = item.getStyle();
            if ((style & SWT.DROP_DOWN) != 0) {
                IMenuCreator mc = getMenuCreator();
                ToolItem toolItem = (ToolItem) item;
                if (mc != null) {
                    Menu m = mc.getMenu(toolItem.getParent());
                    if (m != null) {
                        // position the menu below the drop down item
                        ToolBar toolbar = toolItem.getParent( );
                        // point is now set to toolbar location.
                        Point point = toolbar.toDisplay( new Point(e.x, e.y));
                        // move point over to beneath the button
                        point.x += toolItem.getBounds( ).x;
                        point.y += toolItem.getBounds( ).y + toolItem.getBounds( ).height;
                        m.setLocation(point.x, point.y); 
                        m.setVisible(true);
                        return; 
                    }
                }                
            }
        }
    }
Previous Topic:Can i distinguish the PartVisible event fired for detached view ?
Next Topic:Open Editor from within a Wizard?
Goto Forum:
  


Current Time: Sat Aug 02 04:46:40 EDT 2014

Powered by FUDForum. Page generated in 0.10691 seconds