Mercurial > dive4elements > river
changeset 9114:31b3cae5de0d
sortable table veg'zones
author | gernotbelger |
---|---|
date | Mon, 04 Jun 2018 11:25:29 +0200 (2018-06-04) |
parents | bfc0da2aa3aa |
children | a165cd63099f |
files | gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java |
diffstat | 2 files changed, 25 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java Mon Jun 04 08:50:18 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java Mon Jun 04 11:25:29 2018 +0200 @@ -30,6 +30,7 @@ import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.grid.SortNormalizer; import com.smartgwt.client.widgets.grid.events.RecordClickEvent; import com.smartgwt.client.widgets.grid.events.RecordClickHandler; import com.smartgwt.client.widgets.layout.HLayout; @@ -63,20 +64,32 @@ this.elements.setHeight(300); // this.elements.setShowHeaderContextMenu(false); this.elements.setCanReorderFields(false); - this.elements.setCanSort(false); + // this.elements.setCanSort(true); + this.elements.setCanEdit(editable); final ListGridField vegzoneField = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label()); vegzoneField.setType(ListGridFieldType.TEXT); vegzoneField.setWidth(245); + final SortNormalizer normalizer = new SortNormalizer() { - final ListGridField fromField = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from()); - fromField.setType(ListGridFieldType.INTEGER); + @Override + public Object normalize(final ListGridRecord record, final String fieldName) { + final String number = record.getAttribute(fieldName); + // String.format("%03d", number);// format.format(Integer.valueOf(number)); funktioniert hier leider nicht + final String numberFormat = "000" + number; + return numberFormat.substring(numberFormat.length() - 3); + } + }; final IntegerRangeValidator validator = new IntegerRangeValidator(); validator.setMin(0); validator.setMax(365); validator.setErrorMessage(this.MSG.uinfo_vegetation_zones_validation_range()); + final ListGridField fromField = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from()); + fromField.setType(ListGridFieldType.INTEGER); + fromField.setCanSort(true); + fromField.setSortNormalizer(normalizer); fromField.setValidators(validator); fromField.setWidth(80); fromField.setAlign(Alignment.RIGHT); @@ -86,8 +99,11 @@ toField.setValidators(validator); toField.setWidth(80); toField.setAlign(Alignment.RIGHT); + toField.setSortNormalizer(normalizer); - if (editable) { + if (editable) + + { final ListGridField removeField = createRemoveField(); this.elements.setFields(vegzoneField, fromField, toField, removeField);
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java Mon Jun 04 08:50:18 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java Mon Jun 04 11:25:29 2018 +0200 @@ -66,6 +66,11 @@ r.setAttribute("from", v1); r.setAttribute("to", v2); elements.addData(r); + final String sortField = elements.getSortField(); + if (sortField != null) { + elements.toggleSort(sortField); + elements.toggleSort(sortField); // HACK. has to be. otherwise normalizer won't be called :-( + } } });