// Get List of script extensions from installed plugins
final List<String> extensions = getExtensions();
// Content
String mode = extensions.size() > 0 ? getModeFromExtension(extensions.get(0)) : "py";
final CodeMirrorEditor content = new CodeMirrorEditor("contents", mode, new PropertyModel(script, "contents"));
content.setRequired(true);
form.add(content);
// Name
TextField name = new TextField("name", new PropertyModel(script, "name"));
name.setRequired(true);
form.add(name);
// Type
DropDownChoice<String> typeDropDownChoice = new DropDownChoice<String>("type",
new PropertyModel(script, "type"), new LoadableDetachableModel<List<String>>() {
@Override
protected List<String> load() {
List<String> values = Lists.newArrayList();
for (ScriptType type : ScriptType.values()) {
values.add(type.getLabel());
}
return values;
}
});
typeDropDownChoice.setRequired(true);
form.add(typeDropDownChoice);
// Extension
final DropDownChoice<String> extensionDropDownChoice = new DropDownChoice<String>("extension",
new PropertyModel(script, "extension"),
new LoadableDetachableModel<List<String>>() {
@Override
protected List<String> load() {
return extensions;
}
}
);
extensionDropDownChoice.setRequired(true);
extensionDropDownChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
int i = Integer.parseInt(extensionDropDownChoice.getValue());
String ext = extensions.get(i);
String mode = getModeFromExtension(ext);
content.setMode(mode);
}
});
form.add(extensionDropDownChoice);
SubmitLink submitLink = new SubmitLink("submit", form);