Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/TableDataPanel.java @ 4205:0dd8963cec9c
Set also the width of the GaugeTree when resizing the GaugePanel
GWT is no longer able to calculate and set the correct width of the GaugeTree since
the GaugeTree is added via a Canvas wrapper. Therefore set the width manually
when resizing the GaugeTree.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Mon, 22 Oct 2012 15:33:16 +0200 |
parents | 03de5c424f95 |
children |
line wrap: on
line source
package de.intevation.flys.client.client.ui; import com.google.gwt.core.client.GWT; import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.types.ListGridFieldType; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; 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.VLayout; import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.client.services.CSVExportService; import de.intevation.flys.client.client.services.CSVExportServiceAsync; import de.intevation.flys.client.shared.model.DataList; import java.util.List; /** * 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); 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. * * @return a panel. */ public Canvas create() { Config config = Config.getInstance(); String locale = config.getLocale (); dataTable.setEmptyMessage(MESSAGES.empty_table()); dataTable.setShowHeaderContextMenu(false); dataTable.setCanDragSelectText(true); exportService.getCSV(locale, uuid, name, new AsyncCallback<List<String[]>>() { @Override public void onFailure(Throwable caught) { GWT.log("Could not recieve csv."); SC.warn(caught.getMessage()); } @Override public void onSuccess(List<String[]> l) { GWT.log("Recieved csv with " + l.size() + " lines."); setData(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; } /** * This method sets the data to a dynamic table. * * @param list List if String[] containing the data. */ public void setData(List<String[]> list) { if (list == null || list.size() < 2) { dataTable.setEmptyMessage(MESSAGES.error_no_calc_result()); dataTable.redraw(); return; } Config config = Config.getInstance(); String locale = config.getLocale(); NumberFormat nf; if (locale.equals("de")) { nf = NumberFormat.getFormat("#,##"); } else { nf = NumberFormat.getFormat("#.##"); } String[] header = list.get(0); String[] firstValues = list.get(1); ListGridField[] fields = new ListGridField[header.length]; for(int i = 0; i < header.length; i++) { ListGridField f = new ListGridField(String.valueOf(i)); fields[i] = f; f.setTitle(header[i]); try { nf.parse(firstValues[i]); f.setType(ListGridFieldType.FLOAT); } catch (NumberFormatException nfe) { f.setType(ListGridFieldType.TEXT); } } dataTable.setFields(fields); for(int i = 1; i < list.size(); i++) { String[] sItem = list.get(i); ListGridRecord r = new ListGridRecord(); for(int j = 0; j < sItem.length; j++) { r.setAttribute(String.valueOf(j), sItem[j]); } dataTable.addData(r); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :