[solved] Enable buttons [message #766838] |
Fri, 16 December 2011 14:14 |
sschmitz 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 #767235 is a reply to message #766838] |
Sat, 17 December 2011 11:57 |
sschmitz 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 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
|
|
|
Powered by
FUDForum. Page generated in 0.02136 seconds