use of org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl in project kie-wb-common by kiegroup.
the class ShapeUtils method moveViewConnectorsToTop.
@SuppressWarnings("unchecked")
public static void moveViewConnectorsToTop(final AbstractCanvasHandler canvasHandler, final Node<?, Edge> node) {
final Set<String> connectorIds = new HashSet<>();
// Obtain all view connectors for the node and its children.
appendViewConnectorIds(connectorIds, node);
new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()).setRootUUID(node.getUUID()).traverse(canvasHandler.getGraphIndex().getGraph(), new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() {
@Override
public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> childNode) {
appendViewConnectorIds(connectorIds, childNode);
return true;
}
});
// Update connector's view.
connectorIds.forEach(id -> moveShapeToTop(canvasHandler, id));
}
use of org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl in project kie-wb-common by kiegroup.
the class CloneCanvasNodeCommandTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
super.setUp();
graphInstance = TestingGraphInstanceBuilder.newGraph2(new TestingGraphMockHandler());
graph = graphInstance.graph;
candidate = graphInstance.parentNode;
when(graphIndex.getGraph()).thenReturn(graphInstance.graph);
when(canvas.getShape(graphInstance.edge1.getUUID())).thenReturn(edgeShape);
when(canvas.getShape(graphInstance.edge2.getUUID())).thenReturn(edgeShape);
when(edgeShape.getShapeView()).thenReturn(shapeView);
when(childrenTraverseProcessorManagedInstance.get()).thenReturn(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()));
this.cloneCanvasNodeCommand = new CloneCanvasNodeCommand(parent, candidate, SHAPE_SET_ID, childrenTraverseProcessorManagedInstance);
}
use of org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl in project kie-wb-common by kiegroup.
the class CloneNodeCommandTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
when(candidate.getUUID()).thenReturn(NODE_UUID);
when(candidate.getContent()).thenReturn(candidateContent);
when(childrenTraverseProcessorManagedInstance.get()).thenReturn(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()));
Point2D position = new Point2D(1, 1);
this.cloneNodeCommand = new CloneNodeCommand(candidate, PARENT_UUID, position, null, childrenTraverseProcessorManagedInstance);
}
use of org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl in project kie-wb-common by kiegroup.
the class SafeDeleteNodeCommand method initialize.
@Override
@SuppressWarnings("unchecked")
protected SafeDeleteNodeCommand initialize(final GraphCommandExecutionContext context) {
super.initialize(context);
final Graph<?, Node> graph = getGraph(context);
final Node<Definition<?>, Edge> candidate = (Node<Definition<?>, Edge>) getCandidate(context);
new SafeDeleteNodeProcessor(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()), graph, candidate).run(new SafeDeleteNodeProcessor.Callback() {
private final Set<String> processedConnectors = new HashSet<String>();
@Override
public void deleteCandidateConnector(final Edge<? extends View<?>, Node> edge) {
// This command will delete candidate's connectors once deleting the candidate node later on,
// as it potentially performs the connectors shortcut operation.
}
@Override
public void deleteConnector(final Edge<? extends View<?>, Node> edge) {
doDeleteConnector(edge);
}
@Override
public void removeChild(final Element<?> parent, final Node<?, Edge> candidate) {
log("RemoveChildCommand [parent=" + parent.getUUID() + ", candidate=" + candidate.getUUID() + "]");
addCommand(new RemoveChildCommand((Node<?, Edge>) parent, candidate));
safeDeleteCallback.ifPresent(c -> c.removeChild(parent, candidate));
}
@Override
public void removeDock(final Node<?, Edge> parent, final Node<?, Edge> candidate) {
log("UnDockNodeCommand [parent=" + parent.getUUID() + ", candidate=" + candidate.getUUID() + "]");
addCommand(new UnDockNodeCommand(parent, candidate));
safeDeleteCallback.ifPresent(c -> c.removeDock(parent, candidate));
}
@Override
public void deleteCandidateNode(final Node<?, Edge> node) {
processCandidateConnectors();
deleteNode(node);
}
@Override
public void deleteNode(final Node<?, Edge> node) {
log("DeregisterNodeCommand [node=" + node.getUUID() + "]");
addCommand(new DeregisterNodeCommand(node));
safeDeleteCallback.ifPresent(c -> c.deleteNode(node));
}
private void processCandidateConnectors() {
if (options.isDeleteCandidateConnectors()) {
if (options.isShortcutCandidateConnectors() && hasSingleIncomingEdge().and(hasSingleOutgoingEdge()).test(candidate)) {
final Edge<? extends ViewConnector<?>, Node> in = getViewConnector().apply(candidate.getInEdges());
final Edge<? extends ViewConnector<?>, Node> out = getViewConnector().apply(candidate.getOutEdges());
shortcut(in, out);
} else {
Stream.concat(candidate.getInEdges().stream(), candidate.getOutEdges().stream()).filter(e -> e.getContent() instanceof ViewConnector).forEach(this::deleteConnector);
}
}
}
private void shortcut(final Edge<? extends ViewConnector<?>, Node> in, final Edge<? extends ViewConnector<?>, Node> out) {
final ViewConnector<?> outContent = out.getContent();
final Node targetNode = out.getTargetNode();
addCommand(new DeleteConnectorCommand(out));
safeDeleteCallback.ifPresent(c -> c.deleteCandidateConnector(out));
addCommand(new SetConnectionTargetNodeCommand(targetNode, in, outContent.getTargetConnection().orElse(null)));
safeDeleteCallback.ifPresent(c -> c.setEdgeTargetNode(targetNode, in));
}
private void doDeleteConnector(final Edge<? extends View<?>, Node> edge) {
if (!processedConnectors.contains(edge.getUUID())) {
log("IN DoDeleteConnector [edge=" + edge.getUUID() + "]");
addCommand(new DeleteConnectorCommand(edge));
safeDeleteCallback.ifPresent(c -> c.deleteConnector(edge));
processedConnectors.add(edge.getUUID());
}
}
});
return this;
}
use of org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl in project kie-wb-common by kiegroup.
the class AbstractCloneCommandTest method setUp.
public void setUp() {
super.init(0, 0);
// creating the mock graph for test
TestingGraphMockHandler handler = new TestingGraphMockHandler();
graphInstance = TestingGraphInstanceBuilder.newGraph3(handler);
graph = graphInstance.graph;
graphIndex = handler.graphIndex;
// mocking the clone nodes on the graphIndex
ArgumentCaptor<Node> nodeArgumentCaptor = ArgumentCaptor.forClass(Node.class);
when(handler.graphIndex.addNode(nodeArgumentCaptor.capture())).thenAnswer(t -> {
// Node node = (Node)t.getArguments()[0];
when(graphIndex.getNode(eq(nodeArgumentCaptor.getValue().getUUID()))).thenReturn(nodeArgumentCaptor.getValue());
return graphIndex;
});
// edge mock
connectorContent = new ViewConnectorImpl(connectorDefinition, new BoundsImpl(new BoundImpl(1d, 1d), new BoundImpl(1d, 1d)));
sourceConnection = MagnetConnection.Builder.forElement(graphInstance.startNode);
connectorContent.setSourceConnection(sourceConnection);
targetConnection = MagnetConnection.Builder.forElement(graphInstance.intermNode);
connectorContent.setTargetConnection(targetConnection);
graphInstance.edge1.setContent(connectorContent);
graphInstance.edge2.setContent(connectorContent);
when(definitionManager.cloneManager()).thenReturn(cloneManager);
when(cloneManager.clone(definition, ClonePolicy.ALL)).thenReturn(definition);
when(cloneManager.clone(connectorDefinition, ClonePolicy.ALL)).thenReturn(connectorDefinition);
when(graphCommandExecutionContext.getGraphIndex()).thenReturn(graphIndex);
when(candidateContent.getDefinition()).thenReturn(definition);
when(factoryManager.newElement(anyString(), any(Class.class))).thenReturn(cloneElement);
when(cloneElement.asNode()).thenReturn(clone);
when(cloneElement.asEdge()).thenReturn(cloneEdge);
when(cloneEdge.getContent()).thenReturn(connectorContent);
when(cloneEdge.getUUID()).thenReturn(CLONE_EDGE_UUID);
when(clone.getContent()).thenReturn(cloneContent);
when(clone.getUUID()).thenReturn(CLONE_UUID);
when(cloneElement.getUUID()).thenReturn(CLONE_UUID);
when(cloneContent.getBounds()).thenReturn(bounds);
when(bounds.getUpperLeft()).thenReturn(bound);
when(bounds.getLowerRight()).thenReturn(bound);
when(childrenTraverseProcessorManagedInstance.get()).thenReturn(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()));
}
Aggregations