comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java @ 858:9f07f67f60a5

Subclassed ChartThemePanel, trigger redraws of Chart when interaction with "Action" widgets in ThemePanel occured (but will still crash). flys-client/trunk@2651 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 06 Sep 2011 11:09:13 +0000
parents
children 65204f30877b
comparison
equal deleted inserted replaced
857:fa8efe5b8aee 858:9f07f67f60a5
1 package de.intevation.flys.client.client.ui.chart;
2
3 import com.google.gwt.core.client.GWT;
4
5 import com.smartgwt.client.types.Alignment;
6 import com.smartgwt.client.widgets.Canvas;
7 import com.google.gwt.user.client.rpc.AsyncCallback;
8 import com.smartgwt.client.types.ListGridFieldType;
9 import com.smartgwt.client.widgets.grid.ListGrid;
10 import com.smartgwt.client.widgets.grid.ListGridField;
11 import com.smartgwt.client.widgets.grid.ListGridRecord;
12 import com.smartgwt.client.widgets.layout.HLayout;
13 import com.smartgwt.client.widgets.form.fields.SpinnerItem;
14 import com.smartgwt.client.widgets.form.DynamicForm;
15 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
16 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
17
18 import de.intevation.flys.client.client.Config;
19 import de.intevation.flys.client.shared.model.Artifact;
20 import de.intevation.flys.client.shared.model.Collection;
21 import de.intevation.flys.client.shared.model.OutputMode;
22
23 import de.intevation.flys.client.shared.model.Data;
24 import de.intevation.flys.client.shared.model.DataItem;
25 import de.intevation.flys.client.shared.model.DefaultArtifact;
26 import de.intevation.flys.client.shared.model.DefaultData;
27 import de.intevation.flys.client.shared.model.DefaultDataItem;
28 import de.intevation.flys.client.shared.model.FacetRecord;
29
30
31
32 /**
33 * ThemePanel much like ChartThemePanel, but shows an "Actions" column,
34 * needed for interaction in the CrossSection Charts.
35 */
36 public class CrossSectionChartThemePanel
37 extends ChartThemePanel {
38
39 /**
40 * Trivial constructor.
41 */
42 public CrossSectionChartThemePanel(
43 Collection collection,
44 OutputMode mode)
45 {
46 super(collection, mode);
47 }
48
49
50 /**
51 * Create and configure the Grid to display.
52 */
53 @Override
54 protected ListGrid createGrid() {
55 ListGrid list = new ListGrid() {
56 @Override
57 protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {
58
59 String fieldName = this.getFieldName(colNum);
60
61 if (fieldName.equals("actions")) {
62 GWT.log("Gui: Put Actions");
63 HLayout recordCanvas = new HLayout(3);
64 recordCanvas.setHeight(22);
65 recordCanvas.setAlign(Alignment.CENTER);
66 // TODO decide on per case basis if to put an action
67 // widget or not.
68 // TODO Refactor in createSpinner(data, artifact)
69 SpinnerItem spinnerItem = new SpinnerItem();
70 spinnerItem.setShowTitle(false);
71 spinnerItem.setTitle("Waterlevel-Spinner");
72 spinnerItem.setWidth(50);
73 // TODO actually get the value from artifact
74 // TODO actually get the range from artifact (or river?)
75 spinnerItem.setDefaultValue(0);
76 spinnerItem.setMin(0);
77 spinnerItem.setMax(1000);
78 spinnerItem.setStep(5f);
79
80 Config config = Config.getInstance();
81 final String serverUrl = config.getServerUrl();
82 final String locale = config.getLocale();
83
84 spinnerItem.addChangedHandler(new ChangedHandler() {
85 @Override
86 public void onChanged(ChangedEvent ce) {
87 FacetRecord facetRecord = (FacetRecord) record;
88 DefaultDataItem kmItem = new DefaultDataItem("cross_section.km",
89 "cross_section.km", ce.getValue().toString());
90 DefaultData km = new DefaultData("cross_section.km",
91 null, null, new DataItem[] {kmItem});
92 Data[] feedData = new Data[] {km};
93 feedService.feed(serverUrl,
94 locale,
95 new DefaultArtifact(facetRecord.getTheme().getArtifact(), "TODO:hash"),
96 feedData,
97 new AsyncCallback<Artifact>() {
98 public void onFailure(Throwable caught) {
99 GWT.log("Could not feed artifact " + caught.getMessage());
100 // TODO SC.warn
101 }
102 public void onSuccess(Artifact artifact) {
103 GWT.log("Successfully fed");
104 //TODO and now?
105 // fireOutputParameterChanged();
106 // Also update content of spinnerbox
107 requestRedraw();
108 }
109 });
110 }
111 }
112 );
113
114 DynamicForm formWrap = new DynamicForm();
115 formWrap.setFields(spinnerItem);
116 formWrap.setTitlePrefix("");
117 formWrap.setTitleSuffix("");
118 recordCanvas.addMember(formWrap);
119 return recordCanvas;
120 }
121 else {
122 return null;
123 }
124 }
125 };
126 list.setCanResizeFields(true);
127 list.setShowRecordComponents(true);
128 list.setShowRecordComponentsByCell(true);
129 list.setShowAllRecords(true);
130 return list;
131 }
132
133
134 /**
135 * Initializes the components (columns) of the theme grid.
136 */
137 @Override
138 protected void initGrid() {
139 list.setCanEdit(true);
140 list.setCanSort(false);
141 list.setShowRecordComponents(true);
142 list.setShowRecordComponentsByCell(true);
143 list.setShowHeader(true);
144 //list.setShowHeaderContextMenu(false);
145 list.setWidth100();
146 list.setHeight100();
147
148 list.addEditCompleteHandler(this);
149
150 ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20);
151 active.setType(ListGridFieldType.BOOLEAN);
152
153 ListGridField name = new ListGridField(
154 GRID_FIELD_NAME, MSG.chart_themepanel_header_themes());
155 name.setType(ListGridFieldType.TEXT);
156
157 ListGridField actions = new ListGridField(GRID_FIELD_ACTIONS,
158 GRID_FIELD_ACTIONS, 60);
159
160 list.setFields(active, name, actions);
161 }
162 }
163 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org