Search in sources :

Example 6 with CanvasViolation

use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation 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;
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) BoundsExceededViolation(org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Command(org.kie.workbench.common.stunner.core.command.Command) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) CommandResultImpl(org.kie.workbench.common.stunner.core.command.impl.CommandResultImpl)

Example 7 with CanvasViolation

use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.

the class AddCanvasConnectorCommand method execute.

@Override
@SuppressWarnings("unchecked")
public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) {
    context.register(shapeSetId, candidate);
    context.applyElementMutation(candidate, MutationContext.STATIC);
    if (candidate.getContent() instanceof ViewConnector) {
        ControlPoint[] controlPoints = ((ViewConnector) candidate.getContent()).getControlPoints().stream().toArray(ControlPoint[]::new);
        CommandResult<CanvasViolation> addControlPointsResult = new AddCanvasControlPointCommand(candidate, controlPoints).execute(context);
        ShapeUtils.hideControlPoints(candidate, context);
        if (CommandUtils.isError(addControlPointsResult)) {
            return addControlPointsResult;
        }
    }
    ShapeUtils.updateEdgeConnections(candidate, context);
    ShapeUtils.applyConnections(candidate, context, MutationContext.STATIC);
    final Node source = candidate.getSourceNode();
    if (null != source) {
        context.notifyCanvasElementUpdated(source);
    }
    return buildResult();
}
Also used : 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) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)

Example 8 with CanvasViolation

use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.

the class EdgeBuilderControlImpl method build.

@Override
@SuppressWarnings("unchecked")
public void build(final EdgeBuildRequest request, final BuildCallback buildCallback) {
    final double x = request.getX();
    final double y = request.getY();
    final Edge<? extends ViewConnector<?>, Node> edge = request.getEdge();
    final AbstractCanvasHandler<?, ?> wch = canvasHandler;
    final Node<? extends View<?>, Edge> inNode = request.getInNode();
    final Node<? extends View<?>, Edge> outNode = request.getOutNode();
    final Canvas canvas = canvasHandler.getCanvas();
    if (null == inNode) {
        throw new RuntimeException(" An edge must be into the outgoing edges list from a node.");
    }
    final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
    final CompositeCommand.Builder commandBuilder = new CompositeCommand.Builder().addCommand(commandFactory.addConnector(inNode, edge, MagnetConnection.Builder.forElement(inNode), ssid));
    if (null != outNode) {
        commandBuilder.addCommand(commandFactory.setTargetNode(outNode, edge, MagnetConnection.Builder.forElement(outNode)));
    }
    final CommandResult<CanvasViolation> results = getCommandManager().execute(wch, commandBuilder.build());
    if (CommandUtils.isError(results)) {
        LOGGER.log(Level.WARNING, results.toString());
    }
    canvasHandler.applyElementMutation(edge, MutationContext.STATIC);
    buildCallback.onSuccess(edge.getUUID());
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Node(org.kie.workbench.common.stunner.core.graph.Node) Canvas(org.kie.workbench.common.stunner.core.client.canvas.Canvas) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 9 with CanvasViolation

use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.

the class NotificationMessageUtilsTest method testCanvasValidationMessage.

@Test
public void testCanvasValidationMessage() {
    final RuleViolation ruleViolation = mock(RuleViolation.class);
    final CanvasViolation canvasViolation = mock(CanvasViolation.class);
    when(canvasViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
    when(canvasViolation.getRuleViolation()).thenReturn(ruleViolation);
    when(ruleViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
    when(ruleViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
    final Iterable<CanvasViolation> violations = Collections.singletonList(canvasViolation);
    when(translationService.getValue(eq("aKey"))).thenReturn("aValue");
    when(translationService.getViolationMessage(eq(canvasViolation))).thenReturn("cv1");
    String message = NotificationMessageUtils.getCanvasValidationsErrorMessage(translationService, "aKey", violations);
    message = new SafeHtmlBuilder().appendEscapedLines(message).toSafeHtml().asString();
    assertEquals("aValue." + HTML_NEW_LINE + "R" + COLON + HTML_NEW_LINE + OPEN_BRA + "1" + CLOSE_BRA + "(ERROR) " + "cv1" + HTML_NEW_LINE, message);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Test(org.junit.Test)

Example 10 with CanvasViolation

use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.

the class NotificationsObserverTest method testNotifyCommandSuccess.

@Test
@SuppressWarnings("unchecked")
public void testNotifyCommandSuccess() {
    final Command command = mock(Command.class);
    final CommandResult<CanvasViolation> result = mock(CommandResult.class);
    final CanvasCommandExecutedEvent<? extends CanvasHandler> commandExecutedEvent = new CanvasCommandExecutedEvent<>(canvasHandler, command, result);
    commandNotification = new CommandNotification(Notification.Type.INFO, notificationContext, command, "message1");
    tested.onGraphCommandExecuted(commandExecutedEvent);
    verify(onNotification, times(1)).execute(eq(commandNotification));
    verify(commandSuccess, times(1)).execute(eq(commandNotification));
    verify(commandFailed, never()).execute(any(CommandNotification.class));
    verify(validationSuccess, never()).execute(any(ValidationSuccessNotification.class));
    verify(validationFailed, never()).execute(any(ValidationFailedNotification.class));
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Command(org.kie.workbench.common.stunner.core.command.Command) CanvasCommandExecutedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.command.CanvasCommandExecutedEvent) Test(org.junit.Test)

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