Search in sources :

Example 31 with GraphCommandExecutionContext

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

the class AddRelationColumnCommand method newGraphCommand.

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

        @Override
        protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext gce) {
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext gce) {
            final int iiIndex = uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT;
            relation.getColumn().add(iiIndex, informationItem);
            relation.getRow().forEach(row -> {
                final LiteralExpression le = new LiteralExpression();
                row.getExpression().add(iiIndex, le);
            });
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) {
            final int columnIndex = relation.getColumn().indexOf(informationItem);
            relation.getRow().forEach(row -> row.getExpression().remove(columnIndex));
            relation.getColumn().remove(informationItem);
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 32 with GraphCommandExecutionContext

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

the class AddRelationRowCommand method newGraphCommand.

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

        @Override
        protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext gce) {
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext gce) {
            relation.getRow().add(uiRowIndex, row);
            relation.getColumn().forEach(ii -> {
                final LiteralExpression le = new LiteralExpression();
                row.getExpression().add(le);
            });
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) {
            relation.getRow().remove(row);
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 33 with GraphCommandExecutionContext

use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext 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 34 with GraphCommandExecutionContext

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

the class AddContextEntryCommandTest method testGraphCommandExecuteMultipleEntriesPresent.

@Test
public void testGraphCommandExecuteMultipleEntriesPresent() {
    final ContextEntry firstEntry = new ContextEntry() {

        {
            setVariable(new InformationItem() {

                {
                    setName(new Name("old one"));
                }
            });
        }
    };
    context.getContextEntry().add(0, firstEntry);
    makeCommand();
    final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
    assertEquals(3, context.getContextEntry().size());
    assertEquals(firstEntry, context.getContextEntry().get(0));
    assertEquals(contextEntry, context.getContextEntry().get(1));
    assertEquals(defaultResultContextEntry, context.getContextEntry().get(2));
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContextEntry(org.kie.workbench.common.dmn.api.definition.v1_1.ContextEntry) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 35 with GraphCommandExecutionContext

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

the class AddContextEntryCommandTest method testGraphCommandUndoMultipleEntriesPresent.

@Test
public void testGraphCommandUndoMultipleEntriesPresent() {
    final ContextEntry firstEntry = new ContextEntry() {

        {
            setVariable(new InformationItem() {

                {
                    setName(new Name("old one"));
                }
            });
        }
    };
    context.getContextEntry().add(0, firstEntry);
    makeCommand();
    final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
    // Add column and then undo
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.undo(gce));
    assertEquals(2, context.getContextEntry().size());
    assertEquals(firstEntry, context.getContextEntry().get(0));
    assertEquals(defaultResultContextEntry, context.getContextEntry().get(1));
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContextEntry(org.kie.workbench.common.dmn.api.definition.v1_1.ContextEntry) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Aggregations

GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)60 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)60 Test (org.junit.Test)47 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)18 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)16 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)12 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)10 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)10 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)8 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)8 Binding (org.kie.workbench.common.dmn.api.definition.v1_1.Binding)7 InputClause (org.kie.workbench.common.dmn.api.definition.v1_1.InputClause)6 OutputClause (org.kie.workbench.common.dmn.api.definition.v1_1.OutputClause)5 UnaryTests (org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests)5 ContextEntry (org.kie.workbench.common.dmn.api.definition.v1_1.ContextEntry)4 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)4 Command (org.kie.workbench.common.stunner.core.command.Command)4 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)3 CanvasCommandResultBuilder (org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder)3 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)3