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;
16 import org.eclipse.core.commands.AbstractHandler;
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.commands.ICommandService;
22 import org.eclipse.ui.commands.IElementUpdater;
23 import org.eclipse.ui.menus.UIElement;
24 import org.simantics.g2d.diagram.DiagramHints;
25 import org.simantics.g2d.diagram.IDiagram;
26 import org.simantics.g2d.layers.ILayersEditor;
27 import org.simantics.modeling.ui.diagramEditor.DiagramEditor;
28 import org.simantics.utils.ui.workbench.WorkbenchUtils;
31 * @author Tuukka Lehtonen
33 public class ToggleFocusabilityHandler extends AbstractHandler implements IElementUpdater {
36 public Object execute(ExecutionEvent event) throws ExecutionException {
37 ILayersEditor le = getLayers();
39 boolean b = le.getIgnoreFocusSettings();
40 le.setIgnoreFocusSettings( !b );
42 ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
43 service.refreshElements(event.getCommand().getId(), null);
48 @SuppressWarnings("rawtypes")
50 public void updateElement(UIElement element, Map parameters) {
51 //System.out.println("updateElement: " + element);
52 DiagramEditor editor = getEditor();
54 //System.out.println("updateElement2: " + editor);
55 ILayersEditor le = getLayers(editor);
57 boolean bool = le.getIgnoreFocusSettings();
58 //System.out.println("get ignore focus setting: " + bool);
59 element.setChecked(bool);
60 element.setTooltip((bool ? "Deny" : "Allow") + " Focusing and Editing of Images");
66 protected ILayersEditor getLayers() {
67 DiagramEditor editor = getEditor();
70 return getLayers(editor);
73 protected ILayersEditor getLayers(DiagramEditor editor) {
74 // The diagram might not be available since the diagram editor loads it asynchronously.
75 IDiagram diagram = (IDiagram) editor.getAdapter(IDiagram.class);
78 //System.out.println("getLayersEditor(" + diagram + ")");
79 ILayersEditor le = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR);
83 protected DiagramEditor getEditor() {
84 IEditorPart editorPart = WorkbenchUtils.getActiveEditor();
85 if (editorPart == null)
87 if (editorPart instanceof DiagramEditor) {
88 DiagramEditor editor = (DiagramEditor) editorPart;