X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FdiagramEditor%2Fhandlers%2Fe4%2FToggleFocusabilityHandler.java;h=8eef0300be53300746e4ee4ef37d52d51da32f87;hp=a6cd3be0e87af9861bf809ba6591c9077852b686;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/handlers/e4/ToggleFocusabilityHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/handlers/e4/ToggleFocusabilityHandler.java index a6cd3be0e..8eef0300b 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/handlers/e4/ToggleFocusabilityHandler.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/handlers/e4/ToggleFocusabilityHandler.java @@ -1,85 +1,85 @@ -/******************************************************************************* - * Copyright (c) 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: - * Semantum Oy - initial API and implementation - *******************************************************************************/ -package org.simantics.modeling.ui.diagramEditor.handlers.e4; - -import org.eclipse.e4.core.contexts.Active; -import org.eclipse.e4.core.di.annotations.CanExecute; -import org.eclipse.e4.core.di.annotations.Execute; -import org.eclipse.e4.core.di.annotations.Optional; -import org.eclipse.e4.ui.model.application.ui.basic.MPart; -import org.eclipse.e4.ui.model.application.ui.menu.MToolItem; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor; -import org.simantics.g2d.diagram.DiagramHints; -import org.simantics.g2d.diagram.IDiagram; -import org.simantics.g2d.layers.ILayersEditor; -import org.simantics.modeling.ui.diagramEditor.DiagramEditor; -import org.simantics.utils.ui.workbench.WorkbenchUtils; - -/** - * @author Tuukka Lehtonen - */ -public class ToggleFocusabilityHandler { - - @CanExecute - public boolean canExecute(@Active MPart part) { - if (!(part.getObject() instanceof CompatibilityEditor)) - return false; - CompatibilityEditor editor = (CompatibilityEditor) part.getObject(); - if (!(editor.getPart() instanceof DiagramEditor)) - return false; - return true; - } - - @Execute - public void execute(@Optional MToolItem toolItem) { - ILayersEditor le = getLayers(); - if (le != null) { - boolean b = le.getIgnoreFocusSettings(); - le.setIgnoreFocusSettings( !b ); - - if (toolItem != null) { - toolItem.setSelected(!b); - toolItem.setTooltip((!b ? "Deny" : "Allow") + " Focusing and Editing of Images"); - } - } - } - - protected ILayersEditor getLayers() { - DiagramEditor editor = getEditor(); - if (editor == null) - return null; - return getLayers(editor); - } - - protected ILayersEditor getLayers(DiagramEditor editor) { - // The diagram might not be available since the diagram editor loads it asynchronously. - IDiagram diagram = (IDiagram) editor.getAdapter(IDiagram.class); - if (diagram == null) - return null; - //System.out.println("getLayersEditor(" + diagram + ")"); - ILayersEditor le = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR); - return le; - } - - protected DiagramEditor getEditor() { - IEditorPart editorPart = WorkbenchUtils.getActiveEditor(); - if (editorPart == null) - return null; - if (editorPart instanceof DiagramEditor) { - DiagramEditor editor = (DiagramEditor) editorPart; - return editor; - } - return null; - } - -} +/******************************************************************************* + * Copyright (c) 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: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.ui.diagramEditor.handlers.e4; + +import org.eclipse.e4.core.contexts.Active; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.model.application.ui.menu.MToolItem; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor; +import org.simantics.g2d.diagram.DiagramHints; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.layers.ILayersEditor; +import org.simantics.modeling.ui.diagramEditor.DiagramEditor; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +/** + * @author Tuukka Lehtonen + */ +public class ToggleFocusabilityHandler { + + @CanExecute + public boolean canExecute(@Active MPart part) { + if (!(part.getObject() instanceof CompatibilityEditor)) + return false; + CompatibilityEditor editor = (CompatibilityEditor) part.getObject(); + if (!(editor.getPart() instanceof DiagramEditor)) + return false; + return true; + } + + @Execute + public void execute(@Optional MToolItem toolItem) { + ILayersEditor le = getLayers(); + if (le != null) { + boolean b = le.getIgnoreFocusSettings(); + le.setIgnoreFocusSettings( !b ); + + if (toolItem != null) { + toolItem.setSelected(!b); + toolItem.setTooltip((!b ? "Deny" : "Allow") + " Focusing and Editing of Images"); + } + } + } + + protected ILayersEditor getLayers() { + DiagramEditor editor = getEditor(); + if (editor == null) + return null; + return getLayers(editor); + } + + protected ILayersEditor getLayers(DiagramEditor editor) { + // The diagram might not be available since the diagram editor loads it asynchronously. + IDiagram diagram = (IDiagram) editor.getAdapter(IDiagram.class); + if (diagram == null) + return null; + //System.out.println("getLayersEditor(" + diagram + ")"); + ILayersEditor le = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR); + return le; + } + + protected DiagramEditor getEditor() { + IEditorPart editorPart = WorkbenchUtils.getActiveEditor(); + if (editorPart == null) + return null; + if (editorPart instanceof DiagramEditor) { + DiagramEditor editor = (DiagramEditor) editorPart; + return editor; + } + return null; + } + +}