]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/SubstructureMapRequest.java
Add utility class org.simantics.modeling.help.HelpContexts
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / SubstructureMapRequest.java
1 package org.simantics.modeling;
2
3 import gnu.trove.map.hash.THashMap;
4
5 import java.util.Map;
6
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.ResourceRead;
10 import org.simantics.db.common.uri.UnescapedChildMapOfResource;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.request.PropertyInfo;
13 import org.simantics.db.layer0.request.PropertyInfoRequest;
14 import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource;
15 import org.simantics.layer0.Layer0;
16 import org.simantics.scl.compiler.types.Type;
17 import org.simantics.structural.stubs.StructuralResource2;
18 import org.simantics.utils.datastructures.Pair;
19
20 /**
21  * Deprecated: Use ComponentTypeSubstructure that supports deep references
22  */
23 @Deprecated
24 public class SubstructureMapRequest extends ResourceRead<THashMap<String, Pair<String,Type>>>{
25
26     public SubstructureMapRequest(Resource type) {
27         super(type);
28     }
29
30     private void collect(ReadGraph graph, Resource t, THashMap<String, Pair<String,Type>> result) throws DatabaseException {
31         Layer0 L0 = Layer0.getInstance(graph);
32         for(Resource relation : graph.getObjects(t, L0.DomainOf)) {
33             if(graph.isSubrelationOf(relation, L0.HasProperty)) {
34                 PropertyInfo propertyInfo = graph.syncRequest(new PropertyInfoRequest(relation));
35                 result.put(propertyInfo.name, Pair.make("#" + propertyInfo.name, SCLTypeUtils.getType(propertyInfo)));
36             }
37         }
38     }
39     
40     @Override
41     public THashMap<String, Pair<String,Type>> perform(ReadGraph graph) throws DatabaseException {
42         THashMap<String, Pair<String,Type>> propertyMap = new THashMap<String, Pair<String,Type>>();
43         StructuralResource2 STR = StructuralResource2.getInstance(graph);
44         Resource composite = graph.getPossibleObject(resource, STR.IsDefinedBy);
45         if(composite != null) {
46                 for(Map.Entry<String, Resource> child : graph.sync(new UnescapedChildMapOfResource(composite)).entrySet()) {
47                     for(PropertyInfo property : graph.sync(new UnescapedPropertyMapOfResource(child.getValue())).values()) {
48                         propertyMap.put(child.getKey() + "." + property.name,
49                                 Pair.make("/" + child.getKey() + "#" + property.name, 
50                                         SCLTypeUtils.getType(property)));
51                     }
52                 }
53         }
54
55         collect(graph, resource, propertyMap);
56         for(Resource t : graph.getSupertypes(resource)) collect(graph, t, propertyMap);
57
58         return propertyMap;
59         
60     }
61
62 }