teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5993: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.client.ui; ingo@275: ingo@275: import java.util.List; sascha@2931: import java.util.MissingResourceException; ingo@275: ingo@275: import com.google.gwt.core.client.GWT; ingo@275: ingo@275: import com.smartgwt.client.widgets.Canvas; ingo@275: import com.smartgwt.client.widgets.Label; ingo@275: import com.smartgwt.client.widgets.layout.HLayout; ingo@275: import com.smartgwt.client.widgets.layout.VLayout; ingo@275: teichmann@5835: import org.dive4elements.river.client.shared.model.Collection; teichmann@5835: import org.dive4elements.river.client.shared.model.ExportMode; teichmann@5835: import org.dive4elements.river.client.shared.model.Facet; teichmann@5835: import org.dive4elements.river.client.client.Config; teichmann@5835: import org.dive4elements.river.client.client.FLYSConstants; ingo@275: ingo@275: ingo@275: /** ingo@275: * A panel that displays an download icon for all available export modes of a ingo@275: * Collection. ingo@275: * ingo@275: * @author Ingo Weinzierl ingo@275: */ ingo@275: public class ExportPanel extends VLayout { ingo@275: ingo@275: /** The message class that provides i18n strings.*/ ingo@275: protected FLYSConstants MSG = GWT.create(FLYSConstants.class); ingo@275: ingo@275: protected Collection c; ingo@275: protected List exports; ingo@275: ingo@275: /** This layout will store a list of available export types.*/ ingo@275: protected HLayout container; ingo@275: ingo@275: ingo@275: public ExportPanel(Collection c, List exports) { ingo@275: super(); ingo@275: ingo@275: this.c = c; ingo@275: this.exports = exports; ingo@275: this.container = new HLayout(); ingo@275: ingo@275: Label title = new Label(MSG.dataexport()); ingo@275: title.setHeight(15); ingo@275: title.setStyleName("fontNormalSmallUnderlined"); ingo@275: ingo@275: addMember(title); ingo@275: addMember(createExportItems()); ingo@275: ingo@277: setHeight(45); ingo@275: setMembersMargin(5); ingo@275: } ingo@275: ingo@275: ingo@275: /** ingo@275: * This method is used to create an item (created by createExportButton) for ingo@275: * each facet for each export mode. ingo@275: * ingo@275: * @return a horizontal list of buttons. ingo@275: */ ingo@275: protected HLayout createExportItems() { ingo@275: HLayout layout = new HLayout(); ingo@275: ingo@275: for (ExportMode mode: exports) { ingo@275: String name = mode.getName(); ingo@275: List facets = mode.getFacets(); ingo@275: ingo@275: for (Facet facet: facets) { raimund@3525: if (name.equals("fix_wq_curve_at_export")) { raimund@3525: continue; raimund@3525: } rrenkert@4912: String filename = name; rrenkert@4912: if (name.equals("computed_dischargecurve_at_export")) { rrenkert@4912: filename = "dischargecurve"; rrenkert@4912: } rrenkert@4912: layout.addMember(createExportButton( rrenkert@4912: name, rrenkert@4912: facet.getName(), rrenkert@4912: filename)); ingo@275: } ingo@275: } ingo@275: ingo@275: return layout; ingo@275: } ingo@275: ingo@275: ingo@275: /** ingo@275: * This method is used to create a button (with click handler) for a ingo@275: * concrete export mode / type. ingo@275: * ingo@275: * @param name The name of the export. ingo@275: * @param facet The name of the export type (e.g. CSV, WST). ingo@275: * ingo@275: * @return an image with click handler. ingo@275: */ rrenkert@4912: protected Canvas createExportButton( rrenkert@4912: String name, rrenkert@4912: String facet, rrenkert@4912: String filename rrenkert@4912: ) { rrenkert@4912: String url = getExportUrl(name, facet, filename); rrenkert@5144: String imgUrl = GWT.getHostPageBaseURL(); rrenkert@5144: if (facet.equals("pdf")) { rrenkert@5144: imgUrl += MSG.downloadPDF(); rrenkert@5144: } rrenkert@5144: else if (facet.equals("at")) { rrenkert@5144: imgUrl += MSG.downloadAT(); rrenkert@5144: } rrenkert@5144: else if (facet.equals("wst")) { rrenkert@5144: imgUrl += MSG.downloadWST(); rrenkert@5144: } rrenkert@5144: else if (facet.equals("csv")) { felix@7140: url += "&encoding=windows-1252"; rrenkert@5144: imgUrl += MSG.downloadCSV(); rrenkert@5144: } rrenkert@5144: else { rrenkert@5144: imgUrl += MSG.imageSave(); rrenkert@5144: } rrenkert@5144: ImgLink link = new ImgLink(imgUrl, url, 30, 30); ingo@1343: link.setTooltip(getTooltipText(name, facet)); ingo@275: ingo@1343: return link; ingo@275: } ingo@275: ingo@275: ingo@275: /** ingo@275: * Creates the URL used to trigger an export. ingo@275: * ingo@275: * @param name The name of the export. ingo@275: * @param facet The name of the export type (e.g. CSV, WST). ingo@275: * ingo@275: * @return the export URL. ingo@275: */ rrenkert@4912: protected String getExportUrl(String name, String facet, String filename) { ingo@275: Config config = Config.getInstance(); ingo@275: ingo@275: String url = GWT.getModuleBaseURL(); ingo@275: url += "export"; ingo@275: url += "?uuid=" + c.identifier(); rrenkert@4912: url += "&name=" + filename; ingo@275: url += "&mode=" + name; ingo@275: url += "&type=" + facet; ingo@275: url += "&server=" + config.getServerUrl(); ingo@275: url += "&locale=" + config.getLocale(); ingo@275: ingo@275: return url; ingo@275: } ingo@433: ingo@433: ingo@433: /** ingo@433: * Creates a text used as tooltip for a specific export and type. ingo@433: * ingo@433: * @param name The name of the export. ingo@433: * @param facet The name of the export type (e.g. CSV, WST). ingo@433: * ingo@433: * @return a tooltip text. ingo@433: */ ingo@433: protected String getTooltipText(String name, String facet) { sascha@2931: try { sascha@2931: return MSG.getString(name) + " | " + MSG.getString(facet); sascha@2931: } sascha@2931: catch (MissingResourceException mre) { sascha@2931: return name + " | " + facet; sascha@2931: } ingo@433: } ingo@275: } ingo@275: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :