]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.selection/src/org/simantics/district/selection/ElementSelector.java
Fixed most warnings from district codebase after JavaSE-11 switch
[simantics/district.git] / org.simantics.district.selection / src / org / simantics / district / selection / ElementSelector.java
index 4143248214b97786661ae6465bf160dafec42a77..ff978059dab381aaf86d651fede0f3815613f181 100644 (file)
@@ -56,6 +56,8 @@ public class ElementSelector {
        Selector selector;
        Condition condition;
        
+       private float[] color;
+       
        static Logger LOG = LoggerFactory.getLogger(ElementSelector.class);
        
        static ElementSelectionResource ES;
@@ -81,6 +83,9 @@ public class ElementSelector {
                try {
                        this.name = graph.getRelatedValue(resource, L0.HasLabel);
                        this.expression = getExpression(graph, resource);
+                       
+                       float[] color = graph.getPossibleRelatedValue(resource, ES.Selection_HasHighlightColor);
+                       this.color = color;
                } catch (DatabaseException e) {
                        LOG.error("Error reading element selector", e);
                        throw e;
@@ -149,6 +154,13 @@ public class ElementSelector {
        public Condition getCondition() {
                return condition;
        }
+       
+       /**
+        * Get the selection highlight color as a four element BGRA array.
+        */
+       public float[] getColor() {
+               return color;
+       }
 
        /**
         * 
@@ -170,20 +182,26 @@ public class ElementSelector {
                        return Simantics.getSession().syncRequest(new Read<Map<Resource, String>>() {
                                @Override
                                public Map<Resource, String> perform(ReadGraph graph) throws DatabaseException {
+                                       Layer0 L0 = Layer0.getInstance(graph);
+                                       StructuralResource2 STR = StructuralResource2.getInstance(graph);
+                                       DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+                                       ModelingResources MOD = ModelingResources.getInstance(graph);
+                                       
                                        Map<Resource, String> result = new HashMap<>();
                                        Resource model = graph.syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));
-                                       List<Resource> composites = QueryIndexUtils.searchByType(graph, model, StructuralResource2.getInstance(graph).Composite);
+                                       List<Resource> composites = QueryIndexUtils.searchByType(graph, model, STR.Composite);
                                        for (Resource r : composites) {
                                                // Get diagram
-                                               Resource diagram = graph.getPossibleObject(r, ModelingResources.getInstance(graph).CompositeToDiagram);
-                                               if (diagram == null) continue;
+                                               Resource diagram = graph.getPossibleObject(r, MOD.CompositeToDiagram);
+                                               if (diagram == null || !graph.isInstanceOf(diagram, DN.Diagram))
+                                                       continue;
                                                
                                                // Filter out user component diagrams
-                                               Resource parent = graph.getPossibleObject(r, Layer0.getInstance(graph).PartOf);
-                                               if (parent == null || graph.isInheritedFrom(parent, StructuralResource2.getInstance(graph).Component))
+                                               Resource parent = graph.getPossibleObject(r, L0.PartOf);
+                                               if (parent == null || graph.isInheritedFrom(parent, STR.Component))
                                                        continue;
                                                
-                                               result.put(r, graph.getRelatedValue(r, Layer0.getInstance(graph).HasName));
+                                               result.put(r, graph.getRelatedValue(r, L0.HasName));
                                        }
                                        
                                        return result;
@@ -683,11 +701,14 @@ public class ElementSelector {
                
                Condition(ReadGraph graph, Resource r) throws DatabaseException {
                        this(r);
+                       ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
                        isInverse = graph.hasStatement(r, ES.Condition_IsInverse, r);
                }
                
                public abstract boolean match(ReadGraph graph, Resource r) throws DatabaseException;
                public Resource update(WriteGraph graph) throws DatabaseException {
+                       ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
+                       
                        assert(resource != null);
                        if (isInverse)
                                graph.claim(resource, ES.Condition_IsInverse, resource);
@@ -701,6 +722,7 @@ public class ElementSelector {
                public PropertyCondition(ReadGraph graph, Resource r) throws DatabaseException {
                        super(graph, r);
                        
+                       ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
                        this.propertyName = graph.getRelatedValue(resource, ES.PropertyCondition_HasPropertyName);
                        this.lowerLimit = graph.getPossibleRelatedValue(resource, ES.PropertyCondition_HasLowerLimit);
                        this.upperLimit = graph.getPossibleRelatedValue(resource, ES.PropertyCondition_HasUpperLimit);
@@ -762,6 +784,7 @@ public class ElementSelector {
                public RegionCondition(ReadGraph graph, Resource r) throws DatabaseException {
                        super(graph, r);
                        
+                       ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
                        DiagramRegionsResource DR = DiagramRegionsResource.getInstance(graph);
                        this.regionResource = graph.getPossibleObject(resource, ES.RegionCondition_HasRegion);
                        this.region = regionResource != null ? graph.getRelatedValue(regionResource, DR.Region_area) : null;
@@ -796,8 +819,9 @@ public class ElementSelector {
                
                @Override
                public Resource update(WriteGraph graph) throws DatabaseException {
-                       ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
                        Layer0 L0 = Layer0.getInstance(graph);
+                       ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
+                       DiagramRegionsResource DR = DiagramRegionsResource.getInstance(graph);
                        
                        if (resource == null) {
                                resource = graph.newResource();
@@ -809,7 +833,6 @@ public class ElementSelector {
                        graph.claim(resource, ES.RegionCondition_HasRegion, regionResource);
                        
                        // Re-read region data to match DB
-                       DiagramRegionsResource DR = DiagramRegionsResource.getInstance(graph);
                        this.region = regionResource != null ? graph.getRelatedValue(regionResource, DR.Region_area, Bindings.DOUBLE_ARRAY) : null;
                        this.path = createPathForRegion(region);
                        
@@ -921,8 +944,8 @@ public class ElementSelector {
                
                @Override
                public Resource update(WriteGraph graph) throws DatabaseException {
-                       ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
                        Layer0 L0 = Layer0.getInstance(graph);
+                       ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
                        
                        if (resource == null) {
                                resource = graph.newResource();