-/*******************************************************************************\r
- * Copyright (c) 2010, 2013 Association for Decentralized Information Management\r
- * in 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
- * Semantum Oy - issue #4384\r
- *******************************************************************************/\r
-package org.simantics.diagram.runtime;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.TernaryRead;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.request.PossibleActiveRun;\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.layer0.Layer0;\r
-import org.simantics.modeling.ModelingResources;\r
-\r
-/**\r
- * Extract a triple <Model URI, Variable URI, RVI> from the input arguments if\r
- * possible.\r
- * \r
- * Returns <code>null</code> if it cannot find:\r
- * <ol>\r
- * <li>model resource by its URI</li>\r
- * <li>active realization of the model or base realization as a fallback</li>\r
- * </ol>\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-class RuntimeVariable extends TernaryRead<Resource, RVI, Resource, RuntimeDiagramDesc> {\r
-\r
- public RuntimeVariable(Resource model, RVI rvi, Resource diagramResource) {\r
- super(model, rvi, diagramResource);\r
- }\r
-\r
- @Override\r
- public RuntimeDiagramDesc perform(ReadGraph graph) throws DatabaseException {\r
-\r
- Resource model = parameter;\r
- RVI rvi = parameter2;\r
- Resource diagram = parameter3;\r
-\r
- Variable variable = null;\r
- String runtimeProfileURI = null;\r
-\r
- if (model != null && rvi != null) {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- if (graph.isInstanceOf(model, L0.IndexRoot)) {\r
- Variable activeRun = graph.syncRequest(new PossibleActiveRun(model));\r
- Variable context = activeRun != null ? activeRun : Variables.getPossibleConfigurationContext(graph, model); \r
- if (context != null) variable = rvi.resolvePossible(graph, context);\r
- }\r
-\r
- } else {\r
-\r
- Resource composite = graph.getPossibleObject(diagram, ModelingResources.getInstance(graph).DiagramToComposite);\r
- if (composite != null) {\r
- variable = Variables.getPossibleVariable(graph, composite);\r
- }\r
-\r
- }\r
-\r
- if (model != null) {\r
- Resource runtimeProfile = getActiveProfile(graph, model, diagram);\r
- if (runtimeProfile != null) {\r
- runtimeProfileURI = graph.getPossibleURI(runtimeProfile);\r
- }\r
- }\r
-\r
- return new RuntimeDiagramDesc(makeModelURI(graph, variable, model), makeVariableURI(graph, variable), makeRVIString(graph, variable, rvi), runtimeProfileURI);\r
-\r
- }\r
-\r
- String makeModelURI(ReadGraph graph, Variable variable, Resource model) throws DatabaseException {\r
- if (variable != null) {\r
- Resource m = Variables.getPossibleIndexRoot(graph, variable);\r
- return m != null ? graph.getPossibleURI(m) : null;\r
- }\r
- return model != null ? graph.getPossibleURI(model) : null;\r
- }\r
-\r
- String makeVariableURI(ReadGraph graph, Variable variable) throws DatabaseException {\r
- return variable != null ? variable.getURI(graph) : null;\r
- }\r
-\r
- String makeRVIString(ReadGraph graph, Variable variable, RVI rvi) throws DatabaseException {\r
- if(variable != null) {\r
- RVI r = variable.getPossibleRVI(graph); \r
- if(r != null) return r.toString();\r
- }\r
- return rvi != null ? rvi.toString() : null;\r
- }\r
-\r
- private static Resource getActiveProfile(ReadGraph graph, Resource model, Resource diagram) throws DatabaseException {\r
- DiagramResource DIA = DiagramResource.getInstance(graph);\r
- // This has been disabled to make diagram profile selection model-specific instead of diagram-specific.\r
-// Resource activeProfile = graph.getPossibleObject(diagram, DIA.HasActiveProfile);\r
-// if(activeProfile != null) return activeProfile;\r
- return graph.getPossibleObject(model, DIA.HasActiveProfile);\r
- }\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2010, 2013 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
+ * Semantum Oy - issue #4384
+ *******************************************************************************/
+package org.simantics.diagram.runtime;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.TernaryRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.PossibleActiveRun;
+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.layer0.Layer0;
+import org.simantics.modeling.ModelingResources;
+
+/**
+ * Extract a triple <Model URI, Variable URI, RVI> from the input arguments if
+ * possible.
+ *
+ * Returns <code>null</code> if it cannot find:
+ * <ol>
+ * <li>model resource by its URI</li>
+ * <li>active realization of the model or base realization as a fallback</li>
+ * </ol>
+ *
+ * @author Tuukka Lehtonen
+ */
+class RuntimeVariable extends TernaryRead<Resource, RVI, Resource, RuntimeDiagramDesc> {
+
+ public RuntimeVariable(Resource model, RVI rvi, Resource diagramResource) {
+ super(model, rvi, diagramResource);
+ }
+
+ @Override
+ public RuntimeDiagramDesc perform(ReadGraph graph) throws DatabaseException {
+
+ Resource model = parameter;
+ RVI rvi = parameter2;
+ Resource diagram = parameter3;
+
+ Variable variable = null;
+ String runtimeProfileURI = null;
+
+ if (model != null && rvi != null) {
+ Layer0 L0 = Layer0.getInstance(graph);
+ if (graph.isInstanceOf(model, L0.IndexRoot)) {
+ Variable activeRun = graph.syncRequest(new PossibleActiveRun(model));
+ Variable context = activeRun != null ? activeRun : Variables.getPossibleConfigurationContext(graph, model);
+ if (context != null) variable = rvi.resolvePossible(graph, context);
+ }
+
+ } else {
+
+ Resource composite = graph.getPossibleObject(diagram, ModelingResources.getInstance(graph).DiagramToComposite);
+ if (composite != null) {
+ variable = Variables.getPossibleVariable(graph, composite);
+ }
+
+ }
+
+ if (model != null) {
+ Resource runtimeProfile = getActiveProfile(graph, model, diagram);
+ if (runtimeProfile != null) {
+ runtimeProfileURI = graph.getPossibleURI(runtimeProfile);
+ }
+ }
+
+ return new RuntimeDiagramDesc(makeModelURI(graph, variable, model), makeVariableURI(graph, variable), makeRVIString(graph, variable, rvi), runtimeProfileURI);
+
+ }
+
+ String makeModelURI(ReadGraph graph, Variable variable, Resource model) throws DatabaseException {
+ if (variable != null) {
+ Resource m = Variables.getPossibleIndexRoot(graph, variable);
+ return m != null ? graph.getPossibleURI(m) : null;
+ }
+ return model != null ? graph.getPossibleURI(model) : null;
+ }
+
+ String makeVariableURI(ReadGraph graph, Variable variable) throws DatabaseException {
+ return variable != null ? variable.getURI(graph) : null;
+ }
+
+ String makeRVIString(ReadGraph graph, Variable variable, RVI rvi) throws DatabaseException {
+ if(variable != null) {
+ RVI r = variable.getPossibleRVI(graph);
+ if(r != null) return r.toString();
+ }
+ return rvi != null ? rvi.toString() : null;
+ }
+
+ private static Resource getActiveProfile(ReadGraph graph, Resource model, Resource diagram) throws DatabaseException {
+ DiagramResource DIA = DiagramResource.getInstance(graph);
+ // This has been disabled to make diagram profile selection model-specific instead of diagram-specific.
+// Resource activeProfile = graph.getPossibleObject(diagram, DIA.HasActiveProfile);
+// if(activeProfile != null) return activeProfile;
+ return graph.getPossibleObject(model, DIA.HasActiveProfile);
+ }
+