|
81 | 81 | */ |
82 | 82 | public class CChoiceField |
83 | 83 | extends |
84 | | - CBusinessField<SimpleDataElt> implements ObjectDataElementKeyExtractor<ObjectDataElt,CChoiceFieldValue> { |
| 84 | + CBusinessField<SimpleDataElt> |
| 85 | + implements |
| 86 | + ObjectDataElementKeyExtractor<ObjectDataElt, CChoiceFieldValue> { |
85 | 87 | private static Logger logger = Logger.getLogger(CChoiceField.class.getName()); |
86 | 88 | private String label; |
87 | 89 | private String datafieldname; |
@@ -242,7 +244,14 @@ public CChoiceField(MessageReader reader, CPageSignifPath parentpath) throws OLc |
242 | 244 |
|
243 | 245 | } |
244 | 246 |
|
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) { |
246 | 255 | DataElt thiselement = inputdata.lookupDataElementByName(dataref.getName()); |
247 | 256 | if (thiselement == null) |
248 | 257 | throw new RuntimeException("could not find any page data with name = " + dataref.getName()); |
@@ -280,11 +289,10 @@ public Node getNode( |
280 | 289 | } |
281 | 290 | } else { |
282 | 291 | currentchoice = findChoiceFromStoredValue(defaultvaluecode); |
283 | | - |
284 | 292 |
|
285 | 293 | } |
286 | | - this.initialchoice=currentchoice; |
287 | | - logger.finest("Set Initial Choice = "+currentchoice); |
| 294 | + this.initialchoice = currentchoice; |
| 295 | + logger.finest("Set Initial Choice = " + currentchoice); |
288 | 296 | logger.finest("--- Printing Choice field with label = " + label + ", current choice = " + currentchoice |
289 | 297 | + ",data referenece is " + (datareference == null ? "NULL" : "NOTNULL") |
290 | 298 | + ", restricted values length = " + (restrictedvalues != null ? restrictedvalues.size() : "NONE")); |
@@ -322,10 +330,11 @@ public DataElt getDataElt(DataEltType type, String eltname, String objectfieldna |
322 | 330 | "Only ChoiceDataEltType can be extracted from CChoiceField in single selection mode, but request was %s ", |
323 | 331 | type)); |
324 | 332 | // 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()); |
326 | 335 | // case of read-only element, return the initial choice (the best we have) |
327 | 336 | // 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); |
329 | 338 | } |
330 | 339 |
|
331 | 340 | @Override |
@@ -368,7 +377,7 @@ private CChoiceFieldValue findChoiceFromStoredValue(String storedvalue) { |
368 | 377 | logger.warning("display code not found for list of value, code = " + storedvalue + ", field name = " |
369 | 378 | + this.datafieldname); |
370 | 379 | return generateInvalidValue(storedvalue); |
371 | | - |
| 380 | + |
372 | 381 | } |
373 | 382 |
|
374 | 383 | @Override |
@@ -549,12 +558,13 @@ public ObservableValue<CChoiceFieldValue> call(CellDataFeatures<ObjectTableRow, |
549 | 558 | ArrayList<String> restrictionsonupdate = line.hasFieldRestriction(fieldname); |
550 | 559 | if (displayvalue == null) { |
551 | 560 | 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) |
558 | 568 | displayvalue.setRestrictionsOnNextValues(restrictionsonupdate); |
559 | 569 | if (line.isRowFrozen()) |
560 | 570 | displayvalue = displayvalue.duplicateAsFrozen(); |
@@ -742,12 +752,14 @@ public TableColumn<ObjectTableRow, CChoiceFieldValue> getTableColumn( |
742 | 752 | PageActionManager pageactionmanager, |
743 | 753 | boolean largedisplay, |
744 | 754 | int rowheight, |
745 | | - String actionkeyforupdate,boolean forcefieldupdatable) { |
| 755 | + String actionkeyforupdate, |
| 756 | + boolean forcefieldupdatable) { |
746 | 757 |
|
747 | 758 | TableColumn< |
748 | 759 | ObjectTableRow, |
749 | 760 | 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)) { |
751 | 763 | thiscolumn.setEditable(true); |
752 | 764 | thiscolumn.setOnEditCommit(new TableColumnOnEditCommit(this)); |
753 | 765 | } else { |
@@ -781,7 +793,7 @@ public TableColumn<ObjectTableRow, CChoiceFieldValue> getTableColumn( |
781 | 793 | } |
782 | 794 |
|
783 | 795 | 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); |
785 | 797 | } |
786 | 798 |
|
787 | 799 | /** |
@@ -1012,38 +1024,33 @@ public void overridesLabel(String newlabel) { |
1012 | 1024 |
|
1013 | 1025 | } |
1014 | 1026 |
|
1015 | | - |
1016 | | - |
1017 | 1027 | // --------------------------------------------------------------------------- |
1018 | 1028 | // key extractors |
1019 | 1029 | // --------------------------------------------------------------------------- |
1020 | | - |
| 1030 | + |
1021 | 1031 | @Override |
1022 | 1032 | public Function<ObjectDataElt, CChoiceFieldValue> fieldExtractor() { |
1023 | | - |
| 1033 | + |
1024 | 1034 | 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 | + |
1035 | 1044 | } |
1036 | 1045 |
|
1037 | 1046 | @Override |
1038 | 1047 | public Function<CChoiceFieldValue, String> keyExtractor() { |
1039 | | - return (t) -> (t.getStorageCode()); |
| 1048 | + return (t) -> (t.getStorageCode()); |
1040 | 1049 | } |
1041 | 1050 |
|
1042 | 1051 | @Override |
1043 | 1052 | public Function<CChoiceFieldValue, String> labelExtractor() { |
1044 | | - return (t) -> (t.getDisplayvalue()); |
| 1053 | + return (t) -> (t.getDisplayvalue()); |
1045 | 1054 | } |
1046 | 1055 |
|
1047 | | - |
1048 | | - |
1049 | 1056 | } |
0 commit comments