Community
Participate
Working Groups
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
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?
(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?
I will close it as WORKSFORME. Please reopen if the issue persist and you provide a snippet to reproduce it.
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; }
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.
Fixed in CVS HEAD.
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.
Hi Yury, thanks for the hint.... yes... you are right. Fixed in CVS HEAD. JS test added.