1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.diagram.monitor;
14 import org.simantics.common.format.Formatter;
15 import org.simantics.databoard.Bindings;
16 import org.simantics.datatypes.literal.DecimalFormatFormatter;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.common.request.BinaryRead;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.layer0.exception.VariableException;
22 import org.simantics.db.layer0.variable.RVI;
23 import org.simantics.db.layer0.variable.Variable;
24 import org.simantics.db.layer0.variable.Variables;
25 import org.simantics.diagram.stubs.DiagramResource;
26 import org.simantics.operation.Layer0X;
29 * @author Tuukka Lehtonen
31 public class ResolveMonitorVariable extends BinaryRead<Resource, Resource, MonitorVariable> {
33 public ResolveMonitorVariable(Resource runtimeDiagram, Resource monitorElement) {
34 super(runtimeDiagram, monitorElement);
38 public MonitorVariable perform(ReadGraph graph) throws DatabaseException {
39 Boolean external = null;
40 DiagramResource DIA = DiagramResource.getInstance(graph);
42 Resource monitorComponent = graph.getPossibleObject(parameter2, DIA.HasMonitorComponent);
43 if (monitorComponent == null)
46 String suffix = graph.getPossibleRelatedValue(parameter2, DIA.HasMonitorSuffix, Bindings.STRING);
50 String diagramVariable = graph.getPossibleRelatedValue(parameter, DIA.RuntimeDiagram_HasVariable);
51 if (diagramVariable == null)
54 Variable var = Variables.getPossibleVariable(graph, diagramVariable);
58 Variable component = var.browsePossible(graph, monitorComponent);
59 if (component == null) {
60 // The monitored component is not in this diagram.
61 component = Variables.getPossibleVariable(graph, monitorComponent);
62 if (component == null)
65 String componentRVI = Variables.getPossibleRVI(graph, component);
66 if (componentRVI == null)
69 Resource realization = Variables.getRealization(graph, var);
70 String diagramRealizationURI = graph.getPossibleURI(realization);
71 if (diagramRealizationURI == null)
74 String componentURI = diagramRealizationURI + componentRVI;
75 var = Variables.getPossibleVariable(graph, componentURI);
79 external = Boolean.TRUE;
84 var = var.browsePossible(graph, suffix);
88 Formatter formatter = graph.getPossibleRelatedAdapter(parameter2, DIA.HasFormatter, Formatter.class);
89 if (formatter == null)
90 formatter = new DecimalFormatFormatter();
92 Layer0X L0X = Layer0X.getInstance(graph);
93 String _expression = graph.getPossibleRelatedAdapter(parameter2, L0X.HasExpression, String.class);
94 if(_expression == null) _expression = "value";
98 rvi = Variables.getRVI2(graph, var);
99 } catch (VariableException e) {
100 // No RVI, which is fine for contents that do not originate from the model configuration.
103 return new MonitorVariable(monitorComponent, formatter, _expression, var, rvi, external);