@Test public void testGraphCommandExecuteExistingNotAffected() throws Exception { makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT); final String ruleOneOldOutput = "old rule 1"; final String ruleTwoOldOutput = "old rule 2"; dtable.getOutput().add(new OutputClause()); addRuleWithOutputClauseValues(ruleOneOldOutput); addRuleWithOutputClauseValues(ruleTwoOldOutput); assertEquals(1, dtable.getOutput().size()); final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler); assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext)); assertEquals(2, dtable.getOutput().size()); assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1", dtable.getOutput().get(0).getName()); assertNull(dtable.getOutput().get(1).getName()); final List<LiteralExpression> outputEntriesRuleOne = dtable.getRule().get(0).getOutputEntry(); assertEquals(2, outputEntriesRuleOne.size()); assertEquals(ruleOneOldOutput, outputEntriesRuleOne.get(1).getText().getValue()); assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, outputEntriesRuleOne.get(0).getText().getValue()); assertEquals(dtable.getRule().get(0), outputEntriesRuleOne.get(0).getParent()); final List<LiteralExpression> outputEntriesRuleTwo = dtable.getRule().get(1).getOutputEntry(); assertEquals(2, outputEntriesRuleTwo.size()); assertEquals(ruleTwoOldOutput, outputEntriesRuleTwo.get(1).getText().getValue()); assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, outputEntriesRuleTwo.get(0).getText().getValue()); assertEquals(dtable.getRule().get(1), outputEntriesRuleTwo.get(0).getParent()); assertEquals(dtable, outputClause.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().size(); dtable.getOutput().add(clauseIndex, outputClause); outputClause.setName(name); dtable.getRule().forEach(rule -> { final LiteralExpression le = new LiteralExpression(); le.getText().setValue(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT); rule.getOutputEntry().add(clauseIndex, le); le.setParent(rule); }); outputClause.setParent(dtable); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { dtable.getComponentWidths().remove(uiColumnIndex); final int clauseIndex = dtable.getOutput().indexOf(outputClause); dtable.getRule().forEach(rule -> rule.getOutputEntry().remove(clauseIndex)); dtable.getOutput().remove(outputClause); return GraphCommandResultBuilder.SUCCESS; } }; }
AddOutputClauseCommand 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().size(); dtable.getOutput().add(clauseIndex, outputClause); outputClause.setName(name); dtable.getRule().forEach(rule -> { final LiteralExpression le = new LiteralExpression(); le.getText().setValue(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT); rule.getOutputEntry().add(clauseIndex, le); le.setParent(rule); }); outputClause.setParent(dtable); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { dtable.getComponentWidths().remove(uiColumnIndex); final int clauseIndex = dtable.getOutput().indexOf(outputClause); dtable.getRule().forEach(rule -> rule.getOutputEntry().remove(clauseIndex)); dtable.getOutput().remove(outputClause); return GraphCommandResultBuilder.SUCCESS; } }; } }
AddOutputClauseCommand 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().size(); dtable.getOutput().add(clauseIndex, outputClause); outputClause.setName(name); dtable.getRule().forEach(rule -> { final LiteralExpression le = new LiteralExpression(); le.getText().setValue(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT); rule.getOutputEntry().add(clauseIndex, le); le.setParent(rule); }); outputClause.setParent(dtable); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { dtable.getComponentWidths().remove(uiColumnIndex); final int clauseIndex = dtable.getOutput().indexOf(outputClause); dtable.getRule().forEach(rule -> rule.getOutputEntry().remove(clauseIndex)); dtable.getOutput().remove(outputClause); return GraphCommandResultBuilder.SUCCESS; } }; } AddOutputClauseCommand(final DecisionTable dtable,
                                  final OutputClause outputClause,
                                  final GridData uiModel,
                                  final Supplier<OutputClauseColumn> uiModelColumnSupplier,
                                  final int uiColumnIndex,
                                  final DecisionTableUIModelMapper uiModelMapper,
                                  final org.uberfire.mvp.Command executeCanvasOperation,
                                  final org.uberfire.mvp.Command undoCanvasOperation); }
AddOutputClauseCommand 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().size(); dtable.getOutput().add(clauseIndex, outputClause); outputClause.setName(name); dtable.getRule().forEach(rule -> { final LiteralExpression le = new LiteralExpression(); le.getText().setValue(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT); rule.getOutputEntry().add(clauseIndex, le); le.setParent(rule); }); outputClause.setParent(dtable); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { dtable.getComponentWidths().remove(uiColumnIndex); final int clauseIndex = dtable.getOutput().indexOf(outputClause); dtable.getRule().forEach(rule -> rule.getOutputEntry().remove(clauseIndex)); dtable.getOutput().remove(outputClause); return GraphCommandResultBuilder.SUCCESS; } }; } AddOutputClauseCommand(final DecisionTable dtable,
                                  final OutputClause outputClause,
                                  final GridData uiModel,
                                  final Supplier<OutputClauseColumn> uiModelColumnSupplier,
                                  final int uiColumnIndex,
                                  final DecisionTableUIModelMapper uiModelMapper,
                                  final org.uberfire.mvp.Command executeCanvasOperation,
                                  final org.uberfire.mvp.Command undoCanvasOperation); void updateParentInformation(); }
AddOutputClauseCommand 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().size(); dtable.getOutput().add(clauseIndex, outputClause); outputClause.setName(name); dtable.getRule().forEach(rule -> { final LiteralExpression le = new LiteralExpression(); le.getText().setValue(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT); rule.getOutputEntry().add(clauseIndex, le); le.setParent(rule); }); outputClause.setParent(dtable); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) { dtable.getComponentWidths().remove(uiColumnIndex); final int clauseIndex = dtable.getOutput().indexOf(outputClause); dtable.getRule().forEach(rule -> rule.getOutputEntry().remove(clauseIndex)); dtable.getOutput().remove(outputClause); return GraphCommandResultBuilder.SUCCESS; } }; } AddOutputClauseCommand(final DecisionTable dtable,
                                  final OutputClause outputClause,
                                  final GridData uiModel,
                                  final Supplier<OutputClauseColumn> uiModelColumnSupplier,
                                  final int uiColumnIndex,
                                  final DecisionTableUIModelMapper uiModelMapper,
                                  final org.uberfire.mvp.Command executeCanvasOperation,
                                  final org.uberfire.mvp.Command undoCanvasOperation); void updateParentInformation();  }