Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to update the checked state of a command per window?
How to update the checked state of a command per window? [message #336462] Mon, 15 June 2009 14:55 Go to next message
Eclipse UserFriend
Originally posted by: eclipse-newsgroups.scharf.gr

I have a very hard time finding information
about commands.

Here is a vary simple problem:
- I want to have a command that has a checked (toggle) state
- There is boolean a variable associated with each window
- I want the checked state represent the state of this variable
- when the state changes, the command should change its state
- when handler is called, it should toggle the variable

I have no idea how to do this with commands....


Michael
--
Michael Scharf
Wind River Systems GmbH
http://www.WindRiver.com
http://MichaelScharf.blogspot.com/
Re: How to update the checked state of a command per window? [message #336465 is a reply to message #336462] Mon, 15 June 2009 17:33 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Your handler would be updating the state after implementing
IElementUpdater. But ...

You would need to use
org.eclipse.ui.commands.ICommandService.refreshElements(Stri ng, Map) to
request that the command update its checked state when the active window
changes, so it can reflect the correct state.

Commands in 3.x run off of a global application context. There is also
only one global command (backed by the currently active handler), so
within one window it becomes impossible to show different states for one
command. Between windows, it might just be possible assuming you are
updating your state to the correctly active window.

Or instead of one handler that needs to manage the state for the
application, programmaticly activate a handler when creating each
separate window using window.getService(IHandlerService.class) to get
the IHandlerService in each case (since that will scope the handler to
that window only).

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: How to update the checked state of a command per window? [message #336469 is a reply to message #336465] Mon, 15 June 2009 19:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-newsgroups.scharf.gr

Hi Paul,

thank you for the answer! (I'll try this out
tomorrow)

How would I figure all this out without asking the
newsgroup? I feel really stupid and I don't know
how to figure out all the complexity of commands.

Maybe a set of relatively simple examples would help a lot.
It turns out that the actual code that gets executed int
the handler is not the problem. The problem is hooking
the handlers and commands into the application which
includes plugin.xml and window.getService(IHandlerService.class)
all things that are very hard to figure out.

Michael


> Your handler would be updating the state after implementing
> IElementUpdater. But ...
>
> You would need to use
> org.eclipse.ui.commands.ICommandService.refreshElements(Stri ng, Map) to
> request that the command update its checked state when the active window
> changes, so it can reflect the correct state.
>
> Commands in 3.x run off of a global application context. There is also
> only one global command (backed by the currently active handler), so
> within one window it becomes impossible to show different states for one
> command. Between windows, it might just be possible assuming you are
> updating your state to the correctly active window.
>
> Or instead of one handler that needs to manage the state for the
> application, programmaticly activate a handler when creating each
> separate window using window.getService(IHandlerService.class) to get
> the IHandlerService in each case (since that will scope the handler to
> that window only).
>
> PW
>
>


--
Michael Scharf
Wind River Systems GmbH
http://www.WindRiver.com
http://MichaelScharf.blogspot.com/
Re: How to update the checked state of a command per window? [message #336475 is a reply to message #336469] Tue, 16 June 2009 12:53 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Michael Scharf wrote:
> How would I figure all this out without asking the
> newsgroup? I feel really stupid and I don't know
> how to figure out all the complexity of commands.

It's not you :-)

Right now, the resources on commands are the wiki included in my sig and
the (updated with Galileo out soon) stuff in the Help>Help
Contents>Platform Plug-in Developer Guide. But they're pretty slim.

I had hoped to create some more extensive docs on this along with
examples for each thing that people would like to do (for example,
checked state commands can now save their state so they reflect it
correctly on the next startup without activating their plugin). But
while 3.5 is ramping down, the work we need to put into e4 to be ready
at the end of July is consuming all of our time.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Previous Topic:Default actions in Common Navigator
Next Topic:Use activities to hide objectContribution from popup menus
Goto Forum:
  


Current Time: Sun Dec 21 18:54:36 GMT 2014

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

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