]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network/src/org/simantics/district/network/techtype/requests/TechTypeTableKeyName.java
Updating of component properties when type code changes
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / techtype / requests / TechTypeTableKeyName.java
diff --git a/org.simantics.district.network/src/org/simantics/district/network/techtype/requests/TechTypeTableKeyName.java b/org.simantics.district.network/src/org/simantics/district/network/techtype/requests/TechTypeTableKeyName.java
new file mode 100644 (file)
index 0000000..86b7d72
--- /dev/null
@@ -0,0 +1,33 @@
+package org.simantics.district.network.techtype.requests;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.layer0.Layer0;
+
+public class TechTypeTableKeyName extends ResourceRead<String> {
+       
+       public TechTypeTableKeyName(Resource table) {
+               super(table);
+       }
+
+       @Override
+       public String perform(ReadGraph graph) throws DatabaseException {
+               Layer0 L0 = Layer0.getInstance(graph);
+               DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+               
+               Resource type = graph.getPossibleObject(resource, DN.TechType_TechTypeTable_HasComponentType);
+               if (type != null) {
+                       for (Resource r : graph.getObjects(type, L0.DomainOf)) {
+                               Resource accessor = graph.getPossibleObject(r, L0.valueAccessor);
+                               if (accessor.equals(DN.TechType_Functions_techTypeCodeValueAccessor)) {
+                                       return graph.getRelatedValue2(r, L0.HasName);
+                               }
+                       }
+               }
+               
+               return null;
+       }
+}
\ No newline at end of file