use of org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl 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;
}
use of org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl in project kie-wb-common by kiegroup.
the class AcyclicDirectedGraphWalkerTest method checkSimpleWalk.
@Test
@SuppressWarnings("unchecked")
public void checkSimpleWalk() {
final Node node1 = new NodeImpl<>("node1");
final Node node2 = new NodeImpl<>("node2");
final Node node3 = new NodeImpl<>("node3");
final Edge c1 = new EdgeImpl<>("edge1:node1-node2");
final Edge c2 = new EdgeImpl<>("edge2:node2-node3");
// Connect node1 and node2 with c1
connectNodes(node1, node2, c1);
graph.addNode(node1);
graph.addNode(node2);
// Propose to connect node2 to node3 with c2
walker = new AcyclicDirectedGraphWalker(node2, node3, c2);
walker.traverse(graph, callback);
verify(callback).startGraphTraversal(eq(graph));
verify(callback).endGraphTraversal();
verify(callback, atLeast(1)).startNodeTraversal(nodeStartVisitCaptor.capture());
verify(callback, atLeast(1)).endNodeTraversal(nodeEndVisitCaptor.capture());
verify(callback, atLeast(1)).startEdgeTraversal(edgeStartVisitCaptor.capture());
verify(callback, atLeast(1)).endEdgeTraversal(edgeEndVisitCaptor.capture());
assertEquals(3, nodeStartVisitCaptor.getAllValues().size());
assertEquals(3, nodeEndVisitCaptor.getAllValues().size());
assertNodeVisits(nodeStartVisitCaptor.getAllValues(), "node1", "node2", "node3");
assertNodeVisits(nodeEndVisitCaptor.getAllValues(), "node1", "node2", "node3");
assertEquals(2, edgeStartVisitCaptor.getAllValues().size());
assertEquals(2, edgeEndVisitCaptor.getAllValues().size());
assertEdgeVisits(edgeStartVisitCaptor.getAllValues(), "edge1:node1-node2", "edge2:node2-node3");
assertEdgeVisits(edgeEndVisitCaptor.getAllValues(), "edge1:node1-node2", "edge2:node2-node3");
}
Aggregations