# HG changeset patch # User gernotbelger # Date 1528104329 -7200 # Node ID 31b3cae5de0d0c5811ff11068a8a953ffb03dc6f # Parent bfc0da2aa3aa31954cf836861de22264d6746e4b sortable table veg'zones diff -r bfc0da2aa3aa -r 31b3cae5de0d gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java --- 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); diff -r bfc0da2aa3aa -r 31b3cae5de0d gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java --- 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 :-( + } } });