andre@8231: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde andre@8231: * Software engineering by Intevation GmbH andre@8231: * andre@8231: * This file is Free Software under the GNU AGPL (>=v3) andre@8231: * and comes with ABSOLUTELY NO WARRANTY! Check out the andre@8231: * documentation coming with Dive4Elements River for details. andre@8231: */ andre@8231: andre@8231: package org.dive4elements.river.client.client.ui.minfo; andre@8231: andre@8231: import java.util.ArrayList; andre@8231: import java.util.List; andre@8231: andre@8231: import com.google.gwt.core.client.GWT; andre@8231: import com.google.gwt.user.client.rpc.AsyncCallback; andre@8231: import com.smartgwt.client.data.Record; andre@8231: import com.smartgwt.client.types.ListGridFieldType; andre@8231: import com.smartgwt.client.types.SelectionAppearance; andre@8231: import com.smartgwt.client.types.SelectionStyle; andre@8231: import com.smartgwt.client.util.SC; andre@8231: import com.smartgwt.client.widgets.Canvas; andre@8231: import com.smartgwt.client.widgets.Label; andre@8231: import com.smartgwt.client.widgets.grid.ListGrid; andre@8231: import com.smartgwt.client.widgets.grid.ListGridField; andre@8231: import com.smartgwt.client.widgets.grid.ListGridRecord; andre@8231: import com.smartgwt.client.widgets.layout.HLayout; andre@8231: import com.smartgwt.client.widgets.layout.VLayout; andre@8231: andre@8231: import org.dive4elements.river.client.client.Config; andre@8231: import org.dive4elements.river.client.client.services.SedimentLoadInfoService; andre@8231: import org.dive4elements.river.client.client.services.SedimentLoadInfoServiceAsync; andre@8231: import org.dive4elements.river.client.client.ui.PeriodPanel; andre@8231: import org.dive4elements.river.client.shared.model.ArtifactDescription; andre@8231: import org.dive4elements.river.client.shared.model.Data; andre@8231: import org.dive4elements.river.client.shared.model.DataItem; andre@8231: import org.dive4elements.river.client.shared.model.DataList; andre@8231: import org.dive4elements.river.client.shared.model.DefaultData; andre@8231: import org.dive4elements.river.client.shared.model.DefaultDataItem; andre@8231: import org.dive4elements.river.client.shared.model.SedimentLoadInfoObject; andre@8231: import org.dive4elements.river.client.shared.model.SedimentLoadInfoRecord; andre@8231: andre@8231: /** Show input to select an official epoch. */ andre@8231: public class SedLoadSQTiPanel andre@8231: extends SedLoadOffEpochPanel andre@8231: { andre@8231: /** Creates the helper grid in which off epochs can be selected. */ andre@8231: @Override andre@8231: protected Canvas createHelper() { andre@8231: sedLoadTable = new ListGrid(); andre@8231: sedLoadTable.setShowHeaderContextMenu(false); andre@8231: sedLoadTable.setWidth100(); andre@8231: sedLoadTable.setShowRecordComponents(true); andre@8231: sedLoadTable.setShowRecordComponentsByCell(true); andre@8231: sedLoadTable.setHeight100(); andre@8231: sedLoadTable.setEmptyMessage(MSG.empty_table()); andre@8231: sedLoadTable.setCanReorderFields(false); andre@8231: sedLoadTable.setSelectionAppearance(SelectionAppearance.CHECKBOX); andre@8231: sedLoadTable.setSelectionType(SelectionStyle.SINGLE); andre@8231: andre@8231: ListGridField date = new ListGridField("sq_date", MSG.year()); andre@8231: date.setType(ListGridFieldType.TEXT); andre@8231: date.setWidth(100); andre@8231: andre@8231: sedLoadTable.setFields(date); andre@8231: return sedLoadTable; andre@8231: } andre@8231: andre@8231: /** Get data via listgrid selection. */ andre@8231: @Override andre@8231: public Data[] getData() { andre@8231: List data = new ArrayList(); andre@8231: andre@8231: ListGridRecord[] lgr = sedLoadTable.getSelectedRecords(); andre@8231: if (lgr.length == 0) { andre@8231: GWT.log("returning empty data."); andre@8231: return new Data[0]; andre@8231: } andre@8231: String d = ""; andre@8231: for (int i = 0; i < lgr.length; i++) { andre@8231: /* Should only be one item as this is single selection */ andre@8231: Record r = (Record) lgr[i]; andre@8231: d = r.getAttribute("sq_ti_id"); andre@8231: GWT.log("Got attribute sq_ti_id : " + d); andre@8231: } andre@8231: DataItem item = new DefaultDataItem("sq_ti_id", "sq_ti_id", d); andre@8231: data.add(new DefaultData( andre@8231: "sq_ti_id", andre@8231: null, andre@8231: null, andre@8231: new DataItem[] { item })); andre@8231: return data.toArray(new Data[data.size()]); andre@8231: } andre@8231: andre@8231: /** Fetch load info from service and populate table. */ andre@8231: @Override andre@8231: protected void fetchSedimentLoadData() { andre@8231: Config config = Config.getInstance(); andre@8231: String locale = config.getLocale (); andre@8231: andre@8231: ArtifactDescription adescr = artifact.getArtifactDescription(); andre@8231: DataList[] data = adescr.getOldData(); andre@8231: andre@8231: double[] km = artifact.getArtifactDescription().getKMRange(); andre@8231: String river = artifact.getArtifactDescription().getRiver(); andre@8231: andre@8231: sedLoadInfoService.getSedimentLoadInfo(locale, river, "sq_time_intervals", km[0], km[1], "", andre@8231: new AsyncCallback() { andre@8231: public void onFailure(Throwable caught) { andre@8231: GWT.log("Could not receive sediment load informations."); andre@8231: SC.warn(caught.getMessage()); andre@8231: } andre@8231: andre@8231: public void onSuccess(SedimentLoadInfoObject[] sedLoad) { andre@8231: int num = sedLoad != null ? sedLoad.length :0; andre@8231: GWT.log("Received " + num + " sediment load informations."); andre@8231: andre@8231: if (num == 0) { andre@8231: return; andre@8231: } andre@8231: andre@8231: addSedimentLoadInfo(sedLoad); andre@8231: } andre@8231: } andre@8231: ); andre@8231: } andre@8231: } andre@8231: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :