use of henplus.view.util.SortedMatchIterator in project henplus by neurolabs.
the class DriverCommand method complete.
@Override
public Iterator<String> complete(final CommandDispatcher disp, final String partialCommand, final String lastWord) {
final StringTokenizer st = new StringTokenizer(partialCommand);
final String cmd = (String) st.nextElement();
final int argc = st.countTokens();
// list-drivers gets no names.
if ("list-drivers".equals(cmd)) {
return null;
}
// do not complete beyond first word.
if (argc > ("".equals(lastWord) ? 0 : 1)) {
return null;
}
return new SortedMatchIterator(lastWord, _drivers);
}
use of henplus.view.util.SortedMatchIterator in project henplus by neurolabs.
the class HelpCommand method complete.
/**
* Returns a list of strings that are possible at this stage.
*/
@Override
public Iterator<String> complete(final CommandDispatcher disp, final String partialCommand, final String lastWord) {
// if we already have one arguemnt and try to expand the next: no.
final int argc = argumentCount(partialCommand);
if (argc > 2 || argc == 2 && lastWord.length() == 0) {
return null;
}
final Iterator<String> it = disp.getRegisteredCommandNames(lastWord);
return new SortedMatchIterator(lastWord, it) {
@Override
protected boolean exclude(final String cmdName) {
final Command cmd = disp.getCommandFrom(cmdName);
return cmd.getLongDescription(cmdName) == null;
}
};
}
use of henplus.view.util.SortedMatchIterator in project henplus by neurolabs.
the class PluginCommand method complete.
@Override
public Iterator<String> complete(final CommandDispatcher disp, final String partialCommand, final String lastWord) {
final StringTokenizer st = new StringTokenizer(partialCommand);
final String cmd = (String) st.nextElement();
final int argc = st.countTokens();
// list-plugins gets no names.
if ("list-plugins".equals(cmd)) {
return null;
}
// do not complete beyond first word.
if (argc > ("".equals(lastWord) ? 0 : 1)) {
return null;
}
return new SortedMatchIterator(lastWord, _plugins);
}
use of henplus.view.util.SortedMatchIterator in project henplus by neurolabs.
the class SetCommand method complete.
/**
* complete variable names.
*/
@Override
public Iterator<String> complete(final CommandDispatcher disp, final String partialCommand, final String lastWord) {
final StringTokenizer st = new StringTokenizer(partialCommand);
final String cmd = (String) st.nextElement();
final int argc = st.countTokens();
final HashSet<String> alreadyGiven = new HashSet<String>();
if ("set-var".equals(cmd)) {
if (argc > ("".equals(lastWord) ? 0 : 1)) {
return null;
}
} else {
/*
* remember all variables, that have already been given on the
* commandline and exclude from completion..
*/
while (st.hasMoreElements()) {
alreadyGiven.add(st.nextToken());
}
}
return new SortedMatchIterator(lastWord, _variables) {
@Override
protected boolean exclude(final String current) {
return alreadyGiven.contains(current);
}
};
}
use of henplus.view.util.SortedMatchIterator in project henplus by neurolabs.
the class SetCommand method completeUserVar.
/**
* used, if the command dispatcher notices the attempt to expand a variable. This is a partial variable name, that starts with
* '$' or '${'.
*/
public Iterator<String> completeUserVar(final String variable) {
if (!variable.startsWith("$")) {
// strange, shouldn't happen.
return null;
}
final boolean hasBrace = variable.startsWith("${");
final String prefix = hasBrace ? "${" : "$";
final String postfix = hasBrace ? "}" : "";
final String name = variable.substring(prefix.length());
// HenPlus.msg().println("VAR: " + variable);
// HenPlus.msg().println("NAME: " + name);
final SortedMatchIterator it = new SortedMatchIterator(name, _variables);
it.setPrefix(prefix);
it.setSuffix(postfix);
return it;
}
Aggregations