changeset 8231:dded480e17c9

(issue1448) Add Panel for new sq_ti_select state
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 08 Sep 2014 16:24:16 +0200
parents f54c4b858213
children 8636d2b35cbc
files gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadOffEpochPanel.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadSQTiPanel.java
diffstat 3 files changed, 132 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java	Mon Sep 08 16:23:38 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java	Mon Sep 08 16:24:16 2014 +0200
@@ -24,6 +24,7 @@
 import org.dive4elements.river.client.client.ui.minfo.SedLoadEpochPanel;
 import org.dive4elements.river.client.client.ui.minfo.SedLoadOffEpochPanel;
 import org.dive4elements.river.client.client.ui.minfo.SedLoadPeriodPanel;
+import org.dive4elements.river.client.client.ui.minfo.SedLoadSQTiPanel;
 import org.dive4elements.river.client.client.ui.sq.SQPeriodPanel;
 import org.dive4elements.river.client.shared.model.User;
 
@@ -187,6 +188,9 @@
         else if (uiProvider.equals("minfo.sedimentload_offepoch_select")) {
             return new SedLoadOffEpochPanel();
         }
+        else if (uiProvider.equals("minfo.sedimentload_sqti_select")) {
+            return new SedLoadSQTiPanel();
+        }
         else if (uiProvider.equals("hws_datacage_panel")) {
             return new HWSDatacagePanel(user);
         }
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadOffEpochPanel.java	Mon Sep 08 16:23:38 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadOffEpochPanel.java	Mon Sep 08 16:24:16 2014 +0200
@@ -45,7 +45,7 @@
     protected SedimentLoadInfoServiceAsync sedLoadInfoService =
         GWT.create(SedimentLoadInfoService.class);
 
-    private ListGrid sedLoadTable;
+    protected ListGrid sedLoadTable;
 
     /** Creates layout with title. */
     public Canvas createWidget(DataList data) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadSQTiPanel.java	Mon Sep 08 16:24:16 2014 +0200
@@ -0,0 +1,127 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.client.client.ui.minfo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.data.Record;
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.types.SelectionAppearance;
+import com.smartgwt.client.types.SelectionStyle;
+import com.smartgwt.client.util.SC;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+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 org.dive4elements.river.client.client.Config;
+import org.dive4elements.river.client.client.services.SedimentLoadInfoService;
+import org.dive4elements.river.client.client.services.SedimentLoadInfoServiceAsync;
+import org.dive4elements.river.client.client.ui.PeriodPanel;
+import org.dive4elements.river.client.shared.model.ArtifactDescription;
+import org.dive4elements.river.client.shared.model.Data;
+import org.dive4elements.river.client.shared.model.DataItem;
+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.SedimentLoadInfoObject;
+import org.dive4elements.river.client.shared.model.SedimentLoadInfoRecord;
+
+/** Show input to select an official epoch. */
+public class SedLoadSQTiPanel
+extends SedLoadOffEpochPanel
+{
+    /** Creates the helper grid in which off epochs can be selected. */
+    @Override
+    protected Canvas createHelper() {
+        sedLoadTable = new ListGrid();
+        sedLoadTable.setShowHeaderContextMenu(false);
+        sedLoadTable.setWidth100();
+        sedLoadTable.setShowRecordComponents(true);
+        sedLoadTable.setShowRecordComponentsByCell(true);
+        sedLoadTable.setHeight100();
+        sedLoadTable.setEmptyMessage(MSG.empty_table());
+        sedLoadTable.setCanReorderFields(false);
+        sedLoadTable.setSelectionAppearance(SelectionAppearance.CHECKBOX);
+        sedLoadTable.setSelectionType(SelectionStyle.SINGLE);
+
+        ListGridField date = new ListGridField("sq_date", MSG.year());
+        date.setType(ListGridFieldType.TEXT);
+        date.setWidth(100);
+
+        sedLoadTable.setFields(date);
+        return sedLoadTable;
+    }
+
+    /** Get data via listgrid selection. */
+    @Override
+    public Data[] getData() {
+        List<Data> data = new ArrayList<Data>();
+
+        ListGridRecord[] lgr = sedLoadTable.getSelectedRecords();
+        if (lgr.length == 0) {
+            GWT.log("returning empty data.");
+            return new Data[0];
+        }
+        String d = "";
+        for (int i = 0; i < lgr.length; i++) {
+            /* Should only be one item as this is single selection */
+            Record r = (Record) lgr[i];
+            d = r.getAttribute("sq_ti_id");
+            GWT.log("Got attribute sq_ti_id : " + d);
+        }
+        DataItem item = new DefaultDataItem("sq_ti_id", "sq_ti_id", d);
+            data.add(new DefaultData(
+                        "sq_ti_id",
+                        null,
+                        null,
+                        new DataItem[] { item }));
+        return data.toArray(new Data[data.size()]);
+    }
+
+    /** Fetch load info from service and populate table. */
+    @Override
+    protected void fetchSedimentLoadData() {
+        Config config = Config.getInstance();
+        String locale = config.getLocale ();
+
+        ArtifactDescription adescr = artifact.getArtifactDescription();
+        DataList[] data = adescr.getOldData();
+
+        double[] km = artifact.getArtifactDescription().getKMRange();
+        String river = artifact.getArtifactDescription().getRiver();
+
+        sedLoadInfoService.getSedimentLoadInfo(locale, river, "sq_time_intervals", km[0], km[1], "",
+            new AsyncCallback<SedimentLoadInfoObject[]>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not receive sediment load informations.");
+                    SC.warn(caught.getMessage());
+                }
+
+                public void onSuccess(SedimentLoadInfoObject[] sedLoad) {
+                    int num = sedLoad != null ? sedLoad.length :0;
+                    GWT.log("Received " + num + " sediment load informations.");
+
+                    if (num == 0) {
+                        return;
+                    }
+
+                    addSedimentLoadInfo(sedLoad);
+                }
+            }
+        );
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org