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
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
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