1 /*******************************************************************************
\r
2 * Copyright (c) 2010 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.browser.contributions;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\r
16 import java.util.TreeMap;
\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
36 public class ModuleType extends ViewpointContributor<ModuleTypeNode> {
\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
45 ModelingResources mr = ModelingResources.getInstance(graph);
\r
46 Resource instance = graph.getPossibleObject(module.data, mr.SymbolToComponentType);
\r
48 if(instance == null) return result;
\r
49 Resource conf = graph.getSingleObject(instance, str.IsDefinedBy);
\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
56 for(String key : variables.keySet())
\r
57 result.add(new VariableNode<Resource>(variables.get(key)));
\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
64 for(String key : variables.keySet())
\r
65 result.add(new InputNode(variables.get(key)));
\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
72 for(String key : variables.keySet())
\r
73 result.add(new ModuleNode(variables.get(key)));
\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
80 for(String key : variables.keySet())
\r
81 result.add(new EnumerationNode(variables.get(key)));
\r
87 public String getViewpointId() {
\r