view flys-client/src/main/java/de/intevation/flys/client/client/ui/TableDataPanel.java @ 256:5e1c1b7d6516

Added table and service for calculation output to UI. flys-client/trunk@1868 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 09 May 2011 14:29:53 +0000
parents
children 50a95db68e66
line wrap: on
line source
package de.intevation.flys.client.client.ui;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;

import de.intevation.flys.client.shared.model.DataList;

import de.intevation.flys.client.client.FLYSConstants;
import de.intevation.flys.client.client.Config;

import de.intevation.flys.client.client.services.CSVExportService;
import de.intevation.flys.client.client.services.CSVExportServiceAsync;

/**
 * This UIProvider creates a widget that displays calculated data in a table.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class TableDataPanel
{
    /** The message class that provides i18n strings.*/
    protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);

    /** The DistanceInfoService used to retrieve locations about rivers.*/
    protected CSVExportServiceAsync exportService =
        GWT.create(CSVExportService.class);

    /** A container that will contain the location or the distance panel.*/
    protected VLayout container;

    /** The export type.*/
    protected String name;

    /** The UUID of the collection */
    protected String uuid;

    /** The table*/
    protected ListGrid dataTable;


    /**
     * Creates a new LocationDistancePanel instance.
     */
    public TableDataPanel() {
        container = new VLayout();
        dataTable = new ListGrid();
        name      = "";
    }


    /**
     * This method creates a widget that contains a table
     *
     * @param data The data that might be inserted.//Use this?
     *
     * @return a panel.
     */
    public Canvas create() {
        Config config    = Config.getInstance();
        String url       = config.getServerUrl();
        String locale    = config.getLocale ();
        ListGridField flusskm = new ListGridField("km", MESSAGES.river_km());
        ListGridField w = new ListGridField("w", MESSAGES.unitWNN());
        ListGridField q = new ListGridField("q", MESSAGES.wqQ());
        ListGridField desc = new ListGridField("descr", MESSAGES.description());

        dataTable.setFields(flusskm, w, q, desc);
        exportService.getCSV(url, locale, uuid, name,
            new AsyncCallback<List>() {
                public void onFailure(Throwable caught) {
                    GWT.log("Could not recieve csv.");
                    GWT.log(caught.getMessage());
                }

                public void onSuccess(List l) {
                    GWT.log("Recieved csv with " + l.size() + " lines.");
                    setData(l);
                }
            }
        );

        Label l = new Label (MESSAGES.calcTableTitle());
        l.setHeight(20);

        container.addMember(l);
        container.addMember(dataTable);

        return container;
    }


    public void setName(String name) {
      this.name = name;
    }

    public void setUuid(String uuid) {
      this.uuid = uuid;
    }


    public Canvas createOld(DataList dataList) {
        return null;
    }


    protected Canvas createWidget(DataList data) {
        return null;
    }

    public void setData(List list){
        for(Object item: list) {
            String[] sItem = (String[])item;
            ListGridRecord r = new ListGridRecord();
            if (sItem.length == 3) {
                r.setAttribute("km", sItem[0]);
                r.setAttribute("w", sItem[1]);
                r.setAttribute("q", sItem[2]);
            }
            dataTable.addData(r);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org