]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
76a46f00cccec194fdf7298ec49186d1c7f75952
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
2 \r
3 import java.util.ArrayList;\r
4 import java.util.Collection;\r
5 import java.util.Collections;\r
6 \r
7 import org.simantics.browsing.ui.common.node.AbstractNode;\r
8 import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl;\r
9 import org.simantics.db.ReadGraph;\r
10 import org.simantics.db.Resource;\r
11 import org.simantics.db.common.ResourceArray;\r
12 import org.simantics.db.common.request.ObjectsWithType;\r
13 import org.simantics.db.exception.DatabaseException;\r
14 import org.simantics.layer0.Layer0;\r
15 import org.simantics.sysdyn.SysdynResource;\r
16 \r
17 public class AvailableEnumerations extends ViewpointContributorImpl<ResourceArray> {\r
18 \r
19         @Override\r
20         public Collection<?> getContribution(ReadGraph graph, ResourceArray input)\r
21                         throws DatabaseException {\r
22                 Resource[] selection = input.resources;\r
23                 if(selection.length < 1)\r
24                     return Collections.emptyList();\r
25                 Layer0 l0 = Layer0.getInstance(graph);\r
26                 Resource configuration = null;\r
27                 \r
28                 // Variables need to be from the same configuration\r
29                 for(Resource r : selection) {\r
30                     Resource conf = graph.getPossibleObject(r, l0.PartOf);\r
31                     if(configuration == null || conf.equals(configuration))\r
32                         configuration = conf;\r
33                     else\r
34                         return Collections.emptyList();\r
35                 }\r
36                 \r
37         ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
38         SysdynResource sr = SysdynResource.getInstance(graph);\r
39         if(configuration == null) \r
40                 return result;\r
41         for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) {\r
42                 result.add(new EnumerationNode(r));\r
43         }\r
44         return result;\r
45         }\r
46 \r
47         @Override\r
48         public String getViewpointId() {\r
49                 return "Available enumerations";\r
50         }\r
51 \r
52 \r
53 }\r