Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » MenuDetect Event
MenuDetect Event [message #108450] Tue, 07 October 2008 08:21 Go to next message
Gunnar Wurl is currently offline Gunnar WurlFriend
Messages: 34
Registered: July 2009
Member
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 #108651 is a reply to message #108450] Tue, 07 October 2008 20:29 Go to previous messageGo to next message
Eclipse UserFriend
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 #108665 is a reply to message #108651] Wed, 08 October 2008 07:51 Go to previous messageGo to next message
Gunnar Wurl is currently offline Gunnar WurlFriend
Messages: 34
Registered: July 2009
Member
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.
Re: MenuDetect Event [message #108679 is a reply to message #108665] Wed, 08 October 2008 10:20 Go to previous messageGo to next message
Gunnar Wurl is currently offline Gunnar WurlFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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.
>
Re: MenuDetect Event [message #108814 is a reply to message #108729] Thu, 09 October 2008 07:37 Go to previous message
Gunnar Wurl is currently offline Gunnar WurlFriend
Messages: 34
Registered: July 2009
Member
Thanks for your advice Rüdiger,

I am using the Show Listener now and it kind of works. But it looks
somewhat weird when the application is trying to show a menu without any
elements.

Thanks again

Gunnar
Previous Topic:How do I use debug qooxdoo version?
Next Topic:Don't atomatically start browser - run configuration for Rap Apps
Goto Forum:
  


Current Time: Thu Apr 25 07:03:10 GMT 2024

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

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

Back to the top