]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/ElementSelectionTools.java
Finder visualisation coloring to diagram & checkbox for enable/disable
[simantics/district.git] / org.simantics.district.selection.ui / src / org / simantics / district / selection / ui / ElementSelectionTools.java
index 130e3f4f3550d8e98dc5b9795743dba56a6d867a..06622b82baa73c8125556067a0c39782f30dcb0e 100644 (file)
@@ -22,6 +22,7 @@ import org.simantics.layer0.Layer0;
 import org.simantics.ui.selection.AnyResource;
 import org.simantics.ui.selection.AnyVariable;
 import org.simantics.ui.selection.WorkbenchSelectionContentType;
+import org.simantics.utils.ui.color.Color;
 
 public class ElementSelectionTools {
 
@@ -37,8 +38,9 @@ public class ElementSelectionTools {
                                return (T)element;
                        }
                        else if (contentType instanceof AnyVariable) {
+                               AnyVariable type = (AnyVariable) contentType;
                                try {
-                                       return (T) Simantics.getSession().syncRequest(new ResourceRead<Variable>(element) {
+                                       return (T) type.processor.syncRequest(new ResourceRead<Variable>(element) {
                                                public Variable perform(ReadGraph graph) throws DatabaseException {
                                                        return ElementSelector.getVariableForElement(graph, resource);
                                                }
@@ -81,4 +83,19 @@ public class ElementSelectionTools {
                }
        }
 
+       public static float[] colorToLiteral(Color color) {
+               // BGRA float values out
+               return new float[] {
+                               (float)color.getB() / 255,
+                               (float)color.getG() / 255,
+                               (float)color.getR() / 255,
+                               1.f,
+                       };
+       }
+
+       public static Color literalToColor(float[] color) {
+               // BGRA float values in
+               return new Color((int) (color[2] * 255), (int) (color[1] * 255), (int) (color[0] * 255));
+       }
+
 }