comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ExportPanel.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-client/src/main/java/org/dive4elements/river/client/client/ui/ExportPanel.java@821a02bbfb4e
children 172338b1407f
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.client.client.ui;
2
3 import java.util.List;
4 import java.util.MissingResourceException;
5
6 import com.google.gwt.core.client.GWT;
7
8 import com.smartgwt.client.widgets.Canvas;
9 import com.smartgwt.client.widgets.Label;
10 import com.smartgwt.client.widgets.layout.HLayout;
11 import com.smartgwt.client.widgets.layout.VLayout;
12
13 import org.dive4elements.river.client.shared.model.Collection;
14 import org.dive4elements.river.client.shared.model.ExportMode;
15 import org.dive4elements.river.client.shared.model.Facet;
16 import org.dive4elements.river.client.client.Config;
17 import org.dive4elements.river.client.client.FLYSConstants;
18
19
20 /**
21 * A panel that displays an download icon for all available export modes of a
22 * Collection.
23 *
24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
25 */
26 public class ExportPanel extends VLayout {
27
28 /** The message class that provides i18n strings.*/
29 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
30
31 protected Collection c;
32 protected List<ExportMode> exports;
33
34 /** This layout will store a list of available export types.*/
35 protected HLayout container;
36
37
38 public ExportPanel(Collection c, List<ExportMode> exports) {
39 super();
40
41 this.c = c;
42 this.exports = exports;
43 this.container = new HLayout();
44
45 Label title = new Label(MSG.dataexport());
46 title.setHeight(15);
47 title.setStyleName("fontNormalSmallUnderlined");
48
49 addMember(title);
50 addMember(createExportItems());
51
52 setHeight(45);
53 setMembersMargin(5);
54 }
55
56
57 /**
58 * This method is used to create an item (created by createExportButton) for
59 * each facet for each export mode.
60 *
61 * @return a horizontal list of buttons.
62 */
63 protected HLayout createExportItems() {
64 HLayout layout = new HLayout();
65
66 for (ExportMode mode: exports) {
67 String name = mode.getName();
68 List<Facet> facets = mode.getFacets();
69
70 for (Facet facet: facets) {
71 if (name.equals("fix_wq_curve_at_export")) {
72 continue;
73 }
74 String filename = name;
75 if (name.equals("computed_dischargecurve_at_export")) {
76 filename = "dischargecurve";
77 }
78 layout.addMember(createExportButton(
79 name,
80 facet.getName(),
81 filename));
82 }
83 }
84
85 return layout;
86 }
87
88
89 /**
90 * This method is used to create a button (with click handler) for a
91 * concrete export mode / type.
92 *
93 * @param name The name of the export.
94 * @param facet The name of the export type (e.g. CSV, WST).
95 *
96 * @return an image with click handler.
97 */
98 protected Canvas createExportButton(
99 String name,
100 String facet,
101 String filename
102 ) {
103 String url = getExportUrl(name, facet, filename);
104 String imgUrl = GWT.getHostPageBaseURL();
105 if (facet.equals("pdf")) {
106 imgUrl += MSG.downloadPDF();
107 }
108 else if (facet.equals("at")) {
109 imgUrl += MSG.downloadAT();
110 }
111 else if (facet.equals("wst")) {
112 imgUrl += MSG.downloadWST();
113 }
114 else if (facet.equals("csv")) {
115 imgUrl += MSG.downloadCSV();
116 }
117 else {
118 imgUrl += MSG.imageSave();
119 }
120 ImgLink link = new ImgLink(imgUrl, url, 30, 30);
121 link.setTooltip(getTooltipText(name, facet));
122
123 return link;
124 }
125
126
127 /**
128 * Creates the URL used to trigger an export.
129 *
130 * @param name The name of the export.
131 * @param facet The name of the export type (e.g. CSV, WST).
132 *
133 * @return the export URL.
134 */
135 protected String getExportUrl(String name, String facet, String filename) {
136 Config config = Config.getInstance();
137
138 String url = GWT.getModuleBaseURL();
139 url += "export";
140 url += "?uuid=" + c.identifier();
141 url += "&name=" + filename;
142 url += "&mode=" + name;
143 url += "&type=" + facet;
144 url += "&server=" + config.getServerUrl();
145 url += "&locale=" + config.getLocale();
146
147 return url;
148 }
149
150
151 /**
152 * Creates a text used as tooltip for a specific export and type.
153 *
154 * @param name The name of the export.
155 * @param facet The name of the export type (e.g. CSV, WST).
156 *
157 * @return a tooltip text.
158 */
159 protected String getTooltipText(String name, String facet) {
160 try {
161 return MSG.getString(name) + " | " + MSG.getString(facet);
162 }
163 catch (MissingResourceException mre) {
164 return name + " | " + facet;
165 }
166 }
167 }
168 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org