changeset 4223:015b219a97af

Added new UI provider for sediment load parameter input.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 23 Oct 2012 13:21:57 +0200
parents 94c76129af7d
children 8b5133444bcc
files flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadDistancePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadEpochPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadOffEpochPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadPeriodPanel.java
diffstat 4 files changed, 640 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadDistancePanel.java	Tue Oct 23 13:21:57 2012 +0200
@@ -0,0 +1,280 @@
+package de.intevation.flys.client.client.ui.minfo;
+
+import java.util.List;
+
+import com.google.gwt.core.client.GWT;
+import com.smartgwt.client.data.Record;
+import com.smartgwt.client.util.SC;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
+import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
+import com.smartgwt.client.widgets.grid.events.CellClickEvent;
+import com.smartgwt.client.widgets.grid.events.CellClickHandler;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.client.event.FilterHandler;
+import de.intevation.flys.client.client.event.RangeFilterEvent;
+import de.intevation.flys.client.client.event.StringFilterEvent;
+import de.intevation.flys.client.client.ui.AbstractUIProvider;
+import de.intevation.flys.client.client.ui.DoubleRangeOnlyPanel;
+import de.intevation.flys.client.client.ui.DoubleRangePanel;
+import de.intevation.flys.client.client.ui.LocationPicker;
+import de.intevation.flys.client.client.ui.range.DistanceInfoDataSource;
+import de.intevation.flys.client.shared.model.ArtifactDescription;
+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;
+
+
+public class SedLoadDistancePanel
+extends AbstractUIProvider
+implements BlurHandler, CellClickHandler
+{
+    public static final String FIELD_LOWER = "ld_from";
+    public static final String FIELD_UPPER = "ld_to";
+
+    protected DoubleRangePanel distancePanel;
+    protected double min;
+    protected double max;
+    protected LocationPicker picker;
+
+    @Override
+    public Canvas createOld(DataList dataList) {
+        String s = getOldSelectionString(dataList);
+        String l = dataList.getLabel();
+
+        Label label    = new Label(l);
+        Label selected = new Label(s);
+
+        HLayout layout = new HLayout();
+
+        layout.setWidth(400);
+        label.setWidth(200);
+        selected.setWidth(130);
+
+        layout.addMember(label);
+        layout.addMember(selected);
+        layout.addMember(getBackButton(dataList.getState()));
+
+        return layout;
+    }
+
+    protected String getOldSelectionString(DataList dataList) {
+        List<Data> items = dataList.getAll();
+
+        Data dFrom = getData(items, FIELD_LOWER);
+        Data dTo   = getData(items, FIELD_UPPER);
+
+        DataItem[] from = dFrom.getItems();
+        DataItem[] to   = dTo.getItems();
+
+        StringBuilder sb = new StringBuilder();
+        sb.append(from[0].getLabel());
+        sb.append(" " + MSG.dpUnitFrom() + " - ");
+        sb.append(to[0].getLabel());
+        sb.append(" " + MSG.dpUnitTo());
+
+        return sb.toString();
+    }
+
+    @Override
+    public Canvas create(DataList data) {
+        picker = new LocationPicker(this);
+        distancePanel = new DoubleRangeOnlyPanel(
+            MSG.dpUnitFrom() + " - ", MSG.dpUnitTo(), 0d, 0d, 250, this, "right");
+        VLayout layout = new VLayout();
+        layout.setMembersMargin(10);
+
+        Label label = new Label(MSG.distance_state());
+
+        Canvas submit = getNextButton();
+
+        label.setHeight(25);
+        distancePanel.setHeight(50);
+
+        layout.addMember(label);
+        layout.addMember(distancePanel);
+        layout.addMember(submit);
+
+        initMinMaxValues(data);
+        initDefaultValues(data);
+
+
+        picker.setIsDistance(true);
+        picker.getLocationTable().setAutoFetchData(true);
+        picker.prepareFilter();
+
+        helperContainer.addMember(picker.getLocationTable());
+        helperContainer.addMember(picker.getFilterLayout());
+        helperContainer.addMember(picker.getResultCountForm());
+
+        setPickerDataSource();
+        picker.createLocationTable();
+
+        return layout;
+    }
+
+    protected void initMinMaxValues(DataList data) {
+        Data f = getData(data.getAll(), FIELD_LOWER);
+        Data t = getData(data.getAll(), FIELD_UPPER);
+
+        DataItem[] fItems = f.getItems();
+        DataItem[] tItems = t.getItems();
+
+        try {
+            min = Double.valueOf(fItems[0].getStringValue());
+            max = Double.valueOf(tItems[0].getStringValue());
+        }
+        catch (NumberFormatException nfe) {
+            min = -Double.MAX_VALUE;
+            max =  Double.MAX_VALUE;
+        }
+    }
+
+    protected void initDefaultValues(DataList data) {
+        initDefaultFrom(data);
+        initDefaultTo(data);
+    }
+
+    protected void initDefaultFrom(DataList data) {
+        Data f = getData(data.getAll(), FIELD_LOWER);
+
+        double from = getDefaultFrom();
+
+        try {
+            from = getDefaultValue(f);
+        }
+        catch (NumberFormatException nfe) {
+            // do nothing
+        }
+
+        distancePanel.setFrom(from);
+    }
+
+
+    protected double getDefaultFrom() {
+        return min;
+    }
+
+
+    protected void initDefaultTo(DataList data) {
+        Data t = getData(data.getAll(), FIELD_UPPER);
+
+        double to = getDefaultTo();
+
+        try {
+            to = getDefaultValue(t);
+        }
+        catch (NumberFormatException nfe) {
+            // do nothing
+        }
+
+        distancePanel.setTo(to);
+    }
+
+
+    protected double getDefaultTo() {
+        return max;
+    }
+
+    protected double getDefaultValue(Data data)
+    throws NumberFormatException
+    {
+        DataItem def      = data.getDefault();
+        String   defValue = def != null ? def.getStringValue() : null;
+
+        return Double.valueOf(defValue);
+    }
+
+    /** Hook service to the listgrid with possible input values. */
+    protected void setPickerDataSource() {
+        Config config = Config.getInstance();
+        String url    = config.getServerUrl();
+        String river  = "";
+
+        ArtifactDescription adescr = artifact.getArtifactDescription();
+        DataList[] data = adescr.getOldData();
+
+        // Try to find a "river" data item to set the source for the
+        // list grid.
+        String dataFilter = "locations";
+        if (data != null && data.length > 0) {
+            for (int i = 0; i < data.length; i++) {
+                DataList dl = data[i];
+                if (dl.getState().equals("state.minfo.river")) {
+                    dataFilter = "measuringpoint";
+                }
+                if (dl.getState().equals("state.winfo.river") ||
+                    dl.getState().equals("state.chart.river") ||
+                    dl.getState().equals("state.minfo.river")) {
+                    for (int j = 0; j < dl.size(); j++) {
+                        Data d = dl.get(j);
+                        DataItem[] di = d.getItems();
+                        if (di != null && di.length == 1) {
+                           river = d.getItems()[0].getStringValue();
+                           break;
+                        }
+                    }
+                }
+            }
+        }
+
+        picker.getLocationTable().setDataSource(new DistanceInfoDataSource(
+            url, river, dataFilter));
+    }
+
+    @Override
+    protected Data[] getData() {
+        Data[] data = new Data[2];
+
+        data[0] = getDataFrom();
+        data[1] = getDataTo();
+
+        return data;
+    }
+
+    protected Data getDataFrom() {
+        String value = String.valueOf(distancePanel.getFrom());
+        String field = FIELD_LOWER;
+
+        DataItem item = new DefaultDataItem(field, field, value);
+        return new DefaultData(
+            field, null, null, new DataItem[] { item });
+    }
+
+    protected Data getDataTo() {
+        String value = String.valueOf(distancePanel.getTo());
+        String field = FIELD_UPPER;
+
+        DataItem item = new DefaultDataItem(field, field, value);
+        return new DefaultData(
+            field, null, null, new DataItem[] { item });
+    }
+
+    @Override
+    public void onBlur(BlurEvent event) {
+        distancePanel.validateForm();
+    }
+
+    @Override
+    public void onCellClick(CellClickEvent e) {
+        Record record = e.getRecord();
+        int ndx = e.getColNum();
+        String from   = record.getAttribute("from");
+        try {
+            double value = Double.valueOf(from);
+            switch (ndx) {
+                case 0: distancePanel.setFrom(value); break;
+                case 1: distancePanel.setTo(value); break;
+            }
+        }
+        catch(NumberFormatException nfe) {
+            SC.warn(MSG.wrongFormat());
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadEpochPanel.java	Tue Oct 23 13:21:57 2012 +0200
@@ -0,0 +1,197 @@
+package de.intevation.flys.client.client.ui.minfo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.gwt.core.client.GWT;
+import com.smartgwt.client.data.Record;
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.widgets.Button;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.TextItem;
+import com.smartgwt.client.widgets.form.validator.IsIntegerValidator;
+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.VLayout;
+
+import de.intevation.flys.client.client.ui.AbstractUIProvider;
+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;
+
+
+public class SedLoadEpochPanel
+extends AbstractUIProvider
+{
+    protected ListGrid elements;
+    private TextItem start;
+    private TextItem end;
+
+    public Canvas createWidget(DataList data) {
+        HLayout input = new HLayout();
+        VLayout root = new VLayout();
+        VLayout grid = new VLayout();
+        VLayout intFields = new VLayout();
+        Button add = new Button(MSG.add_date());
+        elements = new ListGrid();
+
+        Label title = new Label(data.get(0).getDescription());
+        title.setHeight("25px");
+
+        DynamicForm form = new DynamicForm();
+        form.setNumCols(4);
+        start = new TextItem(MSG.from());
+        start.setWidth(60);
+        start.setValidators(new IsIntegerValidator());
+        end = new TextItem(MSG.to());
+        end.setWidth(60);
+        end.setValidators(new IsIntegerValidator());
+        form.setFields(start, end);
+        add.addClickHandler(new ClickHandler() {
+            @Override
+            public void onClick(ClickEvent ce) {
+                String v1 = start.getValueAsString();
+                String v2 = end.getValueAsString();
+                //TODO: better validation.
+                if (v1 == null || v2 == null) {
+                    return;
+                }
+                try {
+                    int v1i = Integer.parseInt(v1);
+                    int v2i = Integer.parseInt(v2);
+                }
+                catch(NumberFormatException nfe) {
+                    return;
+                }
+                Record r = new Record();
+                r.setAttribute("from", v1);
+                r.setAttribute("to", v2);
+                elements.addData(r);
+            }
+        });
+
+        Label sel = new Label(MSG.select());
+        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", MSG.from());
+        ListGridField to = new ListGridField("to", MSG.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() {
+                @Override
+                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);
+
+        intFields.addMember(form);
+        intFields.addMember(add);
+        grid.addMember(sel);
+        grid.addMember(elements);
+        input.addMember(intFields);
+        input.addMember(grid);
+        root.addMember(title);
+        root.addMember(input);
+
+        return root;
+    }
+    @Override
+    public Canvas createOld(DataList dataList) {
+        GWT.log("old............................");
+        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, "epochs");
+        DataItem[] strItems = str.getItems();
+
+        String[] pairs = strItems[0].getLabel().split(";");
+        for (int i = 0; i < pairs.length; i++) {
+            String[] vals = pairs[i].split(",");
+            Label dateLabel = new Label(vals[0] + " - " + vals[1]);
+            dateLabel.setHeight(20);
+            vLayout.addMember(dateLabel);
+        }
+        Canvas back = getBackButton(dataList.getState());
+        layout.addMember(label);
+        layout.addMember(vLayout);
+        layout.addMember(back);
+
+        return layout;
+    }
+
+    @Override
+    public Canvas create(DataList data) {
+        VLayout layout = new VLayout();
+        Canvas submit = getNextButton();
+        Canvas widget = createWidget(data);
+
+        layout.addMember(widget);
+        layout.addMember(submit);
+        return layout;
+    }
+
+    @Override
+    protected Data[] getData() {
+        List<Data> data = new ArrayList<Data>();
+
+        ListGridRecord[] lgr = elements.getRecords();
+        if (lgr.length == 0) {
+            return new Data[0];
+        }
+        String d = "";
+        for (int i = 0; i < lgr.length; i++) {
+            Record r = (Record) lgr[i];
+            d += r.getAttribute("from") + "," + r.getAttribute("to");
+            d += ";";
+        }
+
+        DataItem item = new DefaultDataItem("epochs", null, d);
+            data.add(new DefaultData(
+                        "epochs",
+                        null,
+                        null,
+                        new DataItem[] { item }));
+        return data.toArray(new Data[data.size()]);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadOffEpochPanel.java	Tue Oct 23 13:21:57 2012 +0200
@@ -0,0 +1,10 @@
+package de.intevation.flys.client.client.ui.minfo;
+
+import de.intevation.flys.client.client.ui.PeriodPanel;
+
+
+public class SedLoadOffEpochPanel
+extends PeriodPanel
+{
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadPeriodPanel.java	Tue Oct 23 13:21:57 2012 +0200
@@ -0,0 +1,153 @@
+package de.intevation.flys.client.client.ui.minfo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.gwt.core.client.GWT;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.TextItem;
+import com.smartgwt.client.widgets.form.validator.IsIntegerValidator;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.client.ui.AbstractUIProvider;
+import de.intevation.flys.client.client.ui.IntegerRangePanel;
+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;
+
+
+public class SedLoadPeriodPanel
+extends AbstractUIProvider
+//extends SedLoadPanel
+{
+
+    private TextItem start;
+    private TextItem end;
+
+    public SedLoadPeriodPanel () {
+    }
+
+    @Override
+    public Canvas createOld(DataList dataList) {
+        List<Data> items = dataList.getAll();
+        Data start = getData(items, "start");
+        Data end = getData(items, "end");
+        DataItem[] startItem = start.getItems();
+        DataItem[] endItem = end.getItems();
+
+        String v1 = startItem[0].getStringValue();
+        String v2 = endItem[0].getStringValue();
+
+        int v1i = 0;
+        int v2i = 0;
+        try {
+            v1i = Integer.parseInt(v1);
+            v2i = Integer.parseInt(v2);
+        }
+        catch (NumberFormatException nfe) {
+            GWT.log(nfe.toString());
+        }
+        Label old = new Label(v1i + " - " + v2i);
+        HLayout layout = new HLayout();
+        layout.setWidth("400px");
+
+        Label label = new Label(dataList.getLabel());
+        label.setWidth("200px");
+
+        Canvas back = getBackButton(dataList.getState());
+
+        layout.addMember(label);
+        layout.addMember(old);
+        layout.addMember(back);
+
+        return layout;
+    }
+
+    @Override
+    public Canvas create(DataList data) {
+        VLayout layout = new VLayout();
+
+//        Canvas helper = createHelper();
+//        this.helperContainer.addMember(helper);
+
+        Canvas submit = getNextButton();
+        Canvas widget = createWidget(data);
+
+        layout.addMember(widget);
+        layout.addMember(submit);
+        return layout;
+    }
+
+    public Canvas createWidget(DataList data) {
+        VLayout layout = new VLayout();
+
+        Label title = new Label(data.get(0).getDescription());
+        title.setHeight("25px");
+
+        DynamicForm form = new DynamicForm();
+        form.setNumCols(4);
+        start = new TextItem(MSG.from());
+        start.setValidators(new IsIntegerValidator());
+        end = new TextItem(MSG.to());
+        end.setValidators(new IsIntegerValidator());
+        form.setFields(start, end);
+//        inputPanel.setToTitle(MSG.to());
+//        inputPanel.setFromTitle(MSG.from());
+//        inputPanel.setShowTitle(false);
+
+        layout.addMember(title);
+        layout.addMember(form);
+
+        return layout;
+    }
+
+    @Override
+    protected Data[] getData() {
+        int v1;
+        int v2;
+        try {
+            v1 = Integer.parseInt(start.getValueAsString());
+            v2 = Integer.parseInt(end.getValueAsString());
+        }
+        catch(NumberFormatException nfe) {
+            // warn the user...
+            return new Data[0];
+        }
+        if (validateRange(v1, v2)) {
+            List<Data> data = new ArrayList<Data>();
+
+            DataItem startItem = new DefaultDataItem("start", "start", start.getValueAsString());
+            DataItem endItem   = new DefaultDataItem("end", "end", end.getValueAsString());
+            data.add(new DefaultData(
+                "start",
+                null,
+                null,
+                new DataItem[] { startItem }));
+            data.add(new DefaultData(
+                "end",
+                null,
+                null,
+                new DataItem[] { endItem }));
+
+            return data.toArray(new Data[data.size()]);
+        }
+        return new Data[0];
+    }
+
+    protected boolean validateRange(int v1, int v2) {
+        // TODO: Set useful years for validation. Current range is between start
+        // of gregorian calendar and a year in the future...
+        if ((v1 > 1582 && v1 < 2100) 
+            && (v2 > 1582 && v2 < 2100)) {
+            return true;
+        }
+        return false;
+    }
+
+
+}

http://dive4elements.wald.intevation.org