changeset 2883:c3feb721035c

Added ui provider for multiple date range input in fix analysis. flys-client/trunk@4555 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 30 May 2012 12:02:56 +0000
parents 63d1e5428a1c
children 88bca9f735c0
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixMultiPeriodPanel.java
diffstat 3 files changed, 270 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue May 29 07:38:49 2012 +0000
+++ b/flys-client/ChangeLog	Wed May 30 12:02:56 2012 +0000
@@ -1,3 +1,11 @@
+2012-05-30  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/fixation/FixMultiPeriodPanel.java:
+	  New. UI provider for multiple date range input.
+
+	* src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java:
+	  Use the new ui provider for fix analysis parameter input.
+
 2012-05-29	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Tue May 29 07:38:49 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Wed May 30 12:02:56 2012 +0000
@@ -6,6 +6,7 @@
 import de.intevation.flys.client.client.ui.fixation.FixPeriodPanel;
 import de.intevation.flys.client.client.ui.fixation.FixGaugeSelectPanel;
 import de.intevation.flys.client.client.ui.fixation.FixEventSelect;
+import de.intevation.flys.client.client.ui.fixation.FixMultiPeriodPanel;
 
 /**
  * Depending on the provider the state declared, return a UIProvider.
@@ -95,7 +96,7 @@
             return new FixPeriodPanel("ref_start", "ref_end");
         }
         else if (uiProvider.equals("fix.period_ana_panel")) {
-            return new FixPeriodPanel("ana_start", "ana_end");
+            return new FixMultiPeriodPanel();
         }
         else if (uiProvider.equals("fix.gaugeselect_panel")) {
             return new FixGaugeSelectPanel();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixMultiPeriodPanel.java	Wed May 30 12:02:56 2012 +0000
@@ -0,0 +1,260 @@
+package de.intevation.flys.client.client.ui.fixation;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Date;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
+
+import com.smartgwt.client.util.SC;
+
+import com.smartgwt.client.data.Record;
+
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.Button;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
+
+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.layout.HLayout;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.DateRangeItem;
+import com.smartgwt.client.widgets.form.fields.TextAreaItem;
+import com.smartgwt.client.types.ListGridFieldType;
+
+import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
+import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
+
+import de.intevation.flys.client.client.FLYSConstants;
+
+import de.intevation.flys.client.shared.model.Data;
+import de.intevation.flys.client.shared.model.DataItem;
+import de.intevation.flys.client.shared.model.DataList;
+import de.intevation.flys.client.shared.model.DefaultData;
+import de.intevation.flys.client.shared.model.DefaultDataItem;
+
+/**
+ * This UIProvider creates a panel for location or distance input.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class FixMultiPeriodPanel
+extends      FixPeriodPanel
+{
+
+    protected ListGrid elements;
+
+    protected String values;
+
+    public FixMultiPeriodPanel() {
+        this("", "");
+    }
+
+    public FixMultiPeriodPanel(String startName, String endName) {
+        super(startName, endName);
+    }
+
+    public Canvas createWidget(DataList data) {
+        HLayout input = new HLayout();
+        VLayout root = new VLayout();
+        VLayout grid = new VLayout();
+        VLayout layout = (VLayout) super.createWidget(data);
+        Button add = new Button("Add");
+        elements = new ListGrid();
+
+        add.addClickHandler(new ClickHandler() {
+            public void onClick(ClickEvent ce) {
+                Date f = inputPanel.getFromDate();
+                Date t = inputPanel.getToDate();
+                if (f == null || t == null) {
+                    return;
+                }
+                DateRangeRecord drr = new DateRangeRecord(f, t);
+                elements.addData(drr);
+            }
+        });
+        layout.addMember(add);
+
+        Label sel = new Label("Selected");
+        sel.setHeight(25);
+        elements.setWidth(185);
+        elements.setHeight(120);
+        elements.setShowHeaderContextMenu(false);
+        elements.setCanReorderFields(false);
+        elements.setCanSort(false);
+        elements.setCanEdit(false);
+        ListGridField from = new ListGridField("from", "From");
+        ListGridField to = new ListGridField("to", "To");
+        from.setWidth(70);
+        to.setWidth(70);
+
+        final ListGridField removeField  =
+            new ListGridField("_removeRecord", "Remove Record"){{
+                setType(ListGridFieldType.ICON);
+                setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature());
+                setCanEdit(false);
+                setCanFilter(false);
+                setCanSort(false);
+                setCanGroupBy(false);
+                setCanFreeze(false);
+                setWidth(25);
+        }};
+
+        elements.addRecordClickHandler(new RecordClickHandler() {
+                public void onRecordClick(final RecordClickEvent event) {
+                    // Just handle remove-clicks
+                    if(!event.getField().getName().equals(removeField.getName())) {
+                        return;
+                    }
+                    event.getViewer().removeData(event.getRecord());
+                }
+            });
+
+        elements.setFields(from, to, removeField);
+
+        grid.addMember(sel);
+        grid.addMember(elements);
+        input.addMember(layout);
+        input.addMember(grid);
+        root.addMember(input);
+
+        return root;
+    }
+
+    @Override
+    public Canvas createOld(DataList dataList) {
+        HLayout layout = new HLayout();
+        layout.setWidth("400px");
+        VLayout vLayout = new VLayout();
+        vLayout.setWidth(130);
+        Label label = new Label(dataList.getLabel());
+        label.setWidth("200px");
+        label.setHeight(25);
+
+        List<Data> items = dataList.getAll();
+        Data str = getData(items, "ana_data");
+        DataItem[] strItems = str.getItems();
+
+        String[] pairs = strItems[0].getLabel().split(";");
+        for (int i = 0; i < pairs.length; i++) {
+            String[] vals = pairs[i].split(",");
+            try {
+                long f = Long.valueOf(vals[0]).longValue();
+                long t = Long.valueOf(vals[1]).longValue();
+                Date from = new Date(f);
+                Date to = new Date(t);
+                String fromString =
+                    DateTimeFormat.getMediumDateFormat().format(from);
+                String toString =
+                    DateTimeFormat.getMediumDateFormat().format(to);
+
+                Label dateLabel = new Label(fromString + " - " + toString);
+                dateLabel.setHeight(20);
+                vLayout.addMember(dateLabel);
+            }
+            catch(NumberFormatException nfe) {
+            }
+        }
+        Canvas back = getBackButton(dataList.getState());
+        layout.addMember(label);
+        layout.addMember(vLayout);
+        layout.addMember(back);
+
+        return layout;
+    }
+
+
+    /**
+     * This method returns the selected data.
+     *
+     * @return the selected/inserted data.
+     */
+    public Data[] getData() {
+        List<Data> data = new ArrayList<Data>();
+
+        boolean valid = saveDateValues();
+        if(valid) {
+            DataItem item = new DefaultDataItem("ana_data", null, this.values);
+            data.add(new DefaultData(
+                        "ana_data",
+                        null,
+                        null,
+                        new DataItem[] { item }));
+        }
+        return (Data[]) data.toArray(new Data[data.size()]);
+    }
+
+
+
+    public void setFilter(FixFilter filter) {
+        this.fixFilter = filter;
+    }
+
+
+    public FixFilter getFilter() {
+        return this.fixFilter;
+    }
+
+    protected boolean saveDateValues() {
+        ListGridRecord[] lgr = elements.getRecords();
+        if (lgr.length == 0) {
+            return false;
+        }
+        String data = "";
+        for (int i = 0; i < lgr.length; i++) {
+            DateRangeRecord drr = (DateRangeRecord) lgr[i];
+            data += drr.getFrom() + "," + drr.getTo();
+            data += ";";
+        }
+        GWT.log(data);
+        values = data;
+        return true;
+    }
+
+
+    protected static class DateRangeRecord extends ListGridRecord {
+        protected Date from;
+        protected Date to;
+
+        protected final static String FROM_FIELD = "from";
+        protected final static String TO_FIELD = "to";
+
+        public DateRangeRecord (Date from, Date to) {
+            setFrom(from);
+            setTo(to);
+        }
+
+        public void setFrom(Date from) {
+            this.from = from;
+            setAttribute(
+                FROM_FIELD,
+                DateTimeFormat.getMediumDateFormat().format(from));
+        }
+
+
+        public void setTo(Date to) {
+            this.to = to;
+            setAttribute(
+                TO_FIELD,
+                DateTimeFormat.getMediumDateFormat().format(to));
+        }
+
+
+        public long getFrom() {
+            return this.from.getTime();
+        }
+
+
+        public long getTo() {
+            return this.to.getTime();
+        }
+    }
+}

http://dive4elements.wald.intevation.org