]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
4ebe335e712aea0e6c088e2fd67486ed2f4f33f2
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2010 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.browser.contributions;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 import java.util.TreeMap;\r
17 \r
18 import org.simantics.browsing.ui.common.node.AbstractNode;\r
19 import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
20 import org.simantics.databoard.Bindings;\r
21 import org.simantics.db.ReadGraph;\r
22 import org.simantics.db.Resource;\r
23 import org.simantics.db.common.request.ObjectsWithType;\r
24 import org.simantics.db.exception.DatabaseException;\r
25 import org.simantics.layer0.Layer0;\r
26 import org.simantics.modeling.ModelingResources;\r
27 import org.simantics.structural.stubs.StructuralResource2;\r
28 import org.simantics.sysdyn.SysdynResource;\r
29 import org.simantics.sysdyn.ui.browser.nodes.EnumerationNode;\r
30 import org.simantics.sysdyn.ui.browser.nodes.InputNode;\r
31 import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
32 import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode;\r
33 import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
34 import org.simantics.utils.strings.AlphanumComparator;\r
35 \r
36 public class ModuleType extends ViewpointContributor<ModuleTypeNode> {\r
37 \r
38         @Override\r
39         public Collection<?> getContribution(ReadGraph graph, ModuleTypeNode module) throws DatabaseException {\r
40                 ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
41                 Layer0 l0 = Layer0.getInstance(graph);\r
42                 SysdynResource sr = SysdynResource.getInstance(graph);\r
43                 StructuralResource2 str = StructuralResource2.getInstance(graph);\r
44                 \r
45                 ModelingResources mr = ModelingResources.getInstance(graph);\r
46                 Resource instance =  graph.getPossibleObject(module.data, mr.SymbolToComponentType);\r
47 \r
48                 if(instance == null) return result;\r
49                 Resource conf = graph.getSingleObject(instance, str.IsDefinedBy);\r
50                 \r
51                 // Independent variables\r
52                 TreeMap<String, Resource> variables = new TreeMap<String, Resource>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
53                 for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.IndependentVariable))) {\r
54                         variables.put((String)graph.getPossibleRelatedValue(r, l0.HasName, Bindings.STRING), r);\r
55                 }\r
56                 for(String key : variables.keySet())\r
57                         result.add(new VariableNode<Resource>(variables.get(key)));\r
58                 \r
59                 // Inputs\r
60                 variables.clear();\r
61                 for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Input))) {\r
62                         variables.put((String)graph.getPossibleRelatedValue(r, l0.HasName, Bindings.STRING), r);\r
63                 }\r
64                 for(String key : variables.keySet())\r
65                         result.add(new InputNode(variables.get(key)));\r
66                 \r
67                 // Modules\r
68                 variables.clear();\r
69                 for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Module))) {\r
70                         variables.put((String)graph.getPossibleRelatedValue(r, l0.HasName, Bindings.STRING), r);\r
71                 }\r
72                 for(String key : variables.keySet())\r
73                         result.add(new ModuleNode(variables.get(key)));\r
74                 \r
75                 // Enumerations\r
76                 variables.clear();\r
77                 for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Enumeration))) {\r
78                         variables.put((String)graph.getPossibleRelatedValue(r, l0.HasName, Bindings.STRING), r);\r
79                 }\r
80                 for(String key : variables.keySet())\r
81                         result.add(new EnumerationNode(variables.get(key)));\r
82                 \r
83                 return result;\r
84         }\r
85 \r
86         @Override\r
87         public String getViewpointId() {\r
88                 return "Standard";\r
89         }\r
90 \r
91 }\r