Skip to main content



      Home
Home » Eclipse Projects » Eclipse 4 » Check type menuitems
Check type menuitems [message #731352] Fri, 30 September 2011 13:32 Go to next message
Eclipse UserFriend
I've added a command that toggles a two state view preference in my app. I created a HandledMenuItem for this command and set the type to Check. I also added this to a menu and added a Handler for the command and a keybinding.

The menuitem shows up in the menu with a checkbox and the state of the check is remembered correctly. Also, my handler is called when I activate the menuitem or via the keybinding. So far so good.

Here's the problem: I need to know what the state of the check is both in my handler and in my view code that consumes this preference. But I can't figure out how to access the check state either in the handler or elsewhere.

What's the correct way to get at this info?


Re: Check type menuitems [message #732138 is a reply to message #731352] Mon, 03 October 2011 22:06 Go to previous messageGo to next message
Eclipse UserFriend
I found an answer and it's easy of course. Just inject handler with (MMenuItem item) and call item.isSelected().
Re: Check type menuitems [message #736575 is a reply to message #731352] Fri, 14 October 2011 01:58 Go to previous messageGo to next message
Eclipse UserFriend
Unfortunately, the answer I found is incomplete.

While it works when the handler is activated by the menuitem, it fails when it's activated by a keybinding. In the case of a keybinding activation, the MMenuItem will be not be resolved. How is the handler supposed to get at the state which the menuitem holds in this situation?

I suppose the situation gets even worse if there are multiple menuitems bound to the same handler, and with different types.
Re: Check type menuitems [message #736595 is a reply to message #736575] Fri, 14 October 2011 02:27 Go to previous messageGo to next message
Eclipse UserFriend
If it is a preference why don't you set one? You can get preferences
injected using @Preference("myprefvalue") in the @Execute and in views
using @Inject @Preference("myprefvalue")

Tom

Am 14.10.11 07:58, schrieb grillo321:
> Unfortunately, the answer I found is incomplete.
>
> While it works when the handler is activated by the menuitem, it fails
> when it's activated by a keybinding. In the case of a keybinding
> activation, the MMenuItem will be not be resolved. How is the handler
> supposed to get at the state which the menuitem holds in this situation?
>
> I suppose the situation gets even worse if there are multiple menuitems
> bound to the same handler, and with different types.
Re: Check type menuitems [message #909072 is a reply to message #736595] Thu, 06 September 2012 09:42 Go to previous message
Eclipse UserFriend
I got that one working to synchronize from the HandledMenuItem to the Code! But how could I initialize the state of the HandledMenuItem at start given the Preference?

Or more generally, how can I set the state of a HandledMenuItem given by the state of the code at all?

Thanks!

[Updated on: Thu, 06 September 2012 10:02] by Moderator

Previous Topic:Tycho build has different runtime behavior as the Run Configuration
Next Topic:Looking for (open source) projects based on Eclipse4
Goto Forum:
  


Current Time: Wed Jul 23 08:17:42 EDT 2025

Powered by FUDForum. Page generated in 0.04542 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top