org.jboss.forge.addon.ui.input.UISelectOne Java Examples

The following examples show how to use org.jboss.forge.addon.ui.input.UISelectOne. 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: CamelCommandsHelper.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static Callable<Iterable<ComponentDto>> createAllComponentDtoValues(final Project project, final CamelCatalog camelCatalog,
                                                                        final UISelectOne<String> componentCategoryFilter,
                                                                        final boolean excludeComponentsOnClasspath) {
    // use callable so we can live update the filter
    return new Callable<Iterable<ComponentDto>>() {
        @Override
        public Iterable<ComponentDto> call() throws Exception {
            String label = componentCategoryFilter.getValue();
            return new CamelComponentsCompleter(project, camelCatalog, null, excludeComponentsOnClasspath, true, false, false, false).getValueChoices(label);
        }
    };
}
 
Example #3
Source File: CamelCommandsHelper.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static Callable<Iterable<ComponentDto>> createComponentDtoValues(final Project project, final CamelCatalog camelCatalog,
                                                                        final UISelectOne<String> componentCategoryFilter,
                                                                        final boolean excludeComponentsOnClasspath) {
    // use callable so we can live update the filter
    return new Callable<Iterable<ComponentDto>>() {
        @Override
        public Iterable<ComponentDto> call() throws Exception {
            String label = componentCategoryFilter != null ? componentCategoryFilter.getValue() : null;
            return new CamelComponentsCompleter(project, camelCatalog, null, excludeComponentsOnClasspath, false, false, false, false).getValueChoices(label);
        }
    };
}
 
Example #4
Source File: CamelCommandsHelper.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static Callable<Iterable<ComponentDto>> createComponentDtoValues(final Project project, final CamelCatalog camelCatalog,
                                                                        final UISelectOne<String> componentCategoryFilter,
                                                                        final boolean excludeComponentsOnClasspath,
                                                                        final boolean consumerOnly, final boolean producerOnly,
                                                                        final boolean mustHaveOptions) {
    // use callable so we can live update the filter
    return new Callable<Iterable<ComponentDto>>() {
        @Override
        public Iterable<ComponentDto> call() throws Exception {
            String label = componentCategoryFilter != null ? componentCategoryFilter.getValue() : null;
            return new CamelComponentsCompleter(project, camelCatalog, null, excludeComponentsOnClasspath, false, consumerOnly, producerOnly, mustHaveOptions).getValueChoices(label);
        }
    };
}
 
Example #5
Source File: CamelCommandsHelper.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static Callable<Iterable<EipDto>> createAllEipDtoValues(final Project project, final CamelCatalog camelCatalog, final UISelectOne<String> eipCategoryFilter) {
    // use callable so we can live update the filter
    return new Callable<Iterable<EipDto>>() {
        @Override
        public Iterable<EipDto> call() throws Exception {
            String label = eipCategoryFilter != null ? eipCategoryFilter.getValue() : null;
            return new CamelEipsCompleter(project, camelCatalog).getValueChoices(label);
        }
    };
}
 
Example #6
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 #7
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected void configureComponentName(Project project, final UISelectOne<ComponentDto> componentName, boolean consumerOnly, boolean producerOnly) throws Exception {

        // filter the list of components based on consumer and producer only
        Iterable<ComponentDto> it = CamelCommandsHelper.createComponentDtoValues(project, getCamelCatalog(), null, false, consumerOnly, producerOnly, false).call();
        final Map<String, ComponentDto> components = new LinkedHashMap<>();
        for (ComponentDto dto : it) {
            components.put(dto.getScheme(), dto);
        }

        componentName.setValueChoices(components.values());
        // include converter from string->dto
        componentName.setValueConverter(new Converter<String, ComponentDto>() {
            @Override
            public ComponentDto convert(String text) {
                return components.get(text);
            }
        });
        // show note about the chosen component
        componentName.addValueChangeListener(new ValueChangeListener() {
            @Override
            public void valueChanged(ValueChangeEvent event) {
                ComponentDto component = (ComponentDto) event.getNewValue();
                if (component != null) {
                    String description = component.getDescription();
                    componentName.setNote(description != null ? description : "");
                } else {
                    componentName.setNote("");
                }
            }
        });
    }
 
Example #8
Source File: CamelProjectAddComponentStep.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public CamelProjectAddComponentStep(UISelectOne<String> filter, UISelectOne<ComponentDto> componentName, ProjectFactory projectFactory,
                                    DependencyInstaller dependencyInstaller, CamelCatalog camelCatalog) {
    this.filter = filter;
    this.componentName = componentName;
    this.projectFactory = projectFactory;
    this.dependencyInstaller = dependencyInstaller;
    this.camelCatalog = camelCatalog;
}
 
Example #9
Source File: NodeDtoConverter.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
public NodeDtoConverter(CamelCatalog camelCatalog, Project project, UIContext context, UISelectOne<String> xml) {
    this.camelCatalog = camelCatalog;
    this.project = project;
    this.context = context;
    this.xml = xml;
}
 
Example #10
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);
    }
}