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:
<command
    id="piOptimize.commands.doOneIteration"
    name="doOneIteration">
</command>

The Handler:
<extension
    point="org.eclipse.ui.handlers">
        <handler
            class="pioptimize.commands.DoOneIteration"
            commandId="piOptimize.commands.doOneIteration">
        </handler>
</extension>


And the contribution to the toolbar:
<command
    commandId="piOptimize.commands.doOneIteration"
    icon="icons/run_next.png"
    style="push">
</command>


The command which is supposed to enable the button calls:
DoOneIteration.setEnabled(true);

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.

PW


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
button.setBaseEnabled(true);


setBaseEnabled(boolean state)
simply calls
super.setBaseEnabled(state)

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(){
    Activator.getDefault().addButtons(this);
    setBaseEnabled(false);
    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: Sun Dec 21 04:58:39 GMT 2014

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

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