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