]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Fixed DependencyEdgeClass to compile and work again after removing DiagramMutator...
authorlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 28 Oct 2015 14:28:02 +0000 (14:28 +0000)
committerlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 28 Oct 2015 14:28:02 +0000 (14:28 +0000)
refs #6107

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@31885 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyEdgeClass.java

index 5b86bd993dd8ed164ae5d825a3ebb3b917abb105..e7f29f1cae380fa217bcc3756f204a17765189c5 100644 (file)
@@ -23,10 +23,14 @@ import java.beans.PropertyChangeListener;
 import java.util.HashMap;\r
 import java.util.Map;\r
 \r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.simantics.Simantics;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.g2d.diagram.DiagramHints;\r
-import org.simantics.g2d.diagram.DiagramMutator;\r
-import org.simantics.g2d.diagram.DiagramUtils;\r
 import org.simantics.g2d.diagram.IDiagram;\r
 import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy;\r
 import org.simantics.g2d.diagram.handler.Topology;\r
@@ -56,8 +60,8 @@ import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform;
 import org.simantics.g2d.utils.Alignment;\r
 import org.simantics.scenegraph.g2d.G2DParentNode;\r
 import org.simantics.scenegraph.utils.NodeUtil;\r
+import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.sysdyn.ui.editor.routing.DependencyRouter;\r
-import org.simantics.utils.datastructures.Callback;\r
 import org.simantics.utils.datastructures.Pair;\r
 import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
 \r
@@ -157,30 +161,39 @@ public class DependencyEdgeClass {
             DependencyNode node = e.getHint(KEY_SG_NODE);\r
             if(node == null) return;\r
             final IDiagram diagram = ElementUtils.peekDiagram(e);\r
-            \r
+\r
+            IElement edgeParent = ElementUtils.getParent(e);\r
+            Object edgeParentObject = edgeParent != null ? edgeParent.getHint(ElementHints.KEY_OBJECT) : null;\r
+            final Resource parentElement = edgeParentObject instanceof Resource ? (Resource) edgeParentObject : null;\r
+\r
             node.setFieldListener(new PropertyChangeListener() {\r
 \r
                 @Override\r
                 public void propertyChange(final PropertyChangeEvent event) {\r
-                       \r
-                                       String field = event.getPropertyName();\r
-                           Map<String, Pair<Resource, Object>> properties = e.getHint(DiagramHints.PROPERTIES);\r
-                           if(properties == null) return;\r
-                           final Pair<Resource, Object> property = properties.get(field);\r
-                           if(property == null) return;\r
+                    if (parentElement == null)\r
+                        return;\r
+\r
+                    String field = event.getPropertyName();\r
+                    Map<String, Pair<Resource, Object>> properties = e.getHint(DiagramHints.PROPERTIES);\r
+                    if(properties == null) return;\r
+                    final Pair<Resource, Object> property = properties.get(field);\r
+                    if(property == null) return;\r
 \r
-                       DiagramUtils.mutateDiagram(diagram, new Callback<DiagramMutator>() {\r
-                                               \r
-                                               @Override\r
-                                               public void run(DiagramMutator mutator) {\r
-                                                       mutator.modifyProperty(e, property.first, event.getNewValue());\r
-                                               }\r
-                                               \r
-                                       });\r
-                       \r
+                    try {\r
+                        Simantics.getSession().syncRequest(new WriteRequest() {\r
+                            @Override\r
+                            public void perform(WriteGraph graph) throws DatabaseException {\r
+                                graph.claimLiteral((Resource) parentElement, property.first, event.getNewValue());\r
+                            }\r
+                        });\r
+                    } catch (DatabaseException ex) {\r
+                        Activator.getDefault().getLog().log(\r
+                                new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to synchronize property " + field + ".", ex)\r
+                                );\r
+                        \r
+                    }\r
                 }\r
-                \r
-                       });\r
+            });\r
 \r
 \r
 \r