Skip to content

Commit 7579528

Browse files
author
Open Lowcode SAS
committed
Close #94
1 parent 7b65d0b commit 7579528

15 files changed

+2182
-449
lines changed

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.io.IOException;
1414
import java.util.ArrayList;
1515
import java.util.HashMap;
16-
16+
import java.util.function.Function;
1717
import java.util.logging.Logger;
1818

1919
import org.openlowcode.tools.messages.MessageBooleanField;
@@ -31,6 +31,7 @@
3131
import org.openlowcode.client.graphic.CPageNode;
3232
import org.openlowcode.client.graphic.CPageSignifPath;
3333
import org.openlowcode.client.graphic.widget.table.CObjectGridLine;
34+
import org.openlowcode.client.graphic.widget.table.ObjectDataElementKeyExtractor;
3435
import org.openlowcode.client.graphic.widget.table.ObjectTableRow;
3536
import org.openlowcode.client.graphic.widget.tools.CChoiceFieldValue;
3637
import org.openlowcode.client.graphic.widget.tools.ChoiceField;
@@ -80,7 +81,7 @@
8081
*/
8182
public class CChoiceField
8283
extends
83-
CBusinessField<SimpleDataElt> {
84+
CBusinessField<SimpleDataElt> implements ObjectDataElementKeyExtractor<ObjectDataElt,CChoiceFieldValue> {
8485
private static Logger logger = Logger.getLogger(CChoiceField.class.getName());
8586
private String label;
8687
private String datafieldname;
@@ -992,4 +993,38 @@ public void overridesLabel(String newlabel) {
992993

993994
}
994995

996+
997+
998+
// ---------------------------------------------------------------------------
999+
// key extractors
1000+
// ---------------------------------------------------------------------------
1001+
1002+
@Override
1003+
public Function<ObjectDataElt, CChoiceFieldValue> fieldExtractor() {
1004+
1005+
return (t) -> {
1006+
SimpleDataElt field = t.lookupEltByName(CChoiceField.this.datafieldname);
1007+
String code = field.defaultTextRepresentation();
1008+
CChoiceFieldValue displayvalue = CChoiceField.this.valuesbycode.get(code); // try to get display value
1009+
1010+
if (displayvalue == null)
1011+
displayvalue = CChoiceField.this.getBlankChoiceField();
1012+
return displayvalue;
1013+
};
1014+
1015+
1016+
}
1017+
1018+
@Override
1019+
public Function<CChoiceFieldValue, String> keyExtractor() {
1020+
return (t) -> (t.getStorageCode());
1021+
}
1022+
1023+
@Override
1024+
public Function<CChoiceFieldValue, String> labelExtractor() {
1025+
return (t) -> (t.getDisplayvalue());
1026+
}
1027+
1028+
1029+
9951030
}

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

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.text.DecimalFormat;
1616
import java.text.ParseException;
1717
import java.util.ArrayList;
18+
import java.util.function.BiConsumer;
19+
import java.util.function.Function;
1820

1921
import org.openlowcode.tools.messages.MessageBooleanField;
2022
import org.openlowcode.tools.messages.MessageElement;
@@ -29,12 +31,16 @@
2931
import org.openlowcode.client.graphic.CPageNode;
3032
import org.openlowcode.client.graphic.CPageSignifPath;
3133
import org.openlowcode.client.graphic.widget.fields.BigDecimalFormatValidator;
34+
import org.openlowcode.client.graphic.widget.fields.FormatValidator;
3235
import org.openlowcode.client.graphic.widget.format.NiceLockableBigDecimalStringConverter;
3336
import org.openlowcode.client.graphic.widget.table.CObjectGridLine;
3437
import org.openlowcode.client.graphic.widget.table.LargeTextTableCell;
3538
import org.openlowcode.client.graphic.widget.table.LargeTextTreeTableCell;
39+
import org.openlowcode.client.graphic.widget.table.ObjectDataElementValueUpdater;
3640
import org.openlowcode.client.graphic.widget.table.ObjectTableRow;
3741
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;
3844
import org.openlowcode.client.runtime.PageActionManager;
3945
import org.openlowcode.tools.structure.DataElt;
4046
import org.openlowcode.tools.structure.DataEltType;
@@ -76,7 +82,7 @@
7682
*/
7783
public class CDecimalField
7884
extends
79-
CBusinessField<DecimalDataElt> {
85+
CBusinessField<DecimalDataElt> implements ObjectDataElementValueUpdater<ObjectDataElt,BigDecimal>{
8086
private String helper;
8187
private String label;
8288
private String datafieldname;
@@ -288,6 +294,7 @@ public CDecimalField(MessageReader reader, CPageSignifPath parentpath) throws OL
288294
this.decimalformatter = new CDecimalFormatter(reader);
289295
}
290296
reader.returnNextEndStructure("DCF");
297+
this.formatvalidator = new BigDecimalFormatValidator(precision, scale);
291298
}
292299

293300
private CDecimalFormatter decimalformatter;
@@ -384,7 +391,7 @@ public TreeTableColumn<ObjectDataElt, LockableBigDecimal> getTreeTableColumn(
384391
thiscolumn.setCellFactory(column -> {
385392
return new LargeTextTreeTableCell<ObjectDataElt, LockableBigDecimal>(
386393
new NiceLockableBigDecimalStringConverter(precision, scale), validator, this.decimalformatter,
387-
false, true) {
394+
false, true,1) {
388395
@Override
389396
public void updateItem(LockableBigDecimal decimal, boolean empty) {
390397
logger.fine("Updating field for decimal = " + decimal + " empty = " + empty);
@@ -922,4 +929,46 @@ public void overridesLabel(String newlabel) {
922929
this.label = newlabel;
923930

924931
}
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+
}
925974
}

0 commit comments

Comments
 (0)