]> gerrit.simantics Code Review - simantics/district.git/blob - 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
1 package org.simantics.district.network.techtype.requests;
2
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.common.request.ResourceRead;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.district.network.ontology.DistrictNetworkResource;
8 import org.simantics.layer0.Layer0;
9
10 public class TechTypeTableKeyName extends ResourceRead<String> {
11         
12         public TechTypeTableKeyName(Resource table) {
13                 super(table);
14         }
15
16         @Override
17         public String perform(ReadGraph graph) throws DatabaseException {
18                 Layer0 L0 = Layer0.getInstance(graph);
19                 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
20                 
21                 Resource type = graph.getPossibleObject(resource, DN.TechType_TechTypeTable_HasComponentType);
22                 if (type != null) {
23                         for (Resource r : graph.getObjects(type, L0.DomainOf)) {
24                                 Resource accessor = graph.getPossibleObject(r, L0.valueAccessor);
25                                 if (accessor.equals(DN.TechType_Functions_techTypeCodeValueAccessor)) {
26                                         return graph.getRelatedValue2(r, L0.HasName);
27                                 }
28                         }
29                 }
30                 
31                 return null;
32         }
33 }