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.graph.contributor.viewpoint.ViewpointContributor;
\r
19 import org.simantics.db.ReadGraph;
\r
20 import org.simantics.db.Resource;
\r
21 import org.simantics.db.common.request.ObjectsWithType;
\r
22 import org.simantics.db.exception.DatabaseException;
\r
23 import org.simantics.db.layer0.variable.Variable;
\r
24 import org.simantics.db.layer0.variable.Variables;
\r
25 import org.simantics.layer0.Layer0;
\r
26 import org.simantics.spreadsheet.resource.SpreadsheetResource;
\r
27 import org.simantics.sysdyn.SysdynResource;
\r
28 import org.simantics.sysdyn.ui.browser.nodes.BookNode;
\r
29 import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;
\r
30 import org.simantics.sysdyn.ui.browser.nodes.EnumerationNode;
\r
31 import org.simantics.sysdyn.ui.browser.nodes.InputNode;
\r
32 import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;
\r
33 import org.simantics.sysdyn.ui.browser.nodes.VariableNode;
\r
34 import org.simantics.utils.strings.AlphanumComparator;
\r
36 public class Configuration extends ViewpointContributor<ConfigurationNode<Resource>> {
\r
39 public Collection<?> getContribution(ReadGraph graph, ConfigurationNode<Resource> configuration) throws DatabaseException {
\r
40 ArrayList<Object> result = new ArrayList<Object>();
\r
41 Variable variable = configuration.getVariable();
\r
43 if (variable == null) {
\r
47 SysdynResource sr = SysdynResource.getInstance(graph);
\r
48 TreeMap<String, Variable> variables = new TreeMap<String, Variable>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);
\r
49 TreeMap<String, Variable> inputs = new TreeMap<String, Variable>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);
\r
50 TreeMap<String, Variable> modules = new TreeMap<String, Variable>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);
\r
51 TreeMap<String, Variable> enumerations = new TreeMap<String, Variable>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);
\r
54 for(Variable child : variable.browseChildren(graph)) {
\r
55 Resource represents = (Resource)child.getPropertyValue(graph, Variables.REPRESENTS);
\r
56 if(graph.isInstanceOf(represents, sr.IndependentVariable)) {
\r
57 variables.put(child.getName(graph), child);
\r
58 } else if (graph.isInstanceOf(represents, sr.Input)) {
\r
59 inputs.put(child.getName(graph), child);
\r
60 } else if (graph.isInstanceOf(represents, sr.Module)) {
\r
61 modules.put(child.getName(graph), child);
\r
62 } else if (graph.isInstanceOf(represents, sr.Enumeration)) {
\r
63 enumerations.put(child.getName(graph), child);
\r
67 for (String s : variables.keySet()) {
\r
68 Variable v = variables.get(s);
\r
69 Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);
\r
70 result.add(new VariableNode<Variable>(v, represents));
\r
73 for (String s : inputs.keySet()) {
\r
74 Variable v = inputs.get(s);
\r
75 Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);
\r
76 result.add(new InputNode(v, represents));
\r
79 for (String s : modules.keySet()) {
\r
80 Variable v = modules.get(s);
\r
81 Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);
\r
82 result.add(new ModuleNode(v, represents));
\r
85 for (String s : enumerations.keySet()) {
\r
86 Variable v = enumerations.get(s);
\r
87 Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);
\r
88 result.add(new EnumerationNode(v, represents));
\r
91 for(Resource r : graph.syncRequest(new ObjectsWithType(
\r
93 Layer0.getInstance(graph).ConsistsOf,
\r
94 SpreadsheetResource.getInstance(graph).Book))) {
\r
95 result.add(new BookNode(r));
\r
102 public String getViewpointId() {
\r