1 /*******************************************************************************
2 * Copyright (c) 2013 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.diagramEditor.handlers.e4;
14 import org.eclipse.e4.core.contexts.Active;
15 import org.eclipse.e4.core.di.annotations.CanExecute;
16 import org.eclipse.e4.core.di.annotations.Execute;
17 import org.eclipse.e4.core.di.annotations.Optional;
18 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19 import org.eclipse.e4.ui.model.application.ui.menu.MToolItem;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
22 import org.simantics.g2d.diagram.DiagramHints;
23 import org.simantics.g2d.diagram.IDiagram;
24 import org.simantics.g2d.layers.ILayersEditor;
25 import org.simantics.modeling.ui.diagramEditor.DiagramEditor;
26 import org.simantics.utils.ui.workbench.WorkbenchUtils;
29 * @author Tuukka Lehtonen
31 public class ToggleFocusabilityHandler {
34 public boolean canExecute(@Active MPart part) {
35 if (!(part.getObject() instanceof CompatibilityEditor))
37 CompatibilityEditor editor = (CompatibilityEditor) part.getObject();
38 if (!(editor.getPart() instanceof DiagramEditor))
44 public void execute(@Optional MToolItem toolItem) {
45 ILayersEditor le = getLayers();
47 boolean b = le.getIgnoreFocusSettings();
48 le.setIgnoreFocusSettings( !b );
50 if (toolItem != null) {
51 toolItem.setSelected(!b);
52 toolItem.setTooltip((!b ? "Deny" : "Allow") + " Focusing and Editing of Images");
57 protected ILayersEditor getLayers() {
58 DiagramEditor editor = getEditor();
61 return getLayers(editor);
64 protected ILayersEditor getLayers(DiagramEditor editor) {
65 // The diagram might not be available since the diagram editor loads it asynchronously.
66 IDiagram diagram = (IDiagram) editor.getAdapter(IDiagram.class);
69 //System.out.println("getLayersEditor(" + diagram + ")");
70 ILayersEditor le = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR);
74 protected DiagramEditor getEditor() {
75 IEditorPart editorPart = WorkbenchUtils.getActiveEditor();
76 if (editorPart == null)
78 if (editorPart instanceof DiagramEditor) {
79 DiagramEditor editor = (DiagramEditor) editorPart;