@Test public void testGraphCommandExecuteWithExistingColumn_InsertMiddle() { makeCommand(2); final InformationItem existingInformationItemFirst = new InformationItem(); relation.getColumn().add(existingInformationItemFirst); final InformationItem existingInformationItemLast = new InformationItem(); relation.getColumn().add(existingInformationItemLast); final List row = new List(); relation.getRow().add(row); final LiteralExpression existingLiteralExpressionFirst = new LiteralExpression(); final LiteralExpression existingLiteralExpressionLast = new LiteralExpression(); row.getExpression().add(HasExpression.wrap(row, existingLiteralExpressionFirst)); row.getExpression().add(HasExpression.wrap(row, existingLiteralExpressionLast)); final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler); assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce)); assertEquals(3, relation.getColumn().size()); assertEquals(existingInformationItemFirst, relation.getColumn().get(0)); assertEquals(informationItem, relation.getColumn().get(1)); assertEquals(RelationDefaultValueUtilities.PREFIX + "1", informationItem.getName().getValue()); assertEquals(existingInformationItemLast, relation.getColumn().get(2)); assertEquals(1, relation.getRow().size()); assertEquals(3, relation.getRow().get(0).getExpression().size()); assertEquals(existingLiteralExpressionFirst, relation.getRow().get(0).getExpression().get(0).getExpression()); assertTrue(relation.getRow().get(0).getExpression().get(1).getExpression() instanceof LiteralExpression); assertEquals(existingLiteralExpressionLast, relation.getRow().get(0).getExpression().get(2).getExpression()); assertEquals(relation, informationItem.getParent()); assertEquals(relation.getRow().get(0), relation.getRow().get(0).getExpression().get(1).getExpression().getParent()); }
@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.getComponentWidths().add(uiColumnIndex, null); final int iiIndex = uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT; relation.getColumn().add(iiIndex, informationItem); informationItem.getName().setValue(name); relation.getRow().forEach(row -> { final LiteralExpression le = new LiteralExpression(); final HasExpression hasExpression = HasExpression.wrap(row, le); row.getExpression().add(iiIndex, hasExpression); le.setParent(row); }); informationItem.setParent(relation); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) { relation.getComponentWidths().remove(uiColumnIndex); final int columnIndex = relation.getColumn().indexOf(informationItem); relation.getRow().forEach(row -> row.getExpression().remove(columnIndex)); relation.getColumn().remove(informationItem); return GraphCommandResultBuilder.SUCCESS; } }; }
AddRelationColumnCommand extends AbstractCanvasGraphCommand implements VetoExecutionCommand,
                                                                                    VetoUndoCommand { @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.getComponentWidths().add(uiColumnIndex, null); final int iiIndex = uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT; relation.getColumn().add(iiIndex, informationItem); informationItem.getName().setValue(name); relation.getRow().forEach(row -> { final LiteralExpression le = new LiteralExpression(); final HasExpression hasExpression = HasExpression.wrap(row, le); row.getExpression().add(iiIndex, hasExpression); le.setParent(row); }); informationItem.setParent(relation); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) { relation.getComponentWidths().remove(uiColumnIndex); final int columnIndex = relation.getColumn().indexOf(informationItem); relation.getRow().forEach(row -> row.getExpression().remove(columnIndex)); relation.getColumn().remove(informationItem); return GraphCommandResultBuilder.SUCCESS; } }; } }
AddRelationColumnCommand extends AbstractCanvasGraphCommand implements VetoExecutionCommand,
                                                                                    VetoUndoCommand { @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.getComponentWidths().add(uiColumnIndex, null); final int iiIndex = uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT; relation.getColumn().add(iiIndex, informationItem); informationItem.getName().setValue(name); relation.getRow().forEach(row -> { final LiteralExpression le = new LiteralExpression(); final HasExpression hasExpression = HasExpression.wrap(row, le); row.getExpression().add(iiIndex, hasExpression); le.setParent(row); }); informationItem.setParent(relation); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) { relation.getComponentWidths().remove(uiColumnIndex); final int columnIndex = relation.getColumn().indexOf(informationItem); relation.getRow().forEach(row -> row.getExpression().remove(columnIndex)); relation.getColumn().remove(informationItem); return GraphCommandResultBuilder.SUCCESS; } }; } AddRelationColumnCommand(final Relation relation,
                                    final InformationItem informationItem,
                                    final GridData uiModel,
                                    final Supplier<RelationColumn> uiModelColumnSupplier,
                                    final int uiColumnIndex,
                                    final RelationUIModelMapper uiModelMapper,
                                    final org.uberfire.mvp.Command executeCanvasOperation,
                                    final org.uberfire.mvp.Command undoCanvasOperation); }
AddRelationColumnCommand extends AbstractCanvasGraphCommand implements VetoExecutionCommand,
                                                                                    VetoUndoCommand { @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.getComponentWidths().add(uiColumnIndex, null); final int iiIndex = uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT; relation.getColumn().add(iiIndex, informationItem); informationItem.getName().setValue(name); relation.getRow().forEach(row -> { final LiteralExpression le = new LiteralExpression(); final HasExpression hasExpression = HasExpression.wrap(row, le); row.getExpression().add(iiIndex, hasExpression); le.setParent(row); }); informationItem.setParent(relation); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) { relation.getComponentWidths().remove(uiColumnIndex); final int columnIndex = relation.getColumn().indexOf(informationItem); relation.getRow().forEach(row -> row.getExpression().remove(columnIndex)); relation.getColumn().remove(informationItem); return GraphCommandResultBuilder.SUCCESS; } }; } AddRelationColumnCommand(final Relation relation,
                                    final InformationItem informationItem,
                                    final GridData uiModel,
                                    final Supplier<RelationColumn> uiModelColumnSupplier,
                                    final int uiColumnIndex,
                                    final RelationUIModelMapper uiModelMapper,
                                    final org.uberfire.mvp.Command executeCanvasOperation,
                                    final org.uberfire.mvp.Command undoCanvasOperation); void updateParentInformation(); }
AddRelationColumnCommand extends AbstractCanvasGraphCommand implements VetoExecutionCommand,
                                                                                    VetoUndoCommand { @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.getComponentWidths().add(uiColumnIndex, null); final int iiIndex = uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT; relation.getColumn().add(iiIndex, informationItem); informationItem.getName().setValue(name); relation.getRow().forEach(row -> { final LiteralExpression le = new LiteralExpression(); final HasExpression hasExpression = HasExpression.wrap(row, le); row.getExpression().add(iiIndex, hasExpression); le.setParent(row); }); informationItem.setParent(relation); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) { relation.getComponentWidths().remove(uiColumnIndex); final int columnIndex = relation.getColumn().indexOf(informationItem); relation.getRow().forEach(row -> row.getExpression().remove(columnIndex)); relation.getColumn().remove(informationItem); return GraphCommandResultBuilder.SUCCESS; } }; } AddRelationColumnCommand(final Relation relation,
                                    final InformationItem informationItem,
                                    final GridData uiModel,
                                    final Supplier<RelationColumn> uiModelColumnSupplier,
                                    final int uiColumnIndex,
                                    final RelationUIModelMapper uiModelMapper,
                                    final org.uberfire.mvp.Command executeCanvasOperation,
                                    final org.uberfire.mvp.Command undoCanvasOperation); void updateParentInformation();  }