X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fscl%2FVariableStructuralContext.java;fp=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fscl%2FVariableStructuralContext.java;h=43f406d3dfaa9c29471033981d0e45661d3f46ec;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/VariableStructuralContext.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/VariableStructuralContext.java new file mode 100644 index 000000000..43f406d3d --- /dev/null +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/VariableStructuralContext.java @@ -0,0 +1,73 @@ +package org.simantics.structural2.scl; + +import java.util.List; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.adapter.AdaptException; +import org.simantics.databoard.binding.Binding; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.layer0.Layer0; +import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.structural2.scl.StructuralComponent; + +public class VariableStructuralContext extends StructuralComponent { + + final public Variable variable; + + public VariableStructuralContext(ReadGraph graph, Variable selfVariable) throws DatabaseException { + this.variable = selfVariable.getParent(graph).getParent(graph); + } + + public VariableStructuralContext(Variable variable) throws DatabaseException { + this.variable = variable; + } + + @Override + public Resource getType(ReadGraph g) throws DatabaseException { + throw new UnsupportedOperationException(); + } + + @Override + public Object getValue(ReadGraph g, Resource attribute, Binding binding) throws DatabaseException, AdaptException { + + Layer0 L0 = Layer0.getInstance(g); + StructuralResource2 STR = StructuralResource2.getInstance(g); + if(STR.input.equals(attribute)) { + return variable.getPropertyValue(g, "input"); + } + + String name = g.getRelatedValue(attribute, L0.HasName, Bindings.STRING); + return variable.getPropertyValue(g, name); + + } + + @Override + public boolean isParametrized(ReadGraph g) throws DatabaseException { + throw new UnsupportedOperationException(); + } + + @Override + public Variable getConnection(ReadGraph g, Resource connectionPoint) throws DatabaseException { + throw new UnsupportedOperationException(); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public List getConnections(ReadGraph g, Resource connectionPoint) throws DatabaseException { + throw new UnsupportedOperationException(); + } + + @Override + public Resource getResource() { + throw new UnsupportedOperationException(); + } + + @Override + public StructuralComponent getContext() { + throw new UnsupportedOperationException(); + } + +}