X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fhandler%2FCanvasCommandDelegate.java;h=9aac515a3f6dfb431f02364d98895b8dd5004fd3;hb=16ba55a96dc1f81e97663a6b5e3b728267d2eac4;hp=094fc8722316a47821ad55f954d72c2106cc89a4;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/CanvasCommandDelegate.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/CanvasCommandDelegate.java index 094fc8722..9aac515a3 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/CanvasCommandDelegate.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/CanvasCommandDelegate.java @@ -1,71 +1,71 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram.handler; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.swt.widgets.Event; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.simantics.g2d.canvas.ICanvasContext; -import org.simantics.g2d.chassis.ICanvasChassis; -import org.simantics.scenegraph.g2d.events.EventDebugPolicy; -import org.simantics.scenegraph.g2d.events.EventQueue; -import org.simantics.scenegraph.g2d.events.command.Command; -import org.simantics.scenegraph.g2d.events.command.CommandEvent; - -/** - * A handler for the Eclipse Command framework that delegates ID of the command - * that triggered the event to the {@link EventQueue} of the - * {@link ICanvasContext} where the event occurred. - */ -public class CanvasCommandDelegate extends AbstractHandler { - - private final boolean DEBUG = EventDebugPolicy.CANVAS_COMMAND_DELEGATION; - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - Event e = ((Event)event.getTrigger()); - CommandEvent ce = new CommandEvent(null, e.time, new Command(event.getCommand().getId())); - - if (DEBUG) - System.out.println(getClass().getSimpleName() + ": trigger event = " + e + " for command " + ce.command); - - if (e.widget instanceof ICanvasChassis) { - ICanvasChassis chassis = (ICanvasChassis) e.widget; - ICanvasContext canvas = chassis.getCanvasContext(); - if (canvas != null) { - if (DEBUG) - System.out.println(getClass().getSimpleName() + ": sending command " + event.getCommand().getId() + " to " + chassis); - canvas.getEventQueue().queueEvent( ce ); - } - } else { - ICanvasContext canvas = null; - IWorkbenchPart part = HandlerUtil.getActiveEditor(event); - if (part != null) - canvas = (ICanvasContext) part.getAdapter(ICanvasContext.class); - if (canvas == null) { - part = HandlerUtil.getActivePart(event); - if (part != null) - canvas = (ICanvasContext) part.getAdapter(ICanvasContext.class); - } - if (canvas != null) { - if (DEBUG) - System.out.println(getClass().getSimpleName() + ": sending command " + event.getCommand().getId() + " to " + part); - canvas.getEventQueue().queueEvent(ce); - } - } - return null; - } - +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.handler; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.chassis.ICanvasChassis; +import org.simantics.scenegraph.g2d.events.EventDebugPolicy; +import org.simantics.scenegraph.g2d.events.EventQueue; +import org.simantics.scenegraph.g2d.events.command.Command; +import org.simantics.scenegraph.g2d.events.command.CommandEvent; + +/** + * A handler for the Eclipse Command framework that delegates ID of the command + * that triggered the event to the {@link EventQueue} of the + * {@link ICanvasContext} where the event occurred. + */ +public class CanvasCommandDelegate extends AbstractHandler { + + private final boolean DEBUG = EventDebugPolicy.CANVAS_COMMAND_DELEGATION; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + Event e = ((Event)event.getTrigger()); + CommandEvent ce = new CommandEvent(null, e.time, new Command(event.getCommand().getId())); + + if (DEBUG) + System.out.println(getClass().getSimpleName() + ": trigger event = " + e + " for command " + ce.command); + + if (e.widget instanceof ICanvasChassis) { + ICanvasChassis chassis = (ICanvasChassis) e.widget; + ICanvasContext canvas = chassis.getCanvasContext(); + if (canvas != null) { + if (DEBUG) + System.out.println(getClass().getSimpleName() + ": sending command " + event.getCommand().getId() + " to " + chassis); + canvas.getEventQueue().queueEvent( ce ); + } + } else { + ICanvasContext canvas = null; + IWorkbenchPart part = HandlerUtil.getActiveEditor(event); + if (part != null) + canvas = (ICanvasContext) part.getAdapter(ICanvasContext.class); + if (canvas == null) { + part = HandlerUtil.getActivePart(event); + if (part != null) + canvas = (ICanvasContext) part.getAdapter(ICanvasContext.class); + } + if (canvas != null) { + if (DEBUG) + System.out.println(getClass().getSimpleName() + ": sending command " + event.getCommand().getId() + " to " + part); + canvas.getEventQueue().queueEvent(ce); + } + } + return null; + } + } \ No newline at end of file