Skip to main content

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] Thu, 29 November 2012 02:54 Go to next message
Mark Leone is currently offline Mark LeoneFriend
Messages: 69
Registered: April 2012
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: Thu, 29 November 2012 02:55]

Report message to a moderator

Re: Need Command Reference on Startup [message #988237 is a reply to message #988234] Thu, 29 November 2012 03:15 Go to previous message
Mark Leone is currently offline Mark LeoneFriend
Messages: 69
Registered: April 2012
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: Tue Dec 07 22:07:34 GMT 2021

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

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

Back to the top