Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Menu&MenuItem
Menu&MenuItem [message #965444] Wed, 31 October 2012 08:33 Go to next message
bogdan toma is currently offline bogdan tomaFriend
Messages: 39
Registered: February 2010
Member
Hello all,

I have the following code. When a button is pressed a menu with a menuitem is created. When selecting the menuitem an action should be performed.
In rap 1.5.0 & 1.5.1 the action is not performed.
In rap 1.4.0 the code works perfectly.
Should I change this code in some different way for rap 1.5 ?
Thank you.



        final Button menuButton = new Button(parent, SWT.None);
        menuButton.setText("Menu button...");
        menuButton.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent e)
            {
                final Menu menu = new Menu(addButton.getShell(), SWT.POP_UP);
                addButton.setMenu(menu);
                MenuItem item = new MenuItem(menu, SWT.NONE);
                item.setText("Select all");
                item.addSelectionListener(new SelectionListener()
                {

                    public void widgetSelected(SelectionEvent e)
                    {
                        System.out.println("Select all");

                    }

                    public void widgetDefaultSelected(SelectionEvent e)
                    {

                    }

                });
                menu.addMenuListener(new MenuListener()
                {

                    public void menuShown(MenuEvent e)
                    {

                    }

                    public void menuHidden(MenuEvent e)
                    {
                        menu.dispose();
                    }
                });
                
                menu.setLocation(addButton.getShell().getDisplay().map(addButton, null, 0, 0));
                menu.setVisible(true);
                
            }
        });
Re: Menu&MenuItem [message #965841 is a reply to message #965444] Wed, 31 October 2012 14:48 Go to previous messageGo to next message
Cole Markham is currently offline Cole MarkhamFriend
Messages: 150
Registered: July 2009
Location: College Station, TX
Senior Member

I'm not sure what may have changed between 1.4 and 1.5, but you might try creating the menu once instead of creating and disposing each time. It could be that your menuHidden listener fires before the MenuItem selection listener, and so the selection listener never gets called. That is just a guess. Try something like this instead. I tested on 1.5 and it works for me.
		final Button menuButton = new Button(parent, SWT.None);
		menuButton.setText("Menu button...");
		final Menu menu = new Menu(menuButton.getShell(), SWT.POP_UP);
		menuButton.setMenu(menu);
		MenuItem item = new MenuItem(menu, SWT.NONE);
		item.setText("Select all");
		item.addSelectionListener(new SelectionListener()
		{

			public void widgetSelected(SelectionEvent e)
			{
				System.out.println("Select all");

			}

			public void widgetDefaultSelected(SelectionEvent e)
			{

			}

		});

		
		menuButton.addSelectionListener(new SelectionAdapter()
		{
			@Override
			public void widgetSelected(SelectionEvent e)
			{
				menu.setLocation(menuButton.getShell().getDisplay().map(menuButton, null, 0, 0));
				menu.setVisible(true);
			}
		});


Hope that helps,

Cole
Re: Menu&MenuItem [message #968517 is a reply to message #965444] Fri, 02 November 2012 14:20 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
in RAP 1.5 we changed the event processing order [1] to be as close as
possible to SWT. We changed the order of Hide and Selection events. In
RAP 1.4 the Selection event was fired before the Hide event, in RAP 1.5
is the opposite. As you dispose the menu in the Hide event, Selection
event is not fired, because the MenuItem is disposed too. I've checked
your snippet in SWT and it behaves exactly the same like in RAP - no
Selection event.

[1] 325756: Check RAP events processing order against SWT
https://bugs.eclipse.org/bugs/show_bug.cgi?id=325756
HTH,
Ivan

On 10/31/2012 10:33 AM, bogdan toma wrote:
> Hello all,
>
> I have the following code. When a button is pressed a menu with a
> menuitem is created. When selecting the menuitem an action should be
> performed.
> In rap 1.5.0 & 1.5.1 the action is not performed.
> In rap 1.4.0 the code works perfectly.
> Should I change this code in some different way for rap 1.5 ?
> Thank you.
>
>
>
>
> final Button menuButton = new Button(parent, SWT.None);
> menuButton.setText("Menu button...");
> menuButton.addSelectionListener(new SelectionAdapter()
> {
> @Override
> public void widgetSelected(SelectionEvent e)
> {
> final Menu menu = new Menu(addButton.getShell(),
> SWT.POP_UP);
> addButton.setMenu(menu);
> MenuItem item = new MenuItem(menu, SWT.NONE);
> item.setText("Select all");
> item.addSelectionListener(new SelectionListener()
> {
>
> public void widgetSelected(SelectionEvent e)
> {
> System.out.println("Select all");
>
> }
>
> public void widgetDefaultSelected(SelectionEvent e)
> {
>
> }
>
> });
> menu.addMenuListener(new MenuListener()
> {
>
> public void menuShown(MenuEvent e)
> {
>
> }
>
> public void menuHidden(MenuEvent e)
> {
> menu.dispose();
> }
> });
> menu.setLocation(addButton.getShell().getDisplay().map(addButton,
> null, 0, 0));
> menu.setVisible(true);
> }
> });

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Menu&MenuItem [message #971155 is a reply to message #968517] Sun, 04 November 2012 16:46 Go to previous message
bogdan toma is currently offline bogdan tomaFriend
Messages: 39
Registered: February 2010
Member
Thank you. So it was my mistake.
it works like Cole Markham exampled.
Thank you again.
Previous Topic:Deploy problem
Next Topic:Compression of communication in Rap 2.0
Goto Forum:
  


Current Time: Thu Apr 18 15:37:54 GMT 2024

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

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

Back to the top