form = new ModelNodeForm(address, securityContext);
List<FormItem> items = new ArrayList<FormItem>();
// each add operation requires an artificial parameter 'entity.key'
if("add".equals(operationmetaData.get("operation-name").asString()))
items.add(new TextBoxItem("entity.key", "Name", true));
for(Property param : parameterMetaData)
{
char[] stringArray = param.getName().toCharArray();
stringArray[0] = Character.toUpperCase(stringArray[0]);
String label = new String(stringArray).replace("-", " ");
ModelNode attrValue = param.getValue();
boolean required = param.getValue().get(REQUIRED).asBoolean();
// skip non-required parameters
if(!required) continue;
// help
helpTexts.appendHtmlConstant("<tr class='help-field-row'>");
helpTexts.appendHtmlConstant("<td class='help-field-name'>");
helpTexts.appendEscaped(label).appendEscaped(": ");
helpTexts.appendHtmlConstant("</td>");
helpTexts.appendHtmlConstant("<td class='help-field-desc'>");
try {
helpTexts.appendHtmlConstant(attrValue.get("description").asString());
} catch (Throwable e) {
// ignore parse errors
helpTexts.appendHtmlConstant("<i>Failed to parse description</i>");
}
helpTexts.appendHtmlConstant("</td>");
helpTexts.appendHtmlConstant("</tr>");
ModelType type = ModelType.valueOf(attrValue.get(TYPE).asString());
switch(type)
{
case BOOLEAN:
CheckBoxItem checkBoxItem = new CheckBoxItem(param.getName(), label);
items.add(checkBoxItem);
if(param.getValue().hasDefined(DEFAULT))
checkBoxItem.setValue(param.getValue().get(DEFAULT).asBoolean());
break;
case DOUBLE:
NumberBoxItem num = new NumberBoxItem(param.getName(), label);
num.setRequired(required);
items.add(num);
if(param.getValue().hasDefined(DEFAULT))
num.setValue(param.getValue().get(DEFAULT).asDouble());
break;
case LONG:
NumberBoxItem num2 = new NumberBoxItem(param.getName(), label);
num2.setRequired(required);
items.add(num2);
if(param.getValue().hasDefined(DEFAULT))
num2.setValue(param.getValue().get(DEFAULT).asLong());
break;
case INT:
NumberBoxItem num3 = new NumberBoxItem(param.getName(), label);
num3.setRequired(required);
items.add(num3);
if(param.getValue().hasDefined(DEFAULT))
num3.setValue(param.getValue().get(DEFAULT).asInt());
break;
case STRING:
if(attrValue.hasDefined("allowed"))
{
List<ModelNode> allowed = attrValue.get("allowed").asList();
Set<String> allowedValues = new HashSet<String>(allowed.size());
for(ModelNode value : allowed)
allowedValues.add(value.asString());
ComboBoxItem combo = new ComboBoxItem(param.getName(), label);
combo.setValueMap(allowedValues);
if(param.getValue().hasDefined(DEFAULT))
combo.setValue(param.getValue().get(DEFAULT).asString());
}
else
{
TextBoxItem tb = new TextBoxItem(param.getName(), label);
tb.setRequired(required);
items.add(tb);
if(param.getValue().hasDefined(DEFAULT))
tb.setValue(param.getValue().get(DEFAULT).asString());
}
break;
default: