|
15 | 15 | import java.text.DecimalFormat; |
16 | 16 | import java.text.ParseException; |
17 | 17 | import java.util.ArrayList; |
| 18 | +import java.util.function.BiConsumer; |
| 19 | +import java.util.function.Function; |
18 | 20 |
|
19 | 21 | import org.openlowcode.tools.messages.MessageBooleanField; |
20 | 22 | import org.openlowcode.tools.messages.MessageElement; |
|
29 | 31 | import org.openlowcode.client.graphic.CPageNode; |
30 | 32 | import org.openlowcode.client.graphic.CPageSignifPath; |
31 | 33 | import org.openlowcode.client.graphic.widget.fields.BigDecimalFormatValidator; |
| 34 | +import org.openlowcode.client.graphic.widget.fields.FormatValidator; |
32 | 35 | import org.openlowcode.client.graphic.widget.format.NiceLockableBigDecimalStringConverter; |
33 | 36 | import org.openlowcode.client.graphic.widget.table.CObjectGridLine; |
34 | 37 | import org.openlowcode.client.graphic.widget.table.LargeTextTableCell; |
35 | 38 | import org.openlowcode.client.graphic.widget.table.LargeTextTreeTableCell; |
| 39 | +import org.openlowcode.client.graphic.widget.table.ObjectDataElementValueUpdater; |
36 | 40 | import org.openlowcode.client.graphic.widget.table.ObjectTableRow; |
37 | 41 | import org.openlowcode.client.graphic.widget.table.CObjectGridLine.ObjectInGrid; |
| 42 | +import org.openlowcode.client.graphic.widget.table.EditableTreeTable; |
| 43 | +import org.openlowcode.client.graphic.widget.table.EditableTreeTable.Operator; |
38 | 44 | import org.openlowcode.client.runtime.PageActionManager; |
39 | 45 | import org.openlowcode.tools.structure.DataElt; |
40 | 46 | import org.openlowcode.tools.structure.DataEltType; |
|
76 | 82 | */ |
77 | 83 | public class CDecimalField |
78 | 84 | extends |
79 | | - CBusinessField<DecimalDataElt> { |
| 85 | + CBusinessField<DecimalDataElt> implements ObjectDataElementValueUpdater<ObjectDataElt,BigDecimal>{ |
80 | 86 | private String helper; |
81 | 87 | private String label; |
82 | 88 | private String datafieldname; |
@@ -288,6 +294,7 @@ public CDecimalField(MessageReader reader, CPageSignifPath parentpath) throws OL |
288 | 294 | this.decimalformatter = new CDecimalFormatter(reader); |
289 | 295 | } |
290 | 296 | reader.returnNextEndStructure("DCF"); |
| 297 | + this.formatvalidator = new BigDecimalFormatValidator(precision, scale); |
291 | 298 | } |
292 | 299 |
|
293 | 300 | private CDecimalFormatter decimalformatter; |
@@ -384,7 +391,7 @@ public TreeTableColumn<ObjectDataElt, LockableBigDecimal> getTreeTableColumn( |
384 | 391 | thiscolumn.setCellFactory(column -> { |
385 | 392 | return new LargeTextTreeTableCell<ObjectDataElt, LockableBigDecimal>( |
386 | 393 | new NiceLockableBigDecimalStringConverter(precision, scale), validator, this.decimalformatter, |
387 | | - false, true) { |
| 394 | + false, true,1) { |
388 | 395 | @Override |
389 | 396 | public void updateItem(LockableBigDecimal decimal, boolean empty) { |
390 | 397 | logger.fine("Updating field for decimal = " + decimal + " empty = " + empty); |
@@ -922,4 +929,46 @@ public void overridesLabel(String newlabel) { |
922 | 929 | this.label = newlabel; |
923 | 930 |
|
924 | 931 | } |
| 932 | + |
| 933 | + // ------------------------------------------------------------------------- |
| 934 | + // Extractor and integrator for management in tables |
| 935 | + // -------------------------------------------------------------------------- |
| 936 | + |
| 937 | + private DecimalDataElt extractDataElement(ObjectDataElt object) { |
| 938 | + SimpleDataElt simpledataelt = object.lookupEltByName(this.datafieldname); |
| 939 | + if (simpledataelt == null) throw new RuntimeException("Could not find "+this.datafieldname+" for object "+object); |
| 940 | + if (!(simpledataelt instanceof DecimalDataElt)) throw new RuntimeException("field "+this.datafieldname+" is not DecimalDataElt, but "+simpledataelt.getClass().getName()); |
| 941 | + return (DecimalDataElt) simpledataelt; |
| 942 | + } |
| 943 | + |
| 944 | + |
| 945 | + @Override |
| 946 | + public Function<ObjectDataElt, BigDecimal> fieldExtractor() { |
| 947 | + return (t) -> (extractDataElement(t).getPayload()); |
| 948 | + } |
| 949 | + |
| 950 | + @Override |
| 951 | + public Function<BigDecimal, String> keyExtractor() { |
| 952 | + return (t) -> (t.toString()); |
| 953 | + } |
| 954 | + |
| 955 | + @Override |
| 956 | + public Function<BigDecimal, String> labelExtractor() { |
| 957 | + return (t) -> (formatvalidator.print(t)); |
| 958 | + } |
| 959 | + |
| 960 | + @Override |
| 961 | + public BiConsumer<ObjectDataElt, BigDecimal> payloadIntegration() { |
| 962 | + return (t,u) -> {extractDataElement(t).updatePayload(u);}; |
| 963 | + } |
| 964 | + |
| 965 | + @Override |
| 966 | + public Operator<BigDecimal> operator() { |
| 967 | + return EditableTreeTable.BIGDECIMAL_OPERATOR; |
| 968 | + } |
| 969 | + |
| 970 | + @Override |
| 971 | + public FormatValidator<BigDecimal> formatValidator() { |
| 972 | + return formatvalidator; |
| 973 | + } |
925 | 974 | } |
0 commit comments