Search in sources :

Example 31 with CanvasViolation

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

the class NotificationsObserverTest method testNotifyCommandFailed.

@Test
@SuppressWarnings("unchecked")
public void testNotifyCommandFailed() {
    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.ERROR, notificationContext, command, "message1");
    tested.onGraphCommandExecuted(commandExecutedEvent);
    verify(onNotification, times(1)).execute(eq(commandNotification));
    verify(commandFailed, times(1)).execute(eq(commandNotification));
    verify(commandSuccess, 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)

Example 32 with CanvasViolation

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

the class SetKindCommand method newCanvasCommand.

@Override
protected Command<AbstractCanvasHandler, CanvasViolation> newCanvasCommand(final AbstractCanvasHandler handler) {
    return new AbstractCanvasCommand() {

        @Override
        public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler handler) {
            final GridData gridData = cellTuple.getGridWidget().getModel();
            gridData.setCellValue(cellTuple.getRowIndex(), cellTuple.getColumnIndex(), cellTuple.getValue());
            canvasOperation.execute();
            return CanvasCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<CanvasViolation> undo(final AbstractCanvasHandler handler) {
            if (oldCellValue.isPresent()) {
                cellTuple.getGridWidget().getModel().setCellValue(cellTuple.getRowIndex(), cellTuple.getColumnIndex(), oldCellValue.get());
            } else {
                cellTuple.getGridWidget().getModel().deleteCell(cellTuple.getRowIndex(), cellTuple.getColumnIndex());
            }
            canvasOperation.execute();
            return CanvasCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) AbstractCanvasCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasCommand)

Example 33 with CanvasViolation

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

the class SetCellValueCommand method newCanvasCommand.

@Override
protected Command<AbstractCanvasHandler, CanvasViolation> newCanvasCommand(final AbstractCanvasHandler context) {
    return new AbstractCanvasCommand() {

        @Override
        public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) {
            final GridData gridData = cellTuple.getGridWidget().getModel();
            gridData.setCellValue(cellTuple.getRowIndex(), cellTuple.getColumnIndex(), cellTuple.getValue());
            canvasOperation.execute();
            return CanvasCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<CanvasViolation> undo(final AbstractCanvasHandler context) {
            if (oldCellValue.isPresent()) {
                cellTuple.getGridWidget().getModel().setCellValue(cellTuple.getRowIndex(), cellTuple.getColumnIndex(), oldCellValue.get());
            } else {
                cellTuple.getGridWidget().getModel().deleteCell(cellTuple.getRowIndex(), cellTuple.getColumnIndex());
            }
            canvasOperation.execute();
            return CanvasCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) AbstractCanvasCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasCommand)

Example 34 with CanvasViolation

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

the class DecisionTableGrid method setHitPolicy.

@Override
public void setHitPolicy(final HitPolicy hitPolicy, final Command onSuccess) {
    expression.ifPresent(dtable -> {
        final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<>();
        commandBuilder.addCommand(new SetBuiltinAggregatorCommand(dtable, null, gridLayer::batch));
        commandBuilder.addCommand(new SetHitPolicyCommand(dtable, hitPolicy, () -> {
            gridLayer.batch();
            onSuccess.execute();
        }));
        sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), commandBuilder.build());
    });
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) SetHitPolicyCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.SetHitPolicyCommand) SetBuiltinAggregatorCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.SetBuiltinAggregatorCommand) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)

Example 35 with CanvasViolation

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

the class DecisionTableGridTest method testSetHitPolicy.

@Test
public void testSetHitPolicy() {
    final HitPolicy hitPolicy = HitPolicy.ANY;
    setupGrid(makeHasNameForDecision(), 0);
    grid.setHitPolicy(hitPolicy, command);
    verify(sessionCommandManager).execute(eq(canvasHandler), setHitPolicyCommandCaptor.capture());
    final CompositeCommand<AbstractCanvasHandler, CanvasViolation> setHitPolicyCommand = setHitPolicyCommandCaptor.getValue();
    assertEquals(2, setHitPolicyCommand.getCommands().size());
    assertTrue(setHitPolicyCommand.getCommands().get(0) instanceof SetBuiltinAggregatorCommand);
    assertTrue(setHitPolicyCommand.getCommands().get(1) instanceof SetHitPolicyCommand);
    setHitPolicyCommand.execute(canvasHandler);
    verify(gridLayer, atLeast(1)).batch();
    verify(command).execute();
    assertEquals(hitPolicy, expression.get().getHitPolicy());
    assertNull(expression.get().getAggregation());
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) HitPolicy(org.kie.workbench.common.dmn.api.definition.v1_1.HitPolicy) SetHitPolicyCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.SetHitPolicyCommand) SetBuiltinAggregatorCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.SetBuiltinAggregatorCommand) 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