use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class CloneConnectorCommandTest method newCanvasCommand.
@Test
@SuppressWarnings("unchecked")
public void newCanvasCommand() {
Command<AbstractCanvasHandler, CanvasViolation> command = cloneConnectorCommand.newCanvasCommand(context);
assertTrue(command instanceof CompositeCommand);
Consumer<Edge> cloneCallback = cloneConnectorCommand.getCloneCallback();
cloneCallback.accept(clone);
CompositeCommand compositeCommand = (CompositeCommand) command;
assertTrue(compositeCommand.getCommands().stream().anyMatch(c -> c instanceof AddCanvasConnectorCommand));
assertEquals(((AddCanvasConnectorCommand) compositeCommand.getCommands().stream().filter(c -> c instanceof AddCanvasConnectorCommand).findFirst().get()).getCandidate(), clone);
assertTrue(compositeCommand.getCommands().stream().anyMatch(c -> c instanceof SetCanvasConnectionCommand));
assertEquals(((SetCanvasConnectionCommand) compositeCommand.getCommands().stream().filter(c -> c instanceof SetCanvasConnectionCommand).findFirst().get()).getEdge(), clone);
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class DeleteCanvasControlPointCommandTest method execute.
@Test
public void execute() {
CommandResult<CanvasViolation> result = deleteCanvasControlPointCommand.execute(canvasHandler);
InOrder inOrder = inOrder(shape);
inOrder.verify(shape).applyState(ShapeState.NONE);
inOrder.verify(shape).removeControlPoints(controlPoint1);
inOrder.verify(shape).applyState(ShapeState.SELECTED);
assertFalse(CommandUtils.isError(result));
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation 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.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class ContainmentAcceptorControlImpl method evaluate.
private boolean evaluate(final Element parent, final Node[] children, final Function<Command<AbstractCanvasHandler, CanvasViolation>, CommandResult<CanvasViolation>> executor, final boolean highlights) {
// Cannot evaluate with no candidates.
if (children == null || children.length == 0) {
return false;
}
// Do not accept multiple containment if children do not share same parent instance.
if (parent == null && children.length >= 2) {
return false;
}
// Generate the commands and perform the execution.
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().forward();
for (final Node node : children) {
builder.addCommand(canvasCommandFactory.updateChildNode((Node) parent, node));
}
if (builder.size() > 0) {
final Command<AbstractCanvasHandler, CanvasViolation> command = builder.size() == 1 ? builder.get(0) : builder.build();
final CommandResult<CanvasViolation> result = executor.apply(command);
final boolean success = isCommandSuccess(result);
if (highlights && !success) {
canvasHighlight.invalid(result.getViolations());
} else {
canvasHighlight.unhighLight();
}
return success;
}
return true;
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class LocationControlImpl method move.
@Override
@SuppressWarnings("unchecked")
public CommandResult<CanvasViolation> move(final Element[] elements, final Point2D[] locations) {
if (elements.length != locations.length) {
throw new IllegalArgumentException("The length for the elements to move " + "does not match the locations provided.");
}
Command<AbstractCanvasHandler, CanvasViolation> command;
if (elements.length == 1) {
command = createMoveCommand(elements[0], locations[0]);
} else {
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().forward();
int i = 0;
for (final Element element : elements) {
final CanvasCommand<AbstractCanvasHandler> c = createMoveCommand(element, locations[i]);
builder.addCommand(c);
i++;
}
command = builder.build();
}
CommandResult<CanvasViolation> result = getCommandManager().allow(canvasHandler, command);
if (!CommandUtils.isError(result)) {
result = getCommandManager().execute(canvasHandler, command);
if (!CommandUtils.isError(result)) {
List<String> uuids = Arrays.stream(elements).map(Element::getUUID).collect(Collectors.toList());
shapeLocationsChangedEvent.fire(new ShapeLocationsChangedEvent(uuids, canvasHandler));
}
}
return result;
}
Aggregations