From c5509a69b937d26746969b949287ed44c7a7c65a Mon Sep 17 00:00:00 2001 From: Nis Wechselberg Date: Tue, 27 Oct 2015 10:00:54 +0100 Subject: [PATCH] Klighd.picocolo: Implemented new show/hide behaviour to keep existing pnodes at the corect layer. Reverted previous implementations. (reverted from commit 2f39a9cd2f3d3eb63b25e8e4a7080f1432e2eed5) --- .../controller/DiagramController.java | 140 ++++++++---------- 1 file changed, 59 insertions(+), 81 deletions(-) diff --git a/plugins/de.cau.cs.kieler.klighd.piccolo/src/de/cau/cs/kieler/klighd/piccolo/internal/controller/DiagramController.java b/plugins/de.cau.cs.kieler.klighd.piccolo/src/de/cau/cs/kieler/klighd/piccolo/internal/controller/DiagramController.java index 4ce47dfa0..e60533204 100644 --- a/plugins/de.cau.cs.kieler.klighd.piccolo/src/de/cau/cs/kieler/klighd/piccolo/internal/controller/DiagramController.java +++ b/plugins/de.cau.cs.kieler.klighd.piccolo/src/de/cau/cs/kieler/klighd/piccolo/internal/controller/DiagramController.java @@ -490,8 +490,16 @@ public void hide(final KGraphElement diagramElement) { if (parent == null) { return; } - - remove(diagramElement, false); + + RenderingContextData contextData = RenderingContextData.get(diagramElement); + KNodeAbstractNode nodeRep = contextData.getProperty(REP); + + if (nodeRep != null) { + nodeRep.setVisible(false); + contextData.setProperty(KlighdInternalProperties.ACTIVE, false); + } + +// remove(diagramElement, false); } /** @@ -509,7 +517,17 @@ public void show(final KGraphElement diagramElement) { return; } - add(diagramElement, true); + RenderingContextData contextData = RenderingContextData.get(diagramElement); + KNodeAbstractNode nodeRep = contextData.getProperty(REP); + + if (nodeRep != null) { + nodeRep.setVisible(true); + contextData.setProperty(KlighdInternalProperties.ACTIVE, true); + } else { + if (RenderingContextData.get(parent).getProperty(REP) != null) { + add(diagramElement, true); + } + } } private static final String INVALID_CLIP_NODE_ERROR_MSG = @@ -921,16 +939,14 @@ private void addNode(final KNodeAbstractNode parent, final KNode node, final boo // note that this condition implies that invisible children's children // that are still contained in there parent will break the recursion // of this method -// if (nodeNode != null && nodeNode.getParent() != null) { -// return; -// } + if (nodeNode != null && nodeNode.getParent() != null) { + return; + } final int expand; - final boolean newNodeRep; // if there is no Piccolo2D representation of the node create it if (nodeNode == null) { - newNodeRep = true; final KGraphData data = node.getData(KLayoutDataPackage.eINSTANCE.getKLayoutData()); if (!forceShow && !data.getProperty(KlighdProperties.SHOW)) { contextData.setProperty(KlighdInternalProperties.ACTIVE, false); @@ -948,7 +964,6 @@ private void addNode(final KNodeAbstractNode parent, final KNode node, final boo // in case the EXPAND property is not set the default value 'true' is returned } else { - newNodeRep = false; // touch the expansion state, see the methods javadoc for details expand = 2; } @@ -968,11 +983,7 @@ private void addNode(final KNodeAbstractNode parent, final KNode node, final boo handleLabels(nodeNode, node); // add the node to its parents - if (newNodeRep) { - parent.getChildAreaNode().addNode(nodeNode); - } else { - nodeNode.setVisible(true); - } + parent.getChildAreaNode().addNode(nodeNode); // perform expansion strictly AFTER adding 'nodeNode' to its parent as the edge offset adjustment // logic requires that (for registration of an transform change listener on the parents row) @@ -1051,13 +1062,14 @@ private void removeNode(final KNode node, final boolean releaseControllers) { removeEdge(outgoingEdge, releaseControllers); } + // remove the node representation from the containing child area + nodeNode.removeFromParent(); contextData.setProperty(KlighdInternalProperties.ACTIVE, false); + // recursively dispose all attached SWT Resources + NodeDisposeListener.disposePNode(nodeNode); + if (releaseControllers) { - // remove the node representation from the containing child area - nodeNode.removeFromParent(); - // recursively dispose all attached SWT Resources - NodeDisposeListener.disposePNode(nodeNode); // detach the synchronization adapters ModelingUtil.removeAdapters(node, NODE_ADAPTERS); // release the objects kept in mind @@ -1068,9 +1080,6 @@ private void removeNode(final KNode node, final boolean releaseControllers) { nodeNode.removeAllChildren(); // release the node representation from the node's renderingContextData contextData.setProperty(REP, null); - } else { - // Only hide the representation without removing it from the model - nodeNode.setVisible(false); } } @@ -1120,9 +1129,9 @@ private void addEdge(final KEdge edge, final boolean forceShow) { KEdgeNode edgeNode = contextData.getProperty(EDGE_REP); // only add a representation if none is added already -// if (edgeNode != null && edgeNode.getParent() != null) { -// return; -// } + if (edgeNode != null && edgeNode.getParent() != null) { + return; + } final KNode source = edge.getSource(); final KNode target = edge.getTarget(); @@ -1135,11 +1144,8 @@ private void addEdge(final KEdge edge, final boolean forceShow) { return; } - final boolean newEdgeRep; - // if there is no Piccolo2D representation for the node create it if (edgeNode == null) { - newEdgeRep = true; if (!forceShow && !NON_HIDDEN_KGE_FILTER.apply(edge)) { contextData.setProperty(KlighdInternalProperties.ACTIVE, false); return; @@ -1149,8 +1155,6 @@ private void addEdge(final KEdge edge, final boolean forceShow) { contextData.setProperty(EDGE_REP, edgeNode); updateRendering(edgeNode); - } else { - newEdgeRep = false; } // note that 'edgeNode' is not contained in any parent and, thus, fires no events @@ -1169,11 +1173,7 @@ private void addEdge(final KEdge edge, final boolean forceShow) { // the clipping is generally intended and is realized by KChildAreaNode // find and set the parent of the edge, i.e. add it into the figure tree - if (newEdgeRep) { - DiagramControllerHelper.updateEdgeParent(edgeNode); - } else { - edgeNode.setVisible(true); - } + DiagramControllerHelper.updateEdgeParent(edgeNode); contextData.setProperty(KlighdInternalProperties.ACTIVE, true); // update the offset of the edge layout to the containing child area @@ -1197,16 +1197,18 @@ private void removeEdge(final KEdge edge, final boolean releaseControllers) { return; } + // remove the edge offset listeners + DiagramControllerHelper.removeEdgeOffsetListener(edgeNode); + + // remove the edge representation from the containing child area + edgeNode.removeFromParent(); contextData.setProperty(KlighdInternalProperties.ACTIVE, false); + // recursively dispose all attached SWT Resources + NodeDisposeListener.disposePNode(edgeNode); + // due to #removeNode() this method might be performed multiple times so: if (releaseControllers && edgeNode.getRenderingController() != null) { - // remove the edge offset listeners - DiagramControllerHelper.removeEdgeOffsetListener(edgeNode); - // remove the edge representation from the containing child area - edgeNode.removeFromParent(); - // recursively dispose all attached SWT Resources - NodeDisposeListener.disposePNode(edgeNode); // detach the synchronization adapters ModelingUtil.removeAdapters(edge, EDGE_ADAPTERS); // release the objects kept in mind @@ -1217,9 +1219,6 @@ private void removeEdge(final KEdge edge, final boolean releaseControllers) { edgeNode.removeAllChildren(); // release the edge representation from the edge's renderingContextData contextData.setProperty(EDGE_REP, null); - } else { - // Hide the representation of the edge - edgeNode.setVisible(false); } } @@ -1265,14 +1264,12 @@ private void addPort(final KNodeNode parent, final KPort port, final boolean for final RenderingContextData contextData = RenderingContextData.get(port); KPortNode portNode = contextData.getProperty(PORT_REP); -// if (portNode != null && portNode.getParent() != null) { -// return; -// } + if (portNode != null && portNode.getParent() != null) { + return; + } - final boolean newPortRep; // if there is no Piccolo2D representation of the port create it if (portNode == null) { - newPortRep = true; if (!forceShow && !NON_HIDDEN_KGE_FILTER.apply(port)) { contextData.setProperty(KlighdInternalProperties.ACTIVE, false); return; @@ -1282,8 +1279,6 @@ private void addPort(final KNodeNode parent, final KPort port, final boolean for contextData.setProperty(PORT_REP, portNode); updateRendering(portNode); - } else { - newPortRep = false; } if (record && isAutomaticallyArranged(port)) { @@ -1296,11 +1291,7 @@ private void addPort(final KNodeNode parent, final KPort port, final boolean for handleLabels(portNode, port); // add the port - if (newPortRep) { - parent.addPort(portNode); - } else { - portNode.setVisible(true); - } + parent.addPort(portNode); contextData.setProperty(KlighdInternalProperties.ACTIVE, true); } @@ -1321,14 +1312,14 @@ private void removePort(final KPort port, final boolean releaseControllers) { return; } + // remove the port representation from the containing node + portNode.removeFromParent(); contextData.setProperty(KlighdInternalProperties.ACTIVE, false); + // recursively dispose all attached SWT Resources + NodeDisposeListener.disposePNode(portNode); if (releaseControllers) { - // remove the port representation from the containing node - portNode.removeFromParent(); - // recursively dispose all attached SWT Resources - NodeDisposeListener.disposePNode(portNode); // detach the synchronization adapters ModelingUtil.removeAdapters(port, PORT_ADAPTERS); // release the objects kept in mind @@ -1339,9 +1330,6 @@ private void removePort(final KPort port, final boolean releaseControllers) { portNode.removeAllChildren(); // release the port representation from the port's renderingContextData contextData.setProperty(PORT_REP, null); - } else { - // Hide the port representation from the view - portNode.setVisible(false); } } @@ -1389,14 +1377,12 @@ private void addLabel( final RenderingContextData contextData = RenderingContextData.get(label); KLabelNode labelNode = contextData.getProperty(LABEL_REP); -// if (labelNode != null && labelNode.getParent() != null) { -// return; -// } + if (labelNode != null && labelNode.getParent() != null) { + return; + } - final boolean newLabelRep; // if there is no Piccolo2d representation of the label create it if (labelNode == null) { - newLabelRep = true; if (!forceShow && !NON_HIDDEN_KGE_FILTER.apply(label)) { contextData.setProperty(KlighdInternalProperties.ACTIVE, false); return; @@ -1406,8 +1392,6 @@ private void addLabel( contextData.setProperty(LABEL_REP, labelNode); updateRendering(labelNode); - } else { - newLabelRep = false; } if (record && isAutomaticallyArranged(label)) { @@ -1439,11 +1423,7 @@ private void addLabel( } // add the label - if (newLabelRep) { - labeledNode.addLabel(labelNode); - } else { - labelNode.setVisible(true); - } + labeledNode.addLabel(labelNode); contextData.setProperty(KlighdInternalProperties.ACTIVE, true); } @@ -1464,13 +1444,14 @@ private void removeLabel(final KLabel label, final boolean releaseControllers) { return; } + // remove the label representation from the containing node + labelNode.removeFromParent(); contextData.setProperty(KlighdInternalProperties.ACTIVE, false); + // recursively dispose all attached SWT Resources + NodeDisposeListener.disposePNode(labelNode); + if (releaseControllers) { - // remove the label representation from the containing node - labelNode.removeFromParent(); - // recursively dispose all attached SWT Resources - NodeDisposeListener.disposePNode(labelNode); // detach the synchronization adapters ModelingUtil.removeAdapters(label, LABEL_ADAPTERS); // release the objects kept in mind @@ -1479,9 +1460,6 @@ private void removeLabel(final KLabel label, final boolean releaseControllers) { labelNode.setRenderingController(null); // release the label representation from the label's renderingContextData contextData.setProperty(LABEL_REP, null); - } else { - // Hide the label representation - labelNode.setVisible(false); } }