Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java @ 1438:432180235caf
Minor refactoring and fix initial settings when creating ui.
flys-client/trunk@3403 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 13 Dec 2011 13:24:43 +0000 |
parents | 29fc2d1dfe9b |
children | bdac8a72f7e6 |
comparison
equal
deleted
inserted
replaced
1437:1d82a2c695a6 | 1438:432180235caf |
---|---|
20 import com.smartgwt.client.widgets.layout.HLayout; | 20 import com.smartgwt.client.widgets.layout.HLayout; |
21 import com.smartgwt.client.widgets.layout.VLayout; | 21 import com.smartgwt.client.widgets.layout.VLayout; |
22 import com.smartgwt.client.widgets.form.fields.SpinnerItem; | 22 import com.smartgwt.client.widgets.form.fields.SpinnerItem; |
23 import com.smartgwt.client.widgets.form.DynamicForm; | 23 import com.smartgwt.client.widgets.form.DynamicForm; |
24 | 24 |
25 import com.smartgwt.client.widgets.form.fields.ComboBoxItem; | |
26 import com.smartgwt.client.widgets.form.fields.SelectItem; | 25 import com.smartgwt.client.widgets.form.fields.SelectItem; |
27 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; | 26 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; |
28 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; | 27 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; |
29 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; | 28 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; |
30 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; | 29 import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; |
103 }); | 102 }); |
104 } | 103 } |
105 | 104 |
106 | 105 |
107 /** | 106 /** |
107 * sets currentMasterUUID. | |
108 */ | |
109 public String findCurrentMaster() { | |
110 ThemeList themeList = getThemeList(); | |
111 int count = getThemeList().getThemeCount(); | |
112 for (int i = 1; i <= count; i++) { | |
113 Theme theme = themeList.getThemeAt(i); | |
114 String value = theme.getCollectionItem().getData().get("cross_section.master?"); | |
115 | |
116 if (value != null && !value.equals("0")) { | |
117 setCurrentMaster(theme.getArtifact()); | |
118 GWT.log("found a master! " + currentMasterUUID + "/" + theme.getDescription()); | |
119 return theme.getDescription(); | |
120 } | |
121 } | |
122 return null; | |
123 } | |
124 | |
125 /** | |
108 * Create Layout, add a master selection box beneath. | 126 * Create Layout, add a master selection box beneath. |
109 */ | 127 */ |
110 @Override | 128 @Override |
111 protected VLayout createLayout() { | 129 protected VLayout createLayout() { |
112 | 130 layout = super.createLayout(); |
113 layout = super.createLayout(); | |
114 | 131 |
115 // Create "set master" combobox. | 132 // Create "set master" combobox. |
116 SelectItem cbItem = new SelectItem(); | 133 SelectItem cbItem = new SelectItem(); |
117 | 134 |
118 cbItem.setTitle(MSG.chart_themepanel_set_master()); | 135 cbItem.setTitle(MSG.chart_themepanel_set_master()); |
124 final DynamicForm form = new DynamicForm(); | 141 final DynamicForm form = new DynamicForm(); |
125 form.setWidth(200); | 142 form.setWidth(200); |
126 form.setFields(cbItem); | 143 form.setFields(cbItem); |
127 layout.addMember(form); | 144 layout.addMember(form); |
128 | 145 |
129 Config config = Config.getInstance(); | 146 Config config = Config.getInstance(); |
130 final String locale = config.getLocale(); | 147 final String locale = config.getLocale(); |
148 findCurrentMaster(); | |
149 cbItem.setValue(getCurrentMaster()); | |
131 | 150 |
132 // Add Change Handler to first unset the old master and then set the | 151 // Add Change Handler to first unset the old master and then set the |
133 // new master. | 152 // new master. |
134 cbItem.addChangeHandler(new ChangeHandler() { | 153 cbItem.addChangeHandler(new ChangeHandler() { |
135 public void onChange(ChangeEvent event) { | 154 public void onChange(ChangeEvent event) { |
146 locale, | 165 locale, |
147 new DefaultArtifact(getCurrentMaster(), "TODO:hash"), | 166 new DefaultArtifact(getCurrentMaster(), "TODO:hash"), |
148 feedData, | 167 feedData, |
149 new AsyncCallback<Artifact>() { | 168 new AsyncCallback<Artifact>() { |
150 public void onFailure(Throwable caught) { | 169 public void onFailure(Throwable caught) { |
151 GWT.log("Could not un-master artifact: " + | 170 GWT.log("Could not un-master artifact ("+getCurrentMaster()+"): " + |
152 caught.getMessage()); | 171 caught.getMessage()); |
153 SC.warn(MSG.getString(caught.getMessage())); | 172 SC.warn(MSG.getString(caught.getMessage())); |
154 enable(); | 173 enable(); |
155 } | 174 } |
156 public void onSuccess(Artifact oldMaster) { | 175 public void onSuccess(Artifact oldMaster) { |
237 } | 256 } |
238 @Override | 257 @Override |
239 public void onSuccess(Artifact artifact) { | 258 public void onSuccess(Artifact artifact) { |
240 GWT.log("Successfully fed"); | 259 GWT.log("Successfully fed"); |
241 requestRedraw(); | 260 requestRedraw(); |
261 // TODO also feed the winfo/masterartifact? (for plot subtitle) | |
242 enable(); | 262 enable(); |
243 } | 263 } |
244 }); | 264 }); |
245 } | 265 } |
246 | 266 |
339 return km; | 359 return km; |
340 } | 360 } |
341 | 361 |
342 | 362 |
343 /** | 363 /** |
364 * Create a "kilometer spinner" for CrossSection Facets. | |
365 * @param facetRecord The respective Facet/Theme. | |
366 * @return label, intialized SpinnerItem. | |
367 */ | |
368 public SpinnerItem createSpinnerItem(FacetRecord facetRecord) { | |
369 SpinnerItem spinnerItem = new SpinnerItem(); | |
370 spinnerItem.setShowTitle(false); | |
371 spinnerItem.setTitle("Waterlevel-Spinner"); | |
372 spinnerItem.setWidth(45); | |
373 spinnerItem.setDefaultValue(facetRecord.getTheme() | |
374 .getCollectionItem() | |
375 .getData().get("cross_section.km")); | |
376 | |
377 // TODO actually use crosssectionkmservice with | |
378 // min/max-extension | |
379 spinnerItem.setMin(0); | |
380 spinnerItem.setMax(1000); | |
381 spinnerItem.setStep(5f); | |
382 spinnerItem.setChangeOnKeypress(true); | |
383 return spinnerItem; | |
384 } | |
385 | |
386 | |
387 /** | |
344 * Create and configure the Grid to display. | 388 * Create and configure the Grid to display. |
389 * @return ListGrid with Themes and related controls inside. | |
345 */ | 390 */ |
346 @Override | 391 @Override |
347 protected ListGrid createGrid() { | 392 protected ListGrid createGrid() { |
348 ListGrid list = new ListGrid() { | 393 ListGrid list = new ListGrid() { |
349 @Override | 394 @Override |
364 if (fieldName.equals(GRID_FIELD_ACTIONS)) { | 409 if (fieldName.equals(GRID_FIELD_ACTIONS)) { |
365 HLayout recordCanvas = new HLayout(3); | 410 HLayout recordCanvas = new HLayout(3); |
366 recordCanvas.setHeight(22); | 411 recordCanvas.setHeight(22); |
367 recordCanvas.setAlign(Alignment.CENTER); | 412 recordCanvas.setAlign(Alignment.CENTER); |
368 // TODO Refactor in createSpinner(data, artifact) | 413 // TODO Refactor in createSpinner(data, artifact) |
369 SpinnerItem spinnerItem = new SpinnerItem(); | 414 SpinnerItem spinnerItem = createSpinnerItem(facetRecord); |
370 spinnerItem.setShowTitle(false); | |
371 spinnerItem.setTitle("Waterlevel-Spinner"); | |
372 spinnerItem.setWidth(45); | |
373 // TODO actually get the value from artifact | |
374 spinnerItem.setDefaultValue( | |
375 getKmForCrossSectionIdx(facetRecord.getTheme().getIndex())); | |
376 | |
377 // TODO actually use crosssectionkmservive | |
378 spinnerItem.setMin(0); | |
379 spinnerItem.setMax(1000); | |
380 spinnerItem.setStep(5f); | |
381 spinnerItem.setChangeOnKeypress(true); | |
382 | |
383 spinnerItem.addChangedHandler( | 415 spinnerItem.addChangedHandler( |
384 createSpinnerHandler( | 416 createSpinnerHandler(feedService, facetRecord)); |
385 feedService, | |
386 facetRecord)); | |
387 | 417 |
388 DynamicForm formWrap = new DynamicForm(); | 418 DynamicForm formWrap = new DynamicForm(); |
389 formWrap.setFields(spinnerItem); | 419 formWrap.setFields(spinnerItem); |
390 formWrap.setTitlePrefix(""); | 420 formWrap.setTitlePrefix(""); |
391 formWrap.setTitleSuffix(""); | 421 formWrap.setTitleSuffix(""); |