diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java @ 9107:41f4bc83aa7a

vegzones improved
author gernotbelger
date Tue, 29 May 2018 15:19:03 +0200
parents 611a523fc42f
children f5b55b383ef9
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java	Tue May 29 11:38:13 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java	Tue May 29 15:19:03 2018 +0200
@@ -20,15 +20,20 @@
 import org.dive4elements.river.client.shared.model.DefaultData;
 import org.dive4elements.river.client.shared.model.DefaultDataItem;
 
+import com.google.gwt.core.client.GWT;
 import com.smartgwt.client.data.Record;
 import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.ListGridFieldType;
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
-import com.smartgwt.client.widgets.form.fields.TextItem;
+import com.smartgwt.client.widgets.form.validator.IntegerRangeValidator;
 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.events.RecordClickEvent;
+import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
 import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.Layout;
 import com.smartgwt.client.widgets.layout.VLayout;
 
 /**
@@ -37,26 +42,18 @@
  */
 public abstract class AbstractVegZonesTablePanel extends AbstractUIProvider {
     private static final long serialVersionUID = 1L;
-    public static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR";
-    public static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR";
-
-    protected static final String datakey = "vegzones";
 
-    protected final ListGrid elements = new ListGrid();
-    protected TextItem vegzone;
-    protected TextItem start;
-    protected TextItem end;
-    private ListGrid table;
+    private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR";
 
-    protected ListGridField vegzoneField;// = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label());
-    protected ListGridField fromField;// = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from());
-    protected ListGridField toField;// = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to());
+    private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR";
 
-    final protected VLayout root = new VLayout();
-    final protected HLayout input = new HLayout();
-    final protected VLayout tableLayout = new VLayout();
+    private static final String datakey = "vegzones";
 
-    protected final void createTable(final DataList data, final int width) {
+    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!
 
         final Label title = new Label(data.get(0).getDescription());
@@ -67,85 +64,75 @@
         this.elements.setShowHeaderContextMenu(false);
         this.elements.setCanReorderFields(false);
         this.elements.setCanSort(false);
-        this.elements.setCanEdit(false);
-        this.vegzoneField = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label());
-        this.fromField = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from());
-        this.toField = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to());
-        this.vegzoneField.setWidth(245);
-        this.fromField.setWidth(80);
-        this.toField.setWidth(80);
-        this.fromField.setAlign(Alignment.RIGHT);
-        this.toField.setAlign(Alignment.RIGHT);
+        this.elements.setCanEdit(editable);
+
+        final ListGridField vegzoneField = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label());
+        vegzoneField.setType(ListGridFieldType.TEXT);
+        vegzoneField.setWidth(245);
+
+        final ListGridField fromField = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from());
+        fromField.setType(ListGridFieldType.INTEGER);
+        final IntegerRangeValidator validator = new IntegerRangeValidator();
+        validator.setMin(0);
+        validator.setMax(365);
+
+        fromField.setValidators(validator);
+        fromField.setWidth(80);
+        fromField.setAlign(Alignment.RIGHT);
+
+        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);
+
+        if (editable) {
+            final ListGridField removeField = createRemoveField();
+            this.elements.setFields(vegzoneField, fromField, toField, removeField);
+
+        } else {
+            this.elements.setFields(vegzoneField, fromField, toField);
+        }
 
         addDataInit(data);
 
-        this.root.addMember(title);
-        this.tableLayout.addMember(this.elements);
-        this.root.addMember(this.input);
-        this.root.addMember(this.tableLayout);
-        this.root.addMember(PanelHelper.getSpacer(10));
+        root.addMember(title);
+        root.addMember(this.elements);
+        root.addMember(PanelHelper.getSpacer(10));
 
+        return this.elements;
     }
 
-    protected final Canvas createHelper() {
-        this.table = new ListGrid();
-        this.table.setShowHeaderContextMenu(false);
-        this.table.setWidth100();
-        this.table.setShowRecordComponents(true);
-        this.table.setShowRecordComponentsByCell(true);
-        this.table.setHeight100();
-        this.table.setEmptyMessage(this.MSG.empty_table());
-        this.table.setCanReorderFields(false);
+    private ListGridField createRemoveField() {
 
-        /* Input support pins */
-        // final String baseUrl = GWT.getHostPageBaseURL();
-        // final ListGridField pinFrom = new ListGridField("fromIcon", this.MSG.uinfo_vegetation_zones_from());
-        // pinFrom.setWidth(300);
-        // pinFrom.setType(ListGridFieldType.ICON);
-        // pinFrom.setCellIcon(baseUrl + this.MSG.markerGreen());
-        //
-        // final ListGridField pinTo = new ListGridField("toIcon", this.MSG.uinfo_vegetation_zones_to());
-        // pinTo.setType(ListGridFieldType.ICON);
-        // pinTo.setWidth(300);
-        // pinTo.setCellIcon(baseUrl + this.MSG.markerRed());
-        //
-        // pinFrom.addRecordClickHandler(new RecordClickHandler() {
-        // @Override
-        // public void onRecordClick(final RecordClickEvent e) {
-        // final Record r = e.getRecord();
-        // VegetationzonesTableEditPanel.this.vegzone.setValue(r.getAttribute("date")); // date??
-        // }
-        // });
-        //
-        // pinFrom.addRecordClickHandler(new RecordClickHandler() {
-        // @Override
-        // public void onRecordClick(final RecordClickEvent e) {
-        // final Record r = e.getRecord();
-        // VegetationzonesTableEditPanel.this.start.setValue(r.getAttribute("date"));
-        // }
-        // });
-        //
-        // pinTo.addRecordClickHandler(new RecordClickHandler() {
-        // @Override
-        // public void onRecordClick(final RecordClickEvent e) {
-        // final Record r = e.getRecord();
-        // VegetationzonesTableEditPanel.this.end.setValue(r.getAttribute("date"));
-        // }
-        // });
-        //
-        // final ListGridField date = new ListGridField("date", this.MSG.year());
-        // date.setType(ListGridFieldType.TEXT);
-        // date.setWidth(100);
-        //
-        // final ListGridField descr = new ListGridField("description", this.MSG.description());
-        // descr.setType(ListGridFieldType.TEXT);
-        // descr.setWidth("*");
-        //
-        // this.table.setFields(pinFrom, pinTo, date, descr);
-        return this.table;
+        final ListGridField removeField = new ListGridField("_removeRecord", "Remove Record") {
+            {
+                setType(ListGridFieldType.ICON);
+                setIcon(GWT.getHostPageBaseURL() + AbstractVegZonesTablePanel.this.MSG.removeFeature());
+                setCanEdit(false);
+                setCanFilter(false);
+                setCanSort(false);
+                setCanGroupBy(false);
+                setCanFreeze(false);
+                setWidth(25);
+            }
+        };
+
+        this.elements.addRecordClickHandler(new RecordClickHandler() {
+            @Override
+            public void onRecordClick(final RecordClickEvent event) {
+                // Just handle remove-clicks
+                if (!event.getField().getName().equals(removeField.getName())) {
+                    return;
+                }
+                event.getViewer().removeData(event.getRecord());
+            }
+        });
+
+        return removeField;
     }
 
-    public abstract Canvas createWidget(final DataList data);
+    public abstract void createWidget(final Layout root, final DataList data);
 
     private final void addDataInit(final DataList data) {
         for (final Data dataItemContainer : data.getAll()) {
@@ -166,16 +153,17 @@
     @Override
     public final Canvas create(final DataList data) {
         final VLayout layout = new VLayout();
-        final Canvas helper = createHelper();
-        this.helperContainer.addMember(helper);
+
+        // final Canvas helper = createHelper();
+        // this.helperContainer.addMember(helper);
 
         final Canvas submit = getNextButton();
-        final Canvas widget = createWidget(data);
 
-        layout.addMember(widget);
-        layout.addMember(submit); // TODO: SUBMIT
+        final VLayout root = new VLayout();
+        createWidget(root, data);
 
-        // fetchSedimentLoadData(); //TODO: feed from database...
+        layout.addMember(root);
+        layout.addMember(submit);
 
         return layout;
     }
@@ -194,9 +182,9 @@
         final Data str = getData(items, datakey);
         final DataItem[] strItems = str.getItems();
 
-        final String[] entries = strItems[0].getLabel().split(VegetationzonesTablePanel.TABLE_ROW_SEPARATOR);
+        final String[] entries = strItems[0].getLabel().split(AbstractVegZonesTablePanel.TABLE_ROW_SEPARATOR);
         for (final String entry : entries) {
-            final String[] vals = entry.split(VegetationzonesTablePanel.TABLE_CELL_SEPARATOR);
+            final String[] vals = entry.split(AbstractVegZonesTablePanel.TABLE_CELL_SEPARATOR);
             final Label dateLabel = new Label(vals[0] + " (" + vals[1] + "-" + vals[2] + ")");
             dateLabel.setHeight(20);
             vLayout.addMember(dateLabel);
@@ -239,9 +227,9 @@
         String d = "";
         for (final ListGridRecord element : lgr) {
             final Record r = element;
-            d += r.getAttribute("vegzone") + VegetationzonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("from")
-                    + VegetationzonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("to");
-            d += VegetationzonesTablePanel.TABLE_ROW_SEPARATOR;
+            d += r.getAttribute("vegzone") + AbstractVegZonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("from")
+                    + AbstractVegZonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("to");
+            d += AbstractVegZonesTablePanel.TABLE_ROW_SEPARATOR;
         }
 
         final DataItem item = new DefaultDataItem(datakey, null, d); // DATA-key
@@ -274,5 +262,4 @@
         }
         return null;
     }
-
-}
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org