Bug 34744 - [Contributions] Creating view toolbar actions as IAction.AS_RADIO_BUTTON, expected one always selected
Summary: [Contributions] Creating view toolbar actions as IAction.AS_RADIO_BUTTON, exp...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: 3.0   Edit
Assignee: Simon Arsenault CLA
QA Contact:
URL:
Whiteboard:
Keywords: usability
: 35324 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-03-11 16:34 EST by Marcio CLA
Modified: 2003-05-26 14:54 EDT (History)
2 users (show)

See Also:


Attachments
sglebs plugin showing scenario (9.14 KB, application/x-zip-compressed)
2003-03-12 10:53 EST, Marcio CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marcio CLA 2003-03-11 16:34:04 EST
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.
Comment 1 Nick Edgar CLA 2003-03-12 01:38:41 EST
Hi Marcio!

Simon, please investigate as possible RC3 candidate.
Comment 2 Simon Arsenault CLA 2003-03-12 09:38:15 EST
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?
Comment 3 Marcio CLA 2003-03-12 10:38:00 EST
(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 :-)

Comment 4 Marcio CLA 2003-03-12 10:53:51 EST
Created attachment 4050 [details]
sglebs plugin showing scenario
Comment 5 Marcio CLA 2003-03-12 12:06:23 EST
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.
Comment 6 Simon Arsenault CLA 2003-03-12 16:20:21 EST
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.
Comment 7 Marcio CLA 2003-03-12 16:39:24 EST
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.
Comment 8 Simon Arsenault CLA 2003-03-13 11:37:20 EST
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.
Comment 9 Simon Arsenault CLA 2003-03-21 15:23:29 EST
*** Bug 35324 has been marked as a duplicate of this bug. ***
Comment 10 Simon Arsenault CLA 2003-04-01 14:49:25 EST
Reopen to fix...
Comment 11 Simon Arsenault CLA 2003-04-01 16:37:20 EST
ActionContributionItem event handlers changed to query the current selection 
status of the widget and past that along to the action.setChecked method.