@Test public void testGraphCommandExecuteExistingNotAffected() throws Exception { makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT); final String ruleOneOldInput = "old rule 1"; final String ruleTwoOldInput = "old rule 2"; dtable.getInput().add(new InputClause()); addRuleWithInputClauseValues(ruleOneOldInput); addRuleWithInputClauseValues(ruleTwoOldInput); assertEquals(1, dtable.getInput().size()); final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler); assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext)); assertEquals(2, dtable.getInput().size()); assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1", dtable.getInput().get(0).getInputExpression().getText().getValue()); assertNotNull(dtable.getInput().get(1).getInputExpression()); final List<UnaryTests> inputEntriesRuleOne = dtable.getRule().get(0).getInputEntry(); assertEquals(2, inputEntriesRuleOne.size()); assertEquals(ruleOneOldInput, inputEntriesRuleOne.get(1).getText().getValue()); assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, inputEntriesRuleOne.get(0).getText().getValue()); assertEquals(dtable.getRule().get(0), inputEntriesRuleOne.get(0).getParent()); final List<UnaryTests> inputEntriesRuleTwo = dtable.getRule().get(1).getInputEntry(); assertEquals(2, inputEntriesRuleTwo.size()); assertEquals(ruleTwoOldInput, inputEntriesRuleTwo.get(1).getText().getValue()); assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, inputEntriesRuleTwo.get(0).getText().getValue()); assertEquals(dtable.getRule().get(1), inputEntriesRuleTwo.get(0).getParent()); 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();  }