]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Copy copies also expressions
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 8 Sep 2010 11:05:34 +0000 (11:05 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 8 Sep 2010 11:05:34 +0000 (11:05 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17840 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java [new file with mode: 0644]

index 5d10837450429003df76327c3274d2ffa3ef85e5..ef3c3637e1186ac2d2298b590107f8d7971af175 100644 (file)
@@ -18,6 +18,7 @@ import org.simantics.diagram.adapter.FlagClassFactory;
 import org.simantics.diagram.handler.CopyPasteHandler;\r
 import org.simantics.diagram.stubs.DiagramResource;\r
 import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;\r
+import org.simantics.diagram.synchronization.SynchronizationHints;\r
 import org.simantics.diagram.ui.DiagramModelHints;\r
 import org.simantics.diagram.ui.WorkbenchSelectionProvider;\r
 import org.simantics.g2d.canvas.ICanvasContext;\r
@@ -33,10 +34,13 @@ import org.simantics.g2d.element.ElementHints;
 import org.simantics.g2d.element.IElement;\r
 import org.simantics.g2d.element.IElementClassProvider;\r
 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
+import org.simantics.modeling.mapping.ElementCopyAdvisor;\r
+import org.simantics.modeling.mapping.MappedElementCopyAdvisor;\r
 import org.simantics.modeling.ui.diagramEditor.handlers.LinkBrowsingHandler;\r
 import org.simantics.structural2.modelingRules.IModelingRules;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.editor.participant.CreateVariablesShortcutParticipant;\r
+import org.simantics.sysdyn.ui.editor.participant.SysdynComponentCopyAdvisor;\r
 import org.simantics.sysdyn.ui.elements2.connections.ConnectionClasses;\r
 import org.simantics.sysdyn.ui.elements2.connections.SysdynConnectionClass;\r
 import org.simantics.sysdyn.ui.properties.SysdynPropertyPage;\r
@@ -93,6 +97,7 @@ public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.Diagr
        @Override\r
        protected void onCreated() {\r
                sourceDiagram.setHint(DiagramHints.KEY_ALLOW_ROUTE_POINTS, Boolean.FALSE);\r
+               sourceDiagram.setHint(SynchronizationHints.COPY_ADVISOR, new MappedElementCopyAdvisor(new ElementCopyAdvisor(), new SysdynComponentCopyAdvisor()));             \r
        }\r
 \r
        @Override\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java
new file mode 100644 (file)
index 0000000..436127a
--- /dev/null
@@ -0,0 +1,42 @@
+package org.simantics.sysdyn.ui.editor.participant;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.ServiceException;\r
+import org.simantics.diagram.synchronization.ISynchronizationContext;\r
+import org.simantics.diagram.synchronization.graph.CopyAdvisorUtil;\r
+import org.simantics.modeling.mapping.ComponentCopyAdvisor;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.utils.datastructures.BinaryFunction;\r
+\r
+public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor{\r
+\r
+    @Override\r
+    public Object copy(ISynchronizationContext context, WriteGraph graph, Resource source) throws DatabaseException {\r
+       \r
+       BinaryFunction<Boolean, ReadGraph, Statement> tester = new BinaryFunction<Boolean, ReadGraph, Statement>() {\r
+\r
+                       @Override\r
+                       public Boolean call(ReadGraph graph, Statement statement) {\r
+                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                               try {\r
+                                       if(graph.isInstanceOf(statement.getSubject(), sr.IndependentVariable)) {\r
+                                               if(statement.getPredicate().equals(sr.HasExpression))\r
+                                                       return true;\r
+                                       }\r
+                               } catch (ServiceException e) {\r
+                                       e.printStackTrace();\r
+                               }\r
+                               return false;\r
+                       }\r
+               \r
+       };\r
+       \r
+        Resource copy = CopyAdvisorUtil.copy(graph, source, tester);\r
+        renameComponent(context, graph, source, copy);\r
+        return copy;\r
+    }\r
+}\r