use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class AddRelationRowCommandTest method testCanvasCommandUndoWithColumns.
@Test
public void testCanvasCommandUndoWithColumns() {
relation.getColumn().add(new InformationItem());
relation.getRow().add(new org.kie.workbench.common.dmn.api.definition.v1_1.List());
uiModel.appendColumn(uiModelColumn);
uiModel.appendRow(new DMNGridRow());
uiModelMapper.fromDMNModel(0, 0);
// Add Graph column first as RelationUIModelMapper relies on the model being first updated
command.newGraphCommand(handler).execute(gce);
// Add column and then undo
final Command<AbstractCanvasHandler, CanvasViolation> cc = command.newCanvasCommand(handler);
assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.execute(handler));
reset(command, canvasOperation);
assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.undo(handler));
assertEquals(2, uiModel.getColumnCount());
assertEquals(uiRowNumberColumn, uiModel.getColumns().get(0));
assertEquals(uiModelColumn, uiModel.getColumns().get(1));
assertEquals(1, uiModel.getRowCount());
verify(command).updateRowNumbers();
verify(command).updateParentInformation();
verify(canvasOperation).execute();
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class DeleteRelationColumnCommandTest method testCanvasCommandExecuteWithRows.
@Test
public void testCanvasCommandExecuteWithRows() {
relation.getRow().add(new List());
relation.getRow().get(0).getExpression().add(new LiteralExpression());
uiModel.appendRow(new DMNGridRow());
uiModelMapper.fromDMNModel(0, 0);
uiModelMapper.fromDMNModel(0, 1);
makeCommand();
final Command<AbstractCanvasHandler, CanvasViolation> cc = command.newCanvasCommand(handler);
assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.execute(handler));
assertEquals(1, uiModel.getColumnCount());
assertEquals(uiRowNumberColumn, uiModel.getColumns().get(0));
assertEquals(1, uiModel.getRowCount());
assertEquals(1, uiModel.getRows().get(0).getCells().size());
assertEquals(1, uiModel.getCell(0, 0).getValue().getValue());
verify(command).updateParentInformation();
verify(canvasOperation).execute();
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class CaseManagementContainmentAcceptorControlImpl method evaluate.
private boolean evaluate(final Element parent, final Node[] children, final Function<Command<AbstractCanvasHandler, CanvasViolation>, CommandResult<CanvasViolation>> executor) {
if (parent == null && (children == null || children.length == 0)) {
return false;
}
final Node child = children[0];
final Optional<Edge<?, Node>> edge = getFirstIncomingEdge(child, e -> e.getContent() instanceof Child);
if (edge.isPresent()) {
final Command<AbstractCanvasHandler, CanvasViolation> command = buildCommands(parent, child, edge.get());
final CommandResult<CanvasViolation> result = executor.apply(command);
return isCommandSuccess(result);
}
return true;
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class ProjectMessagesListenerTest method testFireNotificationError.
@Test
public void testFireNotificationError() {
NotificationContext context = new NotificationContext.Builder().build("test", "test", "test");
Command<?, CanvasViolation> source = mock(Command.class);
CommandNotification commandNotification = CommandNotification.Builder.build(context, source, Notification.Type.ERROR, "message");
projectMessagesListener.fireNotification(commandNotification);
ArgumentCaptor<PublishMessagesEvent> eventCaptor = ArgumentCaptor.forClass(PublishMessagesEvent.class);
verify(publishMessagesEvent, times(1)).fire(eventCaptor.capture());
final List<SystemMessage> messagesToPublish = eventCaptor.getValue().getMessagesToPublish();
assertEquals(messagesToPublish.size(), 1);
SystemMessage message = messagesToPublish.get(0);
assertEquals(message.getText(), "message");
assertEquals(message.getLevel(), Level.ERROR);
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation 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);
}
Aggregations