Skip to content

Commit

Permalink
Calling controller.initialize() before working with it
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Dec 16, 2013
1 parent d0b4b23 commit 1588a6f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public UIContext getContext()
return context;
}

public CommandController getSourceCommand()
public CommandController getController()
{
return controller;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ public CommandAdapter(ShellImpl shell, AbstractShellInteraction interaction)

public List<UIValidationMessage> validate()
{
return interaction.getSourceCommand().validate();
return interaction.getController().validate();
}

@SuppressWarnings("unchecked")
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws IOException
{
boolean failure = true;
if (interaction.getSourceCommand().isValid())
if (interaction.getController().isValid())
{
Result result = null;
try
{
result = interaction.getSourceCommand().execute();
result = interaction.getController().execute();
}
catch (Exception e)
{
Expand Down Expand Up @@ -105,7 +105,7 @@ public CommandResult execute(CommandInvocation commandInvocation) throws IOExcep
}
else
{
List<UIValidationMessage> messages = interaction.getSourceCommand().validate();
List<UIValidationMessage> messages = interaction.getController().validate();
for (UIValidationMessage message : messages)
{
if (message.getSeverity() == Severity.ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,25 @@
*/
public class ShellSingleCommand extends AbstractShellInteraction
{
private final CommandController command;
private final CommandController controller;
private CommandLineParser commandLineParser;

/**
* Creates a new {@link ShellSingleCommand} based on the shell and initial selection
*/
public ShellSingleCommand(CommandController command, ShellContext shellContext, CommandLineUtil commandLineUtil)
public ShellSingleCommand(CommandController controller, ShellContext shellContext, CommandLineUtil commandLineUtil)
{
super(command, shellContext, commandLineUtil);
this.command = command;
super(controller, shellContext, commandLineUtil);
this.controller = controller;
}

@Override
public CommandLineParser getParser(ShellContext shellContext, String completeLine) throws Exception
{
if (this.commandLineParser == null)
{
this.commandLineParser = commandLineUtil.generateParser(this.command, shellContext, getInputs());
controller.initialize();
this.commandLineParser = commandLineUtil.generateParser(this.controller, shellContext, getInputs());
}
return this.commandLineParser;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,30 @@ public ShellWizard(WizardCommandController wizardCommandController, ShellContext
}

@Override
public WizardCommandController getSourceCommand()
public WizardCommandController getController()
{
return (WizardCommandController) super.getSourceCommand();
return (WizardCommandController) super.getController();
}

@Override
public CommandLineParser getParser(ShellContext shellContext, String completeLine) throws Exception
{
UICommand command = getSourceCommand().getCommand();
UICommand command = getController().getCommand();
return populate(command, shellContext, completeLine);
}

private CommandLineParser populate(UICommand command, ShellContext shellContext, String line)
throws Exception
{
Map<String, InputComponent<?, Object>> inputs = getInputs();
CommandLineParser parser = commandLineUtil.generateParser(getSourceCommand(), shellContext, inputs);
CommandLineParser parser = commandLineUtil.generateParser(getController(), shellContext, inputs);
CommandLine cmdLine = parser.parse(line, true);
Map<String, InputComponent<?, Object>> populatedInputs = commandLineUtil.populateUIInputs(cmdLine, inputs);
if (getSourceCommand().isValid())
if (getController().isValid())
{
if (getSourceCommand().canMoveToNextStep())
if (getController().canMoveToNextStep())
{
getSourceCommand().next();
getController().next().initialize();
inputs.keySet().retainAll(populatedInputs.keySet());
parser = populate(command, shellContext, line);
}
Expand Down

0 comments on commit 1588a6f

Please sign in to comment.