]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/handler/e4/CanvasCommandDelegate.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / handler / e4 / CanvasCommandDelegate.java
index 0e7e7dd34f74864701c1659f799a195b99d88a49..e69192addd408e77f9c26db3b205f7ba418703e9 100644 (file)
@@ -1,92 +1,92 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.diagram.handler.e4;\r
-\r
-import javax.inject.Named;\r
-\r
-import org.eclipse.core.runtime.IAdaptable;\r
-import org.eclipse.e4.core.di.annotations.CanExecute;\r
-import org.eclipse.e4.core.di.annotations.Execute;\r
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;\r
-import org.eclipse.e4.ui.services.IServiceConstants;\r
-import org.eclipse.ui.IEditorPart;\r
-import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.scenegraph.g2d.events.EventDebugPolicy;\r
-import org.simantics.scenegraph.g2d.events.EventQueue;\r
-import org.simantics.scenegraph.g2d.events.command.Command;\r
-import org.simantics.scenegraph.g2d.events.command.CommandEvent;\r
-import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
-\r
-/**\r
- * A handler for the Eclipse Command framework that delegates ID of the command\r
- * that triggered the event to the {@link EventQueue} of the\r
- * {@link ICanvasContext} where the event occurred.\r
- */\r
-public class CanvasCommandDelegate {\r
-\r
-    private final boolean DEBUG = EventDebugPolicy.CANVAS_COMMAND_DELEGATION;\r
-    \r
-    private static final String ACTIVE_PART_PARAMETER = "org.simantics.diagram.commandparameter.canvasCommandHandlerActiveWithPart";\r
-    private static final String DELEGATE_PARAMETER = "org.simantics.diagram.commandparameter.canvasCommandDelegateParameter";\r
-\r
-    @CanExecute\r
-    public boolean canExecute(@Named(ACTIVE_PART_PARAMETER) String activePartId, @Named(IServiceConstants.ACTIVE_PART) MPart activePart) {\r
-        if (activePart == null)\r
-            return false;\r
-        if (!(activePart.getObject() instanceof CompatibilityEditor))\r
-            return false;\r
-        CompatibilityEditor compatibilityEditor = (CompatibilityEditor) activePart.getObject();\r
-        IEditorPart part = compatibilityEditor.getEditor();\r
-        if (part == null)\r
-               return false;\r
-        ICanvasContext ctx = part.getAdapter(ICanvasContext.class);\r
-        if (ctx == null)\r
-            return false;\r
-        String id = compatibilityEditor.getReference().getId();\r
-        if (!(id.equals(activePartId)))\r
-            return false;\r
-        return true;\r
-    }\r
-    \r
-    @SuppressWarnings("restriction")\r
-    @Execute\r
-    public void execute(@Named(DELEGATE_PARAMETER) String commandId, @Named(IServiceConstants.ACTIVE_PART) MPart activePart) {\r
-        CommandEvent ce = new CommandEvent(null, System.currentTimeMillis(), new Command(commandId));\r
-        if (DEBUG)\r
-            System.out.println(getClass().getSimpleName() + ": trigger event for command " + ce.command);\r
-\r
-        Object object = activePart.getObject();\r
-        \r
-        IAdaptable part = null;\r
-        if (object instanceof CompatibilityEditor) {\r
-            CompatibilityEditor editor = (CompatibilityEditor) object;\r
-            part = editor.getPart();\r
-        } else if (object instanceof IAdaptable){\r
-            part = (IAdaptable) object; \r
-        }\r
-        ICanvasContext canvas = null;\r
-        if (part != null)\r
-            canvas = (ICanvasContext) part.getAdapter(ICanvasContext.class);\r
-        if (canvas == null) {\r
-            part = WorkbenchUtils.getActiveWorkbenchPart();\r
-            if (part != null)\r
-                canvas = (ICanvasContext) part.getAdapter(ICanvasContext.class);\r
-        }\r
-        if (canvas != null) {\r
-            if (DEBUG)\r
-                System.out.println(getClass().getSimpleName() + ": sending command " + commandId + " to " + part);\r
-            canvas.getEventQueue().queueEvent(ce);\r
-        }\r
-    }\r
-\r
+/*******************************************************************************
+ * 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.e4;
+
+import javax.inject.Named;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
+import org.simantics.g2d.canvas.ICanvasContext;
+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;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
+
+/**
+ * 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 {
+
+    private final boolean DEBUG = EventDebugPolicy.CANVAS_COMMAND_DELEGATION;
+    
+    private static final String ACTIVE_PART_PARAMETER = "org.simantics.diagram.commandparameter.canvasCommandHandlerActiveWithPart";
+    private static final String DELEGATE_PARAMETER = "org.simantics.diagram.commandparameter.canvasCommandDelegateParameter";
+
+    @CanExecute
+    public boolean canExecute(@Named(ACTIVE_PART_PARAMETER) String activePartId, @Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
+        if (activePart == null)
+            return false;
+        if (!(activePart.getObject() instanceof CompatibilityEditor))
+            return false;
+        CompatibilityEditor compatibilityEditor = (CompatibilityEditor) activePart.getObject();
+        IEditorPart part = compatibilityEditor.getEditor();
+        if (part == null)
+               return false;
+        ICanvasContext ctx = part.getAdapter(ICanvasContext.class);
+        if (ctx == null)
+            return false;
+        String id = compatibilityEditor.getReference().getId();
+        if (!(id.equals(activePartId)))
+            return false;
+        return true;
+    }
+    
+    @SuppressWarnings("restriction")
+    @Execute
+    public void execute(@Named(DELEGATE_PARAMETER) String commandId, @Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
+        CommandEvent ce = new CommandEvent(null, System.currentTimeMillis(), new Command(commandId));
+        if (DEBUG)
+            System.out.println(getClass().getSimpleName() + ": trigger event for command " + ce.command);
+
+        Object object = activePart.getObject();
+        
+        IAdaptable part = null;
+        if (object instanceof CompatibilityEditor) {
+            CompatibilityEditor editor = (CompatibilityEditor) object;
+            part = editor.getPart();
+        } else if (object instanceof IAdaptable){
+            part = (IAdaptable) object; 
+        }
+        ICanvasContext canvas = null;
+        if (part != null)
+            canvas = (ICanvasContext) part.getAdapter(ICanvasContext.class);
+        if (canvas == null) {
+            part = WorkbenchUtils.getActiveWorkbenchPart();
+            if (part != null)
+                canvas = (ICanvasContext) part.getAdapter(ICanvasContext.class);
+        }
+        if (canvas != null) {
+            if (DEBUG)
+                System.out.println(getClass().getSimpleName() + ": sending command " + commandId + " to " + part);
+            canvas.getEventQueue().queueEvent(ce);
+        }
+    }
+
 }
\ No newline at end of file