Mercurial > dive4elements > river
changeset 256:5e1c1b7d6516
Added table and service for calculation output to UI.
flys-client/trunk@1868 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/flys-client/ChangeLog Mon May 09 13:51:39 2011 +0000 +++ b/flys-client/ChangeLog Mon May 09 14:29:53 2011 +0000 @@ -1,3 +1,28 @@ +2011-05-09 Raimund Renkert <rrenkert@intevation.de> + + * src/main/java/de/intevation/flys/client/server/CSVExportServiceImpl.java, + src/main/java/de/intevation/flys/client/client/services/CSVExportServiceAsync.java, + src/main/java/de/intevation/flys/client/client/services/CSVExportService.java: + New service. Requests CSV data and returns a list of lines in a string + array. + + * src/main/java/de/intevation/flys/client/client/ui/TableDataPanel.java: + New. Displays the data requested by the new service. + + * src/main/java/de/intevation/flys/client/client/ui/ParameterList.java, + src/main/java/de/intevation/flys/client/client/ui/CollectionView.java: + Added the table to UI. + + * src/main/webapp/WEB-INF/web.xml: Registered new service. + + * src/main/java/de/intevation/flys/client/client/FLYSConstants.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants.java: + Added strings for the new table. + + * pom.xml: Added dependency: au.com.bytecode.opencsv, version 2.0; + 2011-05-09 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java:
--- a/flys-client/pom.xml Mon May 09 13:51:39 2011 +0000 +++ b/flys-client/pom.xml Mon May 09 14:29:53 2011 +0000 @@ -53,6 +53,11 @@ <version>1.0-SNAPSHOT</version> </dependency> <dependency> + <groupId>au.com.bytecode.opencsv</groupId> + <artifactId>CSVReader</artifactId> + <version>2.0</version> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.4</version>
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Mon May 09 13:51:39 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Mon May 09 14:29:53 2011 +0000 @@ -62,6 +62,8 @@ String next(); + String river_km(); + String location_distance_state(); String location(); @@ -86,10 +88,14 @@ String riverside(); + String calcTableTitle(); + String wqTitle(); String wqadaptedTitle(); + String unitWNN(); + String wqW(); String wqQ();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Mon May 09 13:51:39 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Mon May 09 14:29:53 2011 +0000 @@ -40,13 +40,16 @@ name = Name type = Type wq_value = W/Q/D +river_km = River-Km wqTitle = Input for W/Q Data wqadaptedTitle = Input for W/Q Data +calcTableTitle = Calculated Output wqW = W at Gauge [cm] wqQ = Q [m³/s] wqSingle = Single values wqRange = Range +unitWNN = W [NN+m] unitWSingle = cm unitWFrom = cm - unitWTo = cm a
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Mon May 09 13:51:39 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Mon May 09 14:29:53 2011 +0000 @@ -40,13 +40,16 @@ name = Name type = Typ wq_value = W/Q/D +river_km = Fluss-Km wqTitle = Eingabe für W/Q Daten wqadaptedTitle = Eingabe für W/Q Daten +calcTableTitle = Berechnungsausgabe wqW = W am Pegel [cm] wqQ = Q [m³/s] wqSingle = Einzelwerte wqRange = Wertebereich +unitWNN = W [NN+m] unitWSingle = cm unitWFrom = cm - unitWTo = cm a
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Mon May 09 13:51:39 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Mon May 09 14:29:53 2011 +0000 @@ -40,13 +40,16 @@ name = Name type = Type wq_value = W/Q/D +river_km = River-Km wqTitle = Input for W/Q Data wqadaptedTitle = Input for W/Q Data +calcTableTitle = Calculated Output wqW = W at Gauge [cm] wqQ = Q [m³/s] wqSingle = Single values wqRange = Range +untiWNN = W [NN+m] unitWSingle = cm unitWFrom = cm - unitWTo = cm a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/CSVExportService.java Mon May 09 14:29:53 2011 +0000 @@ -0,0 +1,29 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import java.util.List; + +import de.intevation.flys.client.shared.exceptions.ServerException; + +/** + * This service is used to fetch a list of DistanceInfoObjects from artifact + * server for a specific river. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +@RemoteServiceRelativePath("export") +public interface CSVExportService extends RemoteService { + + /** + * This method returns a list of DistanceInfoObjects for a specific river. + */ + List getCSV( + String serverUrl, + String locale, + String uuid, + String name) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/CSVExportServiceAsync.java Mon May 09 14:29:53 2011 +0000 @@ -0,0 +1,19 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import java.util.List; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public interface CSVExportServiceAsync { + + void getCSV( + String url, + String locale, + String uuid, + String name, + AsyncCallback<List> cb); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Mon May 09 13:51:39 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java Mon May 09 14:29:53 2011 +0000 @@ -352,7 +352,12 @@ protected void addOutputTab(String name, OutputMode out) { // XXX Maybe we should change this determination of visual outputs. I am // not sure if the mimetype is the correct value for this! + if (out.getMimeType().equals("text/plain")) { + TableDataPanel p = new TableDataPanel(); + p.setUuid(collection.identifier()); + p.setName(out.getDescription()); + parameterList.setPanel (p); return; }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java Mon May 09 13:51:39 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java Mon May 09 14:29:53 2011 +0000 @@ -76,6 +76,7 @@ protected UIProvider uiProvider; + protected VLayout topLayout; protected VLayout oldItems; protected VLayout currentItems; protected Canvas helperPanel; @@ -88,6 +89,7 @@ parameterHandlers = new ArrayList<ParameterChangeHandler>(); old = new ArrayList<DataList>(); + topLayout = new VLayout(); oldItems = new VLayout(); currentItems = new VLayout(); @@ -111,6 +113,7 @@ parameterHandlers = new ArrayList<ParameterChangeHandler>(); old = new ArrayList<DataList>(); + topLayout = new VLayout(); oldItems = new VLayout(); currentItems = new VLayout(); @@ -147,13 +150,14 @@ rootLayout.addMember(left); rootLayout.addMember(helperPanel); + topLayout.addMember(rootLayout); if (artifact == null) { Canvas moduleSelection = renderNew(); moduleSelection.setLayoutAlign(VerticalAlignment.TOP); currentItems.addMember(moduleSelection); } - setPane(rootLayout); + setPane(topLayout); } @@ -466,5 +470,16 @@ addOldDatas(desc.getOldData()); } + + /** + * Adds a table to the parameterlist to show calculated data. + * + * @param table The table data panel. + */ + public void setPanel (TableDataPanel table) { + Canvas c = table.create(); + c.setHeight(400); + topLayout.addMember(c); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/TableDataPanel.java Mon May 09 14:29:53 2011 +0000 @@ -0,0 +1,132 @@ +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 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/CSVExportServiceImpl.java Mon May 09 14:29:53 2011 +0000 @@ -0,0 +1,79 @@ +package de.intevation.flys.client.server; + +import java.util.List; + +import java.io.Reader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import au.com.bytecode.opencsv.CSVReader; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.client.services.CSVExportService; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class CSVExportServiceImpl +extends RemoteServiceServlet +implements CSVExportService +{ + public static final String ERROR_NO_EXPORT_FOUND = + "error_no_export_found"; + + public List getCSV( + String url, + String locale, + String uuid, + String name) + throws ServerException + { + System.out.println("CSVExportServiceImpl.getCSV"); + + Document requestDoc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + requestDoc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + if (name.startsWith("output.")) { + name = name.substring(name.indexOf(".") + 1); + } + + Element action = ec.create("art:action"); + action.setAttribute("art:type", "csv"); + action.setAttribute("art:name", name); + + requestDoc.appendChild(action); + + HttpClient client = new HttpClientImpl(url, locale); + try { + InputStream in = client.collectionOut(requestDoc, uuid, "export"); + Reader reader = new InputStreamReader (in, "UTF-8"); + CSVReader csvReader = new CSVReader (reader); + String[] line; + List l = csvReader.readAll (); + return l; + } + catch (IOException ce) { + System.err.println(ce.getLocalizedMessage()); + } + + throw new ServerException(ERROR_NO_EXPORT_FOUND); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml Mon May 09 13:51:39 2011 +0000 +++ b/flys-client/src/main/webapp/WEB-INF/web.xml Mon May 09 14:29:53 2011 +0000 @@ -127,7 +127,15 @@ <url-pattern>/flys/mainvalues</url-pattern> </servlet-mapping> - + <servlet> + <servlet-name>waterlevel_export</servlet-name> + <servlet-class>de.intevation.flys.client.server.CSVExportServiceImpl</servlet-class> + </servlet> + + <servlet-mapping> + <servlet-name>waterlevel_export</servlet-name> + <url-pattern>/flys/export</url-pattern> + </servlet-mapping> <servlet> <servlet-name>ChartOutputService</servlet-name>