Skip to content

Commit c33ad94

Browse files
author
Open Lowcode SAS
committed
Close #243
1 parent 763c516 commit c33ad94

7 files changed

Lines changed: 638 additions & 350 deletions

File tree

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

Lines changed: 268 additions & 231 deletions
Large diffs are not rendered by default.

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

Lines changed: 125 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.IOException;
1414
import java.util.ArrayList;
1515

16+
import org.openlowcode.design.action.DynamicActionDefinition;
1617
import org.openlowcode.design.data.ChoiceValue;
1718
import org.openlowcode.design.data.DataAccessMethod;
1819
import org.openlowcode.design.data.DataObjectDefinition;
@@ -27,6 +28,7 @@
2728
import org.openlowcode.design.generation.SourceGenerator;
2829
import org.openlowcode.design.generation.StringFormatter;
2930
import org.openlowcode.design.module.Module;
31+
import org.openlowcode.tools.misc.NamedList;
3032

3133
/**
3234
* A Companion is a secondary data object linked to a main data object. It
@@ -42,52 +44,63 @@ public class Companion
4244

4345
private DataObjectDefinition maintypedobject;
4446
private ChoiceValue[] types;
47+
private Typed mainobjecttypedproperty;
48+
private HasId hasid;
4549

46-
public Companion(DataObjectDefinition maintypedobject,ChoiceValue[] types) {
50+
public Companion(DataObjectDefinition maintypedobject, ChoiceValue[] types) {
4751
super("COMPANION");
4852
this.maintypedobject = maintypedobject;
4953
this.types = types;
50-
54+
5155
}
5256

5357
@Override
5458
public void controlAfterParentDefinition() {
5559

56-
Typed mainobjecttypedproperty = (Typed) maintypedobject.getPropertyByName("TYPED");
57-
if (mainobjecttypedproperty==null) throw new RuntimeException("Main object "+maintypedobject.getName()+" should have the Typed property added before this statement.");
60+
mainobjecttypedproperty = (Typed) maintypedobject.getPropertyByName("TYPED");
61+
if (mainobjecttypedproperty == null)
62+
throw new RuntimeException("Main object " + maintypedobject.getName()
63+
+ " should have the Typed property added before this statement.");
5864
mainobjecttypedproperty.addCompanionObject(this.getParent(), types);
59-
65+
6066
// READ THE TYPED OBJECTS
6167
DataAccessMethod readtyped = new DataAccessMethod("READTYPED", new TwoObjectsArgument("TYPED",
6268
new ObjectArgument("MAIN", maintypedobject), new ObjectArgument("COMPANION", this.getParent())), false,
6369
false);
6470
readtyped.addInputArgument(new MethodArgument("OBJECTID", new ObjectIdArgument("OBJECT", maintypedobject)));
6571
this.addDataAccessMethod(readtyped);
6672
// UPDATE THE TYPED OBJECT
67-
DataAccessMethod updatetyped = new DataAccessMethod("UPDATETYPED",null,false,false);
68-
updatetyped.addInputArgument(new MethodArgument("THISCOMPANION",new ObjectArgument("COMPANION",this.getParent())));
69-
updatetyped.addInputArgument(new MethodArgument("MAINOBJECT",new ObjectArgument("MAINOBJECT",maintypedobject)));
73+
DataAccessMethod updatetyped = new DataAccessMethod("UPDATETYPED", null, false, false);
74+
updatetyped.addInputArgument(
75+
new MethodArgument("THISCOMPANION", new ObjectArgument("COMPANION", this.getParent())));
76+
updatetyped
77+
.addInputArgument(new MethodArgument("MAINOBJECT", new ObjectArgument("MAINOBJECT", maintypedobject)));
7078

7179
this.addDataAccessMethod(updatetyped);
7280
// CREATE A TYPED OBJECT
73-
DataAccessMethod createtyped = new DataAccessMethod("CREATETYPED",null,false,false);
74-
createtyped.addInputArgument(new MethodArgument("THISCOMPANION",new ObjectArgument("COMPANION",this.getParent())));
75-
createtyped.addInputArgument(new MethodArgument("MAINOBJECT",new ObjectArgument("MAINOBJECT",maintypedobject)));
76-
createtyped.addInputArgument(new MethodArgument("TYPE",new ChoiceArgument("TYPE", mainobjecttypedproperty.getTypes())));
81+
DataAccessMethod createtyped = new DataAccessMethod("CREATETYPED", null, false, false);
82+
createtyped.addInputArgument(
83+
new MethodArgument("THISCOMPANION", new ObjectArgument("COMPANION", this.getParent())));
84+
createtyped
85+
.addInputArgument(new MethodArgument("MAINOBJECT", new ObjectArgument("MAINOBJECT", maintypedobject)));
86+
createtyped.addInputArgument(
87+
new MethodArgument("TYPE", new ChoiceArgument("TYPE", mainobjecttypedproperty.getTypes())));
7788
this.addDataAccessMethod(createtyped);
78-
89+
7990
// INSERT AFTER TYPED OBJECT CREATION
80-
DataAccessMethod insertcompanion = new DataAccessMethod("INSERTCOMPANION",null,false,false);
81-
insertcompanion.addInputArgument(new MethodArgument("THISCOMPANION",new ObjectArgument("COMPANION",this.getParent())));
82-
insertcompanion.addInputArgument(new MethodArgument("MAINOBJECT",new ObjectArgument("MAINOBJECT",maintypedobject)));
91+
DataAccessMethod insertcompanion = new DataAccessMethod("INSERTCOMPANION", null, false, false);
92+
insertcompanion.addInputArgument(
93+
new MethodArgument("THISCOMPANION", new ObjectArgument("COMPANION", this.getParent())));
94+
insertcompanion
95+
.addInputArgument(new MethodArgument("MAINOBJECT", new ObjectArgument("MAINOBJECT", maintypedobject)));
8396
this.addDataAccessMethod(insertcompanion);
84-
85-
86-
97+
8798
// put the main typed object as related to this property
88-
this.addChoiceCategoryHelper("TYPE",((Typed)maintypedobject.getPropertyByName("TYPED")).getTypes() );
89-
this.addPropertyGenerics(new PropertyGenerics("MAINTYPEDOBJECT",maintypedobject, maintypedobject.getPropertyByName("TYPED")));
90-
this.addDependentProperty(this.getParent().getPropertyByName("HASID"));
99+
this.addChoiceCategoryHelper("TYPE", ((Typed) maintypedobject.getPropertyByName("TYPED")).getTypes());
100+
this.addPropertyGenerics(
101+
new PropertyGenerics("MAINTYPEDOBJECT", maintypedobject, maintypedobject.getPropertyByName("TYPED")));
102+
hasid = (HasId) (this.getParent().getPropertyByName("HASID"));
103+
this.addDependentProperty(hasid);
91104
}
92105

93106
@Override
@@ -128,10 +141,99 @@ public String getJavaType() {
128141

129142
@Override
130143
public void writeDependentClass(SourceGenerator sg, Module module) throws IOException {
131-
SimpleChoiceCategory typechoice = ((Typed)maintypedobject.getPropertyByName("TYPED")).getTypes();
144+
SimpleChoiceCategory typechoice = ((Typed) maintypedobject.getPropertyByName("TYPED")).getTypes();
132145
sg.wl("import " + typechoice.getParentModule().getPath() + ".data.choice."
133146
+ StringFormatter.formatForJavaClass(typechoice.getName()) + "ChoiceDefinition;");
134147

135148
}
136149

150+
/**
151+
* @return the list of menus
152+
*/
153+
public ArrayList<String> getSpecificMenuList() {
154+
return hasid.getSpecificMenuList();
155+
}
156+
157+
/**
158+
* get actions assigned on a specific menu
159+
*
160+
* @param specific menu
161+
* @return actions
162+
*/
163+
public ArrayList<DynamicActionDefinition> getActionsOnSpecificMenu(String specifictabname) {
164+
return hasid.getActionsOnSpecificMenu(specifictabname);
165+
}
166+
167+
/**
168+
* @return the list of actions on object id to be added to button band of the
169+
* object page
170+
*/
171+
public NamedList<DynamicActionDefinition> getActionListonObjectId() {
172+
return hasid.getActionListonObjectId();
173+
}
174+
175+
/**
176+
* @return the list of actions on object id to be added to the manage menu of
177+
* the object page
178+
*/
179+
public NamedList<DynamicActionDefinition> getActionListonObjectIdForManageMenu() {
180+
return hasid.getActionListonObjectIdForManageMenu();
181+
}
182+
183+
/**
184+
* @return the list of menu comment to print
185+
*/
186+
public ArrayList<String> getMenuCommentListOnActionForManageTab() {
187+
return hasid.getMenuCommentListOnActionForManageTab();
188+
}
189+
190+
/**
191+
* adds action in the main button band of the object. The action should have a
192+
* single input attribute being the data object id
193+
*
194+
* @param action adds an action on the object id. The action should have a
195+
* single input attribute being the data object id
196+
*/
197+
public void addActionOnObjectId(DynamicActionDefinition action) {
198+
addActionOnObjectId(action, false);
199+
}
200+
201+
/**
202+
* adds action in the main button band of the object. The action should have a
203+
* single input attribute being the data object id
204+
*
205+
* @param action adds an action on the object id. The action should
206+
* have a single input attribute being the data object id
207+
* @param specialmenuname special menu for the action
208+
*/
209+
public void addActionOnObjectId(DynamicActionDefinition action, String specialmenuname) {
210+
hasid.addActionOnObjectId(action, specialmenuname);
211+
}
212+
213+
/**
214+
* adds an action on the object, either in the main button band, or in the
215+
* manage tab
216+
*
217+
* @param action adds an action on the object id. The action should
218+
* have a single input attribute being the data object
219+
* id
220+
* @param actioninmanagetab if true, action is put in manage tabs, if false,
221+
* action is directly in the action button
222+
*/
223+
public void addActionOnObjectId(DynamicActionDefinition action, boolean actioninmanagetab) {
224+
hasid.addActionOnObjectId(action, actioninmanagetab);
225+
}
226+
227+
/**
228+
* adds an action on the object, either in the main button band, or in the
229+
* manage tab
230+
*
231+
* @param action adds an action on the object id. The action should have a
232+
* single input attribute being the data object id
233+
* @param comment a comment to add before the content in manage menu
234+
*/
235+
public void addActionOnObjectIdOnManageMenu(DynamicActionDefinition action, String comment) {
236+
hasid.addActionOnObjectIdOnManageMenu(action, comment);
237+
}
238+
137239
}

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

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
import java.io.IOException;
1414
import java.util.ArrayList;
15+
import java.util.HashMap;
1516

17+
import org.openlowcode.design.action.DynamicActionDefinition;
18+
import org.openlowcode.design.data.ArgumentContent;
1619
import org.openlowcode.design.data.DataAccessMethod;
1720
import org.openlowcode.design.data.DataObjectDefinition;
1821
import org.openlowcode.design.data.Index;
@@ -25,6 +28,7 @@
2528
import org.openlowcode.design.data.argument.ObjectIdArgument;
2629
import org.openlowcode.design.generation.SourceGenerator;
2730
import org.openlowcode.design.module.Module;
31+
import org.openlowcode.tools.misc.NamedList;
2832

2933
/**
3034
* This property is a split of the original UniqueIdentified property to store
@@ -39,9 +43,19 @@
3943
public class HasId
4044
extends
4145
Property<HasId> {
46+
private NamedList<DynamicActionDefinition> actionsonobjectid;
47+
private NamedList<DynamicActionDefinition> actionsonobjectidonmanagemenu;
48+
private ArrayList<String> menucommentinmanagetabs;
49+
private HashMap<String, ArrayList<DynamicActionDefinition>> actionsonspecificmenu;
50+
private ArrayList<String> specificmenus;
4251

4352
public HasId() {
4453
super("HASID");
54+
this.actionsonobjectid = new NamedList<DynamicActionDefinition>();
55+
this.actionsonobjectidonmanagemenu = new NamedList<DynamicActionDefinition>();
56+
this.menucommentinmanagetabs = new ArrayList<String>();
57+
this.actionsonspecificmenu = new HashMap<String, ArrayList<DynamicActionDefinition>>();
58+
this.specificmenus = new ArrayList<String>();
4559

4660
}
4761

@@ -50,7 +64,7 @@ public void controlAfterParentDefinition() {
5064
StoredElement id = new ObjectIdStoredElement("ID", parent);
5165
this.addElement(id, "Id", "technical identification", Property.FIELDDISPLAY_NORMAL, -50, 25);
5266
this.addIndex(new Index("ID", id, true));
53-
67+
5468
DataAccessMethod read = new DataAccessMethod("READONE", new ObjectArgument("OBJECT", parent), false);
5569
read.addInputArgument(new MethodArgument("ID", new ObjectIdArgument("ID", parent)));
5670
this.addDataAccessMethod(read);
@@ -98,4 +112,130 @@ public String getJavaType() {
98112
public void writeDependentClass(SourceGenerator sg, Module module) throws IOException {
99113
}
100114

115+
116+
/**
117+
* @return the list of menus
118+
*/
119+
public ArrayList<String> getSpecificMenuList() {
120+
return this.specificmenus;
121+
}
122+
123+
/**
124+
* get actions assigned on a specific menu
125+
* @param specific menu
126+
* @return actions
127+
*/
128+
public ArrayList<DynamicActionDefinition> getActionsOnSpecificMenu(String specifictabname) {
129+
return this.actionsonspecificmenu.get(specifictabname);
130+
}
131+
132+
/**
133+
* @return the list of actions on object id to be added to button band of the
134+
* object page
135+
*/
136+
public NamedList<DynamicActionDefinition> getActionListonObjectId() {
137+
return actionsonobjectid;
138+
}
139+
140+
/**
141+
* @return the list of actions on object id to be added to the manage menu of the
142+
* object page
143+
*/
144+
public NamedList<DynamicActionDefinition> getActionListonObjectIdForManageMenu() {
145+
return actionsonobjectidonmanagemenu;
146+
}
147+
148+
/**
149+
* @return the list of menu comment to print
150+
*/
151+
@SuppressWarnings("unchecked")
152+
public ArrayList<String> getMenuCommentListOnActionForManageTab() {
153+
return (ArrayList<String>)(this.menucommentinmanagetabs.clone());
154+
}
155+
156+
157+
158+
/**
159+
* adds action in the main button band of the object. The action should have a
160+
* single input attribute being the data object id
161+
*
162+
* @param action adds an action on the object id. The action should have a
163+
* single input attribute being the data object id
164+
*/
165+
public void addActionOnObjectId(DynamicActionDefinition action) {
166+
addActionOnObjectId(action, false);
167+
}
168+
169+
/**
170+
* adds action in the main button band of the object. The action should have a
171+
* single input attribute being the data object id
172+
*
173+
* @param action adds an action on the object id. The action should
174+
* have a single input attribute being the data object id
175+
* @param specialmenuname special menu for the action
176+
*/
177+
public void addActionOnObjectId(DynamicActionDefinition action, String specialmenuname) {
178+
validateActionOnObjectId(action);
179+
ArrayList<DynamicActionDefinition> actionsforspecialmenu = this.actionsonspecificmenu.get(specialmenuname);
180+
if (actionsforspecialmenu == null) {
181+
actionsforspecialmenu = new ArrayList<DynamicActionDefinition>();
182+
this.actionsonspecificmenu.put(specialmenuname, actionsforspecialmenu);
183+
this.specificmenus.add(specialmenuname);
184+
}
185+
actionsforspecialmenu.add(action);
186+
}
187+
188+
private void validateActionOnObjectId(DynamicActionDefinition action) {
189+
if (action.getInputArguments().getSize() != 1)
190+
throw new RuntimeException("you can add an action on object id only if it has 1 argument, action "
191+
+ action.getName() + " has " + action.getInputArguments().getSize() + ".");
192+
ArgumentContent uniqueinputargument = action.getInputArguments().get(0);
193+
if (!(uniqueinputargument instanceof ObjectIdArgument))
194+
throw new RuntimeException("the first argument of " + action.getName()
195+
+ " should be ObjectidArgument, it is actually " + uniqueinputargument.getClass().getName() + ".");
196+
ObjectIdArgument objectidargument = (ObjectIdArgument) uniqueinputargument;
197+
DataObjectDefinition objectforid = objectidargument.getObject();
198+
if (objectforid != parent) {
199+
throw new RuntimeException("objectid should be of consistent type, actionid type = "
200+
+ objectforid.getOwnermodule().getName() + "/" + objectforid.getName() + ", object parentid type = "
201+
+ parent.getOwnermodule().getName() + "/" + parent.getName());
202+
}
203+
}
204+
205+
/**
206+
* adds an action on the object, either in the main button band, or in the
207+
* manage tab
208+
*
209+
* @param action adds an action on the object id. The action should
210+
* have a single input attribute being the data object
211+
* id
212+
* @param actioninmanagetab if true, action is put in manage tabs, if false,
213+
* action is directly in the action button
214+
*/
215+
public void addActionOnObjectId(DynamicActionDefinition action, boolean actioninmanagetab) {
216+
validateActionOnObjectId(action);
217+
218+
if (actioninmanagetab) {
219+
this.actionsonobjectidonmanagemenu.add(action);
220+
this.menucommentinmanagetabs.add(null);
221+
} else {
222+
actionsonobjectid.add(action);
223+
224+
}
225+
}
226+
227+
/**
228+
* adds an action on the object, either in the main button band, or in the
229+
* manage tab
230+
*
231+
* @param action adds an action on the object id. The action should have a
232+
* single input attribute being the data object id
233+
* @param comment a comment to add before the content in manage menu
234+
*/
235+
public void addActionOnObjectIdOnManageMenu(DynamicActionDefinition action, String comment) {
236+
this.actionsonobjectidonmanagemenu.add(action);
237+
this.menucommentinmanagetabs.add(comment);
238+
}
239+
240+
101241
}

0 commit comments

Comments
 (0)