Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintPanel.java @ 5606:0d8564196d73
Break printing to rework the parametrization of the print job
There is now only one print button that opens a dialog
with input fields for additional attributes as specified by
desktop flys.
Currently the print button does not work and this commit
is part of a WIP.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 09 Apr 2013 11:51:29 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintSettingsPanel.java@8af500d62098 |
children | 17e2324c760e |
comparison
equal
deleted
inserted
replaced
5605:6372fd8bfb00 | 5606:0d8564196d73 |
---|---|
1 package de.intevation.flys.client.client.ui.map; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 import com.google.gwt.user.client.rpc.AsyncCallback; | |
5 import com.google.gwt.user.client.Window; | |
6 | |
7 import com.smartgwt.client.util.SC; | |
8 import com.smartgwt.client.widgets.Canvas; | |
9 import com.smartgwt.client.widgets.form.DynamicForm; | |
10 import com.smartgwt.client.widgets.form.fields.ButtonItem; | |
11 import com.smartgwt.client.widgets.form.fields.SelectItem; | |
12 import com.smartgwt.client.widgets.form.fields.TextItem; | |
13 import com.smartgwt.client.widgets.form.fields.events.ClickEvent; | |
14 import com.smartgwt.client.widgets.form.fields.events.ClickHandler; | |
15 | |
16 import org.gwtopenmaps.openlayers.client.Bounds; | |
17 import org.gwtopenmaps.openlayers.client.Map; | |
18 | |
19 import de.intevation.flys.client.client.Config; | |
20 import de.intevation.flys.client.client.FLYSConstants; | |
21 import de.intevation.flys.client.client.services.CollectionAttributeService; | |
22 import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; | |
23 import de.intevation.flys.client.shared.model.Collection; | |
24 import de.intevation.flys.client.shared.model.OutputSettings; | |
25 import de.intevation.flys.client.shared.model.Property; | |
26 import de.intevation.flys.client.shared.model.PropertySetting; | |
27 import de.intevation.flys.client.shared.model.Settings; | |
28 | |
29 import java.util.ArrayList; | |
30 import java.util.LinkedHashMap; | |
31 import java.util.List; | |
32 | |
33 public class MapPrintPanel extends Canvas { | |
34 | |
35 private static final String MAPFISH_MAPTITLE = "mapfish-mapTitle"; | |
36 private static final String MAPFISH_RANGE = "mapfish-range"; | |
37 private static final String MAPFISH_SUBTITLE = "mapfish-subtitle"; | |
38 private static final String MAPFISH_STRETCH = "mapfish-strech"; | |
39 private static final String MAPFISH_CREATED = "mapfish-created"; | |
40 private static final String MAPFISH_SOURCE = "mapfish-source"; | |
41 private static final String MAPFISH_CREATOR = "mapfish-creator"; | |
42 private static final String MAPFISH_DATEPLACE = "mapfish-dateplace"; | |
43 | |
44 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
45 | |
46 /** CollectionAttribute Update Service. */ | |
47 protected CollectionAttributeServiceAsync updater = | |
48 GWT.create(CollectionAttributeService.class); | |
49 | |
50 | |
51 protected Collection collection; | |
52 protected Settings settings; | |
53 protected TextItem pageTitle = new TextItem(); | |
54 protected TextItem pageRange = new TextItem(); | |
55 protected TextItem pageSubtitle = new TextItem(); | |
56 protected TextItem pageStrech = new TextItem(); | |
57 protected TextItem pageCreated = new TextItem(); | |
58 protected TextItem pageSource = new TextItem(); | |
59 protected TextItem pageCreator = new TextItem(); | |
60 protected TextItem pageDatePlace = new TextItem(); | |
61 // protected SelectItem pageFormat = createPageFormatSelectItem(); | |
62 protected MapToolbar mapToolbar; | |
63 protected MapPrintWindow parent; | |
64 | |
65 public MapPrintPanel(Collection collection, MapToolbar mapToolbar, MapPrintWindow parent) { | |
66 this.collection = collection; | |
67 this.mapToolbar = mapToolbar; | |
68 this.parent = parent; | |
69 initLayout(); | |
70 | |
71 this.settings = collection.getSettings("print-settings"); | |
72 if (settings == null) { | |
73 settings = new OutputSettings(); | |
74 GWT.log("settings are empty"); | |
75 } | |
76 else { | |
77 List<Property> properties = settings.getSettings("default"); | |
78 for (Property prop : properties) { | |
79 PropertySetting props = (PropertySetting)prop; | |
80 GWT.log(props.getName() + "=" + props.getValue()); | |
81 if (props.getName().equals(MAPFISH_MAPTITLE)) { | |
82 this.pageTitle.setValue(props.getValue()); | |
83 } | |
84 else if (props.getName().equals(MAPFISH_RANGE)) { | |
85 this.pageRange.setValue(props.getValue()); | |
86 } | |
87 else if (props.getName().equals(MAPFISH_SUBTITLE)) { | |
88 this.pageSubtitle.setValue(props.getValue()); | |
89 } | |
90 else if (props.getName().equals(MAPFISH_STRETCH)) { | |
91 this.pageStrech.setValue(props.getValue()); | |
92 } | |
93 else if (props.getName().equals(MAPFISH_CREATED)) { | |
94 this.pageCreated.setValue(props.getValue()); | |
95 } | |
96 else if (props.getName().equals(MAPFISH_SOURCE)) { | |
97 this.pageSource.setValue(props.getValue()); | |
98 } | |
99 else if (props.getName().equals(MAPFISH_CREATOR)) { | |
100 this.pageCreator.setValue(props.getValue()); | |
101 } | |
102 else if (props.getName().equals(MAPFISH_DATEPLACE)) { | |
103 this.pageDatePlace.setValue(props.getValue()); | |
104 } else { | |
105 GWT.log("Unknown Print property: " + prop.getName()); | |
106 } | |
107 } | |
108 } | |
109 } | |
110 | |
111 protected void initLayout() { | |
112 // TODO: i18n | |
113 this.pageTitle.setTitle("Titel"); | |
114 this.pageSubtitle.setTitle("Untertitel"); | |
115 this.pageRange.setTitle("Bereich"); | |
116 this.pageStrech.setTitle("Strecke"); | |
117 this.pageCreated.setTitle("Aufgestellt"); | |
118 this.pageSource.setTitle("Datenquelle"); | |
119 this.pageCreator.setTitle("Ersteller"); | |
120 this.pageDatePlace.setTitle("Ort, Datum"); | |
121 | |
122 DynamicForm df = new DynamicForm(); | |
123 df.setFields( | |
124 // this.pageFormat, | |
125 this.pageTitle, | |
126 this.pageSubtitle, | |
127 this.pageRange, | |
128 this.pageStrech, | |
129 this.pageCreated, | |
130 this.pageSource, | |
131 this.pageCreator, | |
132 this.pageDatePlace, | |
133 createPrintButtonItem() | |
134 ); | |
135 addChild(df); | |
136 } | |
137 | |
138 /* | |
139 * Commented out because we only provide a layout for A4 Landscape atm | |
140 | |
141 protected SelectItem createPageFormatSelectItem() { | |
142 LinkedHashMap values = new LinkedHashMap(); | |
143 // TODO: i18n | |
144 values.put("A4 landscape", "DIN A4 (Querformat)"); | |
145 //values.put("A4 portrait", "DIN A4 (Hochformat)"); | |
146 //values.put("A0 portrait", "DIN A0 (Hochformat)"); | |
147 | |
148 SelectItem selItem = new SelectItem(); | |
149 selItem.setTitle("Seitengröße:"); // TODO: i18n | |
150 selItem.setValueMap(values); | |
151 selItem.setDefaultToFirstOption(true); | |
152 | |
153 return selItem; | |
154 } | |
155 */ | |
156 protected ButtonItem createPrintButtonItem() { | |
157 ButtonItem btn = new ButtonItem(); | |
158 GWT.log("Button created"); | |
159 btn.addClickHandler(new ClickHandler() { | |
160 | |
161 @Override | |
162 public void onClick(ClickEvent event) { | |
163 GWT.log("Print Button Click"); | |
164 // updateCollection(); | |
165 //Window.open(createPrintUrl(), "_blank", ""); | |
166 // parent.destroy(); | |
167 } | |
168 }); | |
169 btn.setTitle(MSG.print()); | |
170 return btn; | |
171 } | |
172 | |
173 private String createPrintUrl() { | |
174 MapOutputTab ot = (MapOutputTab)mapToolbar.getOutputTab(); | |
175 Collection collection = ot.getCollection(); | |
176 String uuid = collection.identifier(); | |
177 | |
178 String mapType = collection.getOutputModes().containsKey("floodmap") | |
179 ? "floodmap" | |
180 : "map"; | |
181 | |
182 StringBuilder url = new StringBuilder(); | |
183 url.append(GWT.getModuleBaseURL()); | |
184 url.append("map-print?"); | |
185 | |
186 Map map = mapToolbar.getMap(); | |
187 Bounds bounds = map.getExtent(); | |
188 | |
189 if (bounds != null) { | |
190 try { | |
191 url.append("minx="); | |
192 url.append(bounds.getLowerLeftX()); | |
193 url.append("&"); | |
194 | |
195 url.append("maxx="); | |
196 url.append(bounds.getUpperRightX()); | |
197 url.append("&"); | |
198 | |
199 url.append("miny="); | |
200 url.append(bounds.getLowerLeftY()); | |
201 url.append("&"); | |
202 | |
203 url.append("maxy="); | |
204 url.append(bounds.getUpperRightY()); | |
205 url.append("&"); | |
206 } | |
207 catch (Exception e) { | |
208 // XXX: Ignore it. bounds.getXXX() throw | |
209 // exceptions when bound is invalid. :-/ | |
210 } | |
211 } | |
212 | |
213 url.append("uuid="); | |
214 url.append(uuid); | |
215 url.append("&maptype="); | |
216 url.append(mapType); | |
217 | |
218 appendPrintToUrl(collection, url); | |
219 | |
220 return url.toString(); | |
221 } | |
222 | |
223 private void appendPrintToUrl(Collection collection, StringBuilder url) { | |
224 Settings settings = collection.getSettings("print-settings"); | |
225 if (settings != null) { | |
226 List<Property> properties = settings.getSettings("default"); | |
227 for (Property prop : properties) { | |
228 PropertySetting props = (PropertySetting)prop; | |
229 url.append("&"); | |
230 url.append(props.getName()); | |
231 url.append("="); | |
232 url.append(props.getValue()); | |
233 } | |
234 } | |
235 } | |
236 | |
237 protected void updateCollection() { | |
238 final Config config = Config.getInstance(); | |
239 final String loc = config.getLocale(); | |
240 | |
241 GWT.log("MapPrintPanel.updateCollection via RPC now"); | |
242 | |
243 List<Property> properties = new ArrayList<Property>(); | |
244 properties.add(new PropertySetting(MAPFISH_MAPTITLE, this.pageTitle.getValueAsString())); | |
245 // properties.add(new PropertySetting(MAPFISH_LAYOUT, this.pageFormat.getValueAsString())); | |
246 properties.add(new PropertySetting(MAPFISH_SUBTITLE, this.pageSubtitle.getValueAsString())); | |
247 properties.add(new PropertySetting(MAPFISH_RANGE, this.pageRange.getValueAsString())); | |
248 properties.add(new PropertySetting(MAPFISH_STRETCH, this.pageStrech.getValueAsString())); | |
249 properties.add(new PropertySetting(MAPFISH_CREATED, this.pageCreated.getValueAsString())); | |
250 properties.add(new PropertySetting(MAPFISH_SOURCE, this.pageSource.getValueAsString())); | |
251 properties.add(new PropertySetting(MAPFISH_CREATOR, this.pageCreator.getValueAsString())); | |
252 properties.add(new PropertySetting(MAPFISH_DATEPLACE, this.pageDatePlace.getValueAsString())); | |
253 settings.setSettings("default", properties); | |
254 | |
255 collection.addSettings("print-settings", settings); | |
256 updater.update(collection, loc, new AsyncCallback<Collection>() { | |
257 @Override | |
258 public void onFailure(Throwable caught) { | |
259 GWT.log("Could not update collection attributes."); | |
260 SC.warn(MSG.getString(caught.getMessage())); | |
261 } | |
262 @Override | |
263 public void onSuccess(Collection collection) { | |
264 GWT.log("MapPrint: collection attributes updated"); | |
265 } | |
266 }); | |
267 } | |
268 } |