X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2Fworkbench%2Fe4%2FE4ResourceEditorInput2.java;fp=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2Fworkbench%2Fe4%2FE4ResourceEditorInput2.java;h=c67fc68b6103822fd6ad93bcd38ababde67b1658;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4ResourceEditorInput2.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4ResourceEditorInput2.java new file mode 100644 index 000000000..c67fc68b6 --- /dev/null +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/e4/E4ResourceEditorInput2.java @@ -0,0 +1,104 @@ +package org.simantics.ui.workbench.e4; + +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.RVI; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.ui.workbench.IResourceEditorInput2; + +/** + * @author Tuukka Lehtonen + * @since 1.22 + */ +public class E4ResourceEditorInput2 extends E4ResourceEditorInput implements IResourceEditorInput2 { + + protected final Resource model; + protected final String rvi; + protected transient Variable variable; + + public E4ResourceEditorInput2(Resource resource, Resource model, String rvi) { + super(resource); + this.model = model; + this.rvi = rvi; + } + + @Override + public void dispose() { + // Nullify to prevent the class from keeping unnecessary references to + // possible Variable implementation backend resources. + variable = null; + } + + @Override + public Resource getModel(ReadGraph graph) { + return model; + } + + @Override + public String getRVI() { + return rvi; + } + + @Override + public boolean exists(ReadGraph graph) throws DatabaseException { + if (!super.exists(graph)) + return false; + + if (model != null) { + boolean modelExists = graph.hasStatement(model); + if (!modelExists) + return false; + } + + if(rvi != null) { + Variable context = Variables.getPossibleConfigurationContext(graph, model); + if (context == null) + return false; + RVI rvi_ = RVI.fromResourceFormat(graph, rvi); + Variable variable = rvi_.resolvePossible(graph, context); + if (variable == null) + return false; + } + + return true; + } + + @Override + public Variable getVariable() throws DatabaseException { + if (variable != null) + return variable; + return Simantics.getSession().syncRequest(new UniqueRead() { + @Override + public Variable perform(ReadGraph graph) throws DatabaseException { + return getVariable(graph); + } + }); + } + + protected Variable getVariable0(ReadGraph graph) throws DatabaseException { + Resource model = getModel(graph); + String rvi = getRVI(); + // Model + RVI + if (rvi != null) { + Variable configuration = Variables.getConfigurationContext(graph, model); + RVI rrvi = RVI.fromResourceFormat(graph, rvi); + return rrvi.resolve(graph, configuration); + } + // Absolute URI + else { + return Variables.getVariable(graph, model); + } + } + + @Override + public Variable getVariable(ReadGraph graph) throws DatabaseException { + Variable v = getVariable0(graph); + this.variable = v; + return v; + } + +}