Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » CommandContributionItem does not set checkedState for radio styles
CommandContributionItem does not set checkedState for radio styles [message #789502] Thu, 02 February 2012 22:40 Go to next message
Kevin Pfarr is currently offline Kevin Pfarr
Messages: 5
Registered: July 2009
Junior Member
I'm using the RCP version 3.7.1 and ran into an issue with menu contributions having a radio style.

I have a view with commands contributed to the view's toolbar using the org.eclipse.ui.menus extension point. The menu contributions have a radio style. The command handlers implement IElementUpdater so it can call setChecked on the element. Here is the problem. The setChecked method in the CommandContributionItem class is not getting past the first if block. That is because the checkedState field is getting set in the handleWidgetSelection method for styles SWT.TOGGLE or SWT.CHECK but not SWT.RADIO. If you include SWT.RADIO it works as expected.

I have a work around by calling setChecked twice; first is the inverse followed by the actual value. But I think this is a bug that should be looked into further.

I have attached a sample plug-in to demonstrate the issue. Open the Radio Toolbar view. Click the Radio 2 button, then click the Toggle Toolbar state button. The selection listener of the button will refresh the commands, calling the setChecked method on the elements.

-Kevin

Re: CommandContributionItem does not set checkedState for radio styles [message #789860 is a reply to message #789502] Fri, 03 February 2012 08:55 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6850
Registered: July 2009
Location: Ottawa
Senior Member

I believe radio state is not managed by the UIElements, but by toggle state and radio state. See http://blog.eclipse-tips.com/2009/03/commands-part-6-toggle-radio-menu.html

PW


Re: CommandContributionItem does not set checkedState for radio styles [message #789879 is a reply to message #789860] Fri, 03 February 2012 09:28 Go to previous messageGo to next message
Kevin Pfarr is currently offline Kevin Pfarr
Messages: 5
Registered: July 2009
Junior Member
So why would a handler implement IElementUpdater and utilize the UIElement.setChecked method? The javadoc says...

'Update the checked state on this UI element. For example, if this was a toggle or radio button.'

I will look into the radio state as from the URL.

Thanks,
Kevin
Re: CommandContributionItem does not set checkedState for radio styles [message #792033 is a reply to message #789879] Mon, 06 February 2012 09:33 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6850
Registered: July 2009
Location: Ottawa
Senior Member

It can be used that way, especially if the handler is completely responsible for the state (checked state for a toggle, or shared state for a radio button). There are some pitfalls, like correctly setting the last state on a new session (when the handlers aren't loaded by default).

AFAIK then an end-to-end implementation was put in place using the RadioState and tied directly into the CommandContributionItem so that the state of the selection could be restored without instantiating the handler contribution on a new session.

PW


Previous Topic:How to change folder path in Eclipse's custom Import Wizard
Next Topic:Decorators extension point and expression-based constraints
Goto Forum:
  


Current Time: Wed Apr 23 20:47:13 EDT 2014

Powered by FUDForum. Page generated in 0.05855 seconds