Example usage for org.springframework.ide.eclipse.boot.wizard RadioGroup add

List of usage examples for org.springframework.ide.eclipse.boot.wizard RadioGroup add

Introduction

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

Prototype

public void add(RadioInfo radioInfo) 

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.
 *///  w  w w  .  j av a  2  s.  c  o m
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));
        }
    }
}

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

private void addOptions(RadioGroup group, Option[] options) {
    for (Option option : options) {
        RadioInfo radio = new RadioInfo(group.getName(), option.getId(), option.isDefault());
        radio.setLabel(option.getName());
        group.add(radio);
    }/*from  w ww .  java  2 s  . c o m*/
}