]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/ResolveMonitorVariable.java
Externalize strings
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / diagram / monitor / ResolveMonitorVariable.java
index a976dcc8d5b55644a94bf8e782863f0b290b0f87..7cc42e3ad4426babf6738ed6b5362e8ecb724567 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2012 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.modeling.ui.diagram.monitor;\r
-\r
-import org.simantics.common.format.Formatter;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.datatypes.literal.DecimalFormatFormatter;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.BinaryRead;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.exception.VariableException;\r
-import org.simantics.db.layer0.variable.RVI;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.db.layer0.variable.Variables;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.operation.Layer0X;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class ResolveMonitorVariable extends BinaryRead<Resource, Resource, MonitorVariable> {\r
-\r
-    public ResolveMonitorVariable(Resource runtimeDiagram, Resource monitorElement) {\r
-        super(runtimeDiagram, monitorElement);\r
-    }\r
-\r
-    @Override\r
-    public MonitorVariable perform(ReadGraph graph) throws DatabaseException {\r
-        Boolean external = null;\r
-        DiagramResource DIA = DiagramResource.getInstance(graph);\r
-\r
-        Resource monitorComponent = graph.getPossibleObject(parameter2, DIA.HasMonitorComponent);\r
-        if (monitorComponent == null)\r
-            return null;\r
-\r
-        String suffix = graph.getPossibleRelatedValue(parameter2, DIA.HasMonitorSuffix, Bindings.STRING);\r
-        if (suffix == null)\r
-            return null;\r
-\r
-        String diagramVariable = graph.getPossibleRelatedValue(parameter, DIA.RuntimeDiagram_HasVariable);\r
-        if (diagramVariable == null)\r
-            return null;\r
-\r
-        Variable var = Variables.getPossibleVariable(graph, diagramVariable);\r
-        if (var == null)\r
-            return null;\r
-\r
-        Variable component = var.browsePossible(graph, monitorComponent);\r
-        if (component == null) {\r
-            // The monitored component is not in this diagram.\r
-            component = Variables.getPossibleVariable(graph, monitorComponent);\r
-            if (component == null)\r
-                return null;\r
-\r
-            String componentRVI = Variables.getPossibleRVI(graph, component);\r
-            if (componentRVI == null)\r
-                return null;\r
-\r
-            Resource realization = Variables.getRealization(graph, var);\r
-            String diagramRealizationURI = graph.getPossibleURI(realization);\r
-            if (diagramRealizationURI == null)\r
-                return null;\r
-\r
-            String componentURI = diagramRealizationURI + componentRVI;\r
-            var = Variables.getPossibleVariable(graph, componentURI);\r
-            if (var == null)\r
-                return null;\r
-\r
-            external = Boolean.TRUE;\r
-        } else {\r
-            var = component;\r
-        }\r
-\r
-        var = var.browsePossible(graph, suffix);\r
-        if (var == null)\r
-            return null;\r
-\r
-        Formatter formatter = graph.getPossibleRelatedAdapter(parameter2, DIA.HasFormatter, Formatter.class);\r
-        if (formatter == null)\r
-            formatter = new DecimalFormatFormatter();\r
-\r
-        Layer0X L0X = Layer0X.getInstance(graph);\r
-        String _expression = graph.getPossibleRelatedAdapter(parameter2, L0X.HasExpression, String.class);\r
-        if(_expression == null) _expression  = "value";\r
-\r
-        RVI rvi = null;\r
-        try {\r
-            rvi = Variables.getRVI2(graph, var);\r
-        } catch (VariableException e) {\r
-            // No RVI, which is fine for contents that do not originate from the model configuration.\r
-        }\r
-\r
-        return new MonitorVariable(monitorComponent, formatter, _expression, var, rvi, external);\r
-    }\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2012 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.modeling.ui.diagram.monitor;
+
+import org.simantics.common.format.Formatter;
+import org.simantics.databoard.Bindings;
+import org.simantics.datatypes.literal.DecimalFormatFormatter;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.BinaryRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.VariableException;
+import org.simantics.db.layer0.variable.RVI;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.operation.Layer0X;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class ResolveMonitorVariable extends BinaryRead<Resource, Resource, MonitorVariable> {
+
+    public ResolveMonitorVariable(Resource runtimeDiagram, Resource monitorElement) {
+        super(runtimeDiagram, monitorElement);
+    }
+
+    @Override
+    public MonitorVariable perform(ReadGraph graph) throws DatabaseException {
+        Boolean external = null;
+        DiagramResource DIA = DiagramResource.getInstance(graph);
+
+        Resource monitorComponent = graph.getPossibleObject(parameter2, DIA.HasMonitorComponent);
+        if (monitorComponent == null)
+            return null;
+
+        String suffix = graph.getPossibleRelatedValue(parameter2, DIA.HasMonitorSuffix, Bindings.STRING);
+        if (suffix == null)
+            return null;
+
+        String diagramVariable = graph.getPossibleRelatedValue(parameter, DIA.RuntimeDiagram_HasVariable);
+        if (diagramVariable == null)
+            return null;
+
+        Variable var = Variables.getPossibleVariable(graph, diagramVariable);
+        if (var == null)
+            return null;
+
+        Variable component = var.browsePossible(graph, monitorComponent);
+        if (component == null) {
+            // The monitored component is not in this diagram.
+            component = Variables.getPossibleVariable(graph, monitorComponent);
+            if (component == null)
+                return null;
+
+            String componentRVI = Variables.getPossibleRVI(graph, component);
+            if (componentRVI == null)
+                return null;
+
+            Resource realization = Variables.getRealization(graph, var);
+            String diagramRealizationURI = graph.getPossibleURI(realization);
+            if (diagramRealizationURI == null)
+                return null;
+
+            String componentURI = diagramRealizationURI + componentRVI;
+            var = Variables.getPossibleVariable(graph, componentURI);
+            if (var == null)
+                return null;
+
+            external = Boolean.TRUE;
+        } else {
+            var = component;
+        }
+
+        var = var.browsePossible(graph, suffix);
+        if (var == null)
+            return null;
+
+        Formatter formatter = graph.getPossibleRelatedAdapter(parameter2, DIA.HasFormatter, Formatter.class);
+        if (formatter == null)
+            formatter = new DecimalFormatFormatter();
+
+        Layer0X L0X = Layer0X.getInstance(graph);
+        String _expression = graph.getPossibleRelatedAdapter(parameter2, L0X.HasExpression, String.class);
+        if(_expression == null) _expression  = "value"; //$NON-NLS-1$
+
+        RVI rvi = null;
+        try {
+            rvi = Variables.getRVI2(graph, var);
+        } catch (VariableException e) {
+            // No RVI, which is fine for contents that do not originate from the model configuration.
+        }
+
+        return new MonitorVariable(monitorComponent, formatter, _expression, var, rvi, external);
+    }
+
 }
\ No newline at end of file