Community
Participate
Working Groups
Eclipse 2.1 RC2. I am adding toolbar actions to my view, and also to the menu (the one with the triangle as icon). Here's the code: class ViewAction extends Action { public ViewAction (String label, ImageDescriptor desc) { this (label); setImageDescriptor(desc); } public ViewAction (String label) { super (label, IAction.AS_RADIO_BUTTON); } } protected void createActions() { try { URL urlShowAsText = UiPlugin.makeIconFileURL ("textmode.gif"); URL urlShowAsRaw = UiPlugin.makeIconFileURL ("rawmode.gif"); URL urlShowAsDump = UiPlugin.makeIconFileURL ("dumpmode.gif"); actionShowAsText = new ViewAction ("text", ImageDescriptor.createFromURL(urlShowAsText)); actionShowAsText.setToolTipText (actionShowAsText.getText()); actionShowAsText.setChecked(true); actionShowAsRaw = new ViewAction ("raw", ImageDescriptor.createFromURL(urlShowAsRaw)); actionShowAsRaw.setToolTipText(actionShowAsRaw.getText ()); actionShowAsDump = new ViewAction ("dump", ImageDescriptor.createFromURL(urlShowAsDump)); actionShowAsDump.setToolTipText (actionShowAsDump.getText()); } catch (MalformedURLException e) { e.printStackTrace(); } } Now, when I click the radio it correctly de-selects the previous selection and selects the new one. It guarantees that I can't have 2 selected, good. However, if I click on the already selected radio, it de-selects it, leaving none selected. This was not the expected behaviour. A group of radio buttons works so that there's only one, but always one, item enabled. Note: if I add the actions to the menu, the same happens. It is possible to de- select the one selected and have none selected. I don't want that in the menu either.
Hi Marcio! Simon, please investigate as possible RC3 candidate.
Can you provide me with a simple plugin to reproduce this case (I'd need it for today). From the code below, you are not creating radio button style actions, but toggle button style actions. You should see this in the menu - the action would have a check mark next to it instead of a round dot. I'm not sure how when you clicked on the non-selected action, that the selected one became unselected. That's not typical toggle button style behavior. Are you sure your actions are not unchecking each other in code?
(Hi Nick !) Ok, I will package a simple example, in the next few minutes. I'll attach it here when done. Yes, I see a round dot beside my icons in the view's menu (triangle icon with pull-down menu). Meanwhile, please let me know what style to use to achieve true radio functionality then (always one, just one selected). I thought IAction.AS_RADIO_BUTTON meant radio buttons :-)
Created attachment 4050 [details] sglebs plugin showing scenario
You need to open the Debug perspective to see the example. I define a new tab, "Sglebs", which goes with the other tabs (variables etc). I tested as Run- >Debug As->Runtime Workbench.
Confirm this is a problem using the supplied test plugin. I can reproduce this using the Edit > Encoding sub-menu items also. The problem is in ActionContributionItem.handleSelection. It just inverts the checked state. That's fine for a toggle but for a radio, it should not do that. It should lookup the state of the widget's selection. But we need to be careful because this listener can get different widgets like Button, MenuItem, and ToolItem (see the fill methods). We would need a bunch of instanceof or we need different listeners for each type of widget we contribute. This problem will not be fixed for 2.1 since it is not critical (the criteria for RC3 fix). Defer for now; to be fixed in 2.2 stream.
Then please post a workaround that poor users like me can use in their own classes for now, until 2.2 comes out. I just can't say to my users "sorry, it's an eclipse bug". I must make it work. Thanks in advance.
One possible workaround: a) Implement a superSetChecked(boolean) on your ViewAction that simply calls super.setChecked(boolean) b) override setChecked(boolean) on your ViewAction. - If the value passed in is false, then ignore it. - If the value passed in is true, then call super.setChecked(true). Also, call superSetChecked(false) on all the other actions within the radio group.
*** Bug 35324 has been marked as a duplicate of this bug. ***
Reopen to fix...
ActionContributionItem event handlers changed to query the current selection status of the widget and past that along to the action.setChecked method.