@Test public void testGraphCommandExecuteInsertMiddle() throws Exception { makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + 1); final String ruleInputOne = "rule in 1"; final String ruleInputTwo = "rule in 2"; dtable.getInput().add(new InputClause()); dtable.getInput().add(new InputClause()); addRuleWithInputClauseValues(ruleInputOne, ruleInputTwo); assertEquals(2, dtable.getInput().size()); final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler); assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext)); assertEquals(3, dtable.getInput().size()); assertNotNull(dtable.getInput().get(0).getInputExpression()); assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1", dtable.getInput().get(1).getInputExpression().getText().getValue()); assertNotNull(dtable.getInput().get(2).getInputExpression()); final List<UnaryTests> ruleInputs = dtable.getRule().get(0).getInputEntry(); assertEquals(3, ruleInputs.size()); assertEquals(ruleInputOne, ruleInputs.get(0).getText().getValue()); assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, ruleInputs.get(1).getText().getValue()); assertEquals(dtable.getRule().get(0), ruleInputs.get(1).getParent()); assertEquals(ruleInputTwo, ruleInputs.get(2).getText().getValue()); assertEquals(dtable, inputClause.getParent()); }
@Override protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) { return new AbstractGraphCommand() { @Override protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) { return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { dtable.getComponentWidths().add(uiColumnIndex, null); final int clauseIndex = uiColumnIndex - DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT; dtable.getInput().add(clauseIndex, inputClause); final InputClauseLiteralExpression le = new InputClauseLiteralExpression(); inputClause.setInputExpression(le); le.getText().setValue(name); dtable.getRule().forEach(rule -> { final UnaryTests ut = new UnaryTests(); ut.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT); rule.getInputEntry().add(clauseIndex, ut); ut.setParent(rule); }); inputClause.setParent(dtable); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { dtable.getComponentWidths().remove(uiColumnIndex); final int clauseIndex = dtable.getInput().indexOf(inputClause); dtable.getRule().forEach(rule -> rule.getInputEntry().remove(clauseIndex)); dtable.getInput().remove(inputClause); return GraphCommandResultBuilder.SUCCESS; } }; }
AddInputClauseCommand extends AbstractCanvasGraphCommand implements VetoExecutionCommand,
                                                                                 VetoUndoCommand { @Override protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) { return new AbstractGraphCommand() { @Override protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) { return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { dtable.getComponentWidths().add(uiColumnIndex, null); final int clauseIndex = uiColumnIndex - DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT; dtable.getInput().add(clauseIndex, inputClause); final InputClauseLiteralExpression le = new InputClauseLiteralExpression(); inputClause.setInputExpression(le); le.getText().setValue(name); dtable.getRule().forEach(rule -> { final UnaryTests ut = new UnaryTests(); ut.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT); rule.getInputEntry().add(clauseIndex, ut); ut.setParent(rule); }); inputClause.setParent(dtable); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { dtable.getComponentWidths().remove(uiColumnIndex); final int clauseIndex = dtable.getInput().indexOf(inputClause); dtable.getRule().forEach(rule -> rule.getInputEntry().remove(clauseIndex)); dtable.getInput().remove(inputClause); return GraphCommandResultBuilder.SUCCESS; } }; } }
AddInputClauseCommand extends AbstractCanvasGraphCommand implements VetoExecutionCommand,
                                                                                 VetoUndoCommand { @Override protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) { return new AbstractGraphCommand() { @Override protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) { return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { dtable.getComponentWidths().add(uiColumnIndex, null); final int clauseIndex = uiColumnIndex - DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT; dtable.getInput().add(clauseIndex, inputClause); final InputClauseLiteralExpression le = new InputClauseLiteralExpression(); inputClause.setInputExpression(le); le.getText().setValue(name); dtable.getRule().forEach(rule -> { final UnaryTests ut = new UnaryTests(); ut.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT); rule.getInputEntry().add(clauseIndex, ut); ut.setParent(rule); }); inputClause.setParent(dtable); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { dtable.getComponentWidths().remove(uiColumnIndex); final int clauseIndex = dtable.getInput().indexOf(inputClause); dtable.getRule().forEach(rule -> rule.getInputEntry().remove(clauseIndex)); dtable.getInput().remove(inputClause); return GraphCommandResultBuilder.SUCCESS; } }; } AddInputClauseCommand(final DecisionTable dtable,
                                 final InputClause inputClause,
                                 final GridData uiModel,
                                 final Supplier<InputClauseColumn> uiModelColumnSupplier,
                                 final int uiColumnIndex,
                                 final DecisionTableUIModelMapper uiModelMapper,
                                 final org.uberfire.mvp.Command executeCanvasOperation,
                                 final org.uberfire.mvp.Command undoCanvasOperation); }
AddInputClauseCommand extends AbstractCanvasGraphCommand implements VetoExecutionCommand,
                                                                                 VetoUndoCommand { @Override protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) { return new AbstractGraphCommand() { @Override protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) { return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { dtable.getComponentWidths().add(uiColumnIndex, null); final int clauseIndex = uiColumnIndex - DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT; dtable.getInput().add(clauseIndex, inputClause); final InputClauseLiteralExpression le = new InputClauseLiteralExpression(); inputClause.setInputExpression(le); le.getText().setValue(name); dtable.getRule().forEach(rule -> { final UnaryTests ut = new UnaryTests(); ut.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT); rule.getInputEntry().add(clauseIndex, ut); ut.setParent(rule); }); inputClause.setParent(dtable); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { dtable.getComponentWidths().remove(uiColumnIndex); final int clauseIndex = dtable.getInput().indexOf(inputClause); dtable.getRule().forEach(rule -> rule.getInputEntry().remove(clauseIndex)); dtable.getInput().remove(inputClause); return GraphCommandResultBuilder.SUCCESS; } }; } AddInputClauseCommand(final DecisionTable dtable,
                                 final InputClause inputClause,
                                 final GridData uiModel,
                                 final Supplier<InputClauseColumn> uiModelColumnSupplier,
                                 final int uiColumnIndex,
                                 final DecisionTableUIModelMapper uiModelMapper,
                                 final org.uberfire.mvp.Command executeCanvasOperation,
                                 final org.uberfire.mvp.Command undoCanvasOperation); void updateParentInformation(); }
AddInputClauseCommand extends AbstractCanvasGraphCommand implements VetoExecutionCommand,
                                                                                 VetoUndoCommand { @Override protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) { return new AbstractGraphCommand() { @Override protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) { return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { dtable.getComponentWidths().add(uiColumnIndex, null); final int clauseIndex = uiColumnIndex - DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT; dtable.getInput().add(clauseIndex, inputClause); final InputClauseLiteralExpression le = new InputClauseLiteralExpression(); inputClause.setInputExpression(le); le.getText().setValue(name); dtable.getRule().forEach(rule -> { final UnaryTests ut = new UnaryTests(); ut.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT); rule.getInputEntry().add(clauseIndex, ut); ut.setParent(rule); }); inputClause.setParent(dtable); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { dtable.getComponentWidths().remove(uiColumnIndex); final int clauseIndex = dtable.getInput().indexOf(inputClause); dtable.getRule().forEach(rule -> rule.getInputEntry().remove(clauseIndex)); dtable.getInput().remove(inputClause); return GraphCommandResultBuilder.SUCCESS; } }; } AddInputClauseCommand(final DecisionTable dtable,
                                 final InputClause inputClause,
                                 final GridData uiModel,
                                 final Supplier<InputClauseColumn> uiModelColumnSupplier,
                                 final int uiColumnIndex,
                                 final DecisionTableUIModelMapper uiModelMapper,
                                 final org.uberfire.mvp.Command executeCanvasOperation,
                                 final org.uberfire.mvp.Command undoCanvasOperation); void updateParentInformation();  }