Skip to content

Commit cb13f8d

Browse files
author
Open Lowcode SAS
committed
Close #260
1 parent 019cff9 commit cb13f8d

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public class CObjectArrayField
8888
private CPageInlineAction feedinginlineaction;
8989
private CInlineActionDataRef feedinginlineactionoutputdata;
9090
private Tooltip tooltip;
91+
private boolean keeponlyone;
9192

9293
/**
9394
* creates an object array field widget from a message from the server
@@ -144,6 +145,7 @@ public CObjectArrayField(MessageReader reader, CPageSignifPath parentpath) throw
144145
this.feedinginlineactionoutputdata = new CInlineActionDataRef(reader, this);
145146
reader.returnNextEndStructure("INLACT");
146147
}
148+
this.keeponlyone = reader.returnNextBooleanField("KOO");
147149
reader.returnNextEndStructure("OBJARF");
148150

149151
}
@@ -154,7 +156,8 @@ public CPageNode deepcopyWithCallback(Callback callback) {
154156
}
155157

156158
public ArrayDataElt<ObjectDataElt> getExternalContent(CPageData inputdata, CPageDataRef dataref) {
157-
if (dataref==null) return new ArrayDataElt<ObjectDataElt>("INPUTDATA", new ObjectDataEltType());
159+
if (dataref == null)
160+
return new ArrayDataElt<ObjectDataElt>("INPUTDATA", new ObjectDataEltType());
158161
DataElt thiselement = inputdata.lookupDataElementByName(dataref.getName());
159162
if (thiselement == null)
160163
throw new RuntimeException(String.format("could not find any page data with name = %s", dataref.getName()));
@@ -257,13 +260,14 @@ public DataElt getDataElt(DataEltType type, String eltname, String objectfieldna
257260
if (payloadtypeinarray instanceof ObjectDataEltType) {
258261
ObjectDataEltType objecttype = (ObjectDataEltType) payloadtypeinarray;
259262
ArrayDataElt<ObjectDataElt> output = new ArrayDataElt<ObjectDataElt>(eltname, objecttype);
260-
for (int i = 0; i < thiselementarray.getObjectNumber(); i++) {
261-
// fields are not sent back
262-
ObjectDataElt thisobject = thiselementarray.getObjectAtIndex(i);
263-
ObjectDataElt object = new ObjectDataElt(eltname);
264-
object.setUID(thisobject.getUID());
265-
output.addElement(object);
266-
}
263+
if (thiselementarray != null)
264+
for (int i = 0; i < thiselementarray.getObjectNumber(); i++) {
265+
// fields are not sent back
266+
ObjectDataElt thisobject = thiselementarray.getObjectAtIndex(i);
267+
ObjectDataElt object = new ObjectDataElt(eltname);
268+
object.setUID(thisobject.getUID());
269+
output.addElement(object);
270+
}
267271
return output;
268272
}
269273
}
@@ -280,8 +284,11 @@ public void forceUpdateData(DataElt dataelt) {
280284
treated = true;
281285
}
282286
if (dataelt instanceof ObjectDataElt) {
287+
283288
ObjectDataElt element = (ObjectDataElt) dataelt;
289+
if (this.keeponlyone) if (thiselementarray.getObjectNumber()==1) thiselementarray.removeObjectAtIndex(0);
284290
thiselementarray.addElement(element.deepcopy(thiselementarray.getName()));
291+
285292
refreshDisplay();
286293
treated = true;
287294
}

src/org/openlowcode/server/graphic/widget/SObjectArrayField.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class SObjectArrayField<E extends DataObject<E>>
5050
implements
5151
SDefaultPath {
5252
private boolean inlinefeeding;
53+
private boolean keeponlyone;
5354
private String label;
5455
private String helper;
5556
private ArrayDataElt<TObjectDataElt<E>> inputdata;
@@ -99,8 +100,13 @@ public SObjectArrayField(
99100
this.inlinefeeding = false;
100101
this.fieldtoshow = fieldtoshow;
101102
this.activeprofiles = new NamedList<DisplayProfile<E>>();
103+
this.keeponlyone = false;
102104
}
103105

106+
public void setKeepOnlyOne() {
107+
this.keeponlyone=true;
108+
}
109+
104110
/**
105111
* adds a display profile to hide some fields
106112
*
@@ -187,6 +193,7 @@ public void WritePayloadToCDL(MessageWriter writer, SPageData input, SecurityBuf
187193
} else {
188194
writer.addBooleanField("INF", false);
189195
}
196+
writer.addBooleanField("KOO",this.keeponlyone);
190197
}
191198

192199
@Override

src/org/openlowcode/tools/structure/ArrayDataElt.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,21 @@ public ArrayDataElt(String name, DataEltType arrayelementtype, E[] objectarray)
6969
}
7070

7171
/**
72+
*
7273
* @return the number of objects in the array
7374
*/
7475
public int getObjectNumber() {
7576
return this.arraycontent.size();
7677
}
7778

79+
/**
80+
*
81+
* @param index a number between 0 (included) and getObjectNumber (excluded)
82+
*/
83+
public void removeObjectAtIndex(int index) {
84+
this.arraycontent.remove(index);
85+
}
86+
7887
/**
7988
* @param index
8089
* @return

0 commit comments

Comments
 (0)