-/*******************************************************************************\r
- * Copyright (c) 2007, 2013 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.participant;\r
-\r
-import java.awt.event.FocusEvent;\r
-import java.awt.event.FocusListener;\r
-\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;\r
-import org.simantics.g2d.canvas.impl.DependencyReflection.Reference;\r
-import org.simantics.g2d.chassis.AWTChassis;\r
-import org.simantics.g2d.chassis.SWTChassis;\r
-\r
-/**\r
- * The purpose of this participant is to properly handle contexts in Eclipse/SWT\r
- * based deployments G2D canvases where it is possible that Eclipse eats input\r
- * events based on UI contexts, key bindings, etc.\r
- * \r
- * This participant depends on the {@link ContextUtil} canvas participant.\r
- * \r
- * When some other scene graph component or UI Part, besides the root pane, gets focus,\r
- * this participant will deactivate its {@link #contextId}. When the root pane gets the \r
- * focus back, it will restore {@link #contextId} to allow Eclipse key bindings\r
- * for that {@link #contextId} to work properly. \r
- * \r
- * @see ContextUtil\r
- * \r
- * @author J-P Laine\r
- * @author Tuukka Lehtonen\r
- * @author Teemu Lempinen\r
- */\r
-public class SGFocusParticipant extends AbstractCanvasParticipant implements FocusListener {\r
-\r
- @Reference\r
- ContextUtil contextUtil;\r
- \r
- @Reference\r
- org.simantics.diagram.participant.e4.ContextUtil e4ContextUtil;\r
-\r
- final SWTChassis chassis;\r
- String contextId;\r
- ContextState originalContextState;\r
-\r
- public SGFocusParticipant(SWTChassis chassis, String contextId) {\r
- super();\r
- this.chassis = chassis;\r
- this.contextId = contextId;\r
- }\r
-\r
- @Override\r
- public void addedToContext(ICanvasContext ctx) {\r
- super.addedToContext(ctx);\r
- chassis.getAWTComponent().addFocusListener(this);\r
- }\r
-\r
- @Override\r
- public void removedFromContext(ICanvasContext ctx) {\r
- if (!chassis.isDisposed()) {\r
- AWTChassis component = chassis.getAWTComponent();\r
- if (component != null)\r
- component.removeFocusListener(this);\r
- }\r
- super.removedFromContext(ctx);\r
- }\r
-\r
- @Override\r
- public void focusGained(FocusEvent e) {\r
- ContextUtil util = contextUtil;\r
- if (util != null) {\r
- DiagramCommandBindings.activateBindings(util, contextId);\r
- } else {\r
- org.simantics.diagram.participant.e4.ContextUtil e4Util = e4ContextUtil;\r
- if (e4Util != null) {\r
- DiagramCommandBindings.activateBindings(e4Util, contextId);\r
- }\r
- }\r
- }\r
-\r
- @Override\r
- public void focusLost(FocusEvent e) {\r
- ContextUtil util = contextUtil;\r
- if (util != null) {\r
- DiagramCommandBindings.deactivateBindings(util, contextId);\r
- } else {\r
- org.simantics.diagram.participant.e4.ContextUtil e4Util = e4ContextUtil;\r
- if (e4Util != null) {\r
- DiagramCommandBindings.deactivateBindings(e4Util, contextId);\r
- }\r
- }\r
- }\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2013 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.participant;
+
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
+import org.simantics.g2d.canvas.impl.DependencyReflection.Reference;
+import org.simantics.g2d.chassis.AWTChassis;
+import org.simantics.g2d.chassis.SWTChassis;
+
+/**
+ * The purpose of this participant is to properly handle contexts in Eclipse/SWT
+ * based deployments G2D canvases where it is possible that Eclipse eats input
+ * events based on UI contexts, key bindings, etc.
+ *
+ * This participant depends on the {@link ContextUtil} canvas participant.
+ *
+ * When some other scene graph component or UI Part, besides the root pane, gets focus,
+ * this participant will deactivate its {@link #contextId}. When the root pane gets the
+ * focus back, it will restore {@link #contextId} to allow Eclipse key bindings
+ * for that {@link #contextId} to work properly.
+ *
+ * @see ContextUtil
+ *
+ * @author J-P Laine
+ * @author Tuukka Lehtonen
+ * @author Teemu Lempinen
+ */
+public class SGFocusParticipant extends AbstractCanvasParticipant implements FocusListener {
+
+ @Reference
+ ContextUtil contextUtil;
+
+ @Reference
+ org.simantics.diagram.participant.e4.ContextUtil e4ContextUtil;
+
+ final SWTChassis chassis;
+ String contextId;
+ ContextState originalContextState;
+
+ public SGFocusParticipant(SWTChassis chassis, String contextId) {
+ super();
+ this.chassis = chassis;
+ this.contextId = contextId;
+ }
+
+ @Override
+ public void addedToContext(ICanvasContext ctx) {
+ super.addedToContext(ctx);
+ chassis.getAWTComponent().addFocusListener(this);
+ }
+
+ @Override
+ public void removedFromContext(ICanvasContext ctx) {
+ if (!chassis.isDisposed()) {
+ AWTChassis component = chassis.getAWTComponent();
+ if (component != null)
+ component.removeFocusListener(this);
+ }
+ super.removedFromContext(ctx);
+ }
+
+ @Override
+ public void focusGained(FocusEvent e) {
+ ContextUtil util = contextUtil;
+ if (util != null) {
+ DiagramCommandBindings.activateBindings(util, contextId);
+ } else {
+ org.simantics.diagram.participant.e4.ContextUtil e4Util = e4ContextUtil;
+ if (e4Util != null) {
+ DiagramCommandBindings.activateBindings(e4Util, contextId);
+ }
+ }
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ ContextUtil util = contextUtil;
+ if (util != null) {
+ DiagramCommandBindings.deactivateBindings(util, contextId);
+ } else {
+ org.simantics.diagram.participant.e4.ContextUtil e4Util = e4ContextUtil;
+ if (e4Util != null) {
+ DiagramCommandBindings.deactivateBindings(e4Util, contextId);
+ }
+ }
+ }
+