From: lempinen Date: Wed, 8 Sep 2010 11:05:34 +0000 (+0000) Subject: Copy copies also expressions X-Git-Tag: simantics-1.2.0~56 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c77f5001c5d506538a3a1de51ba1db22b2db09cf;p=simantics%2Fsysdyn.git Copy copies also expressions git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17840 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java index 5d108374..ef3c3637 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java @@ -18,6 +18,7 @@ import org.simantics.diagram.adapter.FlagClassFactory; import org.simantics.diagram.handler.CopyPasteHandler; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.diagram.synchronization.IModifiableSynchronizationContext; +import org.simantics.diagram.synchronization.SynchronizationHints; import org.simantics.diagram.ui.DiagramModelHints; import org.simantics.diagram.ui.WorkbenchSelectionProvider; import org.simantics.g2d.canvas.ICanvasContext; @@ -33,10 +34,13 @@ import org.simantics.g2d.element.ElementHints; import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.IElementClassProvider; import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; +import org.simantics.modeling.mapping.ElementCopyAdvisor; +import org.simantics.modeling.mapping.MappedElementCopyAdvisor; import org.simantics.modeling.ui.diagramEditor.handlers.LinkBrowsingHandler; import org.simantics.structural2.modelingRules.IModelingRules; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.editor.participant.CreateVariablesShortcutParticipant; +import org.simantics.sysdyn.ui.editor.participant.SysdynComponentCopyAdvisor; import org.simantics.sysdyn.ui.elements2.connections.ConnectionClasses; import org.simantics.sysdyn.ui.elements2.connections.SysdynConnectionClass; import org.simantics.sysdyn.ui.properties.SysdynPropertyPage; @@ -93,6 +97,7 @@ public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.Diagr @Override protected void onCreated() { sourceDiagram.setHint(DiagramHints.KEY_ALLOW_ROUTE_POINTS, Boolean.FALSE); + sourceDiagram.setHint(SynchronizationHints.COPY_ADVISOR, new MappedElementCopyAdvisor(new ElementCopyAdvisor(), new SysdynComponentCopyAdvisor())); } @Override 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 index 00000000..436127a8 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java @@ -0,0 +1,42 @@ +package org.simantics.sysdyn.ui.editor.participant; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.diagram.synchronization.ISynchronizationContext; +import org.simantics.diagram.synchronization.graph.CopyAdvisorUtil; +import org.simantics.modeling.mapping.ComponentCopyAdvisor; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.datastructures.BinaryFunction; + +public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor{ + + @Override + public Object copy(ISynchronizationContext context, WriteGraph graph, Resource source) throws DatabaseException { + + BinaryFunction tester = new BinaryFunction() { + + @Override + public Boolean call(ReadGraph graph, Statement statement) { + SysdynResource sr = SysdynResource.getInstance(graph); + try { + if(graph.isInstanceOf(statement.getSubject(), sr.IndependentVariable)) { + if(statement.getPredicate().equals(sr.HasExpression)) + return true; + } + } catch (ServiceException e) { + e.printStackTrace(); + } + return false; + } + + }; + + Resource copy = CopyAdvisorUtil.copy(graph, source, tester); + renameComponent(context, graph, source, copy); + return copy; + } +}