From: jsimomaa Date: Mon, 25 Aug 2014 06:12:27 +0000 (+0000) Subject: refs #5185 X-Git-Tag: v1.29.0~216 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=d90bc43c6002ec0f8fdeef89a4eb761ec7cff434;p=simantics%2Fsysdyn.git refs #5185 Undoing stock removal won't return the pipes that went to or left from the stock git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30123 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java index 6515eb05..1b80dcf8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowConnectionFactory.java @@ -128,13 +128,15 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { // Do we need this? element.setHint(DiagramHints.ROUTE_ALGORITHM, new Router4(false)); - + System.out.println(connection); IModelingRules modelingRules = diagram.getHint(DiagramModelHints.KEY_MODELING_RULES); - IElement mappedElement = ElementUtils.getByData(diagram, connection); - if (mappedElement == null) - // FIXME: With undo this seems to happen, don't know why yet! - return; +// IElement mappedElement = ElementUtils.getByData(diagram, connection); +// if (mappedElement == null) { +// System.out.println("taalla ollaan mappedElement == null"); +// // FIXME: With undo this seems to happen, don't know why yet! +// return; +// } Color color = null; DiagramResource DR = DiagramResource.getInstance(graph); @@ -344,7 +346,7 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { // Initialize ConnectionEntity in element // NOTE: MUST use the mapped element with class CE, not the connection (element) were loading into. // GDS will synchronize element into mappedElement in a controlled manner. - element.setHint(ElementHints.KEY_CONNECTION_ENTITY, new CE(connection, mappedElement, backendonnections)); + element.setHint(ElementHints.KEY_CONNECTION_ENTITY, new CE(diagram, connection, element, backendonnections)); // Setup graph writeback support for route graph modifications final Session session = graph.getSession(); @@ -565,6 +567,11 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { */ static class CE implements ConnectionEntity { + + private IDiagram diagram; + + private transient DataElementMap dataMap; + /** * The connection instance resource in the graph backend. */ @@ -573,7 +580,7 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { /** * The connection entity element which is a part of the diagram. */ - final IElement connectionElement; + IElement connectionElement; /** * @see #getTerminalConnections(Collection) @@ -585,15 +592,31 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { */ Set terminalConnections; - CE(Resource connection, IElement connectionElement, Set backendConnections) { + + public CE(IDiagram diagram, Resource connection, IElement connectionElement, Set backendConnections) { + if (connectionElement == null) + throw new NullPointerException("null connection element"); + this.diagram = diagram; + this.dataMap = diagram.getDiagramClass().getSingleItem(DataElementMap.class); this.connection = connection; this.connectionElement = connectionElement; this.backendConnections = backendConnections; + IElement ce = getConnection0(); + if (ce != null) + this.connectionElement = ce; + } + + public IElement getConnection0() { + IElement connectionElement = dataMap.getElement(diagram, connection); + return connectionElement; } @Override public IElement getConnection() { - return connectionElement; + IElement c = getConnection0(); + if (c == null) + c = this.connectionElement; + return c; } public Object getConnectionObject() { @@ -626,7 +649,6 @@ public class RouteFlowConnectionFactory extends SyncElementFactory { } private Set calculateTerminalConnections() { - IDiagram diagram = connectionElement.getDiagram(); DataElementMap dem = diagram.getDiagramClass().getSingleItem(DataElementMap.class); Set result = new HashSet(); ArrayList ts = new ArrayList();