Search in sources :

Example 16 with List

use of org.kie.workbench.common.dmn.api.definition.model.List in project kie-wb-common by kiegroup.

the class DeleteRelationColumnCommandTest method testGraphCommandUndoWithRows.

@Test
public void testGraphCommandUndoWithRows() {
    final List rowList = new List();
    relation.getRow().add(rowList);
    final LiteralExpression literalExpression = new LiteralExpression();
    literalExpression.getText().setValue(VALUE);
    relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, literalExpression));
    makeCommand();
    final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
    // Delete column and then undo
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.undo(gce));
    assertEquals(1, relation.getColumn().size());
    assertEquals(1, relation.getRow().size());
    assertEquals(1, relation.getRow().get(0).getExpression().size());
    assertEquals(VALUE, ((LiteralExpression) relation.getRow().get(0).getExpression().get(0).getExpression()).getText().getValue());
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) List(org.kie.workbench.common.dmn.api.definition.model.List) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 17 with List

use of org.kie.workbench.common.dmn.api.definition.model.List in project kie-wb-common by kiegroup.

the class DeleteRelationColumnCommandTest method testCanvasCommandExecuteWithRows.

@Test
public void testCanvasCommandExecuteWithRows() {
    final List rowList = new List();
    relation.getRow().add(rowList);
    relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, new LiteralExpression()));
    uiModel.appendRow(new BaseGridRow());
    uiModelMapper.fromDMNModel(0, 0);
    uiModelMapper.fromDMNModel(0, 1);
    makeCommand();
    final Command<AbstractCanvasHandler, CanvasViolation> cc = command.newCanvasCommand(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.execute(handler));
    assertEquals(1, uiModel.getColumnCount());
    assertEquals(uiRowNumberColumn, uiModel.getColumns().get(0));
    assertEquals(1, uiModel.getRowCount());
    assertEquals(1, uiModel.getRows().get(0).getCells().size());
    assertEquals(1, uiModel.getCell(0, 0).getValue().getValue());
    verify(command).updateParentInformation();
    verify(executeCanvasOperation).execute();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) List(org.kie.workbench.common.dmn.api.definition.model.List) Test(org.junit.Test)

Example 18 with List

use of org.kie.workbench.common.dmn.api.definition.model.List in project kie-wb-common by kiegroup.

the class DeleteRelationColumnCommandTest method testGraphCommandExecuteDeleteMiddleWithRows.

@Test
public void testGraphCommandExecuteDeleteMiddleWithRows() {
    final List rowList = new List();
    uiModel.appendColumn(mock(RelationColumn.class));
    uiModel.appendColumn(mock(RelationColumn.class));
    relation.getColumn().add(new InformationItem());
    relation.getColumn().add(new InformationItem());
    relation.getRow().add(rowList);
    final LiteralExpression firstExpression = new LiteralExpression();
    final LiteralExpression lastExpression = new LiteralExpression();
    relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, firstExpression));
    relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, new LiteralExpression()));
    relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, lastExpression));
    makeCommand(2);
    final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
    assertEquals(2, relation.getColumn().size());
    assertEquals(1, relation.getRow().size());
    assertEquals(2, relation.getRow().get(0).getExpression().size());
    assertEquals(firstExpression, relation.getRow().get(0).getExpression().get(0).getExpression());
    assertEquals(lastExpression, relation.getRow().get(0).getExpression().get(1).getExpression());
}
Also used : RelationColumn(org.kie.workbench.common.dmn.client.editors.expressions.types.relation.RelationColumn) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) List(org.kie.workbench.common.dmn.api.definition.model.List) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 19 with List

use of org.kie.workbench.common.dmn.api.definition.model.List in project kie-wb-common by kiegroup.

the class DeleteRelationRowCommandTest method setup.

@Before
public void setup() {
    this.relation = new Relation();
    this.rowList = new List();
    this.relation.getRow().add(rowList);
    this.uiModel = new BaseGridData();
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModelMapper = new RelationUIModelMapper(() -> uiModel, () -> Optional.of(relation), listSelector, DEFAULT_HEIGHT);
    makeCommand(0);
    doReturn(ruleManager).when(handler).getRuleManager();
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiModelColumn).getIndex();
}
Also used : RelationUIModelMapper(org.kie.workbench.common.dmn.client.editors.expressions.types.relation.RelationUIModelMapper) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) List(org.kie.workbench.common.dmn.api.definition.model.List) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Before(org.junit.Before)

Example 20 with List

use of org.kie.workbench.common.dmn.api.definition.model.List 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);
                CommandUtils.moveComponentWidths(Relation.STATIC_COLUMNS + relativeIndex, Relation.STATIC_COLUMNS + relativeOldIndex, relation.getComponentWidths(), Collections.singletonList(oldIndex));
                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) List(org.kie.workbench.common.dmn.api.definition.model.List) ArrayList(java.util.ArrayList) CommandUtils(org.kie.workbench.common.dmn.client.commands.util.CommandUtils) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) 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) Collections(java.util.Collections) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) 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) List(org.kie.workbench.common.dmn.api.definition.model.List) ArrayList(java.util.ArrayList) RelationSection(org.kie.workbench.common.dmn.client.editors.expressions.types.relation.RelationUIModelMapperHelper.RelationSection)

Aggregations

List (org.kie.workbench.common.dmn.api.definition.model.List)39 Test (org.junit.Test)22 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)21 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)13 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)10 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)10 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)9 Relation (org.kie.workbench.common.dmn.api.definition.model.Relation)9 ArrayList (java.util.ArrayList)7 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)7 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)7 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)7 Before (org.junit.Before)6 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)5 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)4 Context (org.kie.workbench.common.dmn.api.definition.model.Context)4 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)4 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)4 Invocation (org.kie.workbench.common.dmn.api.definition.model.Invocation)4 IsLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression)4