X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fparticipant%2FSGFocusParticipant.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fparticipant%2FSGFocusParticipant.java;h=a29ecd8a2cb25030c7cf4d2d21b2320b2928c808;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=6adc34a57e524d24ec3aa1adcb831e89e6aae687;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/SGFocusParticipant.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/SGFocusParticipant.java index 6adc34a57..a29ecd8a2 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/SGFocusParticipant.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/SGFocusParticipant.java @@ -1,101 +1,101 @@ -/******************************************************************************* - * 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); - } - } - } - +/******************************************************************************* + * 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); + } + } + } + } \ No newline at end of file