Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » [solved] Enable buttons
[solved] Enable buttons [message #766838] Fri, 16 December 2011 14:14 Go to next message
sschmitz is currently offline sschmitzFriend
Messages: 9
Registered: July 2011
Junior Member
Hey there,

I'm trying to enable some buttons in my toolbar after some action has been executed.

The plugin.xml looks like this:
The command to be enabled:

The Handler:

And the contribution to the toolbar:

The command which is supposed to enable the button calls:

This call does not have an immediate effect and I can't figure out why.
Is there a way to force the toolbar to redraw itself? It does so if I call an instance of TitleAreaDialog, but that's not the desired behaviour, the buttons are supposed to be enabled after I setEnabled(true).

It does not work with an <enableWhen> in the xml either, the change is not immediate.

I would be very pleased, if someone helped me!

[Updated on: Sat, 17 December 2011 12:56]

Report message to a moderator

Re: Enable buttons [message #766975 is a reply to message #766838] Fri, 16 December 2011 19:30 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

DoOneIteration should subclass AbstractHandler and use setBaseEnabled(*). Either that, or you have to fire the handler change event yourself. Read the javadoc for IHandler.


Re: Enable buttons [message #767235 is a reply to message #766838] Sat, 17 December 2011 11:57 Go to previous message
sschmitz is currently offline sschmitzFriend
Messages: 9
Registered: July 2011
Junior Member
DoOneIteration subclasses AbstractHandler now and the class responsible for changing the state of DoOneIteration calls

setBaseEnabled(boolean state)
simply calls

which fires
fireHandlerChanged(new HandlerEvent(this, true, false));

The isEnabled() method of DoOneIteration returns super.isEnabled().

The mechanism works fine when I start a new wizard, but still, the enablement is not changed immediately.
That kind of makes sense, because calling hasListeners() always returns false.
Who is supposed to listen to this event?

Edit: I got it!
I implemented the constructor and let it add a handler:
class EnablementListener implements IHandlerListener {
	boolean lastChange = false;
	public void handlerChanged(HandlerEvent handlerEvent) {
		lastChange = handlerEvent.isEnabledChanged();

So the constructor now looks like this:
public DoOneIteration(){
    addHandlerListener(new EnablementListener());

And it works Smile Thank you for your help!

Edit2 (for completeness' sake): addHandlerListener calls super.addHanderListener, in case someone having the same problem reads this thread.

[Updated on: Sat, 17 December 2011 12:58]

Report message to a moderator

Previous Topic:RCP Continuous Integration Environment advice
Next Topic:Do we have a limited number of decorations per page?
Goto Forum:

Current Time: Fri Oct 09 12:34:12 GMT 2015

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

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