Search in sources :

Example 6 with StringsCompleter

use of org.apache.karaf.shell.console.completer.StringsCompleter in project cytoscape-impl by cytoscape.

the class CommandCompleter method complete.

/**
 * @param buffer
 *            the beginning string typed by the user
 * @param cursor
 *            the position of the cursor
 * @param candidates
 *            the list of completions proposed to the user
 */
public int complete(String buffer, int cursor, List candidates) {
    StringsCompleter delegate = new StringsCompleter();
    final List<ScriptEngineFactory> engines = manager.getEngineFactories();
    for (final ScriptEngineFactory engine : engines) {
        final List<String> names = engine.getNames();
        for (final String name : names) delegate.getStrings().add(name);
    }
    return delegate.complete(buffer, cursor, candidates);
}
Also used : StringsCompleter(org.apache.karaf.shell.console.completer.StringsCompleter) ScriptEngineFactory(javax.script.ScriptEngineFactory)

Example 7 with StringsCompleter

use of org.apache.karaf.shell.console.completer.StringsCompleter in project fabric8 by jboss-fuse.

the class ProfileCompleter method complete.

@Override
public int complete(String buffer, int cursor, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    try {
        Version version = fabricService.getRequiredDefaultVersion();
        List<Profile> profiles = version.getProfiles();
        for (Profile profile : profiles) {
            delegate.getStrings().add(profile.getId());
        }
    } catch (Exception ex) {
    // Ignore Exceptions
    }
    return delegate.complete(buffer, cursor, candidates);
}
Also used : StringsCompleter(org.apache.karaf.shell.console.completer.StringsCompleter) Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Example 8 with StringsCompleter

use of org.apache.karaf.shell.console.completer.StringsCompleter in project fabric8 by jboss-fuse.

the class VersionCompleter method complete.

@Override
public int complete(String buffer, int cursor, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    List<String> versions = profileService.getVersions();
    for (String version : versions) {
        delegate.getStrings().add(version);
    }
    return delegate.complete(buffer, cursor, candidates);
}
Also used : ProfileService(io.fabric8.api.ProfileService) StringsCompleter(org.apache.karaf.shell.console.completer.StringsCompleter)

Example 9 with StringsCompleter

use of org.apache.karaf.shell.console.completer.StringsCompleter in project fabric8 by jboss-fuse.

the class AbstractProfileCompleter method complete.

@Override
public int complete(String buffer, int cursor, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    try {
        Version version = getFabricService().getRequiredDefaultVersion();
        Container container = getFabricService().getCurrentContainer();
        try {
            container = getFabricService().getContainer(getContainer(CommandSessionHolder.getSession(), containerArgumentIndex));
        } catch (Exception ex) {
        // Ignore and use current container.
        }
        Profile[] containerProfiles = container.getProfiles();
        List<String> containerProfileNames = new LinkedList<String>();
        if (containerProfiles != null) {
            for (Profile p : containerProfiles) {
                containerProfileNames.add(p.getId());
            }
        }
        List<Profile> profiles = version.getProfiles();
        List<String> allProfileNames = new LinkedList<String>();
        if (containerProfiles != null) {
            for (Profile p : profiles) {
                allProfileNames.add(p.getId());
            }
        }
        if (assigned && unassigned) {
            delegate.getStrings().addAll(allProfileNames);
        } else if (assigned) {
            delegate.getStrings().addAll(containerProfileNames);
        } else if (unassigned) {
            allProfileNames.removeAll(containerProfileNames);
            delegate.getStrings().addAll(allProfileNames);
        }
    } catch (Exception ex) {
    // Ignore Exceptions
    }
    return delegate.complete(buffer, cursor, candidates);
}
Also used : Container(io.fabric8.api.Container) StringsCompleter(org.apache.karaf.shell.console.completer.StringsCompleter) Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile) LinkedList(java.util.LinkedList)

Example 10 with StringsCompleter

use of org.apache.karaf.shell.console.completer.StringsCompleter in project karaf by apache.

the class ArgumentCompleter method getDefaultCompleter.

private Completer getDefaultCompleter(Field field) {
    Completer completer = null;
    Class<?> type = field.getType();
    if (type.isAssignableFrom(File.class)) {
        completer = new FileCompleter(null);
    } else if (type.isAssignableFrom(Boolean.class) || type.isAssignableFrom(boolean.class)) {
        completer = new StringsCompleter(new String[] { "false", "true" }, false);
    } else if (type.isAssignableFrom(Enum.class)) {
        Set<String> values = new HashSet<>();
        for (Object o : EnumSet.allOf((Class<Enum>) type)) {
            values.add(o.toString());
        }
        completer = new StringsCompleter(values, false);
    } else {
    // TODO any other completers we can add?
    }
    return completer;
}
Also used : FileCompleter(org.apache.karaf.shell.console.completer.FileCompleter) StringsCompleter(org.apache.karaf.shell.console.completer.StringsCompleter) FileCompleter(org.apache.karaf.shell.console.completer.FileCompleter) Completer(org.apache.karaf.shell.console.Completer) StringsCompleter(org.apache.karaf.shell.console.completer.StringsCompleter) NullCompleter(org.apache.karaf.shell.console.completer.NullCompleter) HashSet(java.util.HashSet)

Aggregations

StringsCompleter (org.apache.karaf.shell.console.completer.StringsCompleter)10 Profile (io.fabric8.api.Profile)2 Version (io.fabric8.api.Version)2 Container (io.fabric8.api.Container)1 ProfileService (io.fabric8.api.ProfileService)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 ScriptEngineFactory (javax.script.ScriptEngineFactory)1 Completer (org.apache.karaf.shell.console.Completer)1 FileCompleter (org.apache.karaf.shell.console.completer.FileCompleter)1 NullCompleter (org.apache.karaf.shell.console.completer.NullCompleter)1