Search in sources :

Example 26 with CanvasViolation

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);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Mock(org.mockito.Mock) Edge(org.kie.workbench.common.stunner.core.graph.Edge) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) UUID(org.kie.workbench.common.stunner.core.util.UUID) Consumer(java.util.function.Consumer) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Command(org.kie.workbench.common.stunner.core.command.Command) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Edge(org.kie.workbench.common.stunner.core.graph.Edge) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Test(org.junit.Test)

Example 27 with CanvasViolation

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));
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 28 with CanvasViolation

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();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) Node(org.kie.workbench.common.stunner.core.graph.Node) Edge(org.kie.workbench.common.stunner.core.graph.Edge) MutationContext(org.kie.workbench.common.stunner.core.client.shape.MutationContext) Test(org.junit.Test)

Example 29 with CanvasViolation

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;
}
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) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)

Example 30 with CanvasViolation

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;
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Element(org.kie.workbench.common.stunner.core.graph.Element) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) ShapeLocationsChangedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.ShapeLocationsChangedEvent) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)

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