X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Futils%2FVariableReferences.java;h=9d0f8312ea7397ce7a79aad8356f16fb9a9698ae;hb=9214a600c9401b06057fc2c10ea86a0ce0218d87;hp=c995f723c0510da05b5adee98cb3f60a1a964355;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/VariableReferences.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/VariableReferences.java index c995f723c..9d0f8312e 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/VariableReferences.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/VariableReferences.java @@ -1,89 +1,89 @@ -package org.simantics.modeling.utils; - -import java.util.ArrayList; -import java.util.List; - -import org.simantics.databoard.type.Datatype; -import org.simantics.databoard.util.ObjectUtils; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -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.VariableReference; -import org.simantics.db.layer0.variable.Variables; -import org.simantics.db.request.Read; -import org.simantics.modeling.PropertyVariables; - -/** - * A intermediate hack solution for converting variables to variable references. - * {@link NodeReference}s and {@link Datatype}s for subscription and charting - * purposes. - * - * @author Tuukka Lehtonen - */ -public final class VariableReferences { - - public static Read> toReferences(final List vars) { - return toReferences(null, vars); - } - - public static Read> toReferences(final Resource expectedModel, final List vars) { - return new Read>() { - @Override - public List perform(ReadGraph graph) throws DatabaseException { - List result = new ArrayList(); - for (PropertyVariables v : vars) { - if (expectedModel != null) { - // Check that the model of the variable matches the target model. - Resource model = Variables.getModel(graph, v.getContainer()); - if (!ObjectUtils.objectEquals(expectedModel, model)) - continue; - } - - Datatype datatype = v.getVisualVariable().getPossibleDatatype(graph); - -// System.out.println("URI1: " + v.getContainer().getURI(graph)); -// System.out.println("URI2: " + v.getExperiment().getURI(graph)); -// System.out.println("URI3: " + v.getProperty().getURI(graph)); -// System.out.println("RVI: " + Variables.getRVI(graph, v.getProperty())); - RVI rvi = Variables.getRVI2(graph, v.getVisualVariable()); -// String rvi = Variables.getRVI(graph, v.getVisualVariable()); -// String nodeReference = rvi.replaceFirst("/", ""); -// System.out.println("NODEREF: " + nodeReference); -// System.out.println("DATATYPE: " + datatype); - result.add( VariableReference.of( rvi, datatype, null ) ); - } - return result; - } - }; - } - - public static Read> variablesToReferences(final List vars) { - return variablesToReferences((Resource) null, vars); - } - - public static Read> variablesToReferences(final Resource expectedModel, final List vars) { - return new Read>() { - @Override - public List perform(ReadGraph graph) throws DatabaseException { - List result = new ArrayList(); - for (Variable v : vars) { - if (expectedModel != null) { - // Check that the model of the variable matches the target model. - Resource model = Variables.getModel(graph, v); - if (!ObjectUtils.objectEquals(expectedModel, model)) - continue; - } - Datatype datatype = v.getPossibleDatatype(graph); - RVI rvi = Variables.getRVI2(graph, v); -// String rvi = Variables.getRVI(graph, v); -// String nodeReference = rvi.replaceFirst("/", ""); - result.add( VariableReference.of( rvi, datatype, null ) ); - } - return result; - } - }; - } - -} +package org.simantics.modeling.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.simantics.databoard.type.Datatype; +import org.simantics.databoard.util.ObjectUtils; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +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.VariableReference; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.request.Read; +import org.simantics.modeling.PropertyVariables; + +/** + * A intermediate hack solution for converting variables to variable references. + * {@link NodeReference}s and {@link Datatype}s for subscription and charting + * purposes. + * + * @author Tuukka Lehtonen + */ +public final class VariableReferences { + + public static Read> toReferences(final List vars) { + return toReferences(null, vars); + } + + public static Read> toReferences(final Resource expectedModel, final List vars) { + return new Read>() { + @Override + public List perform(ReadGraph graph) throws DatabaseException { + List result = new ArrayList(); + for (PropertyVariables v : vars) { + if (expectedModel != null) { + // Check that the model of the variable matches the target model. + Resource model = Variables.getModel(graph, v.getContainer()); + if (!ObjectUtils.objectEquals(expectedModel, model)) + continue; + } + + Datatype datatype = v.getVisualVariable().getPossibleDatatype(graph); + +// System.out.println("URI1: " + v.getContainer().getURI(graph)); +// System.out.println("URI2: " + v.getExperiment().getURI(graph)); +// System.out.println("URI3: " + v.getProperty().getURI(graph)); +// System.out.println("RVI: " + Variables.getRVI(graph, v.getProperty())); + RVI rvi = Variables.getRVI2(graph, v.getVisualVariable()); +// String rvi = Variables.getRVI(graph, v.getVisualVariable()); +// String nodeReference = rvi.replaceFirst("/", ""); +// System.out.println("NODEREF: " + nodeReference); +// System.out.println("DATATYPE: " + datatype); + result.add( VariableReference.of( rvi, datatype, null ) ); + } + return result; + } + }; + } + + public static Read> variablesToReferences(final List vars) { + return variablesToReferences((Resource) null, vars); + } + + public static Read> variablesToReferences(final Resource expectedModel, final List vars) { + return new Read>() { + @Override + public List perform(ReadGraph graph) throws DatabaseException { + List result = new ArrayList(); + for (Variable v : vars) { + if (expectedModel != null) { + // Check that the model of the variable matches the target model. + Resource model = Variables.getModel(graph, v); + if (!ObjectUtils.objectEquals(expectedModel, model)) + continue; + } + Datatype datatype = v.getPossibleDatatype(graph); + RVI rvi = Variables.getRVI2(graph, v); +// String rvi = Variables.getRVI(graph, v); +// String nodeReference = rvi.replaceFirst("/", ""); + result.add( VariableReference.of( rvi, datatype, null ) ); + } + return result; + } + }; + } + +}