]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/requests/PossibleTechTypeTable.java
Read tech type table data from model
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / techtype / requests / PossibleTechTypeTable.java
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/requests/PossibleTechTypeTable.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/requests/PossibleTechTypeTable.java
new file mode 100644 (file)
index 0000000..c722dfc
--- /dev/null
@@ -0,0 +1,33 @@
+package org.simantics.district.network.ui.techtype.requests;
+
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ResourceRead2;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.layer0.Layer0;
+
+public class PossibleTechTypeTable extends ResourceRead2<Resource> {
+       public PossibleTechTypeTable(Resource model, Resource componentType) {
+               super(model, componentType);
+       }
+
+       @Override
+       public Resource perform(ReadGraph graph) throws DatabaseException {
+               Layer0 L0 = Layer0.getInstance(graph);
+               DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+               
+               Collection<Resource> children = graph.getObjects(resource, L0.ConsistsOf);
+               for (Resource child : children) {
+                       if (!graph.isInstanceOf(child, DN.TechType_TechTypeTable))
+                               continue;
+                       
+                       if (graph.hasStatement(child, DN.TechType_TechTypeTable_HasComponentType, resource2))
+                               return child;
+               }
+               
+               return null;
+       }
+}
\ No newline at end of file