]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SetFocusableHandler.java
Some more added functionality to simantics district editor etc
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / contributions / SetFocusableHandler.java
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SetFocusableHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SetFocusableHandler.java
new file mode 100644 (file)
index 0000000..b0cfad3
--- /dev/null
@@ -0,0 +1,53 @@
+
+package org.simantics.district.network.ui.contributions;
+
+import java.util.Collection;
+
+import javax.inject.Named;
+
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorPart;
+import org.simantics.g2d.diagram.DiagramHints;
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.ElementLayers;
+import org.simantics.g2d.layers.ILayer;
+import org.simantics.g2d.layers.ILayers;
+import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
+
+public class SetFocusableHandler {
+
+    @CanExecute
+    public boolean canExecute(IEclipseContext popupContext, @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
+        @SuppressWarnings("unchecked")
+        Collection<IElement> elements = (Collection<IElement>) popupContext.get(SetFocusableDynamicMenuContribution.FOCUSABLE_ELEMENTS);
+        return !elements.isEmpty();
+    }
+    
+    @Execute
+    public void execute(IEclipseContext popupContext, @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection, @Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
+        IEditorPart editorPart = E4WorkbenchUtils.getActiveIEditorPart(activePart);
+        
+        IDiagram diagram = editorPart.getAdapter(IDiagram.class);
+        if (diagram == null)
+            return;
+        
+        @SuppressWarnings("unchecked")
+        Collection<IElement> selectedElements = (Collection<IElement>) popupContext.get(SetFocusableDynamicMenuContribution.FOCUSABLE_ELEMENTS);
+        
+        ILayers le = diagram.getHint(DiagramHints.KEY_LAYERS);
+        for (IElement elem : selectedElements) {
+            ElementLayers el = elem.getElementClass().getAtMostOneItemOfClass(ElementLayers.class);
+            for (ILayer layer : le.getVisibleLayers()) {
+                boolean focusable = el.isFocusable(elem, layer);
+                el.setFocusability(elem, layer, !focusable);
+            }
+        }
+    }
+
+}
\ No newline at end of file