comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ExportPanel.java @ 275:8264b02091ef

ISSUE-56 Display download buttons to export the computed data. flys-client/trunk@1901 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 11 May 2011 14:29:35 +0000
parents
children 50b88b641be6
comparison
equal deleted inserted replaced
274:71a7533555d0 275:8264b02091ef
1 package de.intevation.flys.client.client.ui;
2
3 import java.util.List;
4
5 import com.google.gwt.core.client.GWT;
6
7 import com.smartgwt.client.widgets.Canvas;
8 import com.smartgwt.client.widgets.HTMLPane;
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 de.intevation.flys.client.shared.model.Collection;
14 import de.intevation.flys.client.shared.model.ExportMode;
15 import de.intevation.flys.client.shared.model.Facet;
16 import de.intevation.flys.client.client.Config;
17 import de.intevation.flys.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(25);
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 layout.addMember(createExportButton(name, facet.getName()));
72 }
73 }
74
75 return layout;
76 }
77
78
79 /**
80 * This method is used to create a button (with click handler) for a
81 * concrete export mode / type.
82 *
83 * @param name The name of the export.
84 * @param facet The name of the export type (e.g. CSV, WST).
85 *
86 * @return an image with click handler.
87 */
88 protected Canvas createExportButton(String name, String facet) {
89 String url = getExportUrl(name, facet);
90 String iUrl = GWT.getHostPageBaseURL() + MSG.imageSave();
91
92 HTMLPane pane = new HTMLPane();
93 pane.setContents("<a href='" + url + "'><img src='" + iUrl + "'></a>");
94
95 return pane;
96 }
97
98
99 /**
100 * Creates the URL used to trigger an export.
101 *
102 * @param name The name of the export.
103 * @param facet The name of the export type (e.g. CSV, WST).
104 *
105 * @return the export URL.
106 */
107 protected String getExportUrl(String name, String facet) {
108 Config config = Config.getInstance();
109
110 String url = GWT.getModuleBaseURL();
111 url += "export";
112 url += "?uuid=" + c.identifier();
113 url += "&mode=" + name;
114 url += "&type=" + facet;
115 url += "&server=" + config.getServerUrl();
116 url += "&locale=" + config.getLocale();
117
118 return url;
119 }
120 }
121 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org