Skip to content

Commit 7b8e33d

Browse files
author
Open Lowcode SAS
committed
Close #106 #107 #108
1 parent a9e1b8e commit 7b8e33d

File tree

5 files changed

+104
-55
lines changed

5 files changed

+104
-55
lines changed

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,28 @@ public void addActionOnObjectPage(DynamicActionDefinition actiontoadd) {
735735
UniqueIdentified uniqueidentified = (UniqueIdentified) property;
736736
uniqueidentified.addActionOnObjectId(actiontoadd);
737737
}
738+
739+
/**
740+
* Shortcut method performing the following
741+
* <ul>
742+
* <li>Adding action to the module</li>
743+
* <li>adding action on the unique identified property of the data object,
744+
* making it appear in the object page</li>
745+
* </ul>
746+
* @param actiontoadd a dynamic action with as single entry argument the object
747+
* id of the Data Object
748+
* @param comment Optional comment to put in the manage arrow. Should be short as manage menu is narrow
749+
*/
750+
public void addActionOnObjectPageOnManageMenu(DynamicActionDefinition actiontoadd,String comment) {
751+
this.getOwnermodule().addAction(actiontoadd);
752+
Property<?> property = this.getPropertyByName("UNIQUEIDENTIFIED");
753+
if (property == null)
754+
throw new RuntimeException("UniqueIdentified property not found on object " + this.getName());
755+
if (!(property instanceof UniqueIdentified))
756+
throw new RuntimeException("Property with name 'UniqueIdentified' is of incorrect class");
757+
UniqueIdentified uniqueidentified = (UniqueIdentified) property;
758+
uniqueidentified.addActionOnObjectIdOnManageMenu(actiontoadd, comment);;
759+
}
738760

739761
/**
740762
* adds a static action on the search page of the object
@@ -1940,7 +1962,7 @@ public void generateAutomaticPagesAndActions(Module module) {
19401962
module.addAction(this.generatePrepareStandardCreateAction());
19411963
module.addAction(this.generateStandardCreateAction());
19421964

1943-
this.addActionOnObjectPage(this.generateSaveAsAction());
1965+
this.addActionOnObjectPageOnManageMenu(this.generateDuplicateAction(), "Create new "+this.getLabel()+" with similar data");
19441966
module.AddPage(this.generateStandardCreatePage());
19451967
}
19461968

@@ -2131,16 +2153,16 @@ private void addAttributesToCreateobject(
21312153
action.addInputArgumentAsAccessCriteria(mainobject);
21322154
}
21332155

2134-
private DynamicActionDefinition generateSaveAsAction() {
2135-
DynamicActionDefinition saveasaction = new DynamicActionDefinition("SAVEAS" + this.getName().toUpperCase(),
2156+
private DynamicActionDefinition generateDuplicateAction() {
2157+
DynamicActionDefinition duplicateaction = new DynamicActionDefinition("DUPLICATE" + this.getName().toUpperCase(),
21362158
true);
2137-
saveasaction.addInputArgument(new ObjectIdArgument("ORIGINID", this));
2138-
saveasaction.addOutputArgument(new ObjectArgument("COPYOBJECT", this));
2139-
saveasaction.setButtonlabel("Duplicate");
2159+
duplicateaction.addInputArgument(new ObjectIdArgument("ORIGINID", this));
2160+
duplicateaction.addOutputArgument(new ObjectArgument("COPYOBJECT", this));
2161+
duplicateaction.setButtonlabel("Duplicate");
21402162
if (this.isSaveAsInCreateNewGroup())
2141-
this.addActionToCreateNewGroup(saveasaction);
2163+
this.addActionToCreateNewGroup(duplicateaction);
21422164

2143-
return saveasaction;
2165+
return duplicateaction;
21442166
}
21452167

21462168
private ActionDefinition generateStandardCreateAction() {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -924,14 +924,14 @@ public static void generateStandardCreateActionToFile(
924924
}
925925

926926
/**
927-
* generates the code for the save-as (somehow deep copy) action
927+
* generates the code for the duplicate (somehow deep copy) action
928928
*
929929
* @param dataobject data object definition
930930
* @param sg source generator
931931
* @param module parent module
932932
* @throws IOException if anything bad happens during the generation
933933
*/
934-
public static void generateSaveAsActionToFile(DataObjectDefinition dataobject, SourceGenerator sg, Module module)
934+
public static void generateDuplicateActionToFile(DataObjectDefinition dataobject, SourceGenerator sg, Module module)
935935
throws IOException {
936936
String objectclass = StringFormatter.formatForJavaClass(dataobject.getName());
937937
String objectvariable = StringFormatter.formatForAttribute(dataobject.getName());
@@ -962,10 +962,10 @@ public static void generateSaveAsActionToFile(DataObjectDefinition dataobject, S
962962
sg.wl("import org.openlowcode.server.runtime.SModule;");
963963

964964
sg.wl("");
965-
sg.wl("public class AtgSaveas" + objectvariable + "Action extends");
966-
sg.wl(" AbsSaveas" + objectvariable + "Action {");
965+
sg.wl("public class AtgDuplicate" + objectvariable + "Action extends");
966+
sg.wl(" AbsDuplicate" + objectvariable + "Action {");
967967
sg.wl("");
968-
sg.wl(" public AtgSaveas" + objectvariable + "Action(SModule parent) {");
968+
sg.wl(" public AtgDuplicate" + objectvariable + "Action(SModule parent) {");
969969
sg.wl(" super(parent);");
970970
sg.wl("");
971971
sg.wl(" }");

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
223223
UniqueIdentified uniqueidentifiedproperty = (UniqueIdentified) dataobject.getPropertyByName("UNIQUEIDENTIFIED");
224224
NamedList<DynamicActionDefinition> actionlistonobjectid = uniqueidentifiedproperty.getActionListonObjectId();
225225
NamedList<DynamicActionDefinition> actionlistonobjectidinmanagetab = uniqueidentifiedproperty
226-
.getActionListonObjectIdForManageTab();
227-
226+
.getActionListonObjectIdForManageMenu();
227+
ArrayList<String> commentsonobjectsinmanagetab = uniqueidentifiedproperty.getMenuCommentListOnActionForManageTab();
228228
boolean objectbuttonband = false;
229229
objectbuttonband = true; // added as anyways we have the link to search page
230230
if (parentlink != null)
@@ -397,10 +397,10 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
397397
+ objectstoshow.get(i).getName().toLowerCase() + "Action;"); // because tables link to action
398398
}
399399

400-
ArrayList<String> specifictablist = uniqueidentifiedproperty.getSpecificTabList();
401-
for (int i=0;i<specifictablist.size();i++) {
402-
String specifictabname = specifictablist.get(i);
403-
ArrayList<DynamicActionDefinition> actionsfortab = uniqueidentifiedproperty.getActionsOnSpecifictab(specifictabname);
400+
ArrayList<String> specificmenulist = uniqueidentifiedproperty.getSpecificMenuList();
401+
for (int i=0;i<specificmenulist.size();i++) {
402+
String specifictabname = specificmenulist.get(i);
403+
ArrayList<DynamicActionDefinition> actionsfortab = uniqueidentifiedproperty.getActionsOnSpecificMenu(specifictabname);
404404

405405
for (int j = 0; j < actionsfortab.size(); j++) {
406406
DynamicActionDefinition thisaction = actionsfortab.get(j);
@@ -835,17 +835,17 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
835835
sg.wl("");
836836
}
837837

838-
/// ------------------------------------------------ Specific tabs for object --------------------
838+
/// ------------------------------------------------ Specific menu for object --------------------
839839

840-
for (int i=0;i<specifictablist.size();i++) {
841-
String specifictabname = specifictablist.get(i);
842-
sg.wl(" // Manage Specific Band "+i+" - "+specifictabname);
840+
for (int i=0;i<specificmenulist.size();i++) {
841+
String specificmenuname = specificmenulist.get(i);
842+
sg.wl(" // Manage Specific Band "+i+" - "+specificmenuname);
843843
sg.wl("");
844844
sg.wl(" SComponentBand specificpopup"+i+" = new SComponentBand(SComponentBand.DIRECTION_DOWN,this);");
845-
ArrayList<DynamicActionDefinition> actionsfortab = uniqueidentifiedproperty.getActionsOnSpecifictab(specifictabname);
845+
ArrayList<DynamicActionDefinition> actionsformenu = uniqueidentifiedproperty.getActionsOnSpecificMenu(specificmenuname);
846846

847-
for (int j = 0; j < actionsfortab.size(); j++) {
848-
DynamicActionDefinition thisaction = actionsfortab.get(j);
847+
for (int j = 0; j < actionsformenu.size(); j++) {
848+
DynamicActionDefinition thisaction = actionsformenu.get(j);
849849
String actionclassname = StringFormatter.formatForJavaClass(thisaction.getName());
850850
if (thisaction.isAutogenerated())
851851
actionclassname = "Atg" + actionclassname;
@@ -867,7 +867,7 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
867867
}
868868

869869

870-
sg.wl(" SPopupButton specificpopup"+i+"button = new SPopupButton(this, specificpopup"+i+", \""+specifictabname+"\",\"\",true,true,null);");
870+
sg.wl(" SPopupButton specificpopup"+i+"button = new SPopupButton(this, specificpopup"+i+", \""+specificmenuname+"\",\"\",true,true,null);");
871871
sg.wl(" objectbuttonband.addElement(specificpopup"+i+"button);");
872872
}
873873

@@ -964,6 +964,7 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
964964
}
965965
for (int i = 0; i < actionlistonobjectidinmanagetab.getSize(); i++) {
966966
DynamicActionDefinition thisaction = actionlistonobjectidinmanagetab.get(i);
967+
String comment= commentsonobjectsinmanagetab.get(i);
967968
String actionclassname = StringFormatter.formatForJavaClass(thisaction.getName());
968969
if (thisaction.isAutogenerated())
969970
actionclassname = "Atg" + actionclassname;
@@ -980,6 +981,8 @@ public void generateToFile(SourceGenerator sg, Module module) throws IOException
980981
+ "(objectdisplaydefinition.getAttributeInput(" + objectclass + ".getIdMarker()));");
981982
sg.wl(" SActionButton " + actionattributename + "forobjectbandbutton = new SActionButton("
982983
+ buttonname + ",\"\"," + actionattributename + "forobjectbandaction,this);");
984+
if (comment!=null)
985+
sg.wl(" managepopup.addElement(new SPageText(\""+StringFormatter.escapeforjavastring(comment)+"\",SPageText.TYPE_NORMAL,this));");
983986
sg.wl(" managepopup.addElement(" + actionattributename + "forobjectbandbutton); ");
984987
sg.wl("");
985988
}

src/org/openlowcode/design/data/properties/basic/UniqueIdentified.java

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,20 @@ public class UniqueIdentified
4848
extends
4949
Property<UniqueIdentified> {
5050
private NamedList<DynamicActionDefinition> actionsonobjectid;
51-
private NamedList<DynamicActionDefinition> actionsonobjectidonmanagetab;
52-
private HashMap<String,ArrayList<DynamicActionDefinition>> actionsonspecifictab;
53-
private ArrayList<String> specifictabs;
51+
private NamedList<DynamicActionDefinition> actionsonobjectidonmanagemenu;
52+
private ArrayList<String> menucommentinmanagetabs;
53+
private HashMap<String, ArrayList<DynamicActionDefinition>> actionsonspecificmenu;
54+
private ArrayList<String> specificmenus;
5455
private StoredObject storedobject;
5556

56-
public ArrayList<String> getSpecificTabList() {
57-
return this.specifictabs;
57+
public ArrayList<String> getSpecificMenuList() {
58+
return this.specificmenus;
5859
}
59-
60-
public ArrayList<DynamicActionDefinition> getActionsOnSpecifictab(String specifictabname) {
61-
return this.actionsonspecifictab.get(specifictabname);
60+
61+
public ArrayList<DynamicActionDefinition> getActionsOnSpecificMenu(String specifictabname) {
62+
return this.actionsonspecificmenu.get(specifictabname);
6263
}
63-
64+
6465
/**
6566
* @return the list of actions on object id to be added to button band of the
6667
* object page
@@ -70,11 +71,19 @@ public NamedList<DynamicActionDefinition> getActionListonObjectId() {
7071
}
7172

7273
/**
73-
* @return the list of actions on object id to be added to the manage tab of the
74+
* @return the list of actions on object id to be added to the manage menu of the
7475
* object page
7576
*/
76-
public NamedList<DynamicActionDefinition> getActionListonObjectIdForManageTab() {
77-
return actionsonobjectidonmanagetab;
77+
public NamedList<DynamicActionDefinition> getActionListonObjectIdForManageMenu() {
78+
return actionsonobjectidonmanagemenu;
79+
}
80+
81+
/**
82+
* @return the list of menu comment to print
83+
*/
84+
@SuppressWarnings("unchecked")
85+
public ArrayList<String> getMenuCommentListOnActionForManageTab() {
86+
return (ArrayList<String>)(this.menucommentinmanagetabs.clone());
7887
}
7988

8089
/**
@@ -90,9 +99,10 @@ public StoredObject getStoredObject() {
9099
public UniqueIdentified() {
91100
super("UNIQUEIDENTIFIED");
92101
this.actionsonobjectid = new NamedList<DynamicActionDefinition>();
93-
this.actionsonobjectidonmanagetab = new NamedList<DynamicActionDefinition>();
94-
this.actionsonspecifictab = new HashMap<String,ArrayList<DynamicActionDefinition>>();
95-
specifictabs = new ArrayList<String>();
102+
this.actionsonobjectidonmanagemenu = new NamedList<DynamicActionDefinition>();
103+
this.menucommentinmanagetabs = new ArrayList<String>();
104+
this.actionsonspecificmenu = new HashMap<String, ArrayList<DynamicActionDefinition>>();
105+
specificmenus = new ArrayList<String>();
96106
}
97107

98108
@Override
@@ -169,17 +179,17 @@ public void addActionOnObjectId(DynamicActionDefinition action) {
169179
addActionOnObjectId(action, false);
170180
}
171181

172-
public void addActionOnObjectId(DynamicActionDefinition action,String specialmenuname) {
182+
public void addActionOnObjectId(DynamicActionDefinition action, String specialmenuname) {
173183
validateActionOnObjectId(action);
174-
ArrayList<DynamicActionDefinition> actionsforspecialmenu = this.actionsonspecifictab.get(specialmenuname);
175-
if (actionsforspecialmenu==null) {
184+
ArrayList<DynamicActionDefinition> actionsforspecialmenu = this.actionsonspecificmenu.get(specialmenuname);
185+
if (actionsforspecialmenu == null) {
176186
actionsforspecialmenu = new ArrayList<DynamicActionDefinition>();
177-
this.actionsonspecifictab.put(specialmenuname,actionsforspecialmenu);
178-
this.specifictabs.add(specialmenuname);
187+
this.actionsonspecificmenu.put(specialmenuname, actionsforspecialmenu);
188+
this.specificmenus.add(specialmenuname);
179189
}
180190
actionsforspecialmenu.add(action);
181191
}
182-
192+
183193
private void validateActionOnObjectId(DynamicActionDefinition action) {
184194
if (action.getInputArguments().getSize() != 1)
185195
throw new RuntimeException("you can add an action on object id only if it has 1 argument, action "
@@ -196,7 +206,7 @@ private void validateActionOnObjectId(DynamicActionDefinition action) {
196206
+ parent.getOwnermodule().getName() + "/" + parent.getName());
197207
}
198208
}
199-
209+
200210
/**
201211
* adds an action on the object, either in the main button band, or in the
202212
* manage tab
@@ -211,13 +221,27 @@ public void addActionOnObjectId(DynamicActionDefinition action, boolean actionin
211221
validateActionOnObjectId(action);
212222

213223
if (actioninmanagetab) {
214-
this.actionsonobjectidonmanagetab.add(action);
224+
this.actionsonobjectidonmanagemenu.add(action);
225+
this.menucommentinmanagetabs.add(null);
215226
} else {
216227
actionsonobjectid.add(action);
217228

218229
}
219230
}
220231

232+
/**
233+
* adds an action on the object, either in the main button band, or in the
234+
* manage tab
235+
*
236+
* @param action adds an action on the object id. The action should have a
237+
* single input attribute being the data object id
238+
* @param comment a comment to add before the content in manage menu
239+
*/
240+
public void addActionOnObjectIdOnManageMenu(DynamicActionDefinition action, String comment) {
241+
this.actionsonobjectidonmanagemenu.add(action);
242+
this.menucommentinmanagetabs.add(comment);
243+
}
244+
221245
@Override
222246
public String[] getPropertyInitMethod() {
223247
return new String[0];

src/org/openlowcode/design/module/Module.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,12 +1833,12 @@ relevantlinkedtoparent, new SourceGenerator(new File(fullfilepathdeleteandshowob
18331833
this.getVersionid()),
18341834
this);
18351835

1836-
String fullfilepathsaveasaction = srcautoactionfolder + "Atg"
1837-
+ StringFormatter.formatForJavaClass("SAVEAS" + currentobject.getName()) + "Action.java";
1836+
String fullfilepathduplicateaction = srcautoactionfolder + "Atg"
1837+
+ StringFormatter.formatForJavaClass("DUPLICATE" + currentobject.getName()) + "Action.java";
18381838
;
1839-
logger.info("generating file " + fullfilepathsaveasaction);
1840-
DataObjectDefinitionOtherActions.generateSaveAsActionToFile(currentobject, new SourceGenerator(
1841-
new File(fullfilepathsaveasaction), this.getAuthor(), this.getVersionid()), this);
1839+
logger.info("generating file " + fullfilepathduplicateaction);
1840+
DataObjectDefinitionOtherActions.generateDuplicateActionToFile(currentobject, new SourceGenerator(
1841+
new File(fullfilepathduplicateaction), this.getAuthor(), this.getVersionid()), this);
18421842

18431843
}
18441844

0 commit comments

Comments
 (0)