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

The following examples show how to use org.jboss.forge.addon.ui.input.UISelectMany. 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: ProjectGenerator.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
public void createNewSpringBootProject() throws Exception {

        LOG.info("Creating new project");

        String name = "my-project";

        RestUIContext context = new RestUIContext();
        UICommand projectNewCommand = commandFactory.getCommandByName(context, "project-new");

        File outputDir = projectsOutputFolder;
        outputDir.mkdirs();

        CommandController controller = commandControllerFactory.createController(context, runtime, projectNewCommand);
        controller.initialize();

        controller.setValueFor("named", name);
        controller.setValueFor("topLevelPackage", "org.example");
        controller.setValueFor("version", "1.0.0-SNAPSHOT");
        controller.setValueFor("targetLocation", outputDir.getAbsolutePath());
        controller.setValueFor("buildSystem", "Maven");
        controller.setValueFor("type", "Spring Boot");

        WizardCommandController wizardCommandController = assertWizardController(controller);
        validate(wizardCommandController);
        wizardCommandController = wizardCommandController.next();
        LOG.info("Next result: " + wizardCommandController);

        wizardCommandController.setValueFor("springBootVersion", "1.3.7");

        // due to furnace/forge classloading we need to find the dto from the existing choices
        // and then select the dependencies we want to use
        SpringBootDependencyDTO web = null;
        UISelectMany many = (UISelectMany) wizardCommandController.getInput("dependencies");
        for (Object c : many.getValueChoices()) {
            SpringBootDependencyDTO dto = (SpringBootDependencyDTO) c;
            if ("web".equals(dto.getId())) {
                web = dto;
                break;
            }
        }

        wizardCommandController.setValueFor("dependencies", web);

        validate(wizardCommandController);
        try {

            Result result = wizardCommandController.execute();
            printResult(result);

            useNewProject(outputDir, name);
        } catch (Exception e) {
            LOG.error("Failed to create project " + name + " " + e, e);
        }
    }
 
Example #2
Source File: AddFractionCommand.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @return the fractionElements
 */
public UISelectMany<FractionDescriptor> getFractionElements()
{
    return fractionElements;
}
 
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);
    }
}