]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
7afcb1b91878be8641d6e7257ba33b0399568c89
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.browser.childrules;\r
2 \r
3 import java.util.ArrayList;\r
4 import java.util.Collection;\r
5 \r
6 import org.simantics.browsing.ui.model.children.ChildRule;\r
7 import org.simantics.db.ReadGraph;\r
8 import org.simantics.db.Resource;\r
9 import org.simantics.db.common.request.ObjectsWithType;\r
10 import org.simantics.db.exception.DatabaseException;\r
11 import org.simantics.layer0.Layer0;\r
12 import org.simantics.modeling.ModelingResources;\r
13 import org.simantics.structural.stubs.StructuralResource2;\r
14 import org.simantics.sysdyn.SysdynResource;\r
15 \r
16 \r
17 public class ModuleTypeChildRule implements ChildRule {\r
18 \r
19         @Override\r
20         public boolean isCompatible(Class<?> contentType) {\r
21                 return contentType.equals(Resource.class);\r
22         }\r
23 \r
24         @Override\r
25         public Collection<?> getChildren(ReadGraph graph, Object parent)\r
26                         throws DatabaseException {\r
27 \r
28         ArrayList<Resource> children = new ArrayList<Resource>();\r
29         \r
30                 if(!(parent instanceof Resource)) {\r
31                         return children;\r
32                 }\r
33                 \r
34                 Layer0 l0 = Layer0.getInstance(graph);\r
35                 StructuralResource2 st = StructuralResource2.getInstance(graph);\r
36 \r
37                 Resource model = (Resource)parent;\r
38                 if(!graph.isInstanceOf(model, SysdynResource.getInstance(graph).SysdynModel))\r
39                     return children;\r
40                 \r
41         for(Resource r : graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, st.ComponentType))) {\r
42                 if(graph.isInheritedFrom(r, SysdynResource.getInstance(graph).Module)) {\r
43                         Resource symbol = graph.getPossibleObject(r,ModelingResources.getInstance(graph).ComponentTypeToSymbol);\r
44                         children.add(symbol);\r
45                 }\r
46         }\r
47                 \r
48                 return children;\r
49         }\r
50 \r
51         @Override\r
52         public Collection<?> getParents(ReadGraph graph, Object child)\r
53                         throws DatabaseException {\r
54                 return new ArrayList<Resource>();\r
55         }\r
56 \r
57 }