Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » MenuItems have a wrong order in Menu(bug in Menu.js?!)
MenuItems have a wrong order in Menu [message #1060301] Fri, 24 May 2013 00:24 Go to next message
Yury Mising name is currently offline Yury Mising name
Messages: 87
Registered: May 2010
Location: Russia
Member
Hello, RAP community!

Try to describe the problem here. If menu has a show event listener which add some menu items in specified positions - they will be added with +1 position shift.
It seems to me the problem is here (Menu.js):
_menuShown : function() {
      if( !rwt.remote.EventUtil.getSuspended() ) {
        if( this._hasShowListener ) {
          // create preliminary item
          if( this._preItem == null ) {
            this._preItem = new rwt.widgets.MenuItem( "push" );
            this._preItem.setText( "..." );
            this._preItem.setEnabled( false );
            this.addMenuItemAt( this._preItem, 0 );
          }
         ...
      }
    }

We add the _preItem on show event and hide all menu children for a time.
The listener add some menu items with specified positions - it calls the method Menu.addMenuItemAt(...).
    addMenuItemAt : function( menuItem, index ) {
      // seperator does not have this function:
      if( menuItem.setParentMenu ) {
        // it is essential that this happens before the menuItem is added
        menuItem.setParentMenu( this );
      }
      this._layout.addAt( menuItem, index );
    }


But the specified position does not correspond the real position in children list, because the _preItem has been added to the top (and it will not be removed) which create +1 position shift.
Thin we must check _preItem in addMenuItemAt to correct insert position.

PS It takes more time to provide a snippet, but I hope my description is clear. The same code works fine in RCP.

Best regards,
Yury.
Re: MenuItems have a wrong order in Menu [message #1060387 is a reply to message #1060301] Fri, 24 May 2013 07:59 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1691
Registered: July 2009
Senior Member
Hi Yuri,
if there are items set on the menu the _preItem will not visible.
Visually there will be no difference in the items order between client
and server. I don't understand how this affects your application. Could
you provide a snippet to make the things more clear?
> Thin we must check _preItem in addMenuItemAt to correct insert position.
Do you have some javascript code (custom components) that rely on the
exact item index on the client?
Best,
Ivan

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: MenuItems have a wrong order in Menu [message #1060588 is a reply to message #1060387] Mon, 27 May 2013 04:09 Go to previous messageGo to next message
Yury Mising name is currently offline Yury Mising name
Messages: 87
Registered: May 2010
Location: Russia
Member
Hello, Ivan!

I have created the patch for org.eclipse.rap.demo to reproduce the problem (attached here).
Steps to reproduce:
1. Open About dialog - Help->About. It calls the update method for file menu (in my cases this method is called due to activity management).
2. Open File menu -

you will see that "New MenuItem" is the first menu item there, but it was inserted on the second position.
fileMenu.add( new ContributionItem() {

      @Override
      public void fill( Menu menu, int index ) {
        MenuItem item = new MenuItem( menu, SWT.PUSH, 1 );
        item.setText( "New MenuItem" );
      }

      @Override
      public boolean isDynamic() {
        return true;
      }
    } );


If you change the ContributionItem.isDynamic to return false - the item will be inserted correctly.

Best regards,
Yury.
Re: MenuItems have a wrong order in Menu [message #1060600 is a reply to message #1060588] Mon, 27 May 2013 05:07 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1691
Registered: July 2009
Senior Member
Hi Yury,
yes... you are right. I can reproduce it with RAP from master. Please
open a bugzilla to track the progress on this issue. Please attach the
patch there too.
Thanks,
Ivan

On 5/27/2013 11:09 AM, Yury Mising name wrote:
> Hello, Ivan!
>
> I have created the patch for org.eclipse.rap.demo to reproduce the problem (attached here).
> Steps to reproduce:
> 1. Open About dialog - Help->About. It calls the update method for file menu (in my cases this method is called due to activity management).
> 2. Open File menu -
>
> you will see that "New MenuItem" is the first menu item there, but it was inserted on the second position.
>
> fileMenu.add( new ContributionItem() {
>
> @Override
> public void fill( Menu menu, int index ) {
> MenuItem item = new MenuItem( menu, SWT.PUSH, 1 );
> item.setText( "New MenuItem" );
> }
>
> @Override
> public boolean isDynamic() {
> return true;
> }
> } );
>
>
> If you change the ContributionItem.isDynamic to return false - the item will be inserted correctly.
>
> Best regards,
> Yury.

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: MenuItems have a wrong order in Menu [message #1060601 is a reply to message #1060600] Mon, 27 May 2013 05:17 Go to previous messageGo to next message
Yury Mising name is currently offline Yury Mising name
Messages: 87
Registered: May 2010
Location: Russia
Member
Ivan, I've filled the https://bugs.eclipse.org/bugs/show_bug.cgi?id=409124

Best regards,
Yury.
Re: MenuItems have a wrong order in Menu [message #1060612 is a reply to message #1060601] Mon, 27 May 2013 06:15 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1691
Registered: July 2009
Senior Member
Thanks, Yury.
The bug is fixed in RAP 2.1RC2.
Best,
Ivan

On 5/27/2013 12:17 PM, Yury Mising name wrote:
> Ivan, I've filled the
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=409124
>
> Best regards,
> Yury.

--
Ivan Furnadjiev

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

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: MenuItems have a wrong order in Menu [message #1060621 is a reply to message #1060612] Mon, 27 May 2013 07:16 Go to previous message
Yury Mising name is currently offline Yury Mising name
Messages: 87
Registered: May 2010
Location: Russia
Member
Thank you for a quick response and fix!

Best regards,
Yury.
Previous Topic:What is the correct way to resize a TableView?
Next Topic:What is the proper way to determine initial jface dialog size?
Goto Forum:
  


Current Time: Thu Apr 24 14:41:50 EDT 2014

Powered by FUDForum. Page generated in 0.02088 seconds