Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 328437 - MenuItem with RADIO style doesn't pass selection event to it's listeners
Summary: MenuItem with RADIO style doesn't pass selection event to it's listeners
Status: RESOLVED FIXED
Alias: None
Product: RAP
Classification: RT
Component: RWT (show other bugs)
Version: 1.3   Edit
Hardware: All All
: P5 normal (vote)
Target Milestone: 1.4 M6   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-22 04:03 EDT by Yury CLA
Modified: 2011-02-01 03:52 EST (History)
1 user (show)

See Also:


Attachments
Snippet that works for me (1.87 KB, text/plain)
2010-10-22 06:53 EDT, Ivan Furnadjiev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yury CLA 2010-10-22 04:03:18 EDT
Build Identifier: RAP 1.3

MenuItem with RADIO style doesn't pass selection event to it's listeners when selected state is true. Look at MenuItem.js:

    setSelection : function( value ) {
      if( this._selected != value ) {
        this._selected = value;
        if( this._selected ) {
          this.addState( "selected" );
        } else {
          this.removeState( "selected" );
        }
        if( !org_eclipse_rap_rwt_EventUtil_suspend ) {
          var widgetManager = org.eclipse.swt.WidgetManager.getInstance();
          var id = widgetManager.findIdByWidget( this );
          var req = org.eclipse.swt.Request.getInstance();
          req.addParameter( id + ".selection", this._selected );
          org.eclipse.swt.EventUtil.addWidgetSelectedModifier();
        }
      }
    }

setSelection method is invoked from execute method by mouseup event, but if this._selected equals 'true' - no changes will be made and this._sendChanges() method will not send any changes for RADIO menu items, because this._sendEvent is 'false' for this style.
My mind is that setSelection method had been wrongly copy/pasted from AbstractButton.js and we should pass selection event even if the menu item is already selected.

Reproducible: Always
Comment 1 Ivan Furnadjiev CLA 2010-10-22 06:53:11 EDT
Created attachment 181485 [details]
Snippet that works for me

I can't reproduce it with the attached snippet in both RAP 1.3 and 1.4 (HEAD). Could you provide a simple snippet/project to reproduce the problem?
Comment 2 Ralf Sternberg CLA 2010-10-22 16:44:37 EDT
(In reply to comment #0)
> setSelection method is invoked from execute method by mouseup event, but if
> this._selected equals 'true' - no changes will be made and this._sendChanges()
> method will not send any changes for RADIO menu items, because this._sendEvent
> is 'false' for this style.

I can't see this in the code snippet you pasted. Whenever the selection changes, the new selection state is added to the next request. Where's the error?
Comment 3 Ivan Furnadjiev CLA 2010-11-19 07:02:57 EST
I will close it as WORKSFORME. Please reopen if the issue persist and you provide a snippet to reproduce it.
Comment 4 Yury CLA 2010-11-22 06:28:35 EST
Hi, all!

Sorry for a long response (was on vacation).
This is a simple snippet that doesn't work on RAP 1.3 for me.
Try to select an any menu item - it will be successful first time (when it wasn't checked), but failed for the second time for the checked item. 

  public int createUI() {
    Display display = PlatformUI.createDisplay();
    Shell shell = new Shell(display);
    Composite c1 = new Composite(shell, SWT.BORDER);
    c1.setSize(200, 200);
    Menu menu = new Menu(shell, SWT.POP_UP);
    MenuItem item = new MenuItem(menu, SWT.RADIO);
    item.setText("MenuItem1");
    item.addSelectionListener(new SelectionAdapter()
    {

        public void widgetDefaultSelected(SelectionEvent e)
        {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e)
        {
            System.out.println("Menu1 selected");
        }
        
    });
    item = new MenuItem(menu, SWT.RADIO);
    item.setText("MenuItem2");
    item.addSelectionListener(new SelectionAdapter()
    {

        public void widgetDefaultSelected(SelectionEvent e)
        {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e)
        {
            System.out.println("Menu2 selected");
        }
        
    });
    c1.setMenu(menu);
    shell.setMenu(menu);
    shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
    return 0;
  }
Comment 5 Ivan Furnadjiev CLA 2010-11-22 07:08:25 EST
Hi Yury, thanks for the snippet. Just checked it in SWT (Windows) and the SelectionEvent is fired regardless the radio item is selected or not. In RAP the SelectionEvent is fired only if radio item changes its state.
Comment 6 Ivan Furnadjiev CLA 2010-12-14 08:15:29 EST
Fixed in CVS HEAD.
Comment 7 Yury CLA 2011-02-01 03:18:58 EST
Hi, Ivan.

I think correct fixes should be

    setSelection : function( value ) {
	  if( this._selected != value || this._selected) {
	    this._selected = value;
	    if( this._selected ) {
	      this.addState( "selected" );
	    } else {
	      this.removeState( "selected" );
	    }
	    if( !org_eclipse_rap_rwt_EventUtil_suspend ) {
	      var widgetManager = org.eclipse.swt.WidgetManager.getInstance();
	      var id = widgetManager.findIdByWidget( this );
	      var req = org.eclipse.swt.Request.getInstance();
	      req.addParameter( id + ".selection", this._selected );
	      org.eclipse.swt.EventUtil.addWidgetSelectedModifier();
	    }
	  }
	}, 

because we shouldn't fire selection changed event in case when the item isn't selected. It fix this bug and another one which we get in our application with radio menuitems.

Best regards,
Yury.
Comment 8 Ivan Furnadjiev CLA 2011-02-01 03:52:08 EST
Hi Yury, thanks for the hint.... yes... you are right. Fixed in CVS HEAD. JS test added.