1313import java .io .IOException ;
1414import java .util .ArrayList ;
1515
16+ import org .openlowcode .design .action .DynamicActionDefinition ;
1617import org .openlowcode .design .data .ChoiceValue ;
1718import org .openlowcode .design .data .DataAccessMethod ;
1819import org .openlowcode .design .data .DataObjectDefinition ;
2728import org .openlowcode .design .generation .SourceGenerator ;
2829import org .openlowcode .design .generation .StringFormatter ;
2930import 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}
0 commit comments