diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java @ 9118:431f1c269be5

Veg-Zone Table improved, State change data recovery;
author gernotbelger
date Mon, 04 Jun 2018 19:38:59 +0200
parents 31b3cae5de0d
children 36c80c7fd02f
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java	Mon Jun 04 17:31:51 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java	Mon Jun 04 19:38:59 2018 +0200
@@ -19,6 +19,7 @@
 import org.dive4elements.river.client.shared.model.DataList;
 import org.dive4elements.river.client.shared.model.DefaultData;
 import org.dive4elements.river.client.shared.model.DefaultDataItem;
+import org.dive4elements.river.client.shared.model.VegetationZone;
 
 import com.google.gwt.core.client.GWT;
 import com.smartgwt.client.data.Record;
@@ -44,18 +45,11 @@
 public abstract class AbstractVegZonesTablePanel extends AbstractUIProvider {
     private static final long serialVersionUID = 1L;
 
-    private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR";
-
-    private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR";
-
     private static final String datakey = "vegzones";
 
     private final ListGrid elements = new ListGrid();
 
-    // private final HLayout input = new HLayout();
-
-    protected final ListGrid createTable(final Layout root, final DataList data, final int width, final boolean editable) {
-        data.add(VegetationzonesTablePanel.getDummyData()); // TODO: GET REAL DATA!
+    protected final ListGrid createTable(final Layout root, final DataList data, final String width, final boolean editable) {
 
         final Label title = new Label(data.get(0).getDescription());
         title.setHeight("35px"); // orig:25
@@ -64,13 +58,47 @@
         this.elements.setHeight(300); //
         this.elements.setShowHeaderContextMenu(false);
         this.elements.setCanReorderFields(false);
-        // this.elements.setCanSort(true);
+        this.elements.setCanSort(true);
+        this.elements.setSortField(1);
+        this.elements.setCanResizeFields(false);
 
         this.elements.setCanEdit(editable);
 
         final ListGridField vegzoneField = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label());
         vegzoneField.setType(ListGridFieldType.TEXT);
-        vegzoneField.setWidth(245);
+        vegzoneField.setWidth("*"); // 245
+        vegzoneField.setCanSort(false);
+        vegzoneField.setCanDragResize(true);
+
+        final ListGridField fromField = createIntTableField("from", this.MSG.uinfo_vegetation_zones_from(), true);
+
+        final ListGridField toField = createIntTableField("to", this.MSG.uinfo_vegetation_zones_to(), false);// nicht sortierbar nach "ÜFDauer bis"
+
+        if (editable) {
+            final ListGridField removeField = createRemoveField();
+            this.elements.setFields(vegzoneField, fromField, toField, removeField);
+        } else {
+            this.elements.setFields(vegzoneField, fromField, toField);
+        }
+
+        addDataInit(data);
+        root.setWidth(width);
+        root.addMember(title);
+        root.addMember(this.elements);
+        root.addMember(PanelHelper.getSpacer(10));
+
+        return this.elements;
+    }
+
+    private IntegerRangeValidator getValidator() {
+        final IntegerRangeValidator validator = new IntegerRangeValidator();
+        validator.setMin(0);
+        validator.setMax(365);
+        validator.setErrorMessage(this.MSG.uinfo_vegetation_zones_validation_range());
+        return validator;
+    }
+
+    private SortNormalizer getNormalizer() {
         final SortNormalizer normalizer = new SortNormalizer() {
 
             @Override
@@ -81,43 +109,20 @@
                 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);
+        return normalizer;
+    }
 
-        final ListGridField toField = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to());
-        toField.setType(ListGridFieldType.INTEGER);
-        toField.setValidators(validator);
-        toField.setWidth(80);
-        toField.setAlign(Alignment.RIGHT);
-        toField.setSortNormalizer(normalizer);
-
-        if (editable)
+    private ListGridField createIntTableField(final String key, final String msg, final boolean canSort) {
+        final ListGridField intField = new ListGridField(key, msg);
+        intField.setType(ListGridFieldType.INTEGER);
+        intField.setValidators(getValidator());
+        intField.setWidth(90);
+        intField.setAlign(Alignment.RIGHT);
+        intField.setSortNormalizer(getNormalizer());
+        intField.setCanSort(canSort);
+        intField.setCanDragResize(false);
 
-        {
-            final ListGridField removeField = createRemoveField();
-            this.elements.setFields(vegzoneField, fromField, toField, removeField);
-
-        } else {
-            this.elements.setFields(vegzoneField, fromField, toField);
-        }
-
-        addDataInit(data);
-
-        root.addMember(title);
-        root.addMember(this.elements);
-        root.addMember(PanelHelper.getSpacer(10));
-
-        return this.elements;
+        return intField;
     }
 
     private ListGridField createRemoveField() {
@@ -132,6 +137,8 @@
                 setCanGroupBy(false);
                 setCanFreeze(false);
                 setWidth(25);
+                setCanDragResize(false);
+                super.setCanToggle(false);
             }
         };
 
@@ -155,10 +162,10 @@
         for (final Data dataItemContainer : data.getAll()) {
             if (dataItemContainer.getItems() != null) {
                 for (final DataItem dataItem : dataItemContainer.getItems()) {
-                    if (dataItem.getStringValue() != null && dataItem.getStringValue().contains(TABLE_ROW_SEPARATOR)) {
+                    if (dataItem.getStringValue() != null) {
 
-                        final String[] rows = dataItem.getStringValue().split(TABLE_ROW_SEPARATOR);
-                        for (final String row : rows) {
+                        final List<VegetationZone> rows = VegetationZone.parse(dataItem.getStringValue());
+                        for (final VegetationZone row : rows) {
                             this.elements.addData(createEntry(row));
                         }
                     }
@@ -177,6 +184,7 @@
         final Canvas submit = getNextButton();
 
         final VLayout root = new VLayout();
+        root.setWidth(450);
         createWidget(root, data);
 
         layout.addMember(root);
@@ -199,10 +207,10 @@
         final Data str = getData(items, datakey);
         final DataItem[] strItems = str.getItems();
 
-        final String[] entries = strItems[0].getLabel().split(AbstractVegZonesTablePanel.TABLE_ROW_SEPARATOR);
-        for (final String entry : entries) {
-            final String[] vals = entry.split(AbstractVegZonesTablePanel.TABLE_CELL_SEPARATOR);
-            final Label dateLabel = new Label(vals[0] + " (" + vals[1] + "-" + vals[2] + ")");
+        final List<VegetationZone> entries = VegetationZone.parse(strItems[0].getLabel());
+
+        for (final VegetationZone entry : entries) {
+            final Label dateLabel = new Label(entry.getZoneName() + " (" + entry.getMin_day_overflow() + "-" + entry.getMax_day_overflow() + ")");
             dateLabel.setHeight(20);
             vLayout.addMember(dateLabel);
         }
@@ -214,24 +222,14 @@
         return layout;
     }
 
-    protected static final Data[] getDummyData() {
-        final List<Data> data = new ArrayList<Data>();
-
-        // TODO: move to messages
-        final String d = "Zonaler Wald" + TABLE_CELL_SEPARATOR + "0" + TABLE_CELL_SEPARATOR + "5" + TABLE_ROW_SEPARATOR//
-                + "Hartholzaue, trocken" + TABLE_CELL_SEPARATOR + "5" + TABLE_CELL_SEPARATOR + "40" + TABLE_ROW_SEPARATOR//
-                + "Hartholzaue, feucht" + TABLE_CELL_SEPARATOR + "40" + TABLE_CELL_SEPARATOR + "80" + TABLE_ROW_SEPARATOR//
-                + "Silberweidenwald" + TABLE_CELL_SEPARATOR + "80" + TABLE_CELL_SEPARATOR + "140" + TABLE_ROW_SEPARATOR//
-                + "Weidengebüsch" + TABLE_CELL_SEPARATOR + "140" + TABLE_CELL_SEPARATOR + "200" + TABLE_ROW_SEPARATOR//
-                + "Uferröhricht" + TABLE_CELL_SEPARATOR + "200" + TABLE_CELL_SEPARATOR + "260" + TABLE_ROW_SEPARATOR//
-                + "Uferpioniere" + TABLE_CELL_SEPARATOR + "260" + TABLE_CELL_SEPARATOR + "320" + TABLE_ROW_SEPARATOR//
-                + "Vegetationslos" + TABLE_CELL_SEPARATOR + "320" + TABLE_CELL_SEPARATOR + "365" + TABLE_ROW_SEPARATOR//
-                + "Wasserfläche" + TABLE_CELL_SEPARATOR + "365" + TABLE_CELL_SEPARATOR + "365" + TABLE_ROW_SEPARATOR;//
-
-        final DataItem item = new DefaultDataItem(datakey, "entryDescription", d); // DATA-key
-        data.add(new DefaultData(datakey, null, null, new DataItem[] { item }));
-        return data.toArray(new Data[data.size()]);
-    }
+    // protected static final Data[] getDataToAdd(final List<VegetationZone> list) {
+    // final List<Data> data = new ArrayList<Data>();
+    // final String d = VegetationZone.parseListToDataString(list);
+    //
+    // final DataItem item = new DefaultDataItem(datakey, "entryDescription", d);
+    // data.add(new DefaultData(datakey, null, null, new DataItem[] { item }));
+    // return data.toArray(new Data[data.size()]);
+    // }
 
     @Override
     protected final Data[] getData() {
@@ -239,44 +237,35 @@
 
         final ListGridRecord[] lgr = this.elements.getRecords();
         if (lgr.length == 0) {
-            return getDummyData();// new Data[0]; // return getDummyData();
+            return null; // getDataToAdd(VegetationZone.getStandardList());// new Data[0]; //SHOULD NOT HAPPEN
         }
-        String d = "";
+        final List<VegetationZone> zoneList = new ArrayList<VegetationZone>();
         for (final ListGridRecord element : lgr) {
             final Record r = element;
-            d += r.getAttribute("vegzone") + AbstractVegZonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("from")
-                    + AbstractVegZonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("to");
-            d += AbstractVegZonesTablePanel.TABLE_ROW_SEPARATOR;
+            final VegetationZone zone = VegetationZone.createFromTableEntry(r.getAttribute("vegzone"), r.getAttribute("from"), r.getAttribute("to"));
+            zoneList.add(zone);
         }
 
-        final DataItem item = new DefaultDataItem(datakey, null, d); // DATA-key
+        final DataItem item = new DefaultDataItem(datakey, null, VegetationZone.parseListToDataString(zoneList)); // DATA-key
         data.add(new DefaultData(datakey, null, null, new DataItem[] { item }));
         return data.toArray(new Data[data.size()]);
     }
 
-    public final ListGridRecord createEntry(final String row) {
-
-        if (row.contains(TABLE_CELL_SEPARATOR)) {
-
-            final String[] vals = row.split(TABLE_CELL_SEPARATOR);
-            if (vals.length == 3) {
-                final String vegzone = vals[0];
-                final String from = vals[1];
-                final String to = vals[2];
+    public final ListGridRecord createEntry(final VegetationZone row) {
 
-                if (vegzone == null || from == null || to == null) {
-                    return null;
-                }
+        final String vegzone = row.getZoneName();
+        final Integer from = row.getMin_day_overflow();
+        final Integer to = row.getMax_day_overflow();
 
-                final ListGridRecord r = new ListGridRecord();
-                r.setAttribute("vegzone", vegzone);
-                r.setAttribute("from", from);
-                r.setAttribute("to", to);
-                return r;
+        if (vegzone == null || from == null || to == null) {
+            return null;
+        }
 
-            }
+        final ListGridRecord r = new ListGridRecord();
+        r.setAttribute("vegzone", vegzone);
+        r.setAttribute("from", from);
+        r.setAttribute("to", to);
+        return r;
 
-        }
-        return null;
     }
 }
\ No newline at end of file

http://dive4elements.wald.intevation.org