Skip to content

Commit 87e0406

Browse files
author
Open Lowcode SAS
committed
Close #244
1 parent 054198b commit 87e0406

5 files changed

Lines changed: 309 additions & 90 deletions

File tree

src/org/openlowcode/design/data/DataObjectDefinition.java

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,12 +2284,27 @@ public void generateAutomaticPagesAndActions(Module module) {
22842284
|| (this.isShowActionAutomaticallyGenerated())) {
22852285
module.addAction(this.generatePrepareStandardCreateAction());
22862286
module.addAction(this.generateStandardCreateAction());
2287-
2287+
2288+
if (this.getPropertyByName("TYPED") != null) {
2289+
Typed typed = (Typed) (this.getPropertyByName("TYPED"));
2290+
for (int i = 0; i < typed.getCompanionNumber(); i++) {
2291+
DataObjectDefinition companion = typed.getCompanion(i);
2292+
module.addAction(generatePrepareStandardCreateAction(companion));
2293+
module.addAction(generateStandardCreateAction(companion));
2294+
}
2295+
}
2296+
22882297
this.addActionOnObjectPageOnManageMenu(this.generateDuplicateAction(),
22892298
"Create new " + this.getLabel() + " with similar data");
22902299
module.AddPage(this.generateStandardCreatePage());
2300+
if (this.getPropertyByName("TYPED") != null) {
2301+
Typed typed = (Typed) (this.getPropertyByName("TYPED"));
2302+
for (int i = 0; i < typed.getCompanionNumber(); i++) {
2303+
DataObjectDefinition companion = typed.getCompanion(i);
2304+
module.AddPage(this.generateStandardCreatePage(companion));
2305+
}
2306+
}
22912307
}
2292-
22932308
for (int i = 0; i < this.propertylist.getSize(); i++) {
22942309
Property<?> thisproperty = this.propertylist.get(i);
22952310

@@ -2450,9 +2465,12 @@ private ActionDefinition generateLaunchSearchAction() {
24502465
return launchsearch;
24512466
}
24522467

2453-
private PageDefinition generateStandardCreatePage() {
2468+
private PageDefinition generateStandardCreatePage(DataObjectDefinition companion) {
2469+
2470+
String actionname = this.getName().toUpperCase();
2471+
if (companion!=null) actionname = companion.getName().toUpperCase();
24542472
DynamicPageDefinition standardcreatepage = new DynamicPageDefinition(
2455-
"STANDARDCREATE" + this.getName().toUpperCase());
2473+
"STANDARDCREATE" + actionname);
24562474
for (int i = 0; i < this.propertylist.getSize(); i++) {
24572475
Property<?> property = this.propertylist.get(i);
24582476
for (int j = 0; j < property.getContextDataForCreationSize(); j++) {
@@ -2477,8 +2495,16 @@ private PageDefinition generateStandardCreatePage() {
24772495
}
24782496
}
24792497
standardcreatepage.addInputParameter(new ObjectArgument("object", this));
2498+
if (companion!=null) {
2499+
standardcreatepage.addInputParameter(new ObjectArgument("COMPANION",companion));
2500+
2501+
}
24802502
return standardcreatepage;
24812503
}
2504+
2505+
private PageDefinition generateStandardCreatePage() {
2506+
return generateStandardCreatePage(null);
2507+
}
24822508

24832509
private ActionDefinition generateCreateLinkAndRightObjectAction(LinkObject<?, ?> linkobjectproperty) {
24842510
DynamicActionDefinition createlinkandrightobject = new DynamicActionDefinition(
@@ -2530,18 +2556,22 @@ private DynamicActionDefinition generateDuplicateAction() {
25302556
return duplicateaction;
25312557
}
25322558

2533-
private ActionDefinition generateStandardCreateAction() {
2559+
private ActionDefinition generateStandardCreateAction(DataObjectDefinition companion) {
25342560
DynamicActionDefinition standardcreationaction = new DynamicActionDefinition(
2535-
"STANDARDCREATE" + this.getName().toUpperCase(), true);
2561+
"STANDARDCREATE" + (companion==null?this.getName().toUpperCase():companion.getName().toUpperCase()), true);
25362562
addAttributesToCreateobject(standardcreationaction, this);
2563+
if (companion!=null) standardcreationaction.addInputArgument(new ObjectArgument("COMPANION",companion));
25372564
standardcreationaction.addOutputArgument(new ObjectIdArgument("createdobjectid", this));
25382565
this.addActionToCreateNewGroup(standardcreationaction);
25392566
return standardcreationaction;
25402567
}
2568+
private ActionDefinition generateStandardCreateAction() {
2569+
return generateStandardCreateAction(null);
2570+
}
25412571

2542-
private ActionDefinition generatePrepareStandardCreateAction() {
2572+
private ActionDefinition generatePrepareStandardCreateAction(DataObjectDefinition companion) {
25432573
DynamicActionDefinition preparestandardcreationaction = new DynamicActionDefinition(
2544-
"PREPARESTANDARDCREATE" + this.getName().toUpperCase(), true);
2574+
"PREPARESTANDARDCREATE" + (companion==null?this.getName().toUpperCase():companion.getName().toUpperCase()), true);
25452575
// -- contextattributes
25462576
for (int i = 0; i < this.propertylist.getSize(); i++) {
25472577
Property<?> property = this.propertylist.get(i);
@@ -2580,10 +2610,15 @@ private ActionDefinition generatePrepareStandardCreateAction() {
25802610
}
25812611
}
25822612
}
2583-
preparestandardcreationaction.addOutputArgument(new ObjectArgument("object", this));
2613+
preparestandardcreationaction.addOutputArgument(new ObjectArgument("OBJECT", this));
2614+
if (companion!=null) preparestandardcreationaction.addOutputArgument(new ObjectArgument("COMPANION", companion));
25842615
this.addActionToCreateNewGroup(preparestandardcreationaction);
25852616
return preparestandardcreationaction;
25862617
}
2618+
2619+
private ActionDefinition generatePrepareStandardCreateAction() {
2620+
return generatePrepareStandardCreateAction(null);
2621+
}
25872622

25882623
private PageDefinition generateSearchPage() {
25892624
return this.searchpagesandactions.generateSearchPage();

src/org/openlowcode/design/data/DataObjectDefinitionCreatePageToFile.java

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class DataObjectDefinitionCreatePageToFile
3737
implements
3838
GeneratedPages {
3939
private DataObjectDefinition dataobject;
40+
private DataObjectDefinition companion;
4041

4142
/**
4243
* creates the utility class to generate the creation page
@@ -45,13 +46,33 @@ public class DataObjectDefinitionCreatePageToFile
4546
*/
4647
public DataObjectDefinitionCreatePageToFile(DataObjectDefinition dataobject) {
4748
this.dataobject = dataobject;
49+
this.companion=null;
50+
}
51+
52+
53+
/**
54+
* creates the utility class to generate the creation page
55+
*
56+
* @param dataobject data object
57+
*/
58+
public DataObjectDefinitionCreatePageToFile(DataObjectDefinition dataobject,DataObjectDefinition companion) {
59+
this.dataobject = dataobject;
60+
this.companion=companion;
4861
}
4962

5063
@Override
5164
public void generateToFile(SourceGenerator sg, Module module) throws IOException {
5265
String objectclass = StringFormatter.formatForJavaClass(dataobject.getName());
5366
String objectvariable = StringFormatter.formatForAttribute(dataobject.getName());
5467

68+
String pagename = objectvariable;
69+
String companionclass = null;
70+
71+
if (companion!=null) {
72+
pagename = StringFormatter.formatForAttribute(companion.getName());
73+
companionclass = StringFormatter.formatForJavaClass(companion.getName());
74+
}
75+
5576
sg.wl("package " + module.getPath() + ".page.generated;");
5677
sg.wl("");
5778

@@ -131,6 +152,14 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
131152
String objectimport = "import " + dataobject.getOwnermodule().getPath() + ".data." + objectclass + ";";
132153
importdeclaration.put(objectimport, objectimport);
133154

155+
if (companion!=null) {
156+
String companionimport = "import " + companion.getOwnermodule().getPath() + ".data." + companionclass + ";";
157+
158+
importdeclaration.put(companionimport, companionimport);
159+
String companioncreateaction = "import gallium.test.action.generated.AtgStandardcreate"+companion.getName().toLowerCase()+"Action;";
160+
importdeclaration.put(companioncreateaction, companioncreateaction);
161+
}
162+
134163
for (int i = 0; i < dataobject.propertylist.getSize(); i++) {
135164
Property<?> thisproperty = dataobject.propertylist.get(i);
136165
if (thisproperty instanceof LinkedToParent) {
@@ -179,8 +208,8 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
179208
sg.wl("import org.openlowcode.server.graphic.widget.SObjectSearcher;");
180209
sg.wl("import org.openlowcode.server.graphic.widget.SPageText;");
181210
sg.wl("");
182-
sg.wl("public class AtgStandardcreate" + objectvariable + "Page extends");
183-
sg.wl(" AbsStandardcreate" + objectvariable + "Page {");
211+
sg.wl("public class AtgStandardcreate" + pagename + "Page extends");
212+
sg.wl(" AbsStandardcreate" + pagename + "Page {");
184213
for (int i = 0; i < dataobject.propertylist.getSize(); i++)
185214
for (int j = 0; j < dataobject.propertylist.get(i).getContextDataForCreationSize(); j++) {
186215
ArgumentContent contextfordatacreation = dataobject.propertylist.get(i).getContextDataForCreation(j);
@@ -199,15 +228,15 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
199228

200229
sg.wl(" @Override");
201230
sg.wl(" public String generateTitle(" + pageattributedeclaration.toString());
202-
sg.wl(" " + objectclass + " object) {");
231+
sg.wl(" " + objectclass + " object"+(companion!=null?", "+companionclass+" companion":"")+") {");
203232
sg.wl(" return \"Create " + dataobject.getLabel() + "\";");
204233
sg.wl(" }");
205234

206-
sg.wl(" public AtgStandardcreate" + objectvariable + "Page(" + pageattributedeclaration.toString());
207-
sg.wl(" " + objectclass + " object) {");
235+
sg.wl(" public AtgStandardcreate" + pagename + "Page(" + pageattributedeclaration.toString());
236+
sg.wl(" " + objectclass + " object"+(companion!=null?", "+companionclass+" companion":"")+") {");
208237

209238
sg.wl(" super(" + pageattributeentry.toString());
210-
sg.wl(" object);");
239+
sg.wl(" object"+(companion!=null?",companion":"")+");");
211240
sg.wl(" ");
212241
for (int i = 0; i < dataobject.propertylist.getSize(); i++)
213242
for (int j = 0; j < dataobject.propertylist.get(i).getContextDataForCreationSize(); j++) {
@@ -227,8 +256,8 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
227256
sg.wl(" ");
228257
sg.wl(" SComponentBand mainband = new SComponentBand(SComponentBand.DIRECTION_DOWN,this);");
229258

230-
sg.wl(" AtgStandardcreate" + objectvariable + "Action.ActionRef create" + objectvariable
231-
+ "actionref = AtgStandardcreate" + objectvariable + "Action.get().getActionRef();");
259+
sg.wl(" AtgStandardcreate" + pagename + "Action.ActionRef create" + pagename
260+
+ "actionref = AtgStandardcreate" + pagename + "Action.get().getActionRef();");
232261
if (subobject != null) {
233262
sg.wl(" AtgShow" + StringFormatter.formatForAttribute(subobject.getParentObjectForLink().getName())
234263
+ "Action.ActionRef back = AtgShow"
@@ -259,7 +288,7 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
259288
+ " = new SObjectIdStorage<" + objectidclass + ">(\"PARENTID\",this, this.get" + nameclass
260289
+ "());");
261290
sg.wl(" mainband.addElement(" + namevariable + ");");
262-
sg.wl(" create" + objectvariable + "actionref.set" + nameclass + "(" + namevariable
291+
sg.wl(" create" + pagename + "actionref.set" + nameclass + "(" + namevariable
263292
+ ".getObjectIdInput());");
264293
if (issubobject)
265294
sg.wl(" back.setId(" + namevariable + ".getObjectIdInput());");
@@ -271,7 +300,7 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
271300
sg.wl(" mainband.addElement(new SPageText(\"Select relevant "
272301
+ contextobjectid.getObject().getLabel() + "\",SPageText.TYPE_TITLE,this));");
273302
sg.wl(" mainband.addElement(" + objectidvariable + "searcher);");
274-
sg.wl(" create" + objectvariable + "actionref.set" + nameclass + "("
303+
sg.wl(" create" + pagename + "actionref.set" + nameclass + "("
275304
+ objectidvariable + "searcher.getresultarray().getAttributeInput(" + objectidclass
276305
+ ".getIdMarker())); ");
277306
sg.wl(" }");
@@ -299,7 +328,7 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
299328
}
300329

301330
}
302-
sg.wl(" SPageText title = new SPageText(\"Enter data for new " + dataobject.getLabel()
331+
sg.wl(" SPageText title = new SPageText(\"Enter data for new " + (companion!=null?companion.getLabel():dataobject.getLabel())
303332
+ "\",SPageText.TYPE_TITLE,this);");
304333

305334
sg.wl(" mainband.addElement(title);");
@@ -321,7 +350,7 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
321350
sg.wl(" " + argumentvariable + "entryfield.setTextBusinessData(this.get"
322351
+ argumentclass + "());");
323352
sg.wl(" mainband.addElement(" + argumentvariable + "entryfield);");
324-
sg.wl(" create" + objectvariable + "actionref.set" + argumentclass + "("
353+
sg.wl(" create" + pagename + "actionref.set" + argumentclass + "("
325354
+ argumentvariable + "entryfield.getTextInput()); ");
326355
treated = true;
327356
}
@@ -339,7 +368,7 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
339368
sg.wl(" " + argumentvariable + "entryfield.setDateBusinessData(this.get"
340369
+ argumentclass + "());");
341370
sg.wl(" mainband.addElement(" + argumentvariable + "entryfield);");
342-
sg.wl(" create" + objectvariable + "actionref.set" + argumentclass + "("
371+
sg.wl(" create" + pagename + "actionref.set" + argumentclass + "("
343372
+ argumentvariable + "entryfield.getDateInput());");
344373
treated = true;
345374
treated = true;
@@ -358,7 +387,7 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
358387
sg.wl(" STimeslotField timeslotfield = new STimeslotField(\"ORIGINTIMESLOT\",\"Start Time\",\"End Time\",\"Start Time\",\"End Time\", STimeslotField.DEFAULT_EMPTY,");
359388
sg.wl(" this.getStarttime(),this.getEndtime(), true, this);");
360389
sg.wl(" mainband.addElement(timeslotfield);");
361-
sg.wl(" create" + objectvariable
390+
sg.wl(" create" + pagename
362391
+ "actionref.setStarttime(timeslotfield.getStartDateInput());");
363392
sg.wl(" create" + objectvariable + "actionref.setEndtime(timeslotfield.getEndDateInput()); ");
364393

@@ -369,10 +398,10 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
369398
sg.wl(" mainband.addElement(timeslotfield);");
370399
sg.wl(" SIntegerField sequencefield = new SIntegerField(\"Sequence Number\",\"SEQUENCEFIELD\", \"\", new Integer(1), true,this, false,false,false, null);");
371400
sg.wl(" mainband.addElement(sequencefield);");
372-
sg.wl(" create" + objectvariable
401+
sg.wl(" create" + pagename
373402
+ "actionref.setStarttime(timeslotfield.getStartDateInput()); ");
374-
sg.wl(" create" + objectvariable + "actionref.setEndtime(timeslotfield.getEndDateInput()); ");
375-
sg.wl(" create" + objectvariable + "actionref.setSequence(sequencefield.getIntegerInput()); ");
403+
sg.wl(" create" + pagename + "actionref.setEndtime(timeslotfield.getEndDateInput()); ");
404+
sg.wl(" create" + pagename + "actionref.setSequence(sequencefield.getIntegerInput()); ");
376405

377406
sg.wl(" ");
378407

@@ -395,7 +424,13 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
395424
}
396425
sg.wl(" " + objectvariable + "display.setHideReadOnly();");
397426
sg.wl(" mainband.addElement(" + objectvariable + "display);");
398-
427+
if (companion!=null) {
428+
sg.wl(" SObjectDisplay<" + companionclass + "> " + pagename + "display = new SObjectDisplay<"
429+
+ companionclass + ">(\"COMPANIONDISPLAY\", this.getCompanion()," + companionclass
430+
+ ".getDefinition(),this, false);");
431+
sg.wl(" " + pagename + "display.setHideReadOnly();");
432+
sg.wl(" mainband.addElement(" + pagename + "display);") ;
433+
}
399434
for (int i = 0; i < dataobject.propertylist.getSize(); i++) {
400435
Property<?> thisproperty = dataobject.propertylist.get(i);
401436
for (int j = 0; j < thisproperty.getDataInputSize(); j++) {
@@ -414,7 +449,7 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
414449
sg.wl(" " + argumentvariable + "entryfield.setTextBusinessData(this.get"
415450
+ argumentclass + "());");
416451
sg.wl(" mainband.addElement(" + argumentvariable + "entryfield);");
417-
sg.wl(" create" + objectvariable + "actionref.set" + argumentclass + "("
452+
sg.wl(" create" + pagename + "actionref.set" + argumentclass + "("
418453
+ argumentvariable + "entryfield.getActionDataInput());");
419454
treated = true;
420455
}
@@ -426,12 +461,16 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
426461
}
427462
}
428463

429-
sg.wl(" create" + objectvariable + "actionref.setObject(" + objectvariable
464+
sg.wl(" create" + pagename + "actionref.setObject(" + objectvariable
430465
+ "display.getObjectInput()); ");
466+
if (companion!=null) {
467+
sg.wl(" create" + pagename + "actionref.setCompanion(" + pagename
468+
+ "display.getObjectInput()); ");
469+
}
431470
if (dataobject.getPropertyByName("TYPED")!=null) {
432-
sg.wl(" create" + objectvariable + "actionref.setType(typefield.getChoiceInput());");
471+
sg.wl(" create" + pagename + "actionref.setType(typefield.getChoiceInput());");
433472
}
434-
sg.wl(" SActionButton create = new SActionButton(\"Create\", create" + objectvariable
473+
sg.wl(" SActionButton create = new SActionButton(\"Create\", create" + pagename
435474
+ "actionref, this);");
436475
sg.wl(" SActionButton backbutton = new SActionButton(\"Back\",back,this);");
437476
sg.wl(" ");

0 commit comments

Comments
 (0)