From 6786123f98330b2ea5fe6365c961f1e8202fda01 Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 15 Apr 2011 10:21:03 +0000 Subject: [PATCH] Support getting and settin values to variables in the old style git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20507 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/adapter/ChildVariable.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariable.java index 31f32cf9..033dfce2 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ChildVariable.java @@ -1,10 +1,19 @@ package org.simantics.sysdyn.adapter; +import java.util.List; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Datatypes; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.type.Datatype; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.StandardGraphChildVariable; import org.simantics.db.layer0.variable.Variable; +import org.simantics.sysdyn.SysdynResource; public class ChildVariable extends StandardGraphChildVariable { @@ -19,6 +28,48 @@ public class ChildVariable extends StandardGraphChildVariable { public Variable getParent(ReadGraph graph) throws DatabaseException { return parent; } + + // FIXME: Support properties! This is just for the system to work like it used to. + @Override + public T getValue(ReadGraph graph) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(this.resource == null) return null; + //FIXME: doesn't support multiple expressions + Resource expressions = graph.getPossibleObject(this.resource, sr.HasExpressions); + if(expressions == null) return null; + List expressionList = OrderedSetUtils.toList(graph, expressions); + Resource expression = expressionList.get(0); + if(expression == null) return null; + if(!graph.isInstanceOf(expression, sr.ParameterExpression)) return null; + String text = graph.getPossibleRelatedValue(expression, sr.HasEquation); + if(text == null) return null; + Double value = Double.parseDouble(text); + return (T)value; + } + + // FIXME: Support properties! This is just for the system to work like it used to. + @Override + public void setValue(WriteGraph graph, Object object, Binding binding) throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + if(this.resource == null) return; + //FIXME: doesn't support multiple expressions + Resource expressions = graph.getPossibleObject(this.resource, sr.HasExpressions); + if(expressions == null) return; + List expressionList = OrderedSetUtils.toList(graph, expressions); + Resource expression = expressionList.get(0); + if(expression == null) return; + if(!graph.isInstanceOf(expression, sr.ParameterExpression)) return; + graph.claimLiteral(expression, sr.HasEquation, object.toString(), Bindings.STRING); + } + + // FIXME: Support properties! This is just for the system to work like it used to. + @Override + public T getInterface(ReadGraph graph, Class clazz) throws DatabaseException { + if(Datatype.class.equals(clazz)) { + return (T)Datatypes.DOUBLE; + } + return super.getInterface(graph, clazz); + } public String getVariableURI(ReadGraph graph) throws DatabaseException { Variable parent = getParent(graph); -- 2.47.1