Example usage for org.springframework.ide.eclipse.boot.wizard TypeRadioInfo setLabel

List of usage examples for org.springframework.ide.eclipse.boot.wizard TypeRadioInfo setLabel

Introduction

In this page you can find the example usage for org.springframework.ide.eclipse.boot.wizard TypeRadioInfo setLabel.

Prototype

public void setLabel(String label) 

Source Link

Usage

From source file:org.springframework.ide.eclipse.boot.wizard.NewSpringBootWizardModel.java

/**
 * Dynamically discover input fields and 'style' options by parsing initializr form.
 *///from   w w  w  .  j a v  a  2  s. c om
private void discoverOptions(FieldArrayModel<String> fields,
        HierarchicalMultiSelectionFieldModel<Dependency> dependencies) throws Exception {
    InitializrServiceSpec serviceSpec = parseJsonFrom(new URL(JSON_URL));

    Map<String, String> textInputs = serviceSpec.getTextInputs();
    for (Entry<String, String> e : KNOWN_STRING_INPUTS.entrySet()) {
        String name = e.getKey();
        String defaultValue = textInputs.get(name);
        if (defaultValue != null) {
            fields.add(new StringFieldModel(name, defaultValue).label(e.getValue()));
        }
    }

    { //field: type
        String groupName = "type";
        RadioGroup group = radioGroups.ensureGroup(groupName);
        group.label("Type:");
        for (Type type : serviceSpec.getTypeOptions(groupName)) {
            BuildType bt = KNOWN_TYPES.get(type.getId());
            if (bt != null) {
                for (ImportStrategy is : bt.getImportStrategies()) {
                    TypeRadioInfo radio = new TypeRadioInfo(groupName, type, is);
                    radio.setLabel(is.displayName());
                    group.add(radio);
                }
            }
        }
        //When a type is selected the 'baseUrl' should be update according to its action.
        group.getSelection().selection.addListener(new ValueListener<RadioInfo>() {
            public void gotValue(LiveExpression<RadioInfo> exp, RadioInfo value) {
                try {
                    if (value != null) {
                        URI base = new URI(JSON_URL);
                        URI resolved = base.resolve(((TypeRadioInfo) value).getAction());
                        baseUrl.setValue(resolved.toString());
                    }
                } catch (Exception e) {
                    BootWizardActivator.log(e);
                }
            }
        });
    }

    for (Entry<String, String> e : KNOWN_SINGLE_SELECTS.entrySet()) {
        String groupName = e.getKey();
        RadioGroup group = radioGroups.ensureGroup(groupName);
        group.label(e.getValue());
        addOptions(group, serviceSpec.getSingleSelectOptions(groupName));
        if (groupName.equals("bootVersion")) {
            this.bootVersion = group;
        }
    }

    //styles
    for (DependencyGroup dgroup : serviceSpec.getDependencies()) {
        String catName = dgroup.getName();
        for (Dependency dep : dgroup.getContent()) {
            dependencies.choice(catName, dep.getName(), dep, dep.getDescription(),
                    createEnablementExp(bootVersion, dep));
        }
    }
}