|
Re: MenuDetect Event [message #108651 is a reply to message #108450] |
Tue, 07 October 2008 20:29 |
Eclipse User |
|
|
|
Originally posted by: rherrmann.innoopract.com
Gunnar,
I don't quite understand what you want to achieve. Is it about
positioning the context menu?
Cheers,
Rüdiger
Gunnar Wurl wrote:
> Hi,
>
> I' am using the SWT.MenuDetect event in an RCP Application to detect
> when the user is trying to open a menu on a tree. It is needed to
> determine a specific tree item out of the tree so set the menu can be
> set related to the clicked tree item. Now I have a problem converting
> this to RAP as there is no SWT.MenuDetect. I tried with SWT.MouseClick,
> SWT.MouseUp but these events don't return the aspected behaviour.
> Any hints how I could get the same behaviour as with SWT.MenuDetect?
>
|
|
|
|
Re: MenuDetect Event [message #108679 is a reply to message #108665] |
Wed, 08 October 2008 10:20 |
Gunnar Wurl Messages: 34 Registered: July 2009 |
Member |
|
|
I wrote a rcp snippet to show what I mean, maybe it is more obvious than
my attempt to explain my problem with words.
Well here it comes:
public class Application implements IApplication {
public Object start(IApplicationContext context) throws Exception
{
Display display = new Display();
Shell shell = new Shell( display, SWT.SHELL_TRIM );
shell.setLayout( new FillLayout() );
// Creating Tree
Tree myTree = new Tree( shell, 0);
// Populating tree with tree items
myTreeItem myTreeItem1 = new myTreeItem( myTree, SWT.NONE );
myTreeItem1.setText( "Server" );
myTreeItem myTreeItem2 = new myTreeItem( myTree, SWT.NONE );
myTreeItem2.setText( "Options" );
myTreeItem myTreeItem3 = new myTreeItem( myTree, SWT.NONE );
myTreeItem3.setText( "None" );
// creating different menus for the items
Menu menu1 = new Menu( myTree );
MenuItem menuItem11 = new MenuItem( menu1, SWT.NONE );
menuItem11.setText( "add new server" );
myTreeItem1.setMenu( menu1 );
Menu menu2 = new Menu( myTree );
MenuItem menuItem21 = new MenuItem( menu2, SWT.NONE );
menuItem21.setText( "resetOptions" );
myTreeItem2.setMenu( menu2 );
// adding MenuDetect Listener to tree to react when user tries to open
context menu
myTree.addListener( SWT.MenuDetect, new Listener()
{
@Override
public void handleEvent(Event event)
{
Tree tree = (Tree) event.widget;
// getting menu from currently selected tree item
Menu menu = ((myTreeItem) ((Tree)
event.widget).getSelection()[0].getData()).getMenu();
tree.setMenu( menu );
}
});
shell.setSize( 300, 300 );
shell.open();
while( !shell.isDisposed() )
{
if( !display.readAndDispatch() )
{
display.sleep();
}
}
return 0;
}
@Override
public void stop()
{
}
// Class representing a TreeItem
private class myTreeItem
{
// Menu attached to this TreeItem
private Menu menu = null;
private TreeItem treeItem;
public myTreeItem(Tree parent, int style)
{
this.treeItem = new TreeItem( parent, style );
this.treeItem.setData( this );
}
public void setText( String text )
{
treeItem.setText( text );
}
public void setMenu( Menu menu )
{
this.menu = menu;
}
public Menu getMenu( )
{
return this.menu;
}
}
}
|
|
|
Re: MenuDetect Event [message #108729 is a reply to message #108665] |
Wed, 08 October 2008 11:44 |
Eclipse User |
|
|
|
Originally posted by: rherrmann.innoopract.com
Gunnar,
did you try to use a MenuListener that populates the context menu
depending on the selection?
HTH
Rüdiger
Gunnar Wurl wrote:
> No it is not about the position of the context menu. It is about the
> content of the menu. So for a small example I have two entries in one
> tree like this:
>
> |
> |-Server
> |-Options
>
> Now when the user right clicks on on the tree item Server the context
> menu displays server specific entries like add new server or something
> like that.
> When the user right clicks on the tree item options the context menu
> says something like reset options.
> As for SWT the context menu is set for the tree and not for a special
> tree item i need to determine which tree item the user opened the
> context menu for. For this I am using the SWT.MenuDetect event and in
> this event I get the actual selected tree item using the
> Tree#getSelection method. Then I set the menu for this tree regarding
> what tree item this method returns.
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03169 seconds