Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Update command handlers
Update command handlers [message #331702] Wed, 17 September 2008 11:10 Go to next message
Jan Kohnert is currently offline Jan KohnertFriend
Messages: 196
Registered: July 2009
Senior Member
Hello,

I'm using org.eclipse.handlers together with <enabledWhen> syntax to keep
my commands updated.
My problem is, that when executing a command the handler service seems not
to update the toolbar and other controls that are slways shown on the
workbench.

My command implementations look like this:
public class MyCommand extends org.eclipse.core.commands.AbstractHandler{
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Command execution code
return null;
}
}

I've tried to call a update of the Commands manually but this had no
effect at all.
ICommandService service = (ICommandService)
PlatformUI.getWorkbench().getService(ICommandService.class);
service.refreshElements("my.procect.commands.MyCommand", null);

How can I get a update of my handlers to get correctly enabled and
disabled commands?

Thank,
Jan
Re: Update command handlers [message #331717 is a reply to message #331702] Thu, 18 September 2008 08:20 Go to previous messageGo to next message
Jan Kohnert is currently offline Jan KohnertFriend
Messages: 196
Registered: July 2009
Senior Member
Hello,

Further investigation brought me to the insight that my handlers work just
fine. The ‘enableWhen’ (and also ‘activeWhen’ when using it instead)
syntax keeps the handlers updated in my UI.

The problem is, that the handler state is not getting verified when
pressing a button such as a toolbar item.

In my case I have a start and a stop button belonging to a UI plug-in that
mirrors the activity of another plug-in performing cron jobs. The cron job
plug-in knows nothing about the UI. When pressing 'start' for instance the
cron job plug-in gets started and the UI plug-in starts display its
activities.
Just after pressing the start button I want this button to get disabled
and the stop button get enabled instead. Right now the enabled states of
the handlers are only checked when selecting something connected with the
selection service, or when pressing another button.

How can I force the handlers performing a verify of their conditions?

Thanks,
Jan
Re: Update command handlers [message #331726 is a reply to message #331717] Thu, 18 September 2008 14:08 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

If you are programmatically setting your handler enabled state in your
handler, you need to make sure you fire a HandlerEvent when it changes.

Or are you using property testers in the enabledWhen expression?

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: Update command handlers [message #331742 is a reply to message #331726] Fri, 19 September 2008 06:46 Go to previous messageGo to next message
Jan Kohnert is currently offline Jan KohnertFriend
Messages: 196
Registered: July 2009
Senior Member
Paul,

I'm usingthe following configuration:

<handler
class=" com.swisslab.xslprocessor.ui.commands.StartAllProcessorsComm and "
commandId="com.swisslab.xslprocessor.ui.startAllProcessorsCommand ">
<activeWhen>
<reference
definitionId="com.swisslab.xslprocessor.ui.defenitions.processorsStopped ">
</reference>
</activeWhen>
</handler>


<definition
id="com.swisslab.xslprocessor.ui.defenitions.processorsStopped ">
<not>
<test forcePluginActivation="false"
property="com.swisslab.xslprocessor.ui.test.processors.running ">
</test>
</not>
</definition>

<propertyTester class="com.swisslab.xslprocessor.ui.tests.ProcessorsTester"
id="com.swisslab.xslprocessor.ui.test.processors"
namespace="com.swisslab.xslprocessor.ui.test.processors"
properties="running" type="java.lang.Object"> </propertyTester>

And a PropertyTester Class that checks my cron job plug-in:
public class ProcessorsTester extends PropertyTester {

private final static String RUNNING = "running";

@Override
public boolean test(Object receiver, String property, Object[] args,
Object expectedValue) {
// check processors
if (property.equals(RUNNING)){
// check running
for (XSLProcessor processor
:XslProcessorPlugin.getDefault().getProcessors()){
if (processor.isRunning()){
// One is running
return true;
}
}
//no processor running
return false;
}
return false;
}
}

The PropertyTester class returns the correct values.

Jan
Re: Update command handlers [message #331748 is a reply to message #331742] Fri, 19 September 2008 14:04 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Jan Kohnert wrote:
> Paul,
>
> I'm usingthe following configuration:

Oh, refreshElements(*) is a request to the framework to allow a handler
to change aspects of a UI element (text, icon, etc).

To cause a property tester to be re-evaluated you need to use
org.eclipse.ui.services.IEvaluationService.requestEvaluation (String) in 3.4

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:How to refreshing the overall workspace?
Next Topic:Re: widgets size in ManagedForm
Goto Forum:
  


Current Time: Mon Jan 13 21:50:36 GMT 2025

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

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

Back to the top