Search in sources :

Example 16 with CanvasViolation

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();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) DMNGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) List(org.kie.workbench.common.dmn.api.definition.v1_1.List) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem) Test(org.junit.Test)

Example 17 with CanvasViolation

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();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) DMNGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) List(org.kie.workbench.common.dmn.api.definition.v1_1.List) Test(org.junit.Test)

Example 18 with CanvasViolation

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;
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Node(org.kie.workbench.common.stunner.core.graph.Node) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child)

Example 19 with CanvasViolation

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);
}
Also used : NotificationContext(org.kie.workbench.common.stunner.client.widgets.notification.NotificationContext) SystemMessage(org.guvnor.messageconsole.events.SystemMessage) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) PublishMessagesEvent(org.guvnor.messageconsole.events.PublishMessagesEvent) CommandNotification(org.kie.workbench.common.stunner.client.widgets.notification.CommandNotification) Test(org.junit.Test)

Example 20 with CanvasViolation

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);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) ChildrenTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessor) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) ArrayList(java.util.ArrayList) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) AbstractChildrenTraverseCallback(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.AbstractChildrenTraverseCallback) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Node(org.kie.workbench.common.stunner.core.graph.Node) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) View(org.kie.workbench.common.stunner.core.graph.content.view.View) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Aggregations

CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)48 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)35 Test (org.junit.Test)32 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)14 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)11 Node (org.kie.workbench.common.stunner.core.graph.Node)11 Edge (org.kie.workbench.common.stunner.core.graph.Edge)9 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)8 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)7 Command (org.kie.workbench.common.stunner.core.command.Command)7 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)7 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)6 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)5 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)4 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)4 Element (org.kie.workbench.common.stunner.core.graph.Element)4 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)4 Collection (java.util.Collection)3 Optional (java.util.Optional)3