Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Need Command Reference on Startup(How can I get the state of a toggle sty;e copmmand?)
Need Command Reference on Startup [message #988234] Wed, 28 November 2012 21:54 Go to next message
Mark Leone is currently offline Mark Leone
Messages: 67
Registered: April 2012
Member
I contribute a toggle-style Command to a view menu via plugin.xml. The command has a state defined, with id org.eclipse.ui.commands.toggleState, and a default value of true the first time the runtime workspace is created. Afterwards, the state is automatically persisted between workbench restarts. The command shows up on the view menu, selected or not depending on its most recent state. When I select it, the default handler fires and is able to toggle the state and retrieve the old value.

That's all great, but having the command persist its state does me no good if I can't retrieve the state independent of the user executing the command. I use the toggle state to determine a certain behavior in the view. If I don't know the state of the command on startup, I can't make the view behave consistent with the toggle setting of the command, until the user executes the Command the first time, enabling me to retrieve the state in the handler's execute method.

So how can I get a reference to this command or its state value (my real objective), other than from the ExecutionEvent provided in the execute method of the handler?

[Updated on: Wed, 28 November 2012 21:55]

Report message to a moderator

Re: Need Command Reference on Startup [message #988237 is a reply to message #988234] Wed, 28 November 2012 22:15 Go to previous message
Mark Leone is currently offline Mark Leone
Messages: 67
Registered: April 2012
Member
So it looks like the CommandService is what I needed. I put the following inside the init method of my view, and this gives me the command state on startup.

ICommandService commandService = (ICommandService) getSite().getService(ICommandService.class);
Command cmd = commandService.getCommand(TEST_COMMAND_ID);
System.err.println("Command state: " + cmd.getState(RegistryToggleState.STATE_ID).getValue());
Previous Topic:Adding a help system
Next Topic:how we add a plugin to a RCP project
Goto Forum:
  


Current Time: Mon Apr 21 00:36:37 EDT 2014

Powered by FUDForum. Page generated in 0.01500 seconds