Home » Eclipse Projects » Eclipse Platform » Force re-evaluation of handler enabledWhen expressions from Handler (eclipse 3.3)
Force re-evaluation of handler enabledWhen expressions from Handler (eclipse 3.3) [message #490529] |
Thu, 08 October 2009 21:58  |
Eclipse User |
|
|
|
I am posting here because the closest thing I've found to an answer so far was posted on the RCP newsgroup, in a thread titled Command handler enabled state with dynamic data model. Sorry if it should go somewhere else.
I have zoom in and zoom out, each with a toolbar button, command, and handler. The handler is delcared in plugin.xml and it has an enabledWhen condition.
When I zoom in or out, I want to re-evaluate that enabledWhen expression and update the enabled state of the handler. I've attempted to do this like so:
each of the zoomIn and zoomOut handlers adds a listener to the canvas so that on any zoom event, fireHandlerChanged(HandlerEvent) gets called (See the code I've included at the end of the comment).
However, this doesn't actually get the enabledWhen condition to be re-evaluated, and the HandlerProxy.setProxyEnabled(boolean) doesn't get called.
I noticed that selection changes will force the condition to be re-evaluated, and if in the canvasZoomed listener method I have a canvas.fireSelectionChanged(), that does what I want it to do. Unfortunately, this would violate my project's abstractions, so I can't have an Canvas.fireSelectionChanged method.
I saw in the old thread I referenced that maybe I could use org.eclipse.ui.services.IEvaluationService.requestEvaluation (String), but that doesn't exist in Eclipse 3.3.
I also foresee another problem, even if I get the above working:
if zoomOut starts disabled, it can never execute, so it won't get a chance to add a listener to the canvas. Thus I need a way for the zoomIn handler to add a listener that can re-enable zoomOut, and vice-versa.
Many thanks for any help for a first-time poster.
Gary
public Object execute(ExecutionEvent arg0) throws ExecutionException {
Canvas canvas = getCanvas();
if (listener == null) {
listener = new CanvasListener() {
@Override
public void canvasZoomed(DrawCanvasEvent event) {
Object[] listeners = getListeners();
HandlerEvent handlerEvent = new HandlerEvent(ZoomInHandler.this, true, false);
for (int i = 0; i < listeners.length; i++) {
final IHandlerListener listener = (IHandlerListener) listeners[i];
listener.handlerChanged(handlerEvent);
}
ZoomInHandler.this.fireHandlerChanged(handlerEvent);
}
};
}
canvas.addCanvasListener(listener);
return null;
}
|
|
| | | | | | | |
Goto Forum:
Current Time: Sat Jul 05 00:32:25 EDT 2025
Powered by FUDForum. Page generated in 0.04396 seconds
|