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