Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Adding a context menu like in the Eclipse Views
| | |
Re: Adding a context menu like in the Eclipse Views [message #465798 is a reply to message #465712] |
Tue, 20 December 2005 16:03 |
Jeremy Dowdall Messages: 48 Registered: July 2009 |
Member |
|
|
http://www.eclipse.org/swt/snippets/
under "ToolBar, ToolItem" is "place a drop down menu in a tool bar"
this will, however, create a toolbar with a down arrow centered
vertically. to get it more like the eclipse view's, AFAIK, you'll have
to use your own icon (make it 9x16 pixels) by changing:
final ToolItem item = new ToolItem (toolBar, SWT.DROP_DOWN);
to
final ToolItem item = new ToolItem (toolBar, SWT.FLAT);
and then setting the image with item.setImage(image)
Hans wrote:
> I need to add a context menu to a toolbar, to get a similar look and
> feel like the arrow-pointing-down in various Eclipse views. For example
> the Package Explorer's toolbar has a button on the right which on
> mouse-down displays a menu (with items such as Show, Select working set
> etc). How is this implemented?
>
> I couldn't dig deep enough into the Eclipse source to see how this is
> implemented, but my first attempts were to add an Action to the Toolbar
> with the image as icon and then I try to add a mouse listener to the
> item. However, at the point when I want to add the listener, the
> corresponding Button control is not created yet.
>
> Any ideas - thanks!
> Hans
|
|
|
Re: Adding a context menu like in the Eclipse Views [message #465862 is a reply to message #465798] |
Tue, 20 December 2005 17:04 |
Hans Messages: 36 Registered: July 2009 |
Member |
|
|
Thanks, Jeremy. The snippets page is a very useful reference. Your
suggestion with the smaller image is good (actually 10x16 is the correct
size).
However, the remaining problem is that I don't see how I can react on
SWT.MouseDown - the only event that seems to work is SWT.Selection.
SWT.MouseDown does not seem to trigger any event.
final ToolItem item = new ToolItem (toolBar, SWT.FLAT);
item.addListener(SWT.Selection, new Listener () {
public void handleEvent (Event event) {
openContextMenu(toolBar, item);
}
});
Hans
Jeremy Dowdall wrote:
> http://www.eclipse.org/swt/snippets/
> under "ToolBar, ToolItem" is "place a drop down menu in a tool bar"
>
> this will, however, create a toolbar with a down arrow centered
> vertically. to get it more like the eclipse view's, AFAIK, you'll have
> to use your own icon (make it 9x16 pixels) by changing:
> final ToolItem item = new ToolItem (toolBar, SWT.DROP_DOWN);
> to
> final ToolItem item = new ToolItem (toolBar, SWT.FLAT);
> and then setting the image with item.setImage(image)
>
>
> Hans wrote:
>
>> I need to add a context menu to a toolbar, to get a similar look and
>> feel like the arrow-pointing-down in various Eclipse views. For
>> example the Package Explorer's toolbar has a button on the right which
>> on mouse-down displays a menu (with items such as Show, Select working
>> set etc). How is this implemented?
>>
>> I couldn't dig deep enough into the Eclipse source to see how this is
>> implemented, but my first attempts were to add an Action to the
>> Toolbar with the image as icon and then I try to add a mouse listener
>> to the item. However, at the point when I want to add the listener,
>> the corresponding Button control is not created yet.
>>
>> Any ideas - thanks!
>> Hans
|
|
|
Re: Adding a context menu like in the Eclipse Views [message #465863 is a reply to message #465862] |
Tue, 20 December 2005 19:22 |
Jeremy Dowdall Messages: 48 Registered: July 2009 |
Member |
|
|
Hans,
thanks for catching this - I breezed right by once the menu was
dropping where I wanted it!
upon further inspection, the only solution I'm seeing is adding the
mouseDown listener to the toolbar itself and checking to see if the
item's bounds contain the event's x & y coordinates:
toolBar.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
if(item.getBounds().contains(e.x, e.y)) {
openContextMenu(toolBar, item);
}
}
});
any other thoughts?
Hans wrote:
> Thanks, Jeremy. The snippets page is a very useful reference. Your
> suggestion with the smaller image is good (actually 10x16 is the correct
> size).
>
> However, the remaining problem is that I don't see how I can react on
> SWT.MouseDown - the only event that seems to work is SWT.Selection.
> SWT.MouseDown does not seem to trigger any event.
>
>
> final ToolItem item = new ToolItem (toolBar, SWT.FLAT);
> item.addListener(SWT.Selection, new Listener () {
> public void handleEvent (Event event) {
> openContextMenu(toolBar, item);
> }
> });
>
> Hans
>
>
> Jeremy Dowdall wrote:
>
>> http://www.eclipse.org/swt/snippets/
>> under "ToolBar, ToolItem" is "place a drop down menu in a tool bar"
>>
>> this will, however, create a toolbar with a down arrow centered
>> vertically. to get it more like the eclipse view's, AFAIK, you'll
>> have to use your own icon (make it 9x16 pixels) by changing:
>> final ToolItem item = new ToolItem (toolBar, SWT.DROP_DOWN);
>> to
>> final ToolItem item = new ToolItem (toolBar, SWT.FLAT);
>> and then setting the image with item.setImage(image)
>>
>>
>> Hans wrote:
>>
>>> I need to add a context menu to a toolbar, to get a similar look and
>>> feel like the arrow-pointing-down in various Eclipse views. For
>>> example the Package Explorer's toolbar has a button on the right
>>> which on mouse-down displays a menu (with items such as Show, Select
>>> working set etc). How is this implemented?
>>>
>>> I couldn't dig deep enough into the Eclipse source to see how this is
>>> implemented, but my first attempts were to add an Action to the
>>> Toolbar with the image as icon and then I try to add a mouse listener
>>> to the item. However, at the point when I want to add the listener,
>>> the corresponding Button control is not created yet.
>>>
>>> Any ideas - thanks!
>>> Hans
|
|
| | | |
Goto Forum:
Current Time: Mon Dec 09 05:23:49 GMT 2024
Powered by FUDForum. Page generated in 0.04006 seconds
|