Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ExportPanel.java @ 9190:0633f963c5be
uinfo.inundationduration workflow
author | gernotbelger |
---|---|
date | Thu, 28 Jun 2018 15:10:04 +0200 |
parents | fc42d82aa71c |
children | a4121ec450d6 |
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ExportPanel.java Thu Jun 28 14:11:12 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ExportPanel.java Thu Jun 28 15:10:04 2018 +0200 @@ -8,22 +8,25 @@ package org.dive4elements.river.client.client.ui; +import java.util.ArrayList; import java.util.List; import java.util.MissingResourceException; -import com.google.gwt.core.client.GWT; - -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.layout.HLayout; -import com.smartgwt.client.widgets.layout.VLayout; - +import org.dive4elements.river.client.client.Config; +import org.dive4elements.river.client.client.FLYSConstants; import org.dive4elements.river.client.shared.model.Collection; import org.dive4elements.river.client.shared.model.ExportMode; import org.dive4elements.river.client.shared.model.Facet; -import org.dive4elements.river.client.client.Config; -import org.dive4elements.river.client.client.FLYSConstants; +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.TextAreaItem; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; /** * A panel that displays an download icon for all available export modes of a @@ -33,34 +36,82 @@ */ public class ExportPanel extends VLayout { - /** The message class that provides i18n strings.*/ + private static final String LABEL_URL_SEPARATOR = ";";// always sync with server (InundationDurationState) + /** The message class that provides i18n strings. */ protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - protected Collection c; + protected Collection c; protected List<ExportMode> exports; - /** This layout will store a list of available export types.*/ + /** This layout will store a list of available export types. */ protected HLayout container; - - public ExportPanel(Collection c, List<ExportMode> exports) { + public ExportPanel(final Collection c, final List<ExportMode> exports) { super(); - this.c = c; - this.exports = exports; + this.c = c; + this.exports = exports; this.container = new HLayout(); - Label title = new Label(MSG.dataexport()); + final Label title = new Label(this.MSG.dataexport()); title.setHeight(15); title.setStyleName("fontNormalSmallUnderlined"); addMember(title); addMember(createExportItems()); - + addMember(createVlayoutExportItems()); setHeight(45); setMembersMargin(5); } + private VLayout createVlayoutExportItems() { + final VLayout layout = new VLayout(); + final DynamicForm form1 = new DynamicForm(); + form1.setColWidths("10%"); + form1.setWidth(400); + form1.setAlign(Alignment.LEFT); + final List<FormItem> items = new ArrayList<FormItem>(); + for (final ExportMode mode : this.exports) { + final String name = mode.getName(); + final List<Facet> facets = mode.getFacets(); + + for (int i = 0; i < facets.size(); i++) { + final Facet facet = facets.get(i); + final String facetName = facet.getName(); + + if (!facetName.equals("wms_url")) + continue; + if ("wms_url".equals(facetName)) + items.add(createUrlLine(facet.getDescription(), i)); + } + } + form1.setFields(items.toArray(new FormItem[items.size()])); + layout.addMember(form1); + return layout; + } + + private FormItem createUrlLine(final String labelAndUrl, final int count) { + + final String[] labelAndurlSplit = labelAndUrl.split(LABEL_URL_SEPARATOR); + if (labelAndurlSplit.length == 2) { + + final TextAreaItem label = new TextAreaItem(); + label.setTitle(labelAndurlSplit[0]); + + label.setWrapTitle(true); + label.setTitleColSpan(3); + label.setColSpan(7); + label.setWidth(250); + + label.setTitleAlign(Alignment.LEFT); + + label.setValue(labelAndurlSplit[1]); + label.setCanEdit(false); + + return label; + } + return null; + } /** * This method is used to create an item (created by createExportButton) for @@ -69,84 +120,80 @@ * @return a horizontal list of buttons. */ protected HLayout createExportItems() { - HLayout layout = new HLayout(); + final HLayout layout = new HLayout(); - for (ExportMode mode: exports) { - String name = mode.getName(); - List<Facet> facets = mode.getFacets(); + for (final ExportMode mode : this.exports) { + final String name = mode.getName(); + final List<Facet> facets = mode.getFacets(); - for (Facet facet: facets) { - if (name.equals("fix_wq_curve_at_export")) { + for (final Facet facet : facets) { + final String facetName = facet.getName(); + + if (name.equals("fix_wq_curve_at_export")) continue; - } + String filename = name; - if (name.equals("computed_dischargecurve_at_export")) { + if (name.equals("computed_dischargecurve_at_export")) filename = "dischargecurve"; - } - layout.addMember(createExportButton( - name, - facet.getName(), - filename)); + + if ("wms_url".equals(facetName)) + continue; + + layout.addMember(createExportButton(name, facetName, filename)); } } return layout; } - /** * This method is used to create a button (with click handler) for a * concrete export mode / type. * - * @param name The name of the export. - * @param facet The name of the export type (e.g. CSV, WST). + * @param name + * The name of the export. + * @param facet + * The name of the export type (e.g. CSV, WST). * * @return an image with click handler. */ - protected Canvas createExportButton( - String name, - String facet, - String filename - ) { - String url = getExportUrl(name, facet, filename); + protected Canvas createExportButton(final String name, final String facet, final String filename) { + String url = getExportUrl(name, facet, filename); String imgUrl = GWT.getHostPageBaseURL(); if (facet.equals("pdf")) { - imgUrl += MSG.downloadPDF(); - } - else if (facet.equals("at")) { - imgUrl += MSG.downloadAT(); - } - else if (facet.equals("wst")) { - imgUrl += MSG.downloadWST(); + imgUrl += this.MSG.downloadPDF(); + } else if (facet.equals("at")) { + imgUrl += this.MSG.downloadAT(); + } else if (facet.equals("wst")) { + imgUrl += this.MSG.downloadWST(); + } else if (facet.equals("csv")) { + url += "&encoding=UTF-8"; + imgUrl += this.MSG.downloadCSV(); + } else { + imgUrl += this.MSG.imageSave(); } - else if (facet.equals("csv")) { - url += "&encoding=windows-1252"; - imgUrl += MSG.downloadCSV(); - } - else { - imgUrl += MSG.imageSave(); - } - ImgLink link = new ImgLink(imgUrl, url, 30, 30); + final ImgLink link = new ImgLink(imgUrl, url, 30, 30); link.setTooltip(getTooltipText(name, facet)); return link; } - /** * Creates the URL used to trigger an export. * - * @param name The name of the export. - * @param facet The name of the export type (e.g. CSV, WST). + * @param name + * The name of the export. + * @param facet + * The name of the export type (e.g. CSV, WST). * * @return the export URL. */ - protected String getExportUrl(String name, String facet, String filename) { - Config config = Config.getInstance(); + protected String getExportUrl(final String name, final String facet, final String filename) { + final Config config = Config.getInstance(); String url = GWT.getModuleBaseURL(); url += "export"; - url += "?uuid=" + c.identifier(); + url += "?uuid=" + this.c.identifier(); url += "&name=" + filename; url += "&mode=" + name; url += "&type=" + facet; @@ -156,20 +203,21 @@ return url; } - /** * Creates a text used as tooltip for a specific export and type. * - * @param name The name of the export. - * @param facet The name of the export type (e.g. CSV, WST). + * @param name + * The name of the export. + * @param facet + * The name of the export type (e.g. CSV, WST). * * @return a tooltip text. */ - protected String getTooltipText(String name, String facet) { + protected String getTooltipText(final String name, final String facet) { try { - return MSG.getString(name) + " | " + MSG.getString(facet); + return this.MSG.getString(name) + " | " + this.MSG.getString(facet); } - catch (MissingResourceException mre) { + catch (final MissingResourceException mre) { return name + " | " + facet; } }