From: lempinen Date: Tue, 17 Aug 2010 11:10:02 +0000 (+0000) Subject: git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17277 ac1ea38d-2e2b... X-Git-Tag: simantics-1.2.0~103 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=d6de1e7628952795979a370c3fa2e8acfaea5efc;p=simantics%2Fsysdyn.git git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17277 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java index aa398eea..fa1c94ac 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java @@ -15,6 +15,7 @@ import org.simantics.db.common.procedure.single.SingleSetSyncListener; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.RealizationVirtualGraph; +import org.simantics.db.layer0.adapter.RemoverUtil; import org.simantics.db.layer0.adapter.ResourceData; import org.simantics.db.layer0.adapter.RuntimeValuations; import org.simantics.db.request.Read; @@ -22,89 +23,152 @@ import org.simantics.sysdyn.SysdynResource; public class HistoryRealizationVirtualGraph extends RealizationVirtualGraph { - public HistoryRealizationVirtualGraph(Session session, Resource model) throws DatabaseException { - super(session, model, SysdynResource.getInstance(session).HistoryRealization); - } - - @Override - public void initialize(final VirtualGraphContext context, WriteGraph graph) throws DatabaseException { - - graph.asyncRequest(new Read>() { - - @Override - public Collection perform(ReadGraph graph) throws DatabaseException { + public HistoryRealizationVirtualGraph(Session session, Resource model) throws DatabaseException { + super(session, model, SysdynResource.getInstance(session).HistoryRealization); + } + + @Override + public void initialize(final VirtualGraphContext context, WriteGraph graph) throws DatabaseException { + + graph.asyncRequest(new Read>() { + + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { // System.out.println("Compute runs starts"); - HashSet result = new HashSet(); - Builtins b = graph.getBuiltins(); - for(Resource config : graph.getObjects(model, b.ConsistsOf)) { - if(graph.isInstanceOf(config, b.Experiment)) { - for(Resource run : graph.getObjects(config, b.ConsistsOf)) { - if(graph.isInstanceOf(run, b.Run)) { + HashSet result = new HashSet(); + Builtins b = graph.getBuiltins(); + for(Resource config : graph.getObjects(model, b.ConsistsOf)) { + if(graph.isInstanceOf(config, b.Experiment)) { + for(Resource run : graph.getObjects(config, b.ConsistsOf)) { + if(graph.isInstanceOf(run, b.Run)) { // System.out.println("found run " + run); - result.add(run); - } - } - } - } + result.add(run); + } + } + } + } // System.out.println("Compute runs ends"); - return result; - } - - }, new SingleSetSyncListener() { + return result; + } - @Override - public void add(ReadGraph graph, final Resource run) throws DatabaseException { + }, new SingleSetSyncListener() { + + @Override + public void add(ReadGraph graph, final Resource run) throws DatabaseException { + + final String experimentName = graph.getPossibleRelatedValue(run, b.HasName, StringBindingDefault.INSTANCE); - final String experimentName = graph.getPossibleRelatedValue(run, b.HasName, StringBindingDefault.INSTANCE); - // System.out.println("RealizationVirtualGraph new experiment " + experimentName); - RuntimeValuations vs = graph.getService(RuntimeValuations.class); - if(vs.supports(experimentName)) { + RuntimeValuations vs = graph.getService(RuntimeValuations.class); + if(vs.supports(experimentName)) { // System.out.println("RealizationVirtualGraph scheduling " + experimentName); - graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) { - @Override - public void perform(WriteGraph graph) throws DatabaseException { - + graph.asyncRequest(new Read>() { + + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + HashSet result = new HashSet(); + Resource configuration = graph.getPossibleObject(model, b.HasConfiguration); + for(Resource part : graph.getObjects(configuration, b.ConsistsOf)) { + result.add(part); + } + return result; + } + }, new SingleSetSyncListener() { + + @Override + public void add(ReadGraph graph, final Resource part) throws DatabaseException { + graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + int runNode = context.getIndex(run); + String partName = graph.getPossibleRelatedValue(part, b.HasName, StringBindingDefault.INSTANCE); + if(partName != null) { + Resource partResource = graph.newResource(); + int partNode = context.getIndex(partResource); + graph.claim(run, b.ConsistsOf, null, partResource); + undiscovered.put(partNode, new ResourceData(runNode, part, valuation, partName, experimentName, null)); + } + } + }); + } + + @Override + public void remove(ReadGraph graph, final Resource part) throws DatabaseException { + + graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + Integer key = null; + for(int k : undiscovered.keySet()) { + if (undiscovered.get(k).structureResource.equals(part)) { + key = k; + break; + } + } + if(key != null) { + Resource r = context.getResource(key); + RemoverUtil.remove(graph, r); + undiscovered.remove(key); + + } + } + }); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + +/* + graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + // System.out.println("RealizationVirtualGraph about to serve " + experimentName); - int runNode = context.getIndex(run); - - Resource configuration = graph.getPossibleObject(model, b.HasConfiguration); - for(Resource part : graph.getObjects(configuration, b.ConsistsOf)) { - String partName = graph.getPossibleRelatedValue(part, b.HasName, StringBindingDefault.INSTANCE); - if(partName != null) { - Resource partResource = graph.newResource(); - int partNode = context.getIndex(partResource); - graph.claim(run, b.ConsistsOf, null, partResource); - undiscovered.put(partNode, new ResourceData(runNode, part, valuation, partName, experimentName, null)); - } - } - - } - }); - - } - - } - - @Override - public void exception(ReadGraph graph, Throwable throwable) { - throwable.printStackTrace(); - } - - @Override - public boolean isDisposed() { - return false; - } - - }); - - - } - + int runNode = context.getIndex(run); + + Resource configuration = graph.getPossibleObject(model, b.HasConfiguration); + for(Resource part : graph.getObjects(configuration, b.ConsistsOf)) { + String partName = graph.getPossibleRelatedValue(part, b.HasName, StringBindingDefault.INSTANCE); + if(partName != null) { + Resource partResource = graph.newResource(); + int partNode = context.getIndex(partResource); + graph.claim(run, b.ConsistsOf, null, partResource); + undiscovered.put(partNode, new ResourceData(runNode, part, valuation, partName, experimentName, null)); + } + } + + } + }); +*/ + + } + + } + + @Override + public void exception(ReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + } + + @Override + public boolean isDisposed() { + return false; + } + + }); + + + } + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java index 8e43dd3a..312a6b87 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java @@ -187,6 +187,7 @@ public class EquationTab extends PropertyTabContributorImpl { if(expressionWidget!= null) { expressionWidget.getExpression().replaceSelection(var); expressionWidget.getExpression().focus(); + expressionWidget.validateFields(); } } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java index fe27bb3e..4fc7b78e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java @@ -98,9 +98,9 @@ public class BasicExpression implements IExpression { @Override public void save(final Resource variable, Map data) { final String currentText = expression.getExpression(); - String oldEquation = (String)data.get("equation"); + final String oldEquation = (String)data.get("equation"); if(oldEquation == null || - (currentText != null && expressionType != null && !currentText.equals(oldEquation))) { + (currentText != null && expressionType != null)) { data.put("equation", currentText); SimanticsUI.getSession().asyncRequest(new WriteRequest() { @Override @@ -108,6 +108,12 @@ public class BasicExpression implements IExpression { throws DatabaseException { SysdynResource sr = SysdynResource.getInstance(g); Resource expression = g.getPossibleObject(variable, sr.HasExpression); + if (oldEquation != null + && expression != null + && g.isInstanceOf(expression, expressionType) + && currentText.equals(oldEquation)) { + return; + } Builtins b = g.getBuiltins(); if(expression != null && !g.isInstanceOf(expression, expressionType)) { g.deny(variable, sr.HasExpression); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java index 5c8a2cdd..72936620 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java @@ -12,6 +12,7 @@ import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.TableItem; import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; import org.simantics.sysdyn.expressionParser.ExpressionParser; import org.simantics.sysdyn.expressionParser.ParseException; import org.simantics.sysdyn.expressionParser.Token; @@ -38,13 +39,13 @@ public class ExpressionValidation { parser.ReInit(new StringReader(textString)); try { parser.expr(); - HashMap> cr = parser.getReferences(); - references.put(ef, cr); - for(String t : cr.keySet()) - variables.add(t); } catch (ParseException e1) { ef.setSyntaxError(e1.currentToken); } + HashMap> cr = parser.getReferences(); + references.put(ef, cr); + for(String t : cr.keySet()) + variables.add(t); } // Remove variables from variable array that don't exist in the model. Create annotations @@ -53,6 +54,11 @@ public class ExpressionValidation { Set noSuchVariables = new HashSet(); SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession()); SysdynModel model = sdm.getModel(configuration); + try { + model.update(); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } Configuration conf = model.getConfiguration(); ArrayList elements = conf.getElements(); for(IElement e : elements) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java index ed77e98b..50b68e17 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java @@ -31,6 +31,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment { Session session; Runnable modificationListener; + Runnable modificationListener2; Resource experiment; SysdynModel sysdynModel; @@ -153,8 +154,15 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment { @Override public void refresh(Session session) { - // TODO Auto-generated method stub System.out.println("refresh"); + session.asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + init(graph); + } + + }); } public void init(ReadGraph g) { @@ -169,10 +177,20 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment { final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration); sysdynModel = SysdynModelManager.getInstance(session).getModel(graph, configuration); toggleActivation(graph, true); + + if (modificationListener2 == null) { + modificationListener2 = new Runnable() { + + @Override + public void run() { + refresh(session); + }; + }; + sysdynModel.addModificationListener(modificationListener2); + } } }); - } @Override @@ -186,6 +204,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment { @Override public void run(ReadGraph graph) throws DatabaseException { sysdynModel.removeModificationListener(modificationListener); + sysdynModel.removeModificationListener(modificationListener2); modificationListener = null; toggleActivation(graph, false); }