use of org.kie.workbench.common.stunner.core.graph.processing.traverse.content.AbstractChildrenTraverseCallback in project kie-wb-common by kiegroup.
the class CloneCanvasNodeCommand method execute.
@Override
public CommandResult<CanvasViolation> execute(AbstractCanvasHandler context) {
commands = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().reverse().build();
// first add the candidate clone
commands.addCommand(createAddCanvasChildNodeCommand(getParent(), getCandidate(), getShapeSetId()));
// process clone children nodes
if (GraphUtils.hasChildren(getCandidate())) {
Graph graph = context.getGraphIndex().getGraph();
List<Edge> clonedEdges = new ArrayList<>();
childrenTraverseProcessor.get().setRootUUID(getCandidate().getUUID()).traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() {
@Override
public boolean startNodeTraversal(List<Node<View, Edge>> parents, Node<View, Edge> node) {
commands.addCommand(createCloneCanvasNodeCommand(getCandidate(), node, getShapeSetId()));
clonedEdges.addAll(node.getOutEdges());
// just traverse the first level children of the root node
return false;
}
});
// process children edges -> connectors and dock
clonedEdges.stream().filter(edge -> edge.getContent() instanceof Dock).forEach(edge -> commands.addCommand(new CanvasDockNodeCommand(edge.getSourceNode(), edge.getTargetNode())));
clonedEdges.stream().filter(edge -> edge.getContent() instanceof ViewConnector).forEach(edge -> commands.addCommand(new AddCanvasConnectorCommand((Edge) edge, getShapeSetId())));
}
// process clone docked nodes on the root
if (GraphUtils.hasDockedNodes(getCandidate())) {
List<Edge> edges = getCandidate().getOutEdges();
edges.stream().filter(edge -> edge.getContent() instanceof Dock).map(edge -> edge.getTargetNode()).forEach(targetNode -> {
commands.addCommand(new AddCanvasChildNodeCommand(getParent(), targetNode, getShapeSetId()));
commands.addCommand(new CanvasDockNodeCommand(getCandidate(), targetNode));
});
}
return commands.execute(context);
}
Aggregations