imports.addImport(field.getEditorDef().getUseClass(), "Editor");
imports.addImport(field.getAttrDef().getDefinedIn().getDMSASGImport(),"Required schema");
}
ClassDefinition cd = (ClassDefinition) binding.getEditObject();
imports.addImport(cd.getDefinedIn().getSchemaPackage() + ".generated.dmo." + cd.getName() + "DMO", "For the object we're editting");
out.write("package " + genPackage + ".generated.mvw.forms;\n\n");
out.write(imports.getFormattedImports() + "\n");
out.write("// " + DebugInfo.getWhereWeAreNow() + "\n");
out.write("public class " + name + " {\n\n");
out.write(" " + cd.getName() + "DMO dmo;\n\n");
out.write(" // If the object set on the binding doesn't have a name, it is considered a new object\n");
out.write(" boolean isNewObject;\n\n");
out.write(" DmcPresentationTrackerIF tracker;\n\n");
for(EditField field: binding.getEditFieldIterable()){
out.write(getDeclaration(field));
}
out.write("\n");
out.write(" // " + DebugInfo.getWhereWeAreNow() + "\n");
out.write(" public " + name + "(){\n");
out.write("\n");
out.write(" isNewObject = false;\n\n");
for(EditField field: binding.getEditFieldIterable()){
out.write(getInstantiation(field));
}
out.write(" }\n\n");
///////////////////////////////////////////////////////////////////////
if (binding.getEditObject().getIsNamedBy() != null){
out.write(" // " + DebugInfo.getWhereWeAreNow() + "\n");
out.write(" public boolean isNewObject(){\n");
out.write(" return(isNewObject);\n");
out.write(" }\n\n");
}
///////////////////////////////////////////////////////////////////////
out.write(" // " + DebugInfo.getWhereWeAreNow() + "\n");
out.write(" public void setObject(" + cd.getName() + "DMO obj){\n");
out.write(" dmo = obj;\n\n");
if (binding.getEditObject().getIsNamedBy() != null){
out.write(" if (obj instanceof DmcNamedObjectIF){\n");
out.write(" if (((DmcNamedObjectIF)obj).getObjectName() == null)\n");
out.write(" isNewObject = true;\n");
out.write(" }\n");
}
for(EditField field: binding.getEditFieldIterable()){
out.write(getSetDMO(field));
}
out.write("\n");
for(EditField field: binding.getEditFieldIterable()){
out.write(getSetAdapter(field));
}
out.write("\n");
out.write(" tracker.reset();\n");
out.write(" }\n\n");
///////////////////////////////////////////////////////////////////////
out.write(" // " + DebugInfo.getWhereWeAreNow() + "\n");
out.write(" public void setTracker(DmcPresentationTrackerIF t){\n");
out.write(" tracker = t;\n");
out.write("\n");
for(EditField field: binding.getEditFieldIterable()){
out.write(getSetTracker(field));
}
out.write(" }\n\n");
///////////////////////////////////////////////////////////////////////
out.write(" // " + DebugInfo.getWhereWeAreNow() + "\n");
out.write(" public void setEnabledAll(boolean enabled){\n");
for(EditField field: binding.getEditFieldIterable()){
out.write(getSetEnabled(field));
}
out.write(" }\n\n");
///////////////////////////////////////////////////////////////////////
if (binding.getEditObject().getIsNamedBy() == null){
out.write(" // " + DebugInfo.getWhereWeAreNow() + "\n");
out.write(" public " + cd.getName() + "DMO getModifiedObject(){\n");
out.write(" if (dmo == null)\n");
out.write(" return(null);\n\n");
out.write(" " + cd.getName() + "DMO modrec = (" + cd.getName() + "DMO) dmo.getNew();\n");
out.write(" modrec.setModifier(new DmcTypeModifierMV(MetaDMSAG.__modify));\n");
out.write("\n");
out.write(" if (dmo instanceof DmcNamedObjectIF){\n");
out.write(" DmcNamedObjectIF origObj = (DmcNamedObjectIF) dmo;\n");
out.write(" try {\n");
out.write(" modrec.set(origObj.getObjectNameAttribute().getAttributeInfo(), origObj.getObjectNameAttribute());\n");
out.write(" } catch (DmcValueException e) {\n");
out.write(" e.printStackTrace();\n");
out.write(" }\n");
out.write(" }\n\n");
for(EditField field: binding.getEditFieldIterable()){
out.write(getAddMods(field));// out.write(" " + field.getAttribute() + "Adapter.addMods(modrec.getModifier());\n");
}
out.write("\n");
out.write(" " + cd.getName() + "DMO rc = (" + cd.getName() + "DMO) dmo.cloneIt();\n");
out.write("\n");
out.write(" try {\n");
out.write(" rc.applyModifier(modrec.getModifier());\n");
out.write(" } catch(Exception ex){\n");
out.write(" throw(new IllegalStateException(\"Shouldn't thrown an exception when modifying an object.\", ex));\n");
out.write(" }\n");
out.write(" \n");
out.write(" return(rc);\n");
out.write(" }\n\n");
}
else{
out.write(" // " + DebugInfo.getWhereWeAreNow() + "\n");
out.write(" public " + cd.getName() + "DMO getModRec(){\n");
out.write(" if (dmo == null)\n");
out.write(" return(null);\n");
out.write("\n");
out.write(" if (isNewObject)\n");
out.write(" throw(new IllegalStateException(\"You are dealing with a new object, call getModifiedObject(), not getModRec()\"));\n");
out.write("\n");
out.write(" " + cd.getName() + "DMO modrec = dmo.getModificationRecorder();\n");
out.write("\n");
for(EditField field: binding.getEditFieldIterable()){
out.write(getAddMods(field));// out.write(" " + field.getAttribute() + "Adapter.addMods(modrec.getModifier());\n");
}
out.write("\n");
out.write(" return(modrec);\n");
out.write(" }\n\n");
///////////////////////////////////////////////////////////////////
out.write(" // " + DebugInfo.getWhereWeAreNow() + "\n");
out.write(" public " + cd.getName() + "DMO getModifiedObject(){\n");
out.write(" if (dmo == null)\n");
out.write(" return(null);\n");
out.write("\n");
out.write(" " + cd.getName() + "DMO modrec = (" + cd.getName() + "DMO) dmo.getNew();\n");
out.write(" modrec.setModifier(new DmcTypeModifierMV(MetaDMSAG.__modify));\n\n");
for(EditField field: binding.getEditFieldIterable()){
out.write(getAddMods(field));// out.write(" " + field.getAttribute() + "Adapter.addMods(modrec.getModifier());\n");
}
out.write("\n");
out.write(" " + cd.getName() + "DMO rc = (" + cd.getName() + "DMO) dmo.cloneIt();\n");
out.write("\n");
out.write(" try {\n");
out.write(" rc.applyModifier(modrec.getModifier());\n");
out.write(" } catch(DmcValueExceptionSet ex){\n");
out.write(" throw(new IllegalStateException(\"Your form should not permit invalid data\", ex));\n");