comparison 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
comparison
equal deleted inserted replaced
9189:13a0c4be17ea 9190:0633f963c5be
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.client.client.ui; 9 package org.dive4elements.river.client.client.ui;
10 10
11 import java.util.ArrayList;
11 import java.util.List; 12 import java.util.List;
12 import java.util.MissingResourceException; 13 import java.util.MissingResourceException;
13 14
14 import com.google.gwt.core.client.GWT; 15 import org.dive4elements.river.client.client.Config;
15 16 import org.dive4elements.river.client.client.FLYSConstants;
16 import com.smartgwt.client.widgets.Canvas;
17 import com.smartgwt.client.widgets.Label;
18 import com.smartgwt.client.widgets.layout.HLayout;
19 import com.smartgwt.client.widgets.layout.VLayout;
20
21 import org.dive4elements.river.client.shared.model.Collection; 17 import org.dive4elements.river.client.shared.model.Collection;
22 import org.dive4elements.river.client.shared.model.ExportMode; 18 import org.dive4elements.river.client.shared.model.ExportMode;
23 import org.dive4elements.river.client.shared.model.Facet; 19 import org.dive4elements.river.client.shared.model.Facet;
24 import org.dive4elements.river.client.client.Config; 20
25 import org.dive4elements.river.client.client.FLYSConstants; 21 import com.google.gwt.core.client.GWT;
26 22 import com.smartgwt.client.types.Alignment;
23 import com.smartgwt.client.widgets.Canvas;
24 import com.smartgwt.client.widgets.Label;
25 import com.smartgwt.client.widgets.form.DynamicForm;
26 import com.smartgwt.client.widgets.form.fields.FormItem;
27 import com.smartgwt.client.widgets.form.fields.TextAreaItem;
28 import com.smartgwt.client.widgets.layout.HLayout;
29 import com.smartgwt.client.widgets.layout.VLayout;
27 30
28 /** 31 /**
29 * A panel that displays an download icon for all available export modes of a 32 * A panel that displays an download icon for all available export modes of a
30 * Collection. 33 * Collection.
31 * 34 *
32 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 35 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
33 */ 36 */
34 public class ExportPanel extends VLayout { 37 public class ExportPanel extends VLayout {
35 38
36 /** The message class that provides i18n strings.*/ 39 private static final String LABEL_URL_SEPARATOR = ";";// always sync with server (InundationDurationState)
40 /** The message class that provides i18n strings. */
37 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); 41 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
38 42
39 protected Collection c; 43 protected Collection c;
40 protected List<ExportMode> exports; 44 protected List<ExportMode> exports;
41 45
42 /** This layout will store a list of available export types.*/ 46 /** This layout will store a list of available export types. */
43 protected HLayout container; 47 protected HLayout container;
44 48
45 49 public ExportPanel(final Collection c, final List<ExportMode> exports) {
46 public ExportPanel(Collection c, List<ExportMode> exports) {
47 super(); 50 super();
48 51
49 this.c = c; 52 this.c = c;
50 this.exports = exports; 53 this.exports = exports;
51 this.container = new HLayout(); 54 this.container = new HLayout();
52 55
53 Label title = new Label(MSG.dataexport()); 56 final Label title = new Label(this.MSG.dataexport());
54 title.setHeight(15); 57 title.setHeight(15);
55 title.setStyleName("fontNormalSmallUnderlined"); 58 title.setStyleName("fontNormalSmallUnderlined");
56 59
57 addMember(title); 60 addMember(title);
58 addMember(createExportItems()); 61 addMember(createExportItems());
59 62 addMember(createVlayoutExportItems());
60 setHeight(45); 63 setHeight(45);
61 setMembersMargin(5); 64 setMembersMargin(5);
62 } 65 }
63 66
67 private VLayout createVlayoutExportItems() {
68 final VLayout layout = new VLayout();
69 final DynamicForm form1 = new DynamicForm();
70 form1.setColWidths("10%");
71 form1.setWidth(400);
72 form1.setAlign(Alignment.LEFT);
73 final List<FormItem> items = new ArrayList<FormItem>();
74 for (final ExportMode mode : this.exports) {
75 final String name = mode.getName();
76 final List<Facet> facets = mode.getFacets();
77
78 for (int i = 0; i < facets.size(); i++) {
79 final Facet facet = facets.get(i);
80 final String facetName = facet.getName();
81
82 if (!facetName.equals("wms_url"))
83 continue;
84 if ("wms_url".equals(facetName))
85 items.add(createUrlLine(facet.getDescription(), i));
86 }
87 }
88 form1.setFields(items.toArray(new FormItem[items.size()]));
89 layout.addMember(form1);
90 return layout;
91 }
92
93 private FormItem createUrlLine(final String labelAndUrl, final int count) {
94
95 final String[] labelAndurlSplit = labelAndUrl.split(LABEL_URL_SEPARATOR);
96 if (labelAndurlSplit.length == 2) {
97
98 final TextAreaItem label = new TextAreaItem();
99 label.setTitle(labelAndurlSplit[0]);
100
101 label.setWrapTitle(true);
102 label.setTitleColSpan(3);
103 label.setColSpan(7);
104 label.setWidth(250);
105
106 label.setTitleAlign(Alignment.LEFT);
107
108 label.setValue(labelAndurlSplit[1]);
109 label.setCanEdit(false);
110
111 return label;
112 }
113 return null;
114 }
64 115
65 /** 116 /**
66 * This method is used to create an item (created by createExportButton) for 117 * This method is used to create an item (created by createExportButton) for
67 * each facet for each export mode. 118 * each facet for each export mode.
68 * 119 *
69 * @return a horizontal list of buttons. 120 * @return a horizontal list of buttons.
70 */ 121 */
71 protected HLayout createExportItems() { 122 protected HLayout createExportItems() {
72 HLayout layout = new HLayout(); 123 final HLayout layout = new HLayout();
73 124
74 for (ExportMode mode: exports) { 125 for (final ExportMode mode : this.exports) {
75 String name = mode.getName(); 126 final String name = mode.getName();
76 List<Facet> facets = mode.getFacets(); 127 final List<Facet> facets = mode.getFacets();
77 128
78 for (Facet facet: facets) { 129 for (final Facet facet : facets) {
79 if (name.equals("fix_wq_curve_at_export")) { 130 final String facetName = facet.getName();
131
132 if (name.equals("fix_wq_curve_at_export"))
80 continue; 133 continue;
81 } 134
82 String filename = name; 135 String filename = name;
83 if (name.equals("computed_dischargecurve_at_export")) { 136 if (name.equals("computed_dischargecurve_at_export"))
84 filename = "dischargecurve"; 137 filename = "dischargecurve";
85 } 138
86 layout.addMember(createExportButton( 139 if ("wms_url".equals(facetName))
87 name, 140 continue;
88 facet.getName(), 141
89 filename)); 142 layout.addMember(createExportButton(name, facetName, filename));
90 } 143 }
91 } 144 }
92 145
93 return layout; 146 return layout;
94 } 147 }
95
96 148
97 /** 149 /**
98 * This method is used to create a button (with click handler) for a 150 * This method is used to create a button (with click handler) for a
99 * concrete export mode / type. 151 * concrete export mode / type.
100 * 152 *
101 * @param name The name of the export. 153 * @param name
102 * @param facet The name of the export type (e.g. CSV, WST). 154 * The name of the export.
155 * @param facet
156 * The name of the export type (e.g. CSV, WST).
103 * 157 *
104 * @return an image with click handler. 158 * @return an image with click handler.
105 */ 159 */
106 protected Canvas createExportButton( 160 protected Canvas createExportButton(final String name, final String facet, final String filename) {
107 String name, 161 String url = getExportUrl(name, facet, filename);
108 String facet,
109 String filename
110 ) {
111 String url = getExportUrl(name, facet, filename);
112 String imgUrl = GWT.getHostPageBaseURL(); 162 String imgUrl = GWT.getHostPageBaseURL();
113 if (facet.equals("pdf")) { 163 if (facet.equals("pdf")) {
114 imgUrl += MSG.downloadPDF(); 164 imgUrl += this.MSG.downloadPDF();
115 } 165 } else if (facet.equals("at")) {
116 else if (facet.equals("at")) { 166 imgUrl += this.MSG.downloadAT();
117 imgUrl += MSG.downloadAT(); 167 } else if (facet.equals("wst")) {
118 } 168 imgUrl += this.MSG.downloadWST();
119 else if (facet.equals("wst")) { 169 } else if (facet.equals("csv")) {
120 imgUrl += MSG.downloadWST(); 170 url += "&encoding=UTF-8";
121 } 171 imgUrl += this.MSG.downloadCSV();
122 else if (facet.equals("csv")) { 172 } else {
123 url += "&encoding=windows-1252"; 173 imgUrl += this.MSG.imageSave();
124 imgUrl += MSG.downloadCSV(); 174 }
125 } 175 final ImgLink link = new ImgLink(imgUrl, url, 30, 30);
126 else {
127 imgUrl += MSG.imageSave();
128 }
129 ImgLink link = new ImgLink(imgUrl, url, 30, 30);
130 link.setTooltip(getTooltipText(name, facet)); 176 link.setTooltip(getTooltipText(name, facet));
131 177
132 return link; 178 return link;
133 } 179 }
134 180
135
136 /** 181 /**
137 * Creates the URL used to trigger an export. 182 * Creates the URL used to trigger an export.
138 * 183 *
139 * @param name The name of the export. 184 * @param name
140 * @param facet The name of the export type (e.g. CSV, WST). 185 * The name of the export.
186 * @param facet
187 * The name of the export type (e.g. CSV, WST).
141 * 188 *
142 * @return the export URL. 189 * @return the export URL.
143 */ 190 */
144 protected String getExportUrl(String name, String facet, String filename) { 191 protected String getExportUrl(final String name, final String facet, final String filename) {
145 Config config = Config.getInstance(); 192 final Config config = Config.getInstance();
146 193
147 String url = GWT.getModuleBaseURL(); 194 String url = GWT.getModuleBaseURL();
148 url += "export"; 195 url += "export";
149 url += "?uuid=" + c.identifier(); 196 url += "?uuid=" + this.c.identifier();
150 url += "&name=" + filename; 197 url += "&name=" + filename;
151 url += "&mode=" + name; 198 url += "&mode=" + name;
152 url += "&type=" + facet; 199 url += "&type=" + facet;
153 url += "&server=" + config.getServerUrl(); 200 url += "&server=" + config.getServerUrl();
154 url += "&locale=" + config.getLocale(); 201 url += "&locale=" + config.getLocale();
155 202
156 return url; 203 return url;
157 } 204 }
158 205
159
160 /** 206 /**
161 * Creates a text used as tooltip for a specific export and type. 207 * Creates a text used as tooltip for a specific export and type.
162 * 208 *
163 * @param name The name of the export. 209 * @param name
164 * @param facet The name of the export type (e.g. CSV, WST). 210 * The name of the export.
211 * @param facet
212 * The name of the export type (e.g. CSV, WST).
165 * 213 *
166 * @return a tooltip text. 214 * @return a tooltip text.
167 */ 215 */
168 protected String getTooltipText(String name, String facet) { 216 protected String getTooltipText(final String name, final String facet) {
169 try { 217 try {
170 return MSG.getString(name) + " | " + MSG.getString(facet); 218 return this.MSG.getString(name) + " | " + this.MSG.getString(facet);
171 } 219 }
172 catch (MissingResourceException mre) { 220 catch (final MissingResourceException mre) {
173 return name + " | " + facet; 221 return name + " | " + facet;
174 } 222 }
175 } 223 }
176 } 224 }
177 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 225 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org