1 package org.simantics.ui.workbench.e4;
\r
3 import org.simantics.Simantics;
\r
4 import org.simantics.db.ReadGraph;
\r
5 import org.simantics.db.Resource;
\r
6 import org.simantics.db.common.request.UniqueRead;
\r
7 import org.simantics.db.exception.DatabaseException;
\r
8 import org.simantics.db.layer0.variable.RVI;
\r
9 import org.simantics.db.layer0.variable.Variable;
\r
10 import org.simantics.db.layer0.variable.Variables;
\r
11 import org.simantics.ui.workbench.IResourceEditorInput2;
\r
14 * @author Tuukka Lehtonen
\r
17 public class E4ResourceEditorInput2 extends E4ResourceEditorInput implements IResourceEditorInput2 {
\r
19 protected final Resource model;
\r
20 protected final String rvi;
\r
21 protected transient Variable variable;
\r
23 public E4ResourceEditorInput2(Resource resource, Resource model, String rvi) {
\r
30 public void dispose() {
\r
31 // Nullify to prevent the class from keeping unnecessary references to
\r
32 // possible Variable implementation backend resources.
\r
37 public Resource getModel(ReadGraph graph) {
\r
42 public String getRVI() {
\r
47 public boolean exists(ReadGraph graph) throws DatabaseException {
\r
48 if (!super.exists(graph))
\r
51 if (model != null) {
\r
52 boolean modelExists = graph.hasStatement(model);
\r
58 Variable context = Variables.getPossibleConfigurationContext(graph, model);
\r
59 if (context == null)
\r
61 RVI rvi_ = RVI.fromResourceFormat(graph, rvi);
\r
62 Variable variable = rvi_.resolvePossible(graph, context);
\r
63 if (variable == null)
\r
71 public Variable getVariable() throws DatabaseException {
\r
72 if (variable != null)
\r
74 return Simantics.getSession().syncRequest(new UniqueRead<Variable>() {
\r
76 public Variable perform(ReadGraph graph) throws DatabaseException {
\r
77 return getVariable(graph);
\r
82 protected Variable getVariable0(ReadGraph graph) throws DatabaseException {
\r
83 Resource model = getModel(graph);
\r
84 String rvi = getRVI();
\r
87 Variable configuration = Variables.getConfigurationContext(graph, model);
\r
88 RVI rrvi = RVI.fromResourceFormat(graph, rvi);
\r
89 return rrvi.resolve(graph, configuration);
\r
93 return Variables.getVariable(graph, model);
\r
98 public Variable getVariable(ReadGraph graph) throws DatabaseException {
\r
99 Variable v = getVariable0(graph);
\r