]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17277 ac1ea38d-2e2b...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 17 Aug 2010 11:10:02 +0000 (11:10 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 17 Aug 2010 11:10:02 +0000 (11:10 +0000)
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryRealizationVirtualGraph.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionValidation.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java

index aa398eea5830e4f090b2399e38021a80e01c30ab..fa1c94ac4c1bafc3257e7d8b26852f8745018917 100644 (file)
@@ -15,6 +15,7 @@ import org.simantics.db.common.procedure.single.SingleSetSyncListener;
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.adapter.RealizationVirtualGraph;\r
+import org.simantics.db.layer0.adapter.RemoverUtil;\r
 import org.simantics.db.layer0.adapter.ResourceData;\r
 import org.simantics.db.layer0.adapter.RuntimeValuations;\r
 import org.simantics.db.request.Read;\r
@@ -22,89 +23,152 @@ import org.simantics.sysdyn.SysdynResource;
 \r
 public class HistoryRealizationVirtualGraph extends RealizationVirtualGraph {\r
 \r
-       public HistoryRealizationVirtualGraph(Session session, Resource model) throws DatabaseException {\r
-               super(session, model, SysdynResource.getInstance(session).HistoryRealization);\r
-       }\r
-       \r
-       @Override\r
-       public void initialize(final VirtualGraphContext context, WriteGraph graph) throws DatabaseException {\r
-               \r
-               graph.asyncRequest(new Read<Collection<Resource>>() {\r
-\r
-                       @Override\r
-                       public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+    public HistoryRealizationVirtualGraph(Session session, Resource model) throws DatabaseException {\r
+        super(session, model, SysdynResource.getInstance(session).HistoryRealization);\r
+    }\r
+\r
+    @Override\r
+    public void initialize(final VirtualGraphContext context, WriteGraph graph) throws DatabaseException {\r
+\r
+        graph.asyncRequest(new Read<Collection<Resource>>() {\r
+\r
+            @Override\r
+            public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
 //                             System.out.println("Compute runs starts");\r
-                               HashSet<Resource> result = new HashSet<Resource>();\r
-                               Builtins b = graph.getBuiltins();\r
-                               for(Resource config : graph.getObjects(model, b.ConsistsOf)) {\r
-                                       if(graph.isInstanceOf(config, b.Experiment)) {\r
-                                               for(Resource run : graph.getObjects(config, b.ConsistsOf)) {\r
-                                                       if(graph.isInstanceOf(run, b.Run)) {\r
+                HashSet<Resource> result = new HashSet<Resource>();\r
+                Builtins b = graph.getBuiltins();\r
+                for(Resource config : graph.getObjects(model, b.ConsistsOf)) {\r
+                    if(graph.isInstanceOf(config, b.Experiment)) {\r
+                        for(Resource run : graph.getObjects(config, b.ConsistsOf)) {\r
+                            if(graph.isInstanceOf(run, b.Run)) {\r
 //                                                             System.out.println("found run " + run);\r
-                                                               result.add(run);\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                               }\r
+                                result.add(run);\r
+                            }\r
+                        }\r
+                    }\r
+                }\r
 //                             System.out.println("Compute runs ends");\r
-                               return result;\r
-                       }\r
-                       \r
-               }, new SingleSetSyncListener<Resource>() {\r
+                return result;\r
+            }\r
 \r
-                       @Override\r
-                       public void add(ReadGraph graph, final Resource run) throws DatabaseException {\r
+        }, new SingleSetSyncListener<Resource>() {\r
+\r
+            @Override\r
+            public void add(ReadGraph graph, final Resource run) throws DatabaseException {\r
+\r
+                final String experimentName = graph.getPossibleRelatedValue(run, b.HasName, StringBindingDefault.INSTANCE);\r
 \r
-                               final String experimentName = graph.getPossibleRelatedValue(run, b.HasName, StringBindingDefault.INSTANCE);\r
-                               \r
 //                             System.out.println("RealizationVirtualGraph new experiment " + experimentName);\r
 \r
-                               RuntimeValuations vs = graph.getService(RuntimeValuations.class);\r
-                               if(vs.supports(experimentName)) {\r
+                RuntimeValuations vs = graph.getService(RuntimeValuations.class);\r
+                if(vs.supports(experimentName)) {\r
 \r
 //                                     System.out.println("RealizationVirtualGraph scheduling " + experimentName);\r
 \r
-                                       graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) {\r
 \r
-                                               @Override\r
-                                               public void perform(WriteGraph graph) throws DatabaseException {\r
-                                                       \r
+                    graph.asyncRequest(new Read<Collection<Resource>>() {\r
+\r
+                        @Override\r
+                        public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+                            HashSet<Resource> result = new HashSet<Resource>();\r
+                            Resource configuration = graph.getPossibleObject(model, b.HasConfiguration);\r
+                            for(Resource part : graph.getObjects(configuration, b.ConsistsOf)) {\r
+                                result.add(part);\r
+                            }\r
+                            return result;\r
+                        }\r
+                    }, new SingleSetSyncListener<Resource>() {\r
+\r
+                        @Override\r
+                        public void add(ReadGraph graph, final Resource part) throws DatabaseException {\r
+                            graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) {\r
+                                @Override\r
+                                public void perform(WriteGraph graph) throws DatabaseException {\r
+                                    int runNode = context.getIndex(run);\r
+                                    String partName = graph.getPossibleRelatedValue(part, b.HasName, StringBindingDefault.INSTANCE);\r
+                                    if(partName != null) {\r
+                                        Resource partResource = graph.newResource();\r
+                                        int partNode = context.getIndex(partResource);\r
+                                        graph.claim(run, b.ConsistsOf, null, partResource);\r
+                                        undiscovered.put(partNode, new ResourceData(runNode, part, valuation, partName, experimentName, null));\r
+                                    }\r
+                                }\r
+                            });\r
+                        }\r
+\r
+                        @Override\r
+                        public void remove(ReadGraph graph, final Resource part) throws DatabaseException {\r
+                            \r
+                            graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) {\r
+                                @Override\r
+                                public void perform(WriteGraph graph) throws DatabaseException {\r
+                                    Integer key = null;\r
+                                    for(int k : undiscovered.keySet()) {\r
+                                        if (undiscovered.get(k).structureResource.equals(part)) {\r
+                                            key = k;\r
+                                            break;\r
+                                        }\r
+                                    }\r
+                                    if(key != null) {\r
+                                        Resource r = context.getResource(key);\r
+                                        RemoverUtil.remove(graph, r);\r
+                                        undiscovered.remove(key);\r
+                                        \r
+                                    }\r
+                                }\r
+                            });\r
+                        }\r
+\r
+                        @Override\r
+                        public boolean isDisposed() {\r
+                            return false;\r
+                        }\r
+\r
+                    });\r
+\r
+/*\r
+                    graph.getSession().asyncRequest(new WriteRequest(graph.getService(VirtualGraph.class)) {\r
+\r
+                        @Override\r
+                        public void perform(WriteGraph graph) throws DatabaseException {\r
+\r
 //                                                     System.out.println("RealizationVirtualGraph about to serve " + experimentName);\r
 \r
-                                                       int runNode = context.getIndex(run);\r
-\r
-                                                       Resource configuration = graph.getPossibleObject(model, b.HasConfiguration);\r
-                                                       for(Resource part : graph.getObjects(configuration, b.ConsistsOf)) {\r
-                                                               String partName = graph.getPossibleRelatedValue(part, b.HasName, StringBindingDefault.INSTANCE);\r
-                                                               if(partName != null) {\r
-                                                                       Resource partResource = graph.newResource();\r
-                                                                       int partNode = context.getIndex(partResource);\r
-                                                                       graph.claim(run, b.ConsistsOf, null, partResource);\r
-                                                                       undiscovered.put(partNode, new ResourceData(runNode, part, valuation, partName, experimentName, null));\r
-                                                               }\r
-                                                       }\r
-                                                       \r
-                                               }\r
-                                       });\r
-                                       \r
-                               }\r
-                                       \r
-                       }\r
-                       \r
-                       @Override\r
-                       public void exception(ReadGraph graph, Throwable throwable) {\r
-                               throwable.printStackTrace();\r
-                       }\r
-\r
-                       @Override\r
-                       public boolean isDisposed() {\r
-                               return false;\r
-                       }\r
-                       \r
-               });\r
-               \r
-               \r
-       }\r
-       \r
+                            int runNode = context.getIndex(run);\r
+\r
+                            Resource configuration = graph.getPossibleObject(model, b.HasConfiguration);\r
+                            for(Resource part : graph.getObjects(configuration, b.ConsistsOf)) {\r
+                                String partName = graph.getPossibleRelatedValue(part, b.HasName, StringBindingDefault.INSTANCE);\r
+                                if(partName != null) {\r
+                                    Resource partResource = graph.newResource();\r
+                                    int partNode = context.getIndex(partResource);\r
+                                    graph.claim(run, b.ConsistsOf, null, partResource);\r
+                                    undiscovered.put(partNode, new ResourceData(runNode, part, valuation, partName, experimentName, null));\r
+                                }\r
+                            }\r
+\r
+                        }\r
+                    });\r
+*/\r
+                    \r
+                }\r
+\r
+            }\r
+\r
+            @Override\r
+            public void exception(ReadGraph graph, Throwable throwable) {\r
+                throwable.printStackTrace();\r
+            }\r
+\r
+            @Override\r
+            public boolean isDisposed() {\r
+                return false;\r
+            }\r
+\r
+        });\r
+\r
+\r
+    }\r
+\r
 \r
 }\r
index 8e43dd3a25d1e62f84d36c43414ec062ca29e89c..312a6b87ce0902c72ee48efdf20eb4b070ebf2cf 100644 (file)
@@ -187,6 +187,7 @@ public class EquationTab extends PropertyTabContributorImpl {
                             if(expressionWidget!= null) {\r
                                 expressionWidget.getExpression().replaceSelection(var);\r
                                 expressionWidget.getExpression().focus();\r
+                                expressionWidget.validateFields();\r
                             }\r
                         }\r
                     });\r
index fe27bb3ef58d2bb8b17f9b7ab100f9d5197f53fa..4fc7b78e1a3b943622ff7d35d02e2cb793771ec1 100644 (file)
@@ -98,9 +98,9 @@ public class BasicExpression implements IExpression {
     @Override\r
     public void save(final Resource variable, Map<String, Object> data) {\r
         final String currentText = expression.getExpression();\r
-        String oldEquation = (String)data.get("equation");\r
+        final String oldEquation = (String)data.get("equation");\r
         if(oldEquation == null || \r
-                (currentText != null && expressionType != null && !currentText.equals(oldEquation))) {\r
+                (currentText != null && expressionType != null)) {\r
             data.put("equation", currentText);\r
             SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
                 @Override\r
@@ -108,6 +108,12 @@ public class BasicExpression implements IExpression {
                 throws DatabaseException {\r
                     SysdynResource sr = SysdynResource.getInstance(g);\r
                     Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
+                    if (oldEquation != null \r
+                            && expression != null \r
+                            && g.isInstanceOf(expression, expressionType) \r
+                            && currentText.equals(oldEquation)) {\r
+                        return;\r
+                    }\r
                     Builtins b = g.getBuiltins();\r
                     if(expression != null && !g.isInstanceOf(expression, expressionType)) {\r
                         g.deny(variable, sr.HasExpression);\r
index 5c8a2cdd38627bc5fabb152ce25febbb44d47909..7293662076f1f9d432bd100d547a48b3d9cff360 100644 (file)
@@ -12,6 +12,7 @@ import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.graphics.Color;\r
 import org.eclipse.swt.widgets.TableItem;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.sysdyn.expressionParser.ExpressionParser;\r
 import org.simantics.sysdyn.expressionParser.ParseException;\r
 import org.simantics.sysdyn.expressionParser.Token;\r
@@ -38,13 +39,13 @@ public class ExpressionValidation {
             parser.ReInit(new StringReader(textString));\r
             try {\r
                 parser.expr();\r
-                HashMap<String, List<Token>> cr = parser.getReferences();\r
-                references.put(ef, cr);\r
-                for(String t : cr.keySet())\r
-                    variables.add(t);\r
             } catch (ParseException e1) {\r
                 ef.setSyntaxError(e1.currentToken);\r
             }\r
+            HashMap<String, List<Token>> cr = parser.getReferences();\r
+            references.put(ef, cr);\r
+            for(String t : cr.keySet())\r
+                variables.add(t);\r
         }\r
 \r
         // Remove variables from variable array that don't exist in the model. Create annotations\r
@@ -53,6 +54,11 @@ public class ExpressionValidation {
             Set<String> noSuchVariables = new HashSet<String>();\r
             SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession());\r
             SysdynModel model = sdm.getModel(configuration);\r
+            try {\r
+                model.update();\r
+            } catch (DatabaseException e1) {\r
+                e1.printStackTrace();\r
+            }\r
             Configuration conf = model.getConfiguration();\r
             ArrayList<IElement> elements = conf.getElements();\r
             for(IElement e : elements) {\r
index ed77e98b33e74d1963ef349937fbe4b9dcff8905..50b68e17b443ea4e37ae75e55a21cfa6465701f4 100644 (file)
@@ -31,6 +31,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
 \r
     Session session;\r
     Runnable modificationListener;\r
+    Runnable modificationListener2;\r
     Resource experiment;\r
     SysdynModel sysdynModel;\r
 \r
@@ -153,8 +154,15 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
 \r
     @Override\r
     public void refresh(Session session) {\r
-        // TODO Auto-generated method stub\r
         System.out.println("refresh");\r
+        session.asyncRequest(new ReadRequest() {\r
+\r
+            @Override\r
+            public void run(ReadGraph graph) throws DatabaseException {\r
+                init(graph);\r
+            }\r
+            \r
+        });\r
     }\r
 \r
     public void init(ReadGraph g) {\r
@@ -169,10 +177,20 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                 final Resource configuration = graph.getPossibleObject(model, graph.getBuiltins().HasConfiguration);\r
                 sysdynModel = SysdynModelManager.getInstance(session).getModel(graph, configuration);\r
                 toggleActivation(graph, true);\r
+                \r
+                if (modificationListener2 == null) {\r
+                    modificationListener2 = new Runnable() {\r
+\r
+                        @Override\r
+                        public void run() {\r
+                            refresh(session);\r
+                        };\r
+                    };\r
+                    sysdynModel.addModificationListener(modificationListener2);\r
+                }\r
             }\r
         });\r
         \r
-        \r
     }\r
 \r
     @Override\r
@@ -186,6 +204,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                     @Override\r
                     public void run(ReadGraph graph) throws DatabaseException {\r
                         sysdynModel.removeModificationListener(modificationListener);\r
+                        sysdynModel.removeModificationListener(modificationListener2);\r
                         modificationListener = null;\r
                         toggleActivation(graph, false);\r
                     }\r