Last active
December 11, 2015 23:28
-
-
Save stalep/4676928 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface UICommand | |
{ | |
public UICommandID getId(); | |
public void initializeUI(UIContext context) throws Exception; | |
public void validate(UIValidationContext context); | |
public Result execute(UIContext context) throws Exception; | |
//leaning TOWARDS list<string> | |
//public List<UIInpu<?>t> complete(UIInput<?> value); | |
public List<String> complete(UIInput<?> value); | |
} | |
public class FooCommand implements UICommand | |
{ | |
@Inject | |
private UIInput<File> f1; | |
@Inject | |
private UIInput<String> f2; | |
@Inject | |
private UIInput<List<File>> arguments; | |
@Override | |
public UICommandID getId() | |
{ | |
return new SimpleUICommandID("foo", "Do some foo"); | |
} | |
@Override | |
public void initializeUI(UIContext context) throws Exception | |
{ | |
f1.setLabel("config-file"); | |
f1.setRequired(true); | |
context.getUIBuilder().add(f1); | |
f2.setLabel("value"); | |
f2.setRequired(false); | |
context.getUIBuilder().add(f2); | |
arguments.setLabel(""); //no labal means its an argument afaik | |
arguments.setRequired(true); | |
context.getUIBuilder().add(arguments); | |
} | |
@Override | |
public void validate(UIValidationContext context) | |
{ | |
} | |
@Override | |
public Result execute(UIContext context) throws Exception | |
{ | |
//ignore result for now | |
return Results.success("boo"); | |
} | |
//I would argue that List<String> would be easier for the user, but List<UIInput<?>> will also work | |
//public List<UIInput<?>> complete(UIInput<?> value) { | |
public List<String> complete(UIInput<?> value) | |
if(value.getName().equals(f1.getName()) | |
return configFileCompletion(value.getValue()); | |
else if(value.getName().equals(f2.getName()) | |
return valueCompletion(value.getValue()); | |
else if(value.getName().equals(arguments.getName()) | |
return argumentsCompletion(value.getValue()); | |
else | |
return null; | |
} | |
private List<String> configFileCompletion(String configValue) { | |
//blabla | |
} | |
... | |
private List<String> argumentsCompletion(List<File> configValue) { | |
//this would not be needed in the final version as æsh would | |
//recognize arguments set as Files and use the "default" filehandler. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment