Skip to content

Commit

Permalink
Klighd.picocolo: Implemented new show/hide behaviour to keep existing…
Browse files Browse the repository at this point in the history
… pnodes at the corect layer.

Reverted previous implementations. (reverted from commit 2f39a9cd2f3d3eb63b25e8e4a7080f1432e2eed5)
  • Loading branch information
Nis Wechselberg committed Oct 27, 2015
1 parent f89b47b commit c5509a6
Showing 1 changed file with 59 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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 =
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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)) {
Expand All @@ -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);
}

Expand All @@ -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
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -1406,8 +1392,6 @@ private void addLabel(
contextData.setProperty(LABEL_REP, labelNode);

updateRendering(labelNode);
} else {
newLabelRep = false;
}

if (record && isAutomaticallyArranged(label)) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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
Expand All @@ -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);
}
}

Expand Down

0 comments on commit c5509a6

Please sign in to comment.