Java Code Examples for org.jboss.forge.addon.ui.input.UISelectOne#setDefaultValue()

The following examples show how to use org.jboss.forge.addon.ui.input.UISelectOne#setDefaultValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected String configureXml(Project project, UISelectOne<String> xml, String currentFile) {
    XmlFileCompleter xmlFileCompleter = createXmlFileCompleter(project, null);
    Set<String> files = xmlFileCompleter.getFiles();

    // use value choices instead of completer as that works better in web console
    final String first = first(files);
    String answer = first;

    xml.setValueChoices(files);
    if (files.size() == 1) {
        // lets default the value if there's only one choice
        xml.setDefaultValue(first);
    } else if (currentFile != null) {
        // lets default to the current file
        for (String name : files) {
            if (currentFile.endsWith(name)) {
                xml.setDefaultValue(name);
                answer = name;
                break;
            }
        }
    }
    return answer;
}
 
Example 2
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected String configureRouteBuilder(Project project, UISelectOne<String> routeBuilders, String currentFile) {
    RouteBuilderCompleter completer = createRouteBuilderCompleter(project);
    Set<String> builders = completer.getRouteBuilders();

    // use value choices instead of completer as that works better in web console
    final String first = first(builders);
    String answer = first;

    routeBuilders.setValueChoices(builders);
    if (builders.size() == 1) {
        // lets default the value if there's only one choice
        routeBuilders.setDefaultValue(first);
    } else if (currentFile != null) {
        // lets default to the current file
        if (currentFile.endsWith(".java")) {
            currentFile = currentFile.substring(0, currentFile.length() - 5);
        }
        for (String name : builders) {
            if (currentFile.endsWith(name)) {
                routeBuilders.setDefaultValue(name);
                answer = name;
                break;
            }
        }
    }
    return answer;
}
 
Example 3
Source File: WindupCommand.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private void initializeConfigurationOptionComponents(UIBuilder builder)
{
    for (final ConfigurationOption option : WindupConfiguration.getWindupConfigurationOptions())
    {
        InputComponent<?, ?> inputComponent = null;
        switch (option.getUIType())
        {
        case SINGLE:
        {
            UIInput<?> inputSingle = componentFactory.createInput(option.getName(), option.getType());
            inputSingle.setDefaultValue(new DefaultValueAdapter(option));
            inputComponent = inputSingle;
            break;
        }
        case MANY:
        {
            // forge can't handle "Path", so use File
            Class<?> optionType = option.getType() == Path.class ? File.class : option.getType();

            UIInputMany<?> inputMany = componentFactory.createInputMany(option.getName(), optionType);
            inputMany.setDefaultValue(new DefaultValueAdapter(option, Iterable.class));
            inputComponent = inputMany;
            break;
        }
        case SELECT_MANY:
        {
            UISelectMany<?> selectMany = componentFactory.createSelectMany(option.getName(), option.getType());
            selectMany.setValueChoices((Iterable) option.getAvailableValues());
            selectMany.setDefaultValue(new DefaultValueAdapter(option, Iterable.class));
            inputComponent = selectMany;
            break;
        }
        case SELECT_ONE:
        {
            UISelectOne<?> selectOne = componentFactory.createSelectOne(option.getName(), option.getType());
            selectOne.setValueChoices((Iterable) option.getAvailableValues());
            selectOne.setDefaultValue(new DefaultValueAdapter(option));
            inputComponent = selectOne;
            break;
        }
        case DIRECTORY:
        {
            UIInput<DirectoryResource> directoryInput = componentFactory.createInput(option.getName(),
                        DirectoryResource.class);
            directoryInput.setDefaultValue(new DefaultValueAdapter(option, DirectoryResource.class));
            inputComponent = directoryInput;
            break;
        }
        case FILE:
        {
            UIInput<?> fileInput = componentFactory.createInput(option.getName(), FileResource.class);
            fileInput.setDefaultValue(new DefaultValueAdapter(option, FileResource.class));
            inputComponent = fileInput;
            break;
        }
        case FILE_OR_DIRECTORY:
        {
            UIInput<?> fileOrDirInput = componentFactory.createInput(option.getName(), FileResource.class);
            fileOrDirInput.setDefaultValue(new DefaultValueAdapter(option, FileResource.class));
            inputComponent = fileOrDirInput;
            break;
        }
        }
        if (inputComponent == null)
        {
            throw new IllegalArgumentException("Could not build input component for: " + option);
        }
        inputComponent.setLabel(option.getLabel());
        inputComponent.setRequired(option.isRequired());
        inputComponent.setDescription(option.getDescription());
        builder.add(inputComponent);
        inputOptions.put(option, inputComponent);
    }
}