Search in sources :

Example 41 with AbstractCanvasHandler

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

the class MoveColumnsCommand method newGraphCommand.

@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) {
    return new AbstractGraphCommand() {

        @Override
        protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
            return isColumnInValidSection() ? GraphCommandResultBuilder.SUCCESS : GraphCommandResultBuilder.FAILED;
        }

        private boolean isColumnInValidSection() {
            final RelationSection section = RelationUIModelMapperHelper.getSection(relation, index);
            return section == RelationSection.INFORMATION_ITEM;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
            return moveInformationItems(index);
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            return moveInformationItems(oldIndex);
        }

        private CommandResult<RuleViolation> moveInformationItems(final int index) {
            final RelationSection section = RelationUIModelMapperHelper.getSection(relation, index);
            if (section == RelationSection.INFORMATION_ITEM) {
                final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
                final int relativeIndex = RelationUIModelMapperHelper.getInformationItemIndex(relation, index);
                final int relativeOldIndex = RelationUIModelMapperHelper.getInformationItemIndex(relation, oldIndex);
                final java.util.List<Integer> informationItemIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).map(i -> RelationUIModelMapperHelper.getInformationItemIndex(relation, i)).collect(Collectors.toList());
                moveInformationItems(relativeIndex, relativeOldIndex, relation.getColumn(), informationItemIndexesToMove);
                updateRowsData(relativeIndex, relativeOldIndex, relation.getRow(), informationItemIndexesToMove);
                return GraphCommandResultBuilder.SUCCESS;
            } else {
                return GraphCommandResultBuilder.FAILED;
            }
        }

        private <T> void moveInformationItems(final int relativeIndex, final int relativeOldIndex, final java.util.List<T> informationItems, final java.util.List<Integer> informationItemIndexesToMove) {
            final java.util.List<T> informationItemsToMove = informationItemIndexesToMove.stream().map(informationItems::get).collect(Collectors.toList());
            informationItems.removeAll(informationItemsToMove);
            if (relativeIndex < relativeOldIndex) {
                informationItems.addAll(relativeIndex, informationItemsToMove);
            } else if (relativeIndex > relativeOldIndex) {
                informationItems.addAll(relativeIndex - informationItemsToMove.size() + 1, informationItemsToMove);
            }
        }

        private void updateRowsData(final int relativeIndex, final int relativeOldIndex, final java.util.List<List> rows, final java.util.List<Integer> informationItemIndexesToMove) {
            rows.forEach(row -> moveInformationItems(relativeIndex, relativeOldIndex, row.getExpression(), informationItemIndexesToMove));
        }
    };
}
Also used : RelationSection(org.kie.workbench.common.dmn.client.editors.expressions.types.relation.RelationUIModelMapperHelper.RelationSection) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) RelationUIModelMapperHelper(org.kie.workbench.common.dmn.client.editors.expressions.types.relation.RelationUIModelMapperHelper) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) VetoExecutionCommand(org.kie.workbench.common.dmn.client.commands.VetoExecutionCommand) CanvasCommandResultBuilder(org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) AbstractCanvasCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasCommand) Collectors(java.util.stream.Collectors) AbstractCanvasGraphCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasGraphCommand) ArrayList(java.util.ArrayList) CommandUtils(org.kie.workbench.common.dmn.client.commands.util.CommandUtils) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) List(org.kie.workbench.common.dmn.api.definition.v1_1.List) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) Relation(org.kie.workbench.common.dmn.api.definition.v1_1.Relation) Command(org.kie.workbench.common.stunner.core.command.Command) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) VetoUndoCommand(org.kie.workbench.common.dmn.client.commands.VetoUndoCommand) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) ArrayList(java.util.ArrayList) List(org.kie.workbench.common.dmn.api.definition.v1_1.List) RelationSection(org.kie.workbench.common.dmn.client.editors.expressions.types.relation.RelationUIModelMapperHelper.RelationSection)

Example 42 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler 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 43 with AbstractCanvasHandler

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

the class ContextGridData method moveRowsTo.

@Override
public void moveRowsTo(final int index, final List<GridRow> rows) {
    expression.ifPresent(context -> {
        final AbstractCanvasHandler handler = (AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler();
        final MoveRowsCommand command = new MoveRowsCommand(context, delegate, index, rows, canvasOperation);
        if (isAllowed(sessionCommandManager.allow(handler, command))) {
            sessionCommandManager.execute(handler, command);
        }
    });
}
Also used : MoveRowsCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.context.MoveRowsCommand) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)

Example 44 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler 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 45 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler 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

AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)60 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)37 Test (org.junit.Test)30 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)15 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)10 Node (org.kie.workbench.common.stunner.core.graph.Node)10 Command (org.kie.workbench.common.stunner.core.command.Command)9 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)9 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)9 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)8 Edge (org.kie.workbench.common.stunner.core.graph.Edge)8 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)7 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)6 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)6 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)6 Collectors (java.util.stream.Collectors)5 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)5 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)5 CanvasCommandFactory (org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory)5