}
valuesSourcecode.addLn(valuesBody);
// actionPerformed for ControllerDelegate
BoostedStringBuilder actionPerformedMethod = new BoostedStringBuilder(
new StringBuilder());
actionPerformedMethod.addLn("@Override");
actionPerformedMethod
.addLn("public void actionPerformed(java.awt.event.ActionEvent event) {");
actionPerformedMethod.addLn(" try {");
actionPerformedMethod
.addLn("String command = event.getActionCommand();");
actionPerformedMethod.addLn("if (command == null ){");
actionPerformedMethod
.addLn(" throw new NullPointerException(\"command must not be null\");");
actionPerformedMethod.addLn("}");
String delegateName = "delegate";
controllerDelegateSourcecode.add("private ",
controllerSourcecode.getName(), " ", delegateName, ";\n");
controllerDelegateSourcecode.add("public ",
controllerDelegateSourcecode.getName(), " (",
controllerSourcecode.getName(), " ",
delegateName, " ){\n");
controllerDelegateSourcecode.add("this.", delegateName, "= ",
delegateName, ";\n");
controllerDelegateSourcecode.add("}\n");
for (ObjectDescription action : appDescription.getActions()) {
String name = action.getName();
String description = action.getDescription();
Check.notNull(name, "action.getName()");
// define the constant
JavaFeatureDescription constantDescription = appendConstant(constantsSourcecode.getBuilder(), "Action " + name,
action.getName(), description, String.class);
// define the abstract method
JavaFeatureDescription methodDesc = JavaFeatureDescription
.createVoidInterfaceMethod(name, description);
appendMethod(controllerSourcecode, methodDesc);
String methodname = methodDesc.getName();
// implement the delegate method
methodDesc.setDelegateName(delegateName);
methodDesc.setInterface(false);
appendMethod(controllerDelegateSourcecode, methodDesc);
actionPerformedMethod.addLn(" else if (",
constantsSourcecode.getName(), ".",
constantDescription.getName(), ".equals(command)){");
actionPerformedMethod.addLn(" ", methodname, "();");
actionPerformedMethod.addLn("}");
}
for (ObjectDescription value : appDescription.getValues()) {
appendConstant(constantsSourcecode.getBuilder(),
"Value " + value.getName(),
value.getName(), value.getDescription(), String.class);
}
actionPerformedMethod.addLn(" else {");
actionPerformedMethod
.addLn(" throw new IllegalStateException(\"command \" + command + \" not supported\");");
actionPerformedMethod.addLn(" }");
actionPerformedMethod.addLn(" } catch (Exception exception){");
actionPerformedMethod
.addLn(" throw net.sf.gluebooster.java.booster.essentials.utils.ThrowableBoostUtils.toRuntimeException(exception);");
actionPerformedMethod.addLn(" } ");
endBraces(actionPerformedMethod.getBuilder());
controllerDelegateSourcecode.add(actionPerformedMethod.getBuilder());
for (BoostedStringBuilder<String, JavaFeatureDescription> builder : result) {
endBraces(builder.getBuilder());
}