Skip to content

Commit 7c6433d

Browse files
author
Open Lowcode SAS
committed
Close #146
1 parent 2548db2 commit 7c6433d

File tree

10 files changed

+654
-467
lines changed

10 files changed

+654
-467
lines changed

src/org/openlowcode/client/action/CActionDataLoc.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (c) 2019 [Open Lowcode SAS](https://openlowcode.com/)
2+
* Copyright (c) 2019-2020 [Open Lowcode SAS](https://openlowcode.com/)
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -32,6 +32,7 @@ public class CActionDataLoc extends Named {
3232
public static final String TEXT_TYPE = "TXT";
3333
public static final String OBJ_TYPE = "OBJ";
3434
public static final String OBJ_ID_TYPE = "OID";
35+
public static final String OBJ_MS_ID_TYPE = "OMI";
3536
public static final String CHOICE_TYPE = "CHT";
3637
public static final String MULTI_CHOICE_TYPE = "MLC";
3738
public static final String ARRAY_PREFIX = "ARR/";
@@ -58,6 +59,8 @@ public CActionDataLoc(MessageReader reader) throws OLcRemoteException, IOExcepti
5859
typesupported = true;
5960
if (this.type.compareTo(OBJ_ID_TYPE) == 0)
6061
typesupported = true;
62+
if (this.type.compareTo(OBJ_MS_ID_TYPE) == 0)
63+
typesupported=true;
6164
if (this.type.compareTo(CHOICE_TYPE) == 0)
6265
typesupported = true;
6366
if (this.type.compareTo(MULTI_CHOICE_TYPE) == 0)
@@ -81,6 +84,8 @@ public CActionDataLoc(MessageReader reader) throws OLcRemoteException, IOExcepti
8184
typesupported = true;
8285
if (subtype.compareTo(CHOICE_TYPE) == 0)
8386
typesupported = true;
87+
if (subtype.compareTo(OBJ_MS_ID_TYPE) == 0)
88+
typesupported = true;
8489
}
8590
if (!typesupported)
8691
throw new RuntimeException("the type put in the action field " + this.getName()

src/org/openlowcode/client/graphic/widget/CObjectArray.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import org.openlowcode.tools.structure.ObjectDataEltType;
5050
import org.openlowcode.tools.structure.ObjectIdDataElt;
5151
import org.openlowcode.tools.structure.ObjectIdDataEltType;
52+
import org.openlowcode.tools.structure.ObjectMasterIdDataElt;
53+
import org.openlowcode.tools.structure.ObjectMasterIdDataEltType;
5254
import org.openlowcode.tools.structure.SimpleDataElt;
5355
import org.openlowcode.tools.structure.TextDataElt;
5456
import org.openlowcode.tools.structure.TextDataEltType;
@@ -894,6 +896,21 @@ public DataElt getDataElt(DataEltType type, String eltname, String objectfieldna
894896
ObjectIdDataElt objectid = new ObjectIdDataElt(eltname, textfield.getPayload());
895897
return objectid;
896898
}
899+
900+
if (type instanceof ObjectMasterIdDataEltType) {
901+
if (objectfieldname == null)
902+
throw new RuntimeException("objectid field should have an objectfieldname");
903+
ObjectDataElt object = this.thistable.getSelectionModel().getSelectedItem().getObject();
904+
SimpleDataElt field = object.lookupEltByName(objectfieldname);
905+
if (field == null)
906+
throw new RuntimeException(
907+
"field not found " + objectfieldname + ", available fields = " + object.dropFieldNames());
908+
if (!(field instanceof TextDataElt))
909+
throw new RuntimeException("field for name = " + objectfieldname + " is not text");
910+
TextDataElt textfield = (TextDataElt) field;
911+
ObjectMasterIdDataElt objectid = new ObjectMasterIdDataElt(eltname, textfield.getPayload());
912+
return objectid;
913+
}
897914

898915
if (type instanceof TextDataEltType) {
899916
TextDataElt updatenote = new TextDataElt(eltname, this.updatenotecomment);
@@ -977,6 +994,27 @@ public DataElt getDataElt(DataEltType type, String eltname, String objectfieldna
977994
return output;
978995
}
979996

997+
998+
if (payloadtypeinarray instanceof ObjectMasterIdDataEltType) {
999+
Iterator<ObjectTableRow> selectedobjects = this.thistable.getSelectionModel().getSelectedItems()
1000+
.iterator();
1001+
ArrayDataElt<ObjectMasterIdDataElt> output = new ArrayDataElt<ObjectMasterIdDataElt>(eltname, payloadtypeinarray);
1002+
while (selectedobjects.hasNext()) {
1003+
ObjectDataElt thisobject = selectedobjects.next().getObject();
1004+
SimpleDataElt field = thisobject.lookupEltByName(objectfieldname);
1005+
if (field == null)
1006+
throw new RuntimeException("field not found " + objectfieldname + ", available fields = "
1007+
+ thisobject.dropFieldNames());
1008+
if (!(field instanceof TextDataElt))
1009+
throw new RuntimeException("field for name = " + objectfieldname + " is not text");
1010+
TextDataElt textfield = (TextDataElt) field;
1011+
ObjectMasterIdDataElt objectid = new ObjectMasterIdDataElt(eltname, textfield.getPayload());
1012+
output.addElement(objectid);
1013+
}
1014+
return output;
1015+
}
1016+
1017+
9801018
}
9811019
// add here treatment of array element.
9821020

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public void generateWidgetCode(SourceGenerator sg, Module module, String locatio
446446
+ "(blanklinkforaddtoleft" + linkobjectvariable + "s.getObjectInput());");
447447
sg.wl(" createlinkactionforaddtoleft" + linkobjectvariable + "s.setRight" + rightobjectvariable
448448
+ "id(" + rightobjectvariable + "searchforaddtoleft" + linkobjectvariable
449-
+ "s.getresultarray().getAttributeArrayInput(" + rightobjectclass + ".getLinkobjecttomasterrightidMarker()));");
449+
+ "s.getresultarray().getAttributeArrayInput(" + rightobjectclass + ".getIdMarker()));");
450450
sg.wl(" ");
451451
sg.wl(" SActionButton createlinkbuttonforaddtoleft" + linkobjectvariable
452452
+ " = new SActionButton(\"Add Link\", createlinkactionforaddtoleft" + linkobjectvariable

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

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/********************************************************************************
2+
* Copyright (c) 2020 [Open Lowcode SAS](https://openlowcode.com/)
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0 .
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
********************************************************************************/
10+
111
package org.openlowcode.design.data.properties.basic;
212

313
import java.io.IOException;
@@ -16,6 +26,16 @@
1626
import org.openlowcode.design.pages.PageDefinition;
1727
import org.openlowcode.tools.misc.NamedList;
1828

29+
/**
30+
* The property for an object that is left for a link to master relationship
31+
*
32+
* @author <a href="https://openlowcode.com/" rel="nofollow">Open Lowcode
33+
* SAS</a>
34+
*
35+
* @param <E> current object
36+
* @param <F> link to master object
37+
* @since 1.9
38+
*/
1939
public class LeftForLinkToMaster<E extends DataObjectDefinition, F extends DataObjectDefinition>
2040
extends
2141
Property<LeftForLinkToMaster<E, F>> {
@@ -111,7 +131,9 @@ public DataObjectDefinition getLinkObjectDefinition() {
111131
public LinkObjectToMaster<E, F> getLinkObjectProperty() {
112132
DataObjectDefinition linkobject = linkdataobject;
113133
@SuppressWarnings("unchecked")
114-
LinkObjectToMaster<E, F> linkobjectproperty = (LinkObjectToMaster<E, F>) linkobject.getPropertyByName("LINKOBJECTTOMASTER");
134+
LinkObjectToMaster<
135+
E,
136+
F> linkobjectproperty = (LinkObjectToMaster<E, F>) linkobject.getPropertyByName("LINKOBJECTTOMASTER");
115137
if (linkobjectproperty == null)
116138
throw new RuntimeException("link object does not have property");
117139
return linkobjectproperty;
@@ -318,15 +340,16 @@ public void generateWidgetCode(SourceGenerator sg, Module module, String locatio
318340
.formatForAttribute(parentproperty.getRightObjectForLink().getName());
319341
String rightobjectclass = StringFormatter
320342
.formatForJavaClass(parentproperty.getRightObjectForLink().getName());
321-
343+
322344
// ---- temporary code.
323345
DisplayLinkAsAttributeFromLeftObject<E, F> attributeasleft = null;
324346
/*
325-
@SuppressWarnings("unchecked")
326-
DisplayLinkAsAttributeFromLeftObject<E, F> attributeasleft = (DisplayLinkAsAttributeFromLeftObject<
327-
E, F>) parentproperty.getLinkObjectProperty().getBusinessRuleByName("DISPLAYASATTRIBUTEFROMLEFT");
328-
*/
329-
347+
* @SuppressWarnings("unchecked") DisplayLinkAsAttributeFromLeftObject<E, F>
348+
* attributeasleft = (DisplayLinkAsAttributeFromLeftObject< E, F>)
349+
* parentproperty.getLinkObjectProperty().getBusinessRuleByName(
350+
* "DISPLAYASATTRIBUTEFROMLEFT");
351+
*/
352+
330353
if (attributeasleft == null) {
331354
// -------------------------------------------------------------------------------------------------
332355
// show link as table. This is the classical display
@@ -346,7 +369,7 @@ public void generateWidgetCode(SourceGenerator sg, Module module, String locatio
346369
sg.wl(" this);");
347370
sg.wl(" left" + linkobjectvariable + "s.addDisplayProfile(" + linkobjectclass + "Definition.get"
348371
+ linkobjectclass + "Definition().getDisplayProfileHideleftobjectfields());");
349-
372+
sg.wl(" left" + linkobjectvariable + "s.setMinFieldPriority(-900);");
350373
sg.wl(" left" + linkobjectvariable + "s.setWarningForUnsavedEdition();");
351374
sg.wl(" AtgMassupdate" + linkobjectvariable + "andshowleftAction.ActionRef updateleft"
352375
+ linkobjectvariable + "s = AtgMassupdate" + linkobjectvariable
@@ -366,7 +389,8 @@ public void generateWidgetCode(SourceGenerator sg, Module module, String locatio
366389
+ linkobjectvariable + "action = AtgShow" + rightobjectvariable
367390
+ "Action.get().getActionRef();");
368391
sg.wl(" showright" + rightobjectvariable + "for" + linkobjectvariable + "action.setId(left"
369-
+ linkobjectvariable + "s.getAttributeInput(" + linkobjectclass + ".getRgmsidMarker()));");
392+
+ linkobjectvariable + "s.getAttributeInput(" + linkobjectclass
393+
+ ".getLinkobjecttomasterrightidMarker()));");
370394
sg.wl(" left" + linkobjectvariable + "s.addDefaultAction(showright" + rightobjectvariable + "for"
371395
+ linkobjectvariable + "action);");
372396
sg.wl(" ");
@@ -414,8 +438,8 @@ public void generateWidgetCode(SourceGenerator sg, Module module, String locatio
414438
+ "s = new SObjectDisplay<" + linkobjectclass + ">(\"BLANK"
415439
+ linkobject.getName().toUpperCase() + "FORADD\",");
416440

417-
sg.wl(" this.getLeftforlinktomasterfor" + linkobjectvariable + "blankforadd(), " + linkobjectclass
418-
+ ".getDefinition(),this, false);");
441+
sg.wl(" this.getLeftforlinktomasterfor" + linkobjectvariable + "blankforadd(), "
442+
+ linkobjectclass + ".getDefinition(),this, false);");
419443
sg.wl(" blanklinkforaddtoleft" + linkobjectvariable + "s.setHideReadOnly();");
420444
sg.wl(" ");
421445
sg.wl(" addtoleft" + linkobjectvariable + "s.addElement(blanklinkforaddtoleft" + linkobjectvariable
@@ -462,7 +486,7 @@ public void generateWidgetCode(SourceGenerator sg, Module module, String locatio
462486
+ "button);");
463487
sg.wl(" " + locationname + ".addElement(left" + linkobjectvariable + "buttonbar);");
464488
sg.wl(" " + locationname + ".addElement(left" + linkobjectvariable + "s);");
465-
}
489+
}
466490

467491
}
468492

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

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.ArrayList;
1515
import java.util.HashMap;
1616
import java.util.List;
17+
import java.util.function.Function;
1718
import java.util.logging.Logger;
1819

1920
import org.openlowcode.tools.messages.MessageWriter;
@@ -282,12 +283,12 @@ public QueryCondition getUniversalQueryCondition(DataObjectPropertyDefinition<E>
282283
* @return generates a data object id array template.
283284
*/
284285
public abstract DataObjectId<E>[] generateIdArrayTemplate();
285-
286+
286287
/**
287288
* @return generates a data object master id array template
288289
*/
289290
public abstract DataObjectMasterId<E>[] generateMasterIdArrayTemplate();
290-
291+
291292
/**
292293
* @return a blank object
293294
*/
@@ -335,6 +336,48 @@ public <Z extends Object> JoinQueryConditionDefinition<Z> generateJoinQueryDefin
335336
this, operator);
336337
}
337338

339+
/**
340+
* generates a join query definition
341+
*
342+
* @param maintable the main table to join this
343+
* object into
344+
* @param maintablefield the field to use on main table
345+
* @param propertyname name of the property to join in
346+
* @param propertyfield field of the property
347+
* @param sidetablesuffix suffix to add to this table
348+
* @param operator typically equals for a foreign
349+
* key
350+
* @param additionalqueryconditiononsideobject additional condition on side
351+
* object (e.g. only get latest
352+
* version)
353+
* @return a join query condition
354+
* @since 1.9
355+
*/
356+
@SuppressWarnings({ "unchecked", "rawtypes" })
357+
public <Z extends Object> JoinQueryConditionDefinition<Z> generateJoinQueryDefinition(
358+
StoredTableSchema maintable,
359+
StoredFieldSchema<Z> maintablefield,
360+
String propertyname,
361+
String propertyfield,
362+
String sidetablesuffix,
363+
QueryOperator<Z> operator,
364+
Function<String, QueryCondition> additionalqueryconditiononsideobject) {
365+
DataObjectPropertyDefinition<E> propertydefinition = propertydeflist.lookupOnName(propertyname);
366+
if (propertydefinition == null)
367+
throw new RuntimeException("did not find property with name = '" + propertyname + "', available list = "
368+
+ propertydeflist.dropNameList());
369+
FieldSchema<?> field = propertydefinition.getFieldSchemaByName(propertyfield);
370+
if (field == null)
371+
throw new RuntimeException("did not find field with name '" + propertyfield + ", , available list = "
372+
+ propertydefinition.dropfieldnamelist());
373+
if (!(field instanceof StoredFieldSchema))
374+
throw new RuntimeException("definition of externalfield joinquerycondition " + maintablefield.getName()
375+
+ " is referencing another external field : " + field);
376+
StoredFieldSchema<?> storedfield = (StoredFieldSchema<?>) field;
377+
return new JoinQueryConditionDefinition(maintable, maintablefield, tableschema, sidetablesuffix, storedfield,
378+
this, operator, additionalqueryconditiononsideobject);
379+
}
380+
338381
/**
339382
* checks if the property with the given name exists
340383
*

0 commit comments

Comments
 (0)