/**
* Dynamically discover input fields and 'style' options by parsing initializr form.
*/
private void discoverOptions(FieldArrayModel<String> fields, MultiSelectionFieldModel<String> style) throws Exception {
InitializrServiceSpec serviceSpec = parseJsonFrom(new URL(JSON_URL));
for (Entry<String, String> e : KNOWN_STRING_INPUTS.entrySet()) {
String name = e.getKey();
String defaultValue = serviceSpec.getDefaults().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.getTypes()) {
if (KNOWN_TYPES.containsKey(type.getId())) {
TypeRadioInfo radio = new TypeRadioInfo(groupName, type.getId(), type.isDefault(), type.getAction());
radio.setLabel(type.getName());
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) {
WizardPlugin.log(e);
}
}
});
}
{ //field: packaging
String groupName = "packaging";
RadioGroup group = radioGroups.ensureGroup(groupName);
group.label("Packaging:");
addOptions(group, serviceSpec.getPackagings());
}
{ //field: javaVersion
String groupName = "javaVersion";
RadioGroup group = radioGroups.ensureGroup(groupName);
group.label("Java Version:");
addOptions(group, serviceSpec.getJavaVersions());
}
{ //field: language
String groupName = "language";
RadioGroup group = radioGroups.ensureGroup(groupName);
group.label("Language:");
addOptions(group, serviceSpec.getLanguages());
}
{ //field: bootVersion
String groupName = "bootVersion";
RadioGroup group = radioGroups.ensureGroup(groupName);
group.label("Boot Version:");
addOptions(group, serviceSpec.getBootVersions());
}
//styles
for (DependencyGroup dgroup : serviceSpec.getDependencies()) {
for (Depependency dep : dgroup.getContent()) {
style.choice(dep.getName(), dep.getId(), dep.getDescription());
}
}
}