use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class SetConnectionTargetNodeCommandTest method testExecute.
@Test
@SuppressWarnings("unchecked")
public void testExecute() {
final List lastTargetInEdges = mock(List.class);
final List sourceOutEdges = mock(List.class);
final List targetInEdges = mock(List.class);
when(source.getOutEdges()).thenReturn(sourceOutEdges);
when(lastTargetNode.getInEdges()).thenReturn(lastTargetInEdges);
when(node.getInEdges()).thenReturn(targetInEdges);
CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class);
verify(ruleManager, times(3)).evaluate(eq(ruleSet), contextCaptor.capture());
final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues();
assertEquals(3, contexts.size());
verifyConnection((GraphConnectionContext) contexts.get(0), edge, source, node);
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(1), graph, lastTargetNode, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.DELETE));
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(2), graph, node, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.ADD));
assertEquals(CommandResult.Type.INFO, result.getType());
verify(lastTargetInEdges, times(1)).remove(eq(edge));
verify(targetInEdges, times(1)).add(eq(edge));
verify(edgeContent, times(1)).setTargetConnection(any(Connection.class));
verify(edge, times(1)).setTargetNode(eq(node));
verify(targetInEdges, times(0)).remove(any(Edge.class));
verify(sourceOutEdges, times(0)).add(any(Edge.class));
verify(graphIndex, times(0)).removeEdge(any(Edge.class));
verify(graphIndex, times(0)).addEdge(any(Edge.class));
verify(graphIndex, times(0)).addNode(any(Node.class));
verify(graphIndex, times(0)).removeNode(any(Node.class));
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class TreeWalkTraverseProcessorImplTest method testTraverseGraph2UsingRootNode.
@Test
@SuppressWarnings("unchecked")
public void testTraverseGraph2UsingRootNode() {
final TestingGraphInstanceBuilder.TestGraph2 result = TestingGraphInstanceBuilder.newGraph2(graphTestHandler);
Node anotherNode = graphTestHandler.newNode("anotherNode", "anotherId", Optional.empty());
final TreeTraverseCallback callback = mock(TreeTraverseCallback.class);
when(callback.startEdgeTraversal(any(Edge.class))).thenReturn(true);
when(callback.startNodeTraversal(any(Node.class))).thenReturn(true);
tested.traverse(result.graph, result.parentNode, callback);
verify(callback, never()).startNodeTraversal(eq(anotherNode));
verify(callback, never()).endNodeTraversal(eq(anotherNode));
verify(callback, times(1)).startGraphTraversal(eq(result.graph));
verify(callback, times(1)).startNodeTraversal(eq(result.parentNode));
verify(callback, times(1)).startNodeTraversal(eq(result.startNode));
verify(callback, times(1)).startNodeTraversal(eq(result.intermNode));
verify(callback, times(1)).startNodeTraversal(eq(result.endNode));
verify(callback, times(1)).endNodeTraversal(eq(result.parentNode));
verify(callback, times(1)).endNodeTraversal(eq(result.startNode));
verify(callback, times(1)).endNodeTraversal(eq(result.intermNode));
verify(callback, times(1)).endNodeTraversal(eq(result.endNode));
verify(callback, times(1)).startEdgeTraversal(eq(result.edge1));
verify(callback, times(1)).endEdgeTraversal(eq(result.edge1));
verify(callback, times(1)).startEdgeTraversal(eq(result.edge2));
verify(callback, times(1)).endEdgeTraversal(eq(result.edge2));
verify(callback, times(1)).endGraphTraversal();
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class AbstractGraphRuleHandlerTest method mockNode.
@SuppressWarnings("unchecked")
protected Node mockNode(String id, Set<String> labels) {
Node e = mock(Node.class);
View v = mock(View.class);
Object d = mock(Object.class);
when(e.getContent()).thenReturn(v);
when(v.getDefinition()).thenReturn(d);
when(definitionAdapter.getId(eq(d))).thenReturn(id);
when(definitionAdapter.getLabels(eq(d))).thenReturn(labels);
when(e.getLabels()).thenReturn(labels);
return e;
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class ResizeControlImpl method doResize.
@SuppressWarnings("unchecked")
private CommandResult<CanvasViolation> doResize(final Element<? extends View<?>> element, final Double x, final Double y, final double w, final double h) {
// Calculate the new graph element's bounds.
final Point2D current = (null != x && null != y) ? new Point2D(x, y) : GraphUtils.getPosition(element.getContent());
final BoundsImpl newBounds = new BoundsImpl(new BoundImpl(current.getX(), current.getY()), new BoundImpl(current.getX() + w, current.getY() + h));
// Check the new bound values that come from the user's action do not exceed graph ones.
if (!GraphUtils.checkBoundsExceeded(canvasHandler.getDiagram().getGraph(), newBounds)) {
final CanvasViolation cv = CanvasViolationImpl.Builder.build(new BoundsExceededViolation(newBounds).setUUID(canvasHandler.getUuid()));
return new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singleton(cv));
}
// Execute the update position and update property/ies command/s on the bean instance to achieve the new bounds.
final List<Command<AbstractCanvasHandler, CanvasViolation>> commands = getResizeCommands(element, w, h);
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>();
if (null != commands) {
if (null != x && null != y) {
commandBuilder.addCommand(canvasCommandFactory.updatePosition((Node<View<?>, Edge>) element, new Point2D(x, y)));
}
commands.forEach(commandBuilder::addCommand);
}
final CommandResult<CanvasViolation> resizeResults = getCommandManager().execute(canvasHandler, commandBuilder.build());
// Update the view bounds on the node content after successful resize.
if (!CommandUtils.isError(resizeResults)) {
element.getContent().setBounds(newBounds);
}
return resizeResults;
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class CanvasBoundsIndexerImpl method getAt.
@Override
@SuppressWarnings("unchecked")
public Node<View<?>, Edge> getAt(final double x, final double y, final double width, final double height, final Element parentNode) {
final AbstractCanvas canvas = canvasHandler.getAbstractCanvas();
final LienzoLayer lienzoLayer = (LienzoLayer) canvas.getLayer();
Node node;
final String viewUUID_UL = LienzoLayerUtils.getUUID_At(lienzoLayer, x, y);
final String viewUUID_UR = LienzoLayerUtils.getUUID_At(lienzoLayer, x + width, y);
final String viewUUID_CC = LienzoLayerUtils.getUUID_At(lienzoLayer, x + (width / 2), y + (height / 2));
final String viewUUID_LL = LienzoLayerUtils.getUUID_At(lienzoLayer, x, y + height);
final String viewUUID_LR = LienzoLayerUtils.getUUID_At(lienzoLayer, x + width, y + height);
if (null != viewUUID_UL && viewUUID_UL.trim().length() > 0) {
final Shape<?> shape = canvas.getShape(viewUUID_UL);
if (null != shape) {
node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
if (node != parentNode) {
return node;
}
}
} else if (null != viewUUID_UR && viewUUID_UR.trim().length() > 0) {
final Shape<?> shape = canvas.getShape(viewUUID_UR);
if (null != shape) {
node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
if (node != parentNode) {
return node;
}
}
} else if (null != viewUUID_CC && viewUUID_CC.trim().length() > 0) {
final Shape<?> shape = canvas.getShape(viewUUID_CC);
if (null != shape) {
node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
if (node != parentNode) {
return node;
}
}
} else if (null != viewUUID_LL && viewUUID_LL.trim().length() > 0) {
final Shape<?> shape = canvas.getShape(viewUUID_LL);
if (null != shape) {
node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
if (node != parentNode) {
return node;
}
}
} else if (null != viewUUID_LR && viewUUID_LR.trim().length() > 0) {
final Shape<?> shape = canvas.getShape(viewUUID_LR);
if (null != shape) {
node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
if (node != parentNode) {
return node;
}
}
}
return null;
}
Aggregations