use of org.kie.workbench.common.stunner.core.graph.content.relationship.Dock 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);
}
use of org.kie.workbench.common.stunner.core.graph.content.relationship.Dock in project kie-wb-common by kiegroup.
the class DrawCanvasCommand method execute.
@Override
@SuppressWarnings("unchecked")
public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) {
final Graph graph = context.getGraphIndex().getGraph();
final String shapeSetId = getShapeSetId(context);
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().forward();
// Aggregate all nodes in the parent-child-dock hierarchy.
childrenTraverseProcessor.traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() {
@Override
public void startNodeTraversal(final Node<View, Edge> node) {
super.startNodeTraversal(node);
if (!isCanvasRoot().test(context, node.getUUID())) {
addNode(node);
}
}
@Override
public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> node) {
super.startNodeTraversal(parents, node);
final Optional<Edge> dockEdge = node.getInEdges().stream().filter(e -> e.getContent() instanceof Dock).findAny();
final Node parent = dockEdge.map(Edge::getSourceNode).orElseGet(() -> parents.get(parents.size() - 1));
if (dockEdge.isPresent()) {
addDockedNode(parent, node);
} else if (isCanvasRoot().test(context, parent.getUUID())) {
addNode(node);
} else {
addChildNode(parent, node);
}
return true;
}
private void addNode(final Node node) {
commandBuilder.addCommand(new AddCanvasNodeCommand(node, shapeSetId));
}
private void addChildNode(final Node<View, Edge> parent, final Node<View, Edge> node) {
commandBuilder.addCommand(new AddCanvasChildNodeCommand(parent, node, shapeSetId));
}
private void addDockedNode(final Node<View, Edge> parent, final Node<View, Edge> node) {
commandBuilder.addCommand(new AddCanvasDockedNodeCommand(parent, node, shapeSetId));
}
});
// Aggregate all connectors.
viewTraverseProcessor.traverse(graph, new AbstractContentTraverseCallback<View<?>, Node<View, Edge>, Edge<View<?>, Node>>() {
@Override
public void startEdgeTraversal(final Edge<View<?>, Node> edge) {
super.startEdgeTraversal(edge);
commandBuilder.addCommand(new AddCanvasConnectorCommand(edge, shapeSetId));
}
});
return commandBuilder.build().execute(context);
}
use of org.kie.workbench.common.stunner.core.graph.content.relationship.Dock in project kie-wb-common by kiegroup.
the class SetCanvasChildNodeCommandTest method testSkipExecutionAsDockIsPresent.
@Test
@SuppressWarnings("unchecked")
public void testSkipExecutionAsDockIsPresent() {
final Edge dockEdge = mock(Edge.class);
when(dockEdge.getContent()).thenReturn(new Dock());
graph1Instance.intermNode.getInEdges().add(dockEdge);
final CommandResult<CanvasViolation> result = tested.execute(canvasHandler);
assertNotEquals(CommandResult.Type.ERROR, result.getType());
verify(canvasHandler, never()).addChild(eq(graph1Instance.startNode), eq(graph1Instance.intermNode));
verify(canvasHandler, never()).applyElementMutation(eq(graph1Instance.intermNode), any(MutationContext.class));
verify(canvasHandler, never()).applyElementMutation(eq(graph1Instance.startNode), any(MutationContext.class));
verify(canvasHandler, never()).dock(any(Node.class), any(Node.class));
verify(connectorShapeView1, never()).moveToTop();
verify(connectorShapeView1, never()).moveToBottom();
verify(connectorShapeView1, never()).moveUp();
verify(connectorShapeView1, never()).moveDown();
verify(connectorShapeView2, never()).moveToTop();
verify(connectorShapeView2, never()).moveToBottom();
verify(connectorShapeView2, never()).moveUp();
verify(connectorShapeView2, never()).moveDown();
}
use of org.kie.workbench.common.stunner.core.graph.content.relationship.Dock in project kie-wb-common by kiegroup.
the class DockNodeCommand method execute.
@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
final CommandResult<RuleViolation> results = allow(context);
if (!results.getType().equals(CommandResult.Type.ERROR)) {
final Node<?, Edge> parent = getParent(context);
final Node<?, Edge> candidate = getCandidate(context);
final String uuid = UUID.uuid();
final Edge<Dock, Node> edge = new EdgeImpl<>(uuid);
edge.setContent(new Dock());
edge.setSourceNode(parent);
edge.setTargetNode(candidate);
parent.getOutEdges().add(edge);
candidate.getInEdges().add(edge);
getMutableIndex(context).addEdge(edge);
}
return results;
}
Aggregations