1 package org.simantics.modeling.ui.diagram;
5 import org.eclipse.core.runtime.CoreException;
6 import org.eclipse.core.runtime.IConfigurationElement;
7 import org.eclipse.core.runtime.IExecutableExtension;
8 import org.eclipse.jface.action.Action;
9 import org.eclipse.jface.action.ActionContributionItem;
10 import org.eclipse.jface.action.IContributionItem;
11 import org.eclipse.jface.resource.ImageDescriptor;
12 import org.eclipse.ui.IEditorPart;
13 import org.simantics.db.ReadGraph;
14 import org.simantics.db.exception.DatabaseException;
15 import org.simantics.g2d.diagram.DiagramHints;
16 import org.simantics.g2d.diagram.IDiagram;
17 import org.simantics.g2d.layers.ILayersEditor;
18 import org.simantics.modeling.ui.Activator;
19 import org.simantics.modeling.ui.diagramEditor.DiagramEditor;
20 import org.simantics.ui.contribution.DynamicMenuContribution;
21 import org.simantics.utils.threads.AWTThread;
22 import org.simantics.utils.threads.ThreadUtils;
23 import org.simantics.utils.ui.workbench.WorkbenchUtils;
26 * @author Tuukka Lehtonen
28 public class SetFocusabilityContribution extends DynamicMenuContribution implements IExecutableExtension {
31 ImageDescriptor image = null;
35 public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
36 throws CoreException {
37 if (data instanceof Map<?,?>) {
38 @SuppressWarnings("unchecked")
39 Map<String, String> args = (Map<String, String>) data;
40 name = args.get("name");
41 String imageId = args.get("image");
42 image = Activator.getDefault().getImageRegistry().getDescriptor(imageId);
43 allow = Boolean.parseBoolean(args.get("allow"));
48 protected Object[] getSelectedObjects() {
49 IEditorPart editorPart = WorkbenchUtils.getActiveEditor();
50 if (editorPart == null)
52 if(editorPart instanceof DiagramEditor) {
53 DiagramEditor editor = (DiagramEditor) editorPart;
54 IDiagram diagram = (IDiagram) editor.getAdapter(IDiagram.class);
57 ILayersEditor le = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR);
60 return new Object[] { le, le.getIgnoreFocusSettings() };
66 protected IContributionItem[] getContributionItems(ReadGraph graph, Object[] elements) throws DatabaseException {
67 if (elements == NO_OBJECTS)
70 final ILayersEditor le = (ILayersEditor) elements[0];
71 final Boolean value = (Boolean) elements[1];
76 return new IContributionItem[] {
77 new ActionContributionItem(new Action(name, image) {
80 ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
83 le.setIgnoreFocusSettings(!value);