]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Bug fixes to element selection query processing 33/2633/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Wed, 30 Jan 2019 14:33:06 +0000 (16:33 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Wed, 30 Jan 2019 14:36:16 +0000 (16:36 +0200)
* Accept STR.Composite in addition to DIA.Diagram
* Fix error when selected element count in an NLowest or NHighest is
higher than the number of elements available

gitlab #28

TODO:
* UI for listing stored queries
* UI for defining/editing queries
* UI for executing queries

Change-Id: Ia88980863f4a64ec2c44df081596bb67417d298d

org.simantics.district.selection/src/org/simantics/district/selection/ElementSelector.java

index a45839c9325198907bc9c5f7ed2c1ed2a5f7039c..7d429e4e04a5669667b11d35d678851f0af06874 100644 (file)
@@ -13,7 +13,6 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.request.ResourceRead;
 import org.simantics.db.common.utils.ListUtils;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.common.request.ResourceRead;
 import org.simantics.db.common.utils.ListUtils;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.exception.ServiceException;
 import org.simantics.db.layer0.request.ActiveModels;
 import org.simantics.db.layer0.request.ActiveRuns;
 import org.simantics.db.layer0.request.Configuration;
 import org.simantics.db.layer0.request.ActiveModels;
 import org.simantics.db.layer0.request.ActiveRuns;
 import org.simantics.db.layer0.request.Configuration;
@@ -287,7 +286,12 @@ public class ElementSelector {
                }
        }
 
                }
        }
 
-       private static Collection<Resource> elementsOfDiagram(ReadGraph graph, Resource diagram) throws ServiceException {
+       private static Collection<Resource> elementsOfDiagram(ReadGraph graph, Resource diagram) throws DatabaseException {
+               if (graph.isInstanceOf(diagram, STR.Composite)) {
+                       // Resource is a composite - get diagram
+                       return elementsOfDiagram(graph, graph.getSingleObject(diagram, MOD.CompositeToDiagram));
+               }
+               
                Collection<Resource> elements = graph.getObjects(diagram, L0.ConsistsOf);
                Collection<Resource> result = new ArrayList<>();
                for (Resource r : elements)
                Collection<Resource> elements = graph.getObjects(diagram, L0.ConsistsOf);
                Collection<Resource> result = new ArrayList<>();
                for (Resource r : elements)
@@ -466,7 +470,8 @@ public class ElementSelector {
                        
                        result2.sort((t1, t2) -> smallest ? Double.compare((Double) t1.c1, (Double) t2.c1) : Double.compare((Double) t2.c1, (Double) t1.c1));
                        
                        
                        result2.sort((t1, t2) -> smallest ? Double.compare((Double) t1.c1, (Double) t2.c1) : Double.compare((Double) t2.c1, (Double) t1.c1));
                        
-                       result2 = result2.subList(0, resultCount);
+                       if (resultCount < result2.size())
+                               result2 = result2.subList(0, resultCount);
                        
                        result = Lists.map(new FunctionImpl1<Tuple2, Resource>() {
                                @Override
                        
                        result = Lists.map(new FunctionImpl1<Tuple2, Resource>() {
                                @Override