Search in sources :

Example 1 with DecisionTableSection

use of org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection in project kie-wb-common by kiegroup.

the class DecisionTableUIModelMapper method toDMNModel.

@Override
public void toDMNModel(final int rowIndex, final int columnIndex, final Supplier<Optional<GridCellValue<?>>> cell) {
    dmnModel.get().ifPresent(dtable -> {
        final DecisionRule rule = dtable.getRule().get(rowIndex);
        final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, columnIndex);
        switch(section) {
            case ROW_INDEX:
                break;
            case INPUT_CLAUSES:
                final int iei = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, columnIndex);
                rule.getInputEntry().get(iei).setText(cell.get().orElse(new BaseGridCellValue<>("")).getValue().toString());
                break;
            case OUTPUT_CLAUSES:
                final int oei = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, columnIndex);
                rule.getOutputEntry().get(oei).setText(cell.get().orElse(new BaseGridCellValue<>("")).getValue().toString());
                break;
            case DESCRIPTION:
                rule.getDescription().setValue(cell.get().orElse(new BaseGridCellValue<>("")).getValue().toString());
                break;
        }
    });
}
Also used : DecisionTableSection(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Example 2 with DecisionTableSection

use of org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection in project kie-wb-common by kiegroup.

the class DecisionTableUIModelMapper method fromDMNModel.

@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
    dmnModel.get().ifPresent(dtable -> {
        final DecisionRule rule = dtable.getRule().get(rowIndex);
        final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, columnIndex);
        switch(section) {
            case ROW_INDEX:
                uiModel.get().setCell(rowIndex, columnIndex, () -> new DecisionTableGridCell<>(new BaseGridCellValue<>(rowIndex + 1), listSelector));
                uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
                break;
            case INPUT_CLAUSES:
                final int iei = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, columnIndex);
                uiModel.get().setCell(rowIndex, columnIndex, () -> new DecisionTableGridCell<>(new BaseGridCellValue<>(rule.getInputEntry().get(iei).getText()), listSelector));
                break;
            case OUTPUT_CLAUSES:
                final int oei = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, columnIndex);
                uiModel.get().setCell(rowIndex, columnIndex, () -> new DecisionTableGridCell<>(new BaseGridCellValue<>(rule.getOutputEntry().get(oei).getText()), listSelector));
                break;
            case DESCRIPTION:
                uiModel.get().setCell(rowIndex, columnIndex, () -> new DecisionTableGridCell<>(new BaseGridCellValue<>(rule.getDescription().getValue()), listSelector));
                break;
        }
    });
}
Also used : DecisionTableSection(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Example 3 with DecisionTableSection

use of org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection 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 DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, index);
            return section == DecisionTableSection.INPUT_CLAUSES || section == DecisionTableSection.OUTPUT_CLAUSES;
        }

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

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

        private CommandResult<RuleViolation> moveClauses(final int index) {
            final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, index);
            if (section == DecisionTableSection.INPUT_CLAUSES) {
                final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
                final int relativeIndex = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, index);
                final int relativeOldIndex = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, oldIndex);
                final List<Integer> inputClauseIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).map(i -> DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, i)).collect(Collectors.toList());
                moveClauses(relativeIndex, relativeOldIndex, dtable.getInput(), inputClauseIndexesToMove);
                final List<List<UnaryTests>> decisionRulesInputEntries = dtable.getRule().stream().map(DecisionRule::getInputEntry).collect(Collectors.toList());
                updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesInputEntries, inputClauseIndexesToMove);
                return GraphCommandResultBuilder.SUCCESS;
            } else if (section == DecisionTableSection.OUTPUT_CLAUSES) {
                final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
                final int relativeIndex = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, index);
                final int relativeOldIndex = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, oldIndex);
                final List<Integer> outputClauseIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).map(i -> DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, i)).collect(Collectors.toList());
                moveClauses(relativeIndex, relativeOldIndex, dtable.getOutput(), outputClauseIndexesToMove);
                final List<List<LiteralExpression>> decisionRulesOutputEntries = dtable.getRule().stream().map(DecisionRule::getOutputEntry).collect(Collectors.toList());
                updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesOutputEntries, outputClauseIndexesToMove);
                return GraphCommandResultBuilder.SUCCESS;
            } else {
                return GraphCommandResultBuilder.FAILED;
            }
        }

        private <T> void moveClauses(final int relativeIndex, final int relativeOldIndex, final List<T> clauses, final List<Integer> clauseIndexesToMove) {
            final List<T> clausesToMove = clauseIndexesToMove.stream().map(clauses::get).collect(Collectors.toList());
            clauses.removeAll(clausesToMove);
            if (relativeIndex < relativeOldIndex) {
                clauses.addAll(relativeIndex, clausesToMove);
            } else if (relativeIndex > relativeOldIndex) {
                clauses.addAll(relativeIndex - clausesToMove.size() + 1, clausesToMove);
            }
        }

        private <T> void updateDecisionRules(final int relativeIndex, final int relativeOldIndex, final List<List<T>> clauses, final List<Integer> clauseIndexesToMove) {
            clauses.forEach(row -> moveClauses(relativeIndex, relativeOldIndex, row, clauseIndexesToMove));
        }
    };
}
Also used : DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) DecisionTable(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionTable) DecisionTableUIModelMapperHelper(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) 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) List(java.util.List) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) UnaryTests(org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests) 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) DecisionTableSection(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection) DecisionTableSection(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule) 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(java.util.List)

Aggregations

DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)3 DecisionTableSection (org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection)3 BaseGridCellValue (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 DecisionTable (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionTable)1 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)1 UnaryTests (org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests)1 VetoExecutionCommand (org.kie.workbench.common.dmn.client.commands.VetoExecutionCommand)1 VetoUndoCommand (org.kie.workbench.common.dmn.client.commands.VetoUndoCommand)1 DecisionTableUIModelMapperHelper (org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper)1 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 AbstractCanvasCommand (org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasCommand)1 AbstractCanvasGraphCommand (org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasGraphCommand)1 CanvasCommandResultBuilder (org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 Command (org.kie.workbench.common.stunner.core.command.Command)1 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)1