Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java @ 1292:bdc270ea6195
Edited item attributes are saved and send to the server on accept.
flys-client/trunk@2898 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 05 Oct 2011 16:29:14 +0000 |
parents | 1d04f35b2cc0 |
children |
comparison
equal
deleted
inserted
replaced
1291:1d04f35b2cc0 | 1292:bdc270ea6195 |
---|---|
1 package de.intevation.flys.client.client.ui.chart; | 1 package de.intevation.flys.client.client.ui.chart; |
2 | 2 |
3 import com.google.gwt.core.client.GWT; | 3 import com.google.gwt.core.client.GWT; |
4 import com.google.gwt.user.client.rpc.AsyncCallback; | |
4 | 5 |
5 import com.smartgwt.client.widgets.Window; | 6 import com.smartgwt.client.widgets.Window; |
6 import com.smartgwt.client.widgets.layout.VLayout; | 7 import com.smartgwt.client.widgets.layout.VLayout; |
7 import com.smartgwt.client.widgets.layout.HLayout; | 8 import com.smartgwt.client.widgets.layout.HLayout; |
8 import com.smartgwt.client.widgets.Button; | 9 import com.smartgwt.client.widgets.Button; |
10 import com.smartgwt.client.widgets.form.fields.FormItem; | 11 import com.smartgwt.client.widgets.form.fields.FormItem; |
11 import com.smartgwt.client.widgets.form.fields.CheckboxItem; | 12 import com.smartgwt.client.widgets.form.fields.CheckboxItem; |
12 import com.smartgwt.client.widgets.form.fields.SpinnerItem; | 13 import com.smartgwt.client.widgets.form.fields.SpinnerItem; |
13 import com.smartgwt.client.widgets.form.fields.ColorPickerItem; | 14 import com.smartgwt.client.widgets.form.fields.ColorPickerItem; |
14 import com.smartgwt.client.widgets.form.fields.ComboBoxItem; | 15 import com.smartgwt.client.widgets.form.fields.ComboBoxItem; |
16 import com.smartgwt.client.widgets.form.fields.TextItem; | |
15 | 17 |
16 import com.smartgwt.client.widgets.events.ClickEvent; | 18 import com.smartgwt.client.widgets.events.ClickEvent; |
17 import com.smartgwt.client.widgets.events.ClickHandler; | 19 import com.smartgwt.client.widgets.events.ClickHandler; |
20 import com.smartgwt.client.widgets.form.events.ItemChangedEvent; | |
21 import com.smartgwt.client.widgets.form.events.ItemChangedHandler; | |
18 import com.smartgwt.client.types.Alignment; | 22 import com.smartgwt.client.types.Alignment; |
19 | 23 |
20 import de.intevation.flys.client.shared.model.Collection; | 24 import de.intevation.flys.client.shared.model.Collection; |
21 import de.intevation.flys.client.shared.model.CollectionItemAttribute; | 25 import de.intevation.flys.client.shared.model.CollectionItemAttribute; |
22 import de.intevation.flys.client.shared.model.Style; | 26 import de.intevation.flys.client.shared.model.Style; |
23 import de.intevation.flys.client.shared.model.StyleSetting; | 27 import de.intevation.flys.client.shared.model.StyleSetting; |
28 import de.intevation.flys.client.shared.model.FacetRecord; | |
29 | |
30 import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync; | |
31 import de.intevation.flys.client.client.services.CollectionItemAttributeService; | |
24 import de.intevation.flys.client.client.ui.CollectionView; | 32 import de.intevation.flys.client.client.ui.CollectionView; |
25 | 33 |
26 import de.intevation.flys.client.client.FLYSConstants; | 34 import de.intevation.flys.client.client.FLYSConstants; |
35 import de.intevation.flys.client.client.Config; | |
27 | 36 |
28 /** | 37 /** |
29 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 38 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
30 */ | 39 */ |
31 public class StyleEditorWindow | 40 public class StyleEditorWindow |
42 protected CollectionView view; | 51 protected CollectionView view; |
43 | 52 |
44 /** The attributes */ | 53 /** The attributes */ |
45 protected CollectionItemAttribute attributes; | 54 protected CollectionItemAttribute attributes; |
46 | 55 |
56 /** The selected facet. */ | |
57 protected FacetRecord facet; | |
58 | |
47 /** Main layout */ | 59 /** Main layout */ |
48 protected VLayout layout; | 60 protected VLayout layout; |
49 | 61 |
62 /** The service used to set collection item attributes. */ | |
63 protected CollectionItemAttributeServiceAsync itemAttributeService = | |
64 GWT.create(CollectionItemAttributeService.class); | |
50 | 65 |
51 public StyleEditorWindow ( | 66 public StyleEditorWindow ( |
52 Collection collection, | 67 Collection collection, |
53 CollectionItemAttribute attributes) | 68 CollectionItemAttribute attributes, |
69 FacetRecord facet) | |
54 { | 70 { |
55 this.collection = collection; | 71 this.collection = collection; |
56 this.attributes = attributes; | 72 this.attributes = attributes; |
73 this.facet = facet; | |
57 this.layout = new VLayout(); | 74 this.layout = new VLayout(); |
58 | 75 |
59 init(); | 76 init(); |
60 initPanels(); | 77 initPanels(); |
61 } | 78 } |
80 Button accept = new Button(MSG.label_ok()); | 97 Button accept = new Button(MSG.label_ok()); |
81 Button cancel = new Button(MSG.label_cancel()); | 98 Button cancel = new Button(MSG.label_cancel()); |
82 cancel.addClickHandler(this); | 99 cancel.addClickHandler(this); |
83 accept.addClickHandler(new ClickHandler() { | 100 accept.addClickHandler(new ClickHandler() { |
84 public void onClick(ClickEvent e) { | 101 public void onClick(ClickEvent e) { |
85 | 102 saveStyle(); |
86 } | 103 } |
87 }); | 104 }); |
88 | 105 |
89 buttons.addMember(accept); | 106 buttons.addMember(accept); |
90 buttons.addMember(cancel); | 107 buttons.addMember(cancel); |
91 buttons.setAlign(Alignment.RIGHT); | 108 buttons.setAlign(Alignment.RIGHT); |
92 | 109 |
93 layout.addMember(createPropertyGrid("LongitudinalSectionW"));; | 110 layout.addMember(createPropertyGrid());; |
94 layout.addMember(buttons); | 111 layout.addMember(buttons); |
95 addItem(layout); | 112 addItem(layout); |
96 } | 113 } |
97 | 114 |
98 | 115 |
105 public void onClick(ClickEvent event) { | 122 public void onClick(ClickEvent event) { |
106 this.hide(); | 123 this.hide(); |
107 } | 124 } |
108 | 125 |
109 | 126 |
110 protected VLayout createPropertyGrid(String stylename) { | 127 protected VLayout createPropertyGrid() { |
111 //TODO use the style-(theme-)name from response to get the correct | |
112 //attribute set. | |
113 | |
114 VLayout properties = new VLayout(); | 128 VLayout properties = new VLayout(); |
115 | 129 |
116 // get the correct style using the name. | 130 Style s = attributes.getStyle(facet.getTheme().getFacet()); |
117 Style s = attributes.getStyle(0); | 131 |
132 TextItem name = new TextItem("name", "Name"); | |
133 name.setValue(facet.getName()); | |
134 name.setTitleStyle("color:#000; width:120px"); | |
135 name.setTitleAlign(Alignment.LEFT); | |
136 name.setDisabled(true); | |
137 name.setShowDisabled(false); | |
138 DynamicForm f = new DynamicForm(); | |
139 f.setFields(name); | |
140 properties.addMember(f); | |
118 | 141 |
119 for (int i = 0; i < s.getNumSettings(); i ++) { | 142 for (int i = 0; i < s.getNumSettings(); i ++) { |
120 final StyleSetting set = s.getSetting(i); | 143 final StyleSetting set = s.getSetting(i); |
121 DynamicForm property = createPropertyUI( | 144 DynamicForm property = createPropertyUI( |
122 set.getDisplayName(), | 145 set.getDisplayName(), |
168 f = new FormItem(); | 191 f = new FormItem(); |
169 } | 192 } |
170 f.setTitleStyle("color:#000; width:120px"); | 193 f.setTitleStyle("color:#000; width:120px"); |
171 f.setTitleAlign(Alignment.LEFT); | 194 f.setTitleAlign(Alignment.LEFT); |
172 df.setFields(f); | 195 df.setFields(f); |
196 df.addItemChangedHandler(new ItemChangedHandler() { | |
197 public void onItemChanged(ItemChangedEvent e) { | |
198 String name = e.getItem().getName(); | |
199 String newValue = e.getNewValue().toString(); | |
200 GWT.log("changed: " + name); | |
201 setNewValue(name, newValue); | |
202 } | |
203 }); | |
173 | 204 |
174 return df; | 205 return df; |
175 } | 206 } |
176 | 207 |
177 protected String rgbToHtml(String rgb) { | 208 protected String rgbToHtml(String rgb) { |
186 return "#000000"; | 217 return "#000000"; |
187 } | 218 } |
188 } | 219 } |
189 String hex = "#"; | 220 String hex = "#"; |
190 for (int i = 0; i < values.length; i++) { | 221 for (int i = 0; i < values.length; i++) { |
191 hex += Integer.toHexString(values[i]); | 222 if (values[i] < 16) { |
223 hex += "0"; | |
224 } | |
225 hex += Integer.toHexString(values[i]); | |
192 } | 226 } |
193 return hex; | 227 return hex; |
194 } | 228 } |
195 | 229 |
196 protected String htmlToRgb(String html) { | 230 protected String htmlToRgb(String html) { |
197 if (!html.startsWith("#")) { | 231 if (!html.startsWith("#")) { |
198 return "0, 0, 0"; | 232 return "0, 0, 0"; |
199 } | 233 } |
200 | 234 |
201 GWT.log("sub: " + html.substring(1, 3)); | |
202 int r = Integer.valueOf(html.substring(1, 3), 16); | 235 int r = Integer.valueOf(html.substring(1, 3), 16); |
203 int g = Integer.valueOf(html.substring(3, 5), 16); | 236 int g = Integer.valueOf(html.substring(3, 5), 16); |
204 int b = Integer.valueOf(html.substring(5, 7), 16); | 237 int b = Integer.valueOf(html.substring(5, 7), 16); |
205 | 238 |
206 return r + ", " + g + ", " + b; | 239 return r + ", " + g + ", " + b; |
207 } | 240 } |
208 | 241 |
242 protected void saveStyle () { | |
243 GWT.log("StyleEditorWindow.saveStyle()"); | |
244 Config config = Config.getInstance(); | |
245 String url = config.getServerUrl(); | |
246 String locale = config.getLocale(); | |
247 | |
248 itemAttributeService.setCollectionItemAttribute( | |
249 this.collection, | |
250 attributes.getArtifact(), | |
251 url, | |
252 locale, | |
253 attributes, | |
254 new AsyncCallback<Void>() { | |
255 public void onFailure (Throwable caught) { | |
256 GWT.log("Could not set Collection item attributes."); | |
257 } | |
258 public void onSuccess(Void v) { | |
259 GWT.log("Successfully saved collection item attributes."); | |
260 } | |
261 }); | |
262 | |
263 | |
264 this.hide(); | |
265 } | |
266 | |
267 protected final void setNewValue(String name, String value) { | |
268 Style s = attributes.getStyle(facet.getTheme().getFacet()); | |
269 StyleSetting set = s.getSetting(name); | |
270 if(name.equals("linecolor")) { | |
271 value = htmlToRgb(value); | |
272 } | |
273 set.setDefaultValue(value); | |
274 } | |
209 } | 275 } |
210 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 276 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |