]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/runtime/RuntimeVariableForInput.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / runtime / RuntimeVariableForInput.java
1 /*******************************************************************************\r
2  * Copyright (c) 2013 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\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
8  *\r
9  * Contributors:\r
10  *     Semantum Oy - initial API and implementation for issue #4384\r
11  *******************************************************************************/\r
12 package org.simantics.diagram.runtime;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.common.request.UnaryRead;\r
17 import org.simantics.db.exception.DatabaseException;\r
18 import org.simantics.db.layer0.variable.RVI;\r
19 import org.simantics.ui.workbench.IResourceEditorInput2;\r
20 \r
21 /**\r
22  * Extract a triple <Model URI, Variable URI, RVI> from the input argument. This\r
23  * request is needed in addition to {@link RuntimeVariable} to support possible\r
24  * changes in the data contained by {@link IResourceEditorInput2}.\r
25  * \r
26  * Returns <code>null</code> if it cannot find:\r
27  * <ol>\r
28  * <li>model resource by its URI</li>\r
29  * <li>active realization of the model or base realization as a fallback</li>\r
30  * </ol>\r
31  * \r
32  * @author Tuukka Lehtonen\r
33  * @see RuntimeVariable\r
34  */\r
35 class RuntimeVariableForInput extends UnaryRead<IResourceEditorInput2, RuntimeDiagramDesc> {\r
36 \r
37     public RuntimeVariableForInput(IResourceEditorInput2 input) {\r
38         super(input);\r
39     }\r
40 \r
41     @Override\r
42     public RuntimeDiagramDesc perform(ReadGraph graph) throws DatabaseException {\r
43         Resource model = parameter.getModel(graph);\r
44         String rvis = parameter.getRVI();\r
45         RVI rvi = rvis == null ? null : RVI.fromResourceFormat(graph, rvis);\r
46         return graph.syncRequest(new RuntimeVariable(\r
47                 model,\r
48                 rvi,\r
49                 parameter.getResource()));\r
50     }\r
51 \r
52 }