Search in sources :

Example 1 with AbstractChildrenTraverseCallback

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);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) ChildrenTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessor) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) ArrayList(java.util.ArrayList) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) AbstractChildrenTraverseCallback(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.AbstractChildrenTraverseCallback) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Node(org.kie.workbench.common.stunner.core.graph.Node) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) View(org.kie.workbench.common.stunner.core.graph.content.view.View) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ManagedInstance (org.jboss.errai.ioc.client.api.ManagedInstance)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)1 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 Graph (org.kie.workbench.common.stunner.core.graph.Graph)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)1 Dock (org.kie.workbench.common.stunner.core.graph.content.relationship.Dock)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)1 AbstractChildrenTraverseCallback (org.kie.workbench.common.stunner.core.graph.processing.traverse.content.AbstractChildrenTraverseCallback)1 ChildrenTraverseProcessor (org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessor)1 GraphUtils (org.kie.workbench.common.stunner.core.graph.util.GraphUtils)1