List<String> tableActions = get(this.actionsForItem, "TableLayoutMenuItem");
List<String> labelActions = get(this.actionsForItem, "LabelMenuItem");
List<String> textfieldActions = get(this.actionsForItem, "TextFieldMenuItem");
List<String> completeButtonActions = get(this.actionsForItem, "CompleteButtonMenuItem");
FormRepresentation form = new FormRepresentation();
form.setInputs(toInputDataMap(task.getInputs()));
form.setOutputs(toOutputDataMap(task.getOutputs()));
if (task.getTaskId() != null) {
HeaderRepresentation header = new HeaderRepresentation();
header.setValue("Task: " + task.getTaskId());
header.setEffectClasses(headerEffects);
header.setEventActions(asMapOfNull(headerActions, FBScript.class));
form.addFormItem(header);
}
List<TaskPropertyRef> inputs = task.getInputs();
if (inputs != null && !inputs.isEmpty()) {
TableRepresentation tableOfInputs = new TableRepresentation();
tableOfInputs.setRows(inputs.size());
tableOfInputs.setColumns(2);
tableOfInputs.setHeight("" + (inputs.size() * 30) + "px");
tableOfInputs.setEffectClasses(tableEffects);
tableOfInputs.setEventActions(asMapOfNull(tableActions, FBScript.class));
for (int index = 0; index < inputs.size(); index++) {
TaskPropertyRef input = inputs.get(index);
LabelRepresentation labelName = new LabelRepresentation();
labelName.setEventActions(asMapOfNull(labelActions, FBScript.class));
labelName.setEffectClasses(labelEffects);
labelName.setValue(input.getName());
labelName.setWidth("100px");
tableOfInputs.setElement(index, 0, labelName);
LabelRepresentation labelValue = new LabelRepresentation();
labelValue.setEventActions(asMapOfNull(labelActions, FBScript.class));
labelValue.setEffectClasses(labelEffects);
labelValue.setWidth("200px");
InputData data = new InputData();
data.setName(input.getName());
data.setValue(input.getSourceExpresion());
data.setMimeType("multipart/form-data");
data.setFormatter(new Formatter() {
@Override
public Object format(Object object) {
return object;
}
@Override
public Map<String, Object> getDataMap() {
return new HashMap<String, Object>();
}
});
labelValue.setInput(data);
labelValue.setValue("{variable}");
tableOfInputs.setElement(index, 1, labelValue);
}
LabelRepresentation labelInputs = new LabelRepresentation();
labelInputs.setEventActions(asMapOfNull(labelActions, FBScript.class));
labelInputs.setEffectClasses(labelEffects);
labelInputs.setValue("Inputs:");
form.addFormItem(labelInputs);
form.addFormItem(tableOfInputs);
}
List<TaskPropertyRef> outputs = task.getOutputs();
if (outputs != null && !outputs.isEmpty()) {
TableRepresentation tableOfOutputs = new TableRepresentation();
tableOfOutputs.setRows(outputs.size());
tableOfOutputs.setColumns(2);
tableOfOutputs.setHeight("" + (outputs.size() * 30) + "px");
tableOfOutputs.setEffectClasses(tableEffects);
tableOfOutputs.setEventActions(asMapOfNull(tableActions, FBScript.class));
for (int index = 0; index < outputs.size(); index++) {
TaskPropertyRef output = outputs.get(index);
LabelRepresentation labelName = new LabelRepresentation();
labelName.setEventActions(asMapOfNull(labelActions, FBScript.class));
labelName.setEffectClasses(labelEffects);
labelName.setValue(output.getName());
labelName.setWidth("100px");
tableOfOutputs.setElement(index, 0, labelName);
TextFieldRepresentation textField = new TextFieldRepresentation();
textField.setEventActions(asMapOfNull(textfieldActions, FBScript.class));
textField.setWidth("200px");
textField.setEffectClasses(textfieldEffects);
OutputData data = new OutputData();
data.setName(output.getName());
data.setValue(output.getSourceExpresion());
data.setMimeType("multipart/form-data");
data.setFormatter(new Formatter() {
@Override
public Object format(Object object) {
return object;
}
@Override
public Map<String, Object> getDataMap() {
return new HashMap<String, Object>();
}
});
textField.setOutput(data);
tableOfOutputs.setElement(index, 1, textField);
}
LabelRepresentation labelOutputs = new LabelRepresentation();
labelOutputs.setEventActions(asMapOfNull(labelActions, FBScript.class));
labelOutputs.setEffectClasses(labelEffects);
labelOutputs.setValue("Outputs:");
form.addFormItem(labelOutputs);
form.addFormItem(tableOfOutputs);
}
CompleteButtonRepresentation completeButton = new CompleteButtonRepresentation();
completeButton.setText("Complete");
completeButton.setEffectClasses(completeButtonEffects);
completeButton.setEventActions(asMapOfNull(completeButtonActions, FBScript.class));
form.addFormItem(completeButton);
form.setAction("complete");
form.setEnctype("multipart/form-data");
form.setMethod("POST");
form.setName(task.getTaskId() + "AutoForm");
form.setProcessName(task.getProcessId());
form.setTaskId(task.getTaskId());
return form;
}