Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/StyleEditorWindow.java @ 2540:e75b15818435
Added a style chooser to the style editor to provide predefined styles and
implemented a service to request theme styles.
flys-client/trunk@4471 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 23 May 2012 08:59:49 +0000 |
parents | 8f36d4b5890c |
children | d632a6526ad9 |
comparison
equal
deleted
inserted
replaced
2539:a9cdd62aa73e | 2540:e75b15818435 |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | 2 |
3 import java.util.Arrays; | 3 import java.util.Arrays; |
4 import java.util.Map; | |
4 import java.util.LinkedHashMap; | 5 import java.util.LinkedHashMap; |
6 import java.util.Set; | |
7 import java.util.Iterator; | |
5 | 8 |
6 import com.google.gwt.core.client.GWT; | 9 import com.google.gwt.core.client.GWT; |
7 import com.google.gwt.user.client.rpc.AsyncCallback; | 10 import com.google.gwt.user.client.rpc.AsyncCallback; |
8 | 11 |
9 import com.smartgwt.client.util.SC; | 12 import com.smartgwt.client.util.SC; |
10 | 13 |
11 import com.smartgwt.client.widgets.Window; | 14 import com.smartgwt.client.widgets.Window; |
15 import com.smartgwt.client.widgets.Canvas; | |
12 import com.smartgwt.client.widgets.layout.VLayout; | 16 import com.smartgwt.client.widgets.layout.VLayout; |
13 import com.smartgwt.client.widgets.layout.HLayout; | 17 import com.smartgwt.client.widgets.layout.HLayout; |
14 import com.smartgwt.client.widgets.Button; | 18 import com.smartgwt.client.widgets.Button; |
15 import com.smartgwt.client.widgets.form.DynamicForm; | 19 import com.smartgwt.client.widgets.form.DynamicForm; |
16 import com.smartgwt.client.widgets.form.fields.FormItem; | 20 import com.smartgwt.client.widgets.form.fields.FormItem; |
21 | 25 |
22 import com.smartgwt.client.widgets.events.ClickEvent; | 26 import com.smartgwt.client.widgets.events.ClickEvent; |
23 import com.smartgwt.client.widgets.events.ClickHandler; | 27 import com.smartgwt.client.widgets.events.ClickHandler; |
24 import com.smartgwt.client.widgets.form.events.ItemChangedEvent; | 28 import com.smartgwt.client.widgets.form.events.ItemChangedEvent; |
25 import com.smartgwt.client.widgets.form.events.ItemChangedHandler; | 29 import com.smartgwt.client.widgets.form.events.ItemChangedHandler; |
30 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; | |
31 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; | |
32 | |
26 import com.smartgwt.client.types.Alignment; | 33 import com.smartgwt.client.types.Alignment; |
27 | 34 |
28 import de.intevation.flys.client.shared.model.Collection; | 35 import de.intevation.flys.client.shared.model.Collection; |
29 import de.intevation.flys.client.shared.model.CollectionItemAttribute; | 36 import de.intevation.flys.client.shared.model.CollectionItemAttribute; |
30 import de.intevation.flys.client.shared.model.Style; | 37 import de.intevation.flys.client.shared.model.Style; |
32 import de.intevation.flys.client.shared.model.FacetRecord; | 39 import de.intevation.flys.client.shared.model.FacetRecord; |
33 import de.intevation.flys.client.shared.model.Theme; | 40 import de.intevation.flys.client.shared.model.Theme; |
34 | 41 |
35 import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync; | 42 import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync; |
36 import de.intevation.flys.client.client.services.CollectionItemAttributeService; | 43 import de.intevation.flys.client.client.services.CollectionItemAttributeService; |
44 import de.intevation.flys.client.client.services.ThemeListingServiceAsync; | |
45 import de.intevation.flys.client.client.services.ThemeListingService; | |
46 | |
37 import de.intevation.flys.client.client.ui.ThemePanel; | 47 import de.intevation.flys.client.client.ui.ThemePanel; |
38 | 48 |
39 import de.intevation.flys.client.client.FLYSConstants; | 49 import de.intevation.flys.client.client.FLYSConstants; |
40 import de.intevation.flys.client.client.Config; | 50 import de.intevation.flys.client.client.Config; |
41 | 51 |
62 protected FacetRecord facet; | 72 protected FacetRecord facet; |
63 | 73 |
64 /** Main layout. */ | 74 /** Main layout. */ |
65 protected VLayout layout; | 75 protected VLayout layout; |
66 | 76 |
77 protected VLayout properties; | |
78 protected Canvas container; | |
79 | |
80 protected Map<String, Style> styleGroups; | |
81 | |
82 protected Style current; | |
83 | |
84 protected SelectItem styleChooser; | |
85 | |
67 /** The service used to set collection item attributes. */ | 86 /** The service used to set collection item attributes. */ |
68 protected CollectionItemAttributeServiceAsync itemAttributeService = | 87 protected CollectionItemAttributeServiceAsync itemAttributeService = |
69 GWT.create(CollectionItemAttributeService.class); | 88 GWT.create(CollectionItemAttributeService.class); |
70 | 89 |
90 /** The service used to request a list of themes. */ | |
91 protected ThemeListingServiceAsync themeListingService = | |
92 GWT.create(ThemeListingService.class); | |
71 | 93 |
72 /** | 94 /** |
73 * Setup editor dialog. | 95 * Setup editor dialog. |
74 * @param collection The collection the current theme belongs to. | 96 * @param collection The collection the current theme belongs to. |
75 * @param attributes The collection attributes. | 97 * @param attributes The collection attributes. |
82 { | 104 { |
83 this.collection = collection; | 105 this.collection = collection; |
84 this.attributes = attributes; | 106 this.attributes = attributes; |
85 this.facet = facet; | 107 this.facet = facet; |
86 this.layout = new VLayout(); | 108 this.layout = new VLayout(); |
87 | 109 this.properties = new VLayout(); |
110 this.container = new Canvas(); | |
111 this.styleChooser = new SelectItem("style", "Style"); | |
112 | |
113 styleChooser.setTitleStyle("color:#000;"); | |
114 styleChooser.setTitleAlign(Alignment.LEFT); | |
115 styleChooser.setValue("aktuell"); | |
116 styleChooser.addChangedHandler(new ChangedHandler() { | |
117 public void onChanged(ChangedEvent ce) { | |
118 String value = ce.getValue().toString(); | |
119 Style s = null; | |
120 if (value.equals("aktuell")) { | |
121 s = current; | |
122 } | |
123 else if (styleGroups.containsKey(value)) { | |
124 s = styleGroups.get(value); | |
125 } | |
126 | |
127 if (s != null) { | |
128 setNewStyle(s); | |
129 properties.removeMember(container); | |
130 container = createPropertyGrid(s); | |
131 properties.addMember(container); | |
132 } | |
133 } | |
134 }); | |
135 | |
136 DynamicForm f = new DynamicForm(); | |
137 f.setFields(styleChooser); | |
138 f.setColWidths("40%", "60%"); | |
139 | |
140 layout.addMember(f); | |
88 init(); | 141 init(); |
89 initPanels(); | 142 initPanels(); |
90 } | 143 } |
91 | 144 |
92 | 145 |
99 setCanDragResize(true); | 152 setCanDragResize(true); |
100 layout.setMargin(10); | 153 layout.setMargin(10); |
101 | 154 |
102 layout.setWidth100(); | 155 layout.setWidth100(); |
103 layout.setHeight100(); | 156 layout.setHeight100(); |
157 | |
158 Config config = Config.getInstance(); | |
159 String locale = config.getLocale(); | |
160 | |
161 Theme theme = facet.getTheme(); | |
162 Style style = attributes.getStyle(theme.getFacet(), theme.getIndex()); | |
163 String name = style.getName(); | |
164 this.current = style; | |
165 | |
166 themeListingService.list( | |
167 locale, | |
168 name, | |
169 new AsyncCallback<Map<String, Style> >() { | |
170 public void onFailure(Throwable caught) { | |
171 GWT.log("No listloaded."); | |
172 } | |
173 public void onSuccess(Map<String, Style> list) { | |
174 GWT.log("Successfully loaded list."); | |
175 | |
176 styleGroups = list; | |
177 Set keys = list.keySet(); | |
178 LinkedHashMap<String, String> valueMap = | |
179 new LinkedHashMap<String, String>(); | |
180 valueMap.put("aktuell", "Aktuell"); | |
181 Iterator i = keys.iterator(); | |
182 while (i.hasNext()) { | |
183 String s = i.next().toString(); | |
184 Style tmp = styleGroups.get(s); | |
185 tmp.setFacet(facet.getTheme().getFacet()); | |
186 tmp.setIndex(0); | |
187 valueMap.put(s, s); | |
188 } | |
189 styleChooser.setValueMap(valueMap); | |
190 } | |
191 }); | |
104 } | 192 } |
105 | 193 |
106 | 194 |
107 /** | 195 /** |
108 * Initialize the static window content like buttons and main layout. | 196 * Initialize the static window content like buttons and main layout. |
121 buttons.addMember(accept); | 209 buttons.addMember(accept); |
122 buttons.addMember(cancel); | 210 buttons.addMember(cancel); |
123 buttons.setAlign(Alignment.CENTER); | 211 buttons.setAlign(Alignment.CENTER); |
124 buttons.setHeight(30); | 212 buttons.setHeight(30); |
125 | 213 |
126 VLayout propGrid = createPropertyGrid(); | 214 Theme theme = facet.getTheme(); |
127 | 215 Style style = attributes.getStyle(theme.getFacet(), theme.getIndex()); |
128 layout.addMember(propGrid); | 216 |
217 container = createPropertyGrid(style); | |
218 properties.addMember(container); | |
219 layout.addMember(properties); | |
129 layout.addMember(buttons); | 220 layout.addMember(buttons); |
130 addItem(layout); | 221 addItem(layout); |
131 setWidth(400); | 222 setWidth(400); |
132 setHeight(410); | 223 setHeight(410); |
133 } | 224 } |
153 | 244 |
154 /** | 245 /** |
155 * This method creates the property grid for available styling attributes. | 246 * This method creates the property grid for available styling attributes. |
156 * @return The layout containing the UI elements. | 247 * @return The layout containing the UI elements. |
157 */ | 248 */ |
158 protected VLayout createPropertyGrid() { | 249 protected VLayout createPropertyGrid(Style style) { |
159 VLayout properties = new VLayout(); | 250 VLayout vl = new VLayout(); |
160 | |
161 Theme theme = facet.getTheme(); | |
162 Style style = attributes.getStyle(theme.getFacet(), theme.getIndex()); | |
163 | 251 |
164 StaticTextItem name = new StaticTextItem("name", "Name"); | 252 StaticTextItem name = new StaticTextItem("name", "Name"); |
165 name.setValue(facet.getName()); | 253 name.setValue(facet.getName()); |
166 name.setTitleStyle("color:#000;"); | 254 name.setTitleStyle("color:#000;"); |
167 name.setTitleAlign(Alignment.LEFT); | 255 name.setTitleAlign(Alignment.LEFT); |
168 name.setDisabled(true); | 256 name.setDisabled(true); |
169 name.setShowDisabled(false); | 257 name.setShowDisabled(false); |
258 | |
170 DynamicForm form = new DynamicForm(); | 259 DynamicForm form = new DynamicForm(); |
171 form.setFields(name); | 260 form.setFields(name); |
172 form.setColWidths("40%", "60%"); | 261 form.setColWidths("40%", "60%"); |
173 | 262 |
174 properties.addMember(form); | 263 |
264 vl.addMember(form); | |
175 | 265 |
176 if (style == null) { | 266 if (style == null) { |
177 SC.warn("No style for " + theme.getFacet() + " found."); | 267 SC.warn("No style found."); |
178 return properties; | 268 return vl; |
179 } | 269 } |
180 | 270 |
181 // Done via array to keep the order. | 271 // Done via array to keep the order. |
182 String[] sets = {"showlines", | 272 String[] sets = {"showlines", |
183 "showpoints", | 273 "showpoints", |
210 DynamicForm property = createPropertyUI( | 300 DynamicForm property = createPropertyUI( |
211 set.getDisplayName(), | 301 set.getDisplayName(), |
212 set.getName(), | 302 set.getName(), |
213 set.getType(), | 303 set.getType(), |
214 set.getDefaultValue()); | 304 set.getDefaultValue()); |
215 properties.addMember(property); | 305 vl.addMember(property); |
216 } | 306 } |
217 | 307 |
218 // Add settings not in whitelist above. | 308 // Add settings not in whitelist above. |
219 for (StyleSetting set: style.getSettings()) { | 309 for (StyleSetting set: style.getSettings()) { |
220 | 310 |
225 DynamicForm property = createPropertyUI( | 315 DynamicForm property = createPropertyUI( |
226 set.getDisplayName(), | 316 set.getDisplayName(), |
227 set.getName(), | 317 set.getName(), |
228 set.getType(), | 318 set.getType(), |
229 set.getDefaultValue()); | 319 set.getDefaultValue()); |
230 properties.addMember(property); | 320 vl.addMember(property); |
231 } | 321 } |
232 | 322 |
233 return properties; | 323 return vl; |
234 } | 324 } |
235 | 325 |
236 | 326 |
237 /** | 327 /** |
238 * Create a property form. | 328 * Create a property form. |
493 || (type != null && type.toLowerCase().indexOf("color") > -1)) { | 583 || (type != null && type.toLowerCase().indexOf("color") > -1)) { |
494 value = htmlToRgb(value); | 584 value = htmlToRgb(value); |
495 } | 585 } |
496 set.setDefaultValue(value); | 586 set.setDefaultValue(value); |
497 } | 587 } |
588 | |
589 | |
590 protected final void setNewStyle(Style style) { | |
591 Theme t = facet.getTheme(); | |
592 Style s = attributes.getStyle(t.getFacet(), t.getIndex()); | |
593 attributes.removeStyle(s.getName()); | |
594 attributes.appendStyle(style); | |
595 } | |
498 } | 596 } |
499 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 597 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |