comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java @ 1465:d0bcf5ba7adf

Create the properties dialog content dynamically based on the properties read from describe collection document. flys-client/trunk@3505 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 21 Dec 2011 10:53:02 +0000
parents 8da36efc839a
children 237e7450ae2e
comparison
equal deleted inserted replaced
1464:c899a7ffdc8f 1465:d0bcf5ba7adf
1 package de.intevation.flys.client.client.ui.chart; 1 package de.intevation.flys.client.client.ui.chart;
2 2
3 import java.util.List;
3 4
4 import com.google.gwt.core.client.GWT; 5 import com.google.gwt.core.client.GWT;
5 6
6 import com.smartgwt.client.widgets.Window; 7 import com.smartgwt.client.widgets.Window;
7 import com.smartgwt.client.widgets.tab.TabSet; 8 import com.smartgwt.client.widgets.tab.TabSet;
8 import com.smartgwt.client.widgets.tab.Tab; 9 import com.smartgwt.client.widgets.tab.Tab;
9 import com.smartgwt.client.widgets.layout.VLayout; 10 import com.smartgwt.client.widgets.layout.VLayout;
10 import com.smartgwt.client.widgets.layout.HLayout; 11 import com.smartgwt.client.widgets.layout.HLayout;
11 import com.smartgwt.client.widgets.Button; 12 import com.smartgwt.client.widgets.Button;
12 import com.smartgwt.client.widgets.Label; 13 import com.smartgwt.client.widgets.Label;
14 import com.smartgwt.client.widgets.Canvas;
15
13 import com.smartgwt.client.widgets.form.DynamicForm; 16 import com.smartgwt.client.widgets.form.DynamicForm;
14 import com.smartgwt.client.widgets.form.fields.FormItem; 17 import com.smartgwt.client.widgets.form.fields.FormItem;
15 import com.smartgwt.client.widgets.form.fields.CheckboxItem; 18 import com.smartgwt.client.widgets.form.fields.CheckboxItem;
16 import com.smartgwt.client.widgets.form.fields.TextItem; 19 import com.smartgwt.client.widgets.form.fields.TextItem;
17 20
18 import com.smartgwt.client.widgets.events.ClickEvent; 21 import com.smartgwt.client.widgets.events.ClickEvent;
19 import com.smartgwt.client.widgets.events.ClickHandler; 22 import com.smartgwt.client.widgets.events.ClickHandler;
23 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
24 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
20 import com.smartgwt.client.types.Alignment; 25 import com.smartgwt.client.types.Alignment;
21 26
22 import de.intevation.flys.client.client.FLYSConstants; 27 import de.intevation.flys.client.client.FLYSConstants;
23 import de.intevation.flys.client.client.ui.OutputTab; 28 import de.intevation.flys.client.client.ui.OutputTab;
24 29 import de.intevation.flys.client.shared.model.Property;
30 import de.intevation.flys.client.shared.model.PropertyGroup;
31 import de.intevation.flys.client.shared.model.PropertySetting;
32 import de.intevation.flys.client.shared.model.BooleanProperty;
33 import de.intevation.flys.client.shared.model.DoubleProperty;
34 import de.intevation.flys.client.shared.model.IntegerProperty;
35 import de.intevation.flys.client.shared.model.StringProperty;
36 import de.intevation.flys.client.shared.model.Settings;
37
38 import de.intevation.flys.client.shared.model.Collection;
25 /** 39 /**
26 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 40 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
27 */ 41 */
28 public class ChartPropertiesEditor 42 public class ChartPropertiesEditor
29 extends Window 43 extends Window
55 protected void init() { 69 protected void init() {
56 setTitle(MSG.properties()); 70 setTitle(MSG.properties());
57 setCanDragReposition(true); 71 setCanDragReposition(true);
58 setCanDragResize(true); 72 setCanDragResize(true);
59 73
60 Tab diagram = new Tab(MSG.diagram()); 74
61 Tab axes = new Tab(MSG.axes()); 75 Collection c = tab.getCollectionView().getCollection();
62 Tab legend = new Tab(MSG.legend()); 76 String outputName = tab.getOutputName();
63 tabs.addTab(diagram); 77 Settings settings = c.getSettings(outputName);
64 tabs.addTab(axes); 78
65 tabs.addTab(legend); 79 if (settings == null) {
80 return;
81 }
82 List<String> list = settings.getCategories();
83
84 for (int i = 0; i < list.size(); i++) {
85 Tab t = new Tab(MSG.getString(list.get(i)));
86 List<Property> props = settings.getSettings(list.get(i));
87 VLayout layout = new VLayout();
88 for (int j = 0; j < props.size(); j++) {
89 if (props.get(j) instanceof PropertyGroup) {
90 layout.addMember(generatePropertyGroup(props.get(j)));
91 }
92 else if (props.get(j) instanceof PropertySetting) {
93 PropertySetting p = (PropertySetting)props.get(j);
94
95 if (p.getAttribute("display").equals("false")) {
96 continue;
97 }
98 layout.addMember(generatePropertySetting(props.get(j)));
99 }
100 }
101 t.setPane(layout);
102 tabs.addTab(t);
103 }
66 104
67 Button accept = new Button(MSG.label_ok()); 105 Button accept = new Button(MSG.label_ok());
68 Button cancel = new Button(MSG.label_cancel()); 106 Button cancel = new Button(MSG.label_cancel());
69 cancel.addClickHandler(this); 107 cancel.addClickHandler(this);
70 accept.addClickHandler(new ClickHandler() { 108 accept.addClickHandler(new ClickHandler() {
77 buttons.addMember(accept); 115 buttons.addMember(accept);
78 buttons.addMember(cancel); 116 buttons.addMember(cancel);
79 buttons.setAlign(Alignment.CENTER); 117 buttons.setAlign(Alignment.CENTER);
80 buttons.setHeight(30); 118 buttons.setHeight(30);
81 119
82 initChartPropertiesTab(diagram);
83 initAxesPropertiesTab(axes);
84 initLegendPropertiesTab(legend);
85
86 addItem(tabs); 120 addItem(tabs);
87 addItem(buttons); 121 addItem(buttons);
88 setWidth(340); 122 setWidth(340);
89 setHeight(470); 123 setHeight(470);
90 centerInPage(); 124 centerInPage();
96 */ 130 */
97 public void onClick(ClickEvent event) { 131 public void onClick(ClickEvent event) {
98 this.hide(); 132 this.hide();
99 } 133 }
100 134
101 /** 135
102 * Initializes the tab for general chart properties. 136 /**
103 */ 137 *
104 protected void initChartPropertiesTab(Tab t) { 138 */
105 VLayout properties = new VLayout(); 139 protected Canvas generatePropertyGroup(Property group) {
140 PropertyGroup pg = (PropertyGroup)group;
141 List<Property> list = pg.getProperties();
142
143 if (pg.getName().equals("axis")) {
144 Label scale = new Label(MSG.scale() + " :");
145 scale.setHeight(25);
146 scale.setMargin(2);
147
148 DynamicForm form1 = new DynamicForm();
149 DynamicForm form2 = new DynamicForm();
150 form2.setNumCols(6);
151
152 StringProperty label =
153 (StringProperty)pg.getPropertyByName("label");
154 FormItem title = createStringProperty(label);
155 title.setValue(label.getValue());
156
157 IntegerProperty fontsize =
158 (IntegerProperty)pg.getPropertyByName("font-size");
159 FormItem fs = createIntegerProperty(fontsize);
160 fs.setValue(fontsize.getValue());
161
162 DoubleProperty upper =
163 (DoubleProperty)pg.getPropertyByName("upper");
164 final FormItem range1 = createDoubleProperty(upper);
165 range1.setValue(upper.getValue());
166 range1.setWidth(50);
167
168 DoubleProperty lower =
169 (DoubleProperty)pg.getPropertyByName("lower");
170 final FormItem range2 = createDoubleProperty(lower);
171 range2.setValue(lower.getValue());
172 range2.setWidth(50);
173
174 BooleanProperty fixation =
175 (BooleanProperty)pg.getPropertyByName("fixation");
176 FormItem fix = createBooleanProperty(fixation);
177 fix.addChangedHandler(new ChangedHandler() {
178 public void onChanged(ChangedEvent e) {
179 if ((Boolean)e.getValue()) {
180 range1.enable();
181 range2.enable();
182 }
183 else {
184 range1.disable();
185 range2.disable();
186 }
187 }
188 });
189 if (fixation.getValue().equals("true")) {
190 fix.setValue(true);
191 range1.enable();
192 range2.enable();
193 }
194 else {
195 fix.setValue(false);
196 range1.disable();
197 range2.disable();
198 }
199
200 form1.setFields(title, fs);
201 form2.setFields(fix, range1, range2);
202
203 HLayout scaleLayout = new HLayout();
204 scaleLayout.setHeight(30);
205 scaleLayout.addMember(scale);
206 scaleLayout.addMember(form2);
207 scaleLayout.addStyleName("property-dialog-axis");
208
209 VLayout root = new VLayout();
210 root.addMember(form1);
211 root.addMember(scaleLayout);
212 root.setHeight(90);
213
214 return root;
215 }
216 return null;
217 }
218
219
220 /**
221 *
222 */
223 protected DynamicForm generatePropertySetting(Property setting) {
106 DynamicForm form = new DynamicForm(); 224 DynamicForm form = new DynamicForm();
107 225 if (setting instanceof BooleanProperty) {
108 TextItem title = new TextItem (); 226 form.setFields(createBooleanProperty((BooleanProperty)setting));
109 title.setTitle(MSG.chart_title()); 227 }
110 title.setTitleAlign(Alignment.LEFT); 228 else if (setting instanceof DoubleProperty) {
111 229 form.setFields(createDoubleProperty((DoubleProperty)setting));
112 TextItem subTitle = new TextItem(); 230 }
113 subTitle.setTitle(MSG.chart_subtitle()); 231 else if (setting instanceof IntegerProperty) {
114 subTitle.setTitleAlign(Alignment.LEFT); 232 form.setFields(createIntegerProperty((IntegerProperty)setting));
115 233 }
116 CheckboxItem grid = new CheckboxItem("grid", MSG.grid()); 234 else if (setting instanceof StringProperty) {
117 grid.setLabelAsTitle(true); 235 form.setFields(createStringProperty((StringProperty)setting));
118 grid.setTitleStyle("color:#000;"); 236 }
119 grid.setTitleAlign(Alignment.LEFT); 237 return form;
120 238 }
121 CheckboxItem antialiasing = new CheckboxItem("antialiasing", 239
122 MSG.antialiasing()); 240
123 antialiasing.setLabelAsTitle(true); 241 /**
124 antialiasing.setTitleStyle("color:#000;"); 242 *
125 antialiasing.setTitleAlign(Alignment.LEFT); 243 */
126 244 protected FormItem createStringProperty(StringProperty sp) {
127 form.setFields(new FormItem[] {title, subTitle, grid, antialiasing}); 245 String name = sp.getName();
128 properties.addMember(form); 246 if (name.contains("-")) {
129 t.setPane(properties); 247 name = name.replace("-", "_");
130 } 248 }
131 249 TextItem item = new TextItem();
132 /** 250 item.setTitle(MSG.getString(name));
133 * Initializes the tab for axes properties. 251 item.setTitleAlign(Alignment.LEFT);
134 */ 252 return item;
135 protected void initAxesPropertiesTab(Tab t) { 253 }
136 VLayout properties = new VLayout(); 254
137 Label scale = new Label(MSG.scale() + " :"); 255
138 Label scale1 = new Label(MSG.scale() + " :"); 256 /**
139 Label scale2 = new Label(MSG.scale() + " :"); 257 *
140 Label scale3 = new Label(MSG.scale() + " :"); 258 */
141 scale.setHeight(25); 259 protected FormItem createBooleanProperty(BooleanProperty bp) {
142 scale1.setHeight(25); 260 String name = bp.getName();
143 scale2.setHeight(25); 261 if (name.contains("-")) {
144 scale3.setHeight(25); 262 name = name.replace("-", "_");
145 263 }
146 DynamicForm xform1 = new DynamicForm(); 264
147 DynamicForm xform2 = new DynamicForm(); 265 CheckboxItem item = new CheckboxItem("item", MSG.getString(name));
148 xform2.setNumCols(6); 266 item.setLabelAsTitle(true);
149 267 item.setTitleStyle("color:#000;");
150 Label x_axis = new Label (MSG.x_axis()); 268 item.setTitleAlign(Alignment.LEFT);
151 x_axis.setHeight(30); 269 return item;
152 HLayout x_scale = new HLayout(); 270 }
153 TextItem xname = new TextItem (); 271
154 xname.setTitle(MSG.axis_name()); 272
155 xname.setTitleAlign(Alignment.LEFT); 273 /**
156 274 *
157 TextItem xrange1 = new TextItem(); 275 */
158 xrange1.setTitle(MSG.chart_start()); 276 protected FormItem createDoubleProperty(DoubleProperty dp) {
159 xrange1.setTitleAlign(Alignment.LEFT); 277 String name = dp.getName();
160 xrange1.setWidth(50); 278 if (name.contains("-")) {
161 279 name = name.replace("-", "_");
162 TextItem xrange2 = new TextItem(); 280 }
163 xrange2.setTitle(MSG.chart_end()); 281
164 xrange2.setTitleAlign(Alignment.LEFT); 282 TextItem item = new TextItem();
165 xrange2.setWidth(50); 283 item.setTitle(MSG.getString(name));
166 284 item.setTitleAlign(Alignment.LEFT);
167 CheckboxItem xfix = new CheckboxItem("xfix", "Fix"); 285 return item;
168 xfix.setLabelAsTitle(true); 286 }
169 xfix.setTitleStyle("color:#000;"); 287
170 xfix.setTitleAlign(Alignment.LEFT); 288
171 289 /**
172 xform1.setFields(xname); 290 *
173 xform2.setFields(xrange1, xrange2, xfix); 291 */
174 x_scale.addMember(scale); 292 protected FormItem createIntegerProperty(IntegerProperty ip) {
175 x_scale.addMember(xform2); 293 String name = ip.getName();
176 294 if (name.contains("-")) {
177 295 name = name.replace("-", "_");
178 DynamicForm y1form1 = new DynamicForm(); 296 }
179 DynamicForm y1form2 = new DynamicForm(); 297
180 y1form2.setNumCols(6); 298 TextItem item = new TextItem();
181 299 item.setTitle(MSG.getString(name));
182 Label y1_axis = new Label (MSG.y1_axis()); 300 item.setTitleAlign(Alignment.LEFT);
183 y1_axis.setHeight(30); 301 return item;
184 HLayout y1_scale = new HLayout(); 302 }
185 TextItem y1name = new TextItem ();
186 y1name.setTitle(MSG.axis_name());
187 y1name.setTitleAlign(Alignment.LEFT);
188
189 TextItem y1range1 = new TextItem();
190 y1range1.setTitle(MSG.chart_start());
191 y1range1.setTitleAlign(Alignment.LEFT);
192 y1range1.setWidth(50);
193
194 TextItem y1range2 = new TextItem();
195 y1range2.setTitle(MSG.chart_end());
196 y1range2.setTitleAlign(Alignment.LEFT);
197 y1range2.setWidth(50);
198
199 CheckboxItem y1fix = new CheckboxItem("y1fix", "Fix");
200 y1fix.setLabelAsTitle(true);
201 y1fix.setTitleStyle("color:#000;");
202 y1fix.setTitleAlign(Alignment.LEFT);
203
204 y1form1.setFields(y1name);
205 y1form2.setFields(y1range1, y1range2, y1fix);
206 y1_scale.addMember(scale1);
207 y1_scale.addMember(y1form2);
208
209
210 DynamicForm y2form1 = new DynamicForm();
211 DynamicForm y2form2 = new DynamicForm();
212 y2form2.setNumCols(6);
213
214 Label y2_axis = new Label (MSG.y2_axis());
215 y2_axis.setHeight(30);
216 HLayout y2_scale = new HLayout();
217 TextItem y2name = new TextItem ();
218 y2name.setTitle(MSG.axis_name());
219 y2name.setTitleAlign(Alignment.LEFT);
220
221 TextItem y2range1 = new TextItem();
222 y2range1.setTitle(MSG.chart_start());
223 y2range1.setTitleAlign(Alignment.LEFT);
224 y2range1.setWidth(50);
225
226 TextItem y2range2 = new TextItem();
227 y2range2.setTitle(MSG.chart_end());
228 y2range2.setTitleAlign(Alignment.LEFT);
229 y2range2.setWidth(50);
230
231 CheckboxItem y2fix = new CheckboxItem("y2fix", "Fix");
232 y2fix.setLabelAsTitle(true);
233 y2fix.setTitleStyle("color:#000;");
234 y2fix.setTitleAlign(Alignment.LEFT);
235
236 y2form1.setFields(y2name);
237 y2form2.setFields(y2range1, y2range2, y2fix);
238 y2_scale.addMember(scale2);
239 y2_scale.addMember(y2form2);
240
241
242 DynamicForm y3form1 = new DynamicForm();
243 DynamicForm y3form2 = new DynamicForm();
244 y3form2.setNumCols(6);
245
246 Label y3_axis = new Label (MSG.y3_axis());
247 y3_axis.setHeight(30);
248 HLayout y3_scale = new HLayout();
249 TextItem y3name = new TextItem ();
250 y3name.setTitle(MSG.axis_name());
251 y3name.setTitleAlign(Alignment.LEFT);
252
253 TextItem y3range1 = new TextItem();
254 y3range1.setTitle(MSG.chart_start());
255 y3range1.setTitleAlign(Alignment.LEFT);
256 y3range1.setWidth(50);
257
258 TextItem y3range2 = new TextItem();
259 y3range2.setTitle(MSG.chart_end());
260 y3range2.setTitleAlign(Alignment.LEFT);
261 y3range2.setWidth(50);
262
263 CheckboxItem y3fix = new CheckboxItem("y3fix", "Fix");
264 y3fix.setLabelAsTitle(true);
265 y3fix.setTitleStyle("color:#000;");
266 y3fix.setTitleAlign(Alignment.LEFT);
267
268 y3form1.setFields(y3name);
269 y3form2.setFields(y3range1, y3range2, y3fix);
270 y3_scale.addMember(scale3);
271 y3_scale.addMember(y3form2);
272
273
274 properties.addMember(x_axis);
275 properties.addMember(xform1);
276 properties.addMember(x_scale);
277 properties.addMember(y1_axis);
278 properties.addMember(y1form1);
279 properties.addMember(y1_scale);
280 properties.addMember(y2_axis);
281 properties.addMember(y2form1);
282 properties.addMember(y2_scale);
283 properties.addMember(y3_axis);
284 properties.addMember(y3form1);
285 properties.addMember(y3_scale);
286
287 t.setPane(properties);
288 }
289
290 /**
291 * Initializes the tab for legend properties.
292 */
293 protected void initLegendPropertiesTab(Tab t) {
294 VLayout properties = new VLayout();
295 DynamicForm form = new DynamicForm();
296
297 TextItem name = new TextItem ();
298 name.setTitle(MSG.legend_name());
299 name.setTitleAlign(Alignment.LEFT);
300
301 CheckboxItem show = new CheckboxItem("show", MSG.show_legend());
302 show.setLabelAsTitle(true);
303 show.setTitleStyle("color:#000;");
304 show.setTitleAlign(Alignment.LEFT);
305
306 form.setFields(name, show);
307 properties.addMember(form);
308 t.setPane(properties);
309 }
310
311 } 303 }

http://dive4elements.wald.intevation.org