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
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
@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
--- /dev/null
+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