Skip to content

Commit e37d94b

Browse files
author
Open Lowcode SAS
committed
Helper for #258
1 parent 9f2d476 commit e37d94b

1 file changed

Lines changed: 42 additions & 35 deletions

File tree

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

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@
8181
*/
8282
public class CChoiceField
8383
extends
84-
CBusinessField<SimpleDataElt> implements ObjectDataElementKeyExtractor<ObjectDataElt,CChoiceFieldValue> {
84+
CBusinessField<SimpleDataElt>
85+
implements
86+
ObjectDataElementKeyExtractor<ObjectDataElt, CChoiceFieldValue> {
8587
private static Logger logger = Logger.getLogger(CChoiceField.class.getName());
8688
private String label;
8789
private String datafieldname;
@@ -242,7 +244,14 @@ public CChoiceField(MessageReader reader, CPageSignifPath parentpath) throws OLc
242244

243245
}
244246

245-
private ChoiceDataElt<CChoiceFieldValue> getExternalContent(CPageData inputdata, CPageDataRef dataref) {
247+
/**
248+
* Parses a data element from the page input data
249+
*
250+
* @param inputdata input data for th epage
251+
* @param dataref reference of the page
252+
* @return the choice data element
253+
*/
254+
public static ChoiceDataElt<CChoiceFieldValue> getExternalContent(CPageData inputdata, CPageDataRef dataref) {
246255
DataElt thiselement = inputdata.lookupDataElementByName(dataref.getName());
247256
if (thiselement == null)
248257
throw new RuntimeException("could not find any page data with name = " + dataref.getName());
@@ -280,11 +289,10 @@ public Node getNode(
280289
}
281290
} else {
282291
currentchoice = findChoiceFromStoredValue(defaultvaluecode);
283-
284292

285293
}
286-
this.initialchoice=currentchoice;
287-
logger.finest("Set Initial Choice = "+currentchoice);
294+
this.initialchoice = currentchoice;
295+
logger.finest("Set Initial Choice = " + currentchoice);
288296
logger.finest("--- Printing Choice field with label = " + label + ", current choice = " + currentchoice
289297
+ ",data referenece is " + (datareference == null ? "NULL" : "NOTNULL")
290298
+ ", restricted values length = " + (restrictedvalues != null ? restrictedvalues.size() : "NONE"));
@@ -322,10 +330,11 @@ public DataElt getDataElt(DataEltType type, String eltname, String objectfieldna
322330
"Only ChoiceDataEltType can be extracted from CChoiceField in single selection mode, but request was %s ",
323331
type));
324332
// case of read-write element
325-
if (this.choicebox!=null) return new ChoiceDataElt<CChoiceFieldValue>(eltname, this.choicebox.getValue());
333+
if (this.choicebox != null)
334+
return new ChoiceDataElt<CChoiceFieldValue>(eltname, this.choicebox.getValue());
326335
// case of read-only element, return the initial choice (the best we have)
327336
// do not read it from widget as it would be more complex
328-
return new ChoiceDataElt<CChoiceFieldValue>(eltname,this.initialchoice);
337+
return new ChoiceDataElt<CChoiceFieldValue>(eltname, this.initialchoice);
329338
}
330339

331340
@Override
@@ -368,7 +377,7 @@ private CChoiceFieldValue findChoiceFromStoredValue(String storedvalue) {
368377
logger.warning("display code not found for list of value, code = " + storedvalue + ", field name = "
369378
+ this.datafieldname);
370379
return generateInvalidValue(storedvalue);
371-
380+
372381
}
373382

374383
@Override
@@ -549,12 +558,13 @@ public ObservableValue<CChoiceFieldValue> call(CellDataFeatures<ObjectTableRow,
549558
ArrayList<String> restrictionsonupdate = line.hasFieldRestriction(fieldname);
550559
if (displayvalue == null) {
551560
displayvalue = thischoicefield.getBlankChoiceField();
552-
if (code!=null) if (code.length()>0) {
553-
displayvalue = thischoicefield.generateInvalidValue(code);
554-
}
555-
}
556-
557-
if (displayvalue != null)
561+
if (code != null)
562+
if (code.length() > 0) {
563+
displayvalue = thischoicefield.generateInvalidValue(code);
564+
}
565+
}
566+
567+
if (displayvalue != null)
558568
displayvalue.setRestrictionsOnNextValues(restrictionsonupdate);
559569
if (line.isRowFrozen())
560570
displayvalue = displayvalue.duplicateAsFrozen();
@@ -742,12 +752,14 @@ public TableColumn<ObjectTableRow, CChoiceFieldValue> getTableColumn(
742752
PageActionManager pageactionmanager,
743753
boolean largedisplay,
744754
int rowheight,
745-
String actionkeyforupdate,boolean forcefieldupdatable) {
755+
String actionkeyforupdate,
756+
boolean forcefieldupdatable) {
746757

747758
TableColumn<
748759
ObjectTableRow,
749760
CChoiceFieldValue> thiscolumn = new TableColumn<ObjectTableRow, CChoiceFieldValue>(this.getLabel());
750-
if (((actionkeyforupdate != null) && (this.isEditable())) || (actionkeyforupdate!=null && forcefieldupdatable)) {
761+
if (((actionkeyforupdate != null) && (this.isEditable()))
762+
|| (actionkeyforupdate != null && forcefieldupdatable)) {
751763
thiscolumn.setEditable(true);
752764
thiscolumn.setOnEditCommit(new TableColumnOnEditCommit(this));
753765
} else {
@@ -781,7 +793,7 @@ public TableColumn<ObjectTableRow, CChoiceFieldValue> getTableColumn(
781793
}
782794

783795
public CChoiceFieldValue generateInvalidValue(String code) {
784-
return new CChoiceFieldValue(code,"Invalid value "+code,"Invalid value currently in database",-5);
796+
return new CChoiceFieldValue(code, "Invalid value " + code, "Invalid value currently in database", -5);
785797
}
786798

787799
/**
@@ -1012,38 +1024,33 @@ public void overridesLabel(String newlabel) {
10121024

10131025
}
10141026

1015-
1016-
10171027
// ---------------------------------------------------------------------------
10181028
// key extractors
10191029
// ---------------------------------------------------------------------------
1020-
1030+
10211031
@Override
10221032
public Function<ObjectDataElt, CChoiceFieldValue> fieldExtractor() {
1023-
1033+
10241034
return (t) -> {
1025-
SimpleDataElt field = t.lookupEltByName(CChoiceField.this.datafieldname);
1026-
String code = field.defaultTextRepresentation();
1027-
CChoiceFieldValue displayvalue = CChoiceField.this.valuesbycode.get(code); // try to get display value
1028-
1029-
if (displayvalue == null)
1030-
displayvalue = CChoiceField.this.getBlankChoiceField();
1031-
return displayvalue;
1032-
};
1033-
1034-
1035+
SimpleDataElt field = t.lookupEltByName(CChoiceField.this.datafieldname);
1036+
String code = field.defaultTextRepresentation();
1037+
CChoiceFieldValue displayvalue = CChoiceField.this.valuesbycode.get(code); // try to get display value
1038+
1039+
if (displayvalue == null)
1040+
displayvalue = CChoiceField.this.getBlankChoiceField();
1041+
return displayvalue;
1042+
};
1043+
10351044
}
10361045

10371046
@Override
10381047
public Function<CChoiceFieldValue, String> keyExtractor() {
1039-
return (t) -> (t.getStorageCode());
1048+
return (t) -> (t.getStorageCode());
10401049
}
10411050

10421051
@Override
10431052
public Function<CChoiceFieldValue, String> labelExtractor() {
1044-
return (t) -> (t.getDisplayvalue());
1053+
return (t) -> (t.getDisplayvalue());
10451054
}
10461055

1047-
1048-
10491056
}

0 commit comments

Comments
 (0)