comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java @ 1456:1c2cd46d526d

Have 'area' context menu in Longitudinal-Section diagrams themepanels, too. flys-client/trunk@3486 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 20 Dec 2011 10:54:55 +0000
parents 6bb6d43eeb2d
children 3d9f81c3f00d
comparison
equal deleted inserted replaced
1455:75a40270efa8 1456:1c2cd46d526d
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 4
5 import com.google.gwt.user.client.rpc.AsyncCallback;
6
5 import com.smartgwt.client.types.ListGridFieldType; 7 import com.smartgwt.client.types.ListGridFieldType;
8
6 import com.smartgwt.client.widgets.grid.ListGridField; 9 import com.smartgwt.client.widgets.grid.ListGridField;
10 import com.smartgwt.client.widgets.grid.ListGridRecord;
7 import com.smartgwt.client.widgets.layout.VLayout; 11 import com.smartgwt.client.widgets.layout.VLayout;
8 12 import com.smartgwt.client.widgets.menu.events.ClickHandler;
13
14 import com.smartgwt.client.widgets.menu.Menu;
15 import com.smartgwt.client.widgets.menu.MenuItem;
16 import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
17
18 import com.smartgwt.client.util.SC;
19
20 import de.intevation.flys.client.shared.model.Artifact;
9 import de.intevation.flys.client.shared.model.Collection; 21 import de.intevation.flys.client.shared.model.Collection;
22 import de.intevation.flys.client.shared.model.Data;
23 import de.intevation.flys.client.shared.model.DefaultData;
24 import de.intevation.flys.client.shared.model.DefaultArtifact;
25 import de.intevation.flys.client.shared.model.FacetRecord;
26 import de.intevation.flys.client.shared.model.OutputMode;
27 import de.intevation.flys.client.shared.model.Recommendation;
10 import de.intevation.flys.client.shared.model.Theme; 28 import de.intevation.flys.client.shared.model.Theme;
11 import de.intevation.flys.client.shared.model.OutputMode; 29 import de.intevation.flys.client.shared.model.ThemeList;
12 30
31 import de.intevation.flys.client.client.Config;
13 import de.intevation.flys.client.client.FLYSConstants; 32 import de.intevation.flys.client.client.FLYSConstants;
14 import de.intevation.flys.client.client.ui.ThemePanel; 33 import de.intevation.flys.client.client.ui.ThemePanel;
15 34
16 import de.intevation.flys.client.client.services.FeedService; 35 import de.intevation.flys.client.client.services.FeedService;
17 import de.intevation.flys.client.client.services.FeedServiceAsync; 36 import de.intevation.flys.client.client.services.FeedServiceAsync;
37
38 import de.intevation.flys.client.client.services.LoadArtifactService;
39 import de.intevation.flys.client.client.services.LoadArtifactServiceAsync;
40
18 41
19 /** 42 /**
20 * ThemePanel on the left in CollectionView. 43 * ThemePanel on the left in CollectionView.
21 * Contains control widgets for "themes", which are plotted in a diagram (chart). 44 * Contains control widgets for "themes", which are plotted in a diagram (chart).
22 * 45 *
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 46 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
24 */ 47 */
25 public class ChartThemePanel extends ThemePanel { 48 public class ChartThemePanel extends ThemePanel {
49 /** Artifact Clone/Creation service. */
50 protected LoadArtifactServiceAsync loadService =
51 GWT.create(LoadArtifactService.class);
26 52
27 /** The interface that provides i18n messages. */ 53 /** The interface that provides i18n messages. */
28 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); 54 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
29 55
30 /** The collection */ 56 /** The collection */
34 public static final String GRID_FIELD_NAME = "name"; 60 public static final String GRID_FIELD_NAME = "name";
35 public static final String GRID_FIELD_ACTIONS = "actions"; 61 public static final String GRID_FIELD_ACTIONS = "actions";
36 62
37 FeedServiceAsync feedService = GWT.create( 63 FeedServiceAsync feedService = GWT.create(
38 de.intevation.flys.client.client.services.FeedService.class); 64 de.intevation.flys.client.client.services.FeedService.class);
65
39 66
40 public ChartThemePanel(Collection collection, OutputMode mode) { 67 public ChartThemePanel(Collection collection, OutputMode mode) {
41 super(collection, mode); 68 super(collection, mode);
42 this.collection = collection; 69 this.collection = collection;
43 70
56 layout.addMember(list); 83 layout.addMember(list);
57 layout.addMember(navigation); 84 layout.addMember(navigation);
58 85
59 return layout; 86 return layout;
60 } 87 }
88
61 89
62 /** 90 /**
63 * Initializes the layout of this panel. 91 * Initializes the layout of this panel.
64 */ 92 */
65 protected void initLayout() { 93 protected void initLayout() {
98 126
99 @Override 127 @Override
100 public void activateTheme(Theme theme, boolean active) { 128 public void activateTheme(Theme theme, boolean active) {
101 theme.setActive(active ? 1 : 0); 129 theme.setActive(active ? 1 : 0);
102 } 130 }
131
132
133 /**
134 * Tell an area artifact where to get the upper and lower curve from.
135 * @param over if null, something
136 */
137 public void feedTellArea(final String artifact, Theme under, Theme over) {
138
139 Data[] feedData;
140
141 if (over != null && under != null) {
142 feedData = new Data[] {
143 DefaultData.createSimpleStringData("area.curve_under",
144 under.getArtifact() + under.getIndex()),
145 DefaultData.createSimpleStringData("area.curve_over",
146 over.getArtifact() + over.getIndex()),
147 DefaultData.createSimpleStringData("area.name",
148 over.getDescription() + " / " + under.getDescription()),
149 DefaultData.createSimpleStringData("area.facet",
150 "longitudinal_section.area")
151 };
152 GWT.log("Have over and under");
153 }
154 else if (over == null && under != null) {
155 feedData = new Data[] {
156 DefaultData.createSimpleStringData("area.curve_under",
157 under.getArtifact() + under.getIndex()),
158 DefaultData.createSimpleStringData("area.name",
159 under.getDescription() + " / " + MSG.getString("x_axis")),
160 DefaultData.createSimpleStringData("area.facet",
161 "longitudinal_section.area")
162 };
163 GWT.log("Have under only");
164 }
165 else if (over != null && under == null) {
166 feedData = new Data[] {
167 DefaultData.createSimpleStringData("area.curve_over",
168 over.getArtifact() + over.getIndex()),
169 DefaultData.createSimpleStringData("area.name",
170 MSG.getString("x_axis") + " / " + over.getDescription()),
171 DefaultData.createSimpleStringData("area.facet",
172 "longitudinal_section.area")
173 };
174 GWT.log("Have over only");
175 }
176 else {
177 GWT.log("Missing Data for area painting.");
178 return;
179 }
180
181
182 feedService.feed(
183 Config.getInstance().getLocale(),
184 new DefaultArtifact(artifact, "TODO:hash"),
185 feedData,
186 new AsyncCallback<Artifact>() {
187 public void onFailure(Throwable caught) {
188 GWT.log("Could not feed artifact (" + artifact
189 + ") with area info: " + caught.getMessage());
190 SC.warn(MSG.getString(caught.getMessage()));
191 enable();
192 }
193 public void onSuccess(Artifact artifact) {
194 GWT.log("Successfully set area params to " + artifact);
195 requestRedraw();
196 updateCollection();
197 updateGrid();
198 enable();
199 }
200 });
201 }
202
203
204 /**
205 * Create and parameterize a new area artifact.
206 * @param under
207 * @param over if null, something.
208 */
209 public void createAreaArtifact(
210 final Theme under,
211 final Theme over,
212 boolean between
213 ) {
214 Config config = Config.getInstance();
215 String locale = config.getLocale();
216
217 Recommendation area = new Recommendation(
218 "area",
219 "",
220 "",
221 null);
222 Recommendation[] recommendations = new Recommendation[] {area};
223
224 loadService.loadMany(
225 this.collection,
226 recommendations,
227 null, //use individual factories.
228 locale,
229 new AsyncCallback<Artifact[]>() {
230 public void onFailure(Throwable caught) {
231 GWT.log("Failed, no area artifact: " + caught.getMessage());
232 enable();
233 // TODO SC.warn
234 }
235 public void onSuccess(Artifact[] artifacts) {
236 GWT.log("Success, created area artifact: "
237 + artifacts[0].getUuid());
238 // Now, feed the artifact with the relevant data.
239 feedTellArea(artifacts[0].getUuid(), under, over);
240 }
241 }
242 );
243 }
244
245
246 /**
247 * Return true if two themes are canditates for an area being
248 * rendered between them.
249 * TODO join with canArea, generalize to allow easier modification
250 * in subclasses.
251 */
252 protected boolean areAreaCompatible(Theme a, Theme b) {
253 if (a.equals(b)) {
254 return false;
255 }
256 if (a.getFacet().equals("longitudinal_section.w")) {
257 return b.getFacet().equals("longitudinal_section.w");
258 }
259 else if (a.getFacet().equals("longitudinal_section.q")) {
260 return b.getFacet().equals("longitudinal_section.q");
261 }
262 return false;
263 }
264
265
266 /**
267 * True if context menu should contain 'create area' submenu on
268 * this theme.
269 */
270 protected boolean canArea(Theme a) {
271 return a.getFacet().equals("longitudinal_section.q")
272 || a.getFacet().equals("longitudinal_section.w");
273 }
274
275
276 /**
277 * Include area specific menu items.
278 */
279 protected Menu getSingleContextMenu(final ListGridRecord[] records) {
280 Menu menu = super.getSingleContextMenu(records);
281
282 final Theme facetTheme = ((FacetRecord)records[0]).getTheme();
283 String thisItem = facetTheme.getDescription();
284 if (!canArea(facetTheme)) {
285 return menu;
286 }
287
288 menu.addItem(createSeparator());
289
290 MenuItem areaMenuItem = new MenuItem(MSG.chart_themepanel_new_area());
291 Menu areaMenu = new Menu();
292
293 ThemeList themes = getThemeList();
294 int nThemes = themes.getThemeCount();
295
296 MenuItem underMenuItem = new MenuItem(MSG.chart_themepanel_area_under());
297 Menu underMenu = new Menu();
298 for (int i = 0; i < nThemes; i++) {
299 final Theme theme = themes.getThemeAt(i+1);
300 if (!areAreaCompatible(facetTheme, theme)) {
301 continue;
302 }
303 MenuItem againster = new MenuItem(theme.getDescription());
304 underMenu.addItem(againster);
305
306 againster.addClickHandler(new ClickHandler() {
307 public void onClick(MenuItemClickEvent evt) {
308 disable();
309 createAreaArtifact(theme, facetTheme, false);
310 }
311 });
312 }
313
314 MenuItem overMenuItem = new MenuItem(MSG.chart_themepanel_area_over());
315 Menu overMenu = new Menu();
316 for (int i = 0; i < nThemes; i++) {
317 final Theme theme = themes.getThemeAt(i+1);
318 if (!areAreaCompatible(facetTheme, theme)) {
319 continue;
320 }
321 MenuItem againster = new MenuItem(theme.getDescription());
322 overMenu.addItem(againster);
323
324 againster.addClickHandler(new ClickHandler() {
325 public void onClick(MenuItemClickEvent evt) {
326 disable();
327 createAreaArtifact(facetTheme, theme, false);
328 }
329 });
330 }
331 overMenu.addItem(createSeparator());
332 MenuItem againstAxis = new MenuItem(MSG.getString("x_axis"));
333 againstAxis.addClickHandler(new ClickHandler() {
334 public void onClick(MenuItemClickEvent evt) {
335 disable();
336 createAreaArtifact(facetTheme, null, false);
337 }
338 });
339 overMenu.addItem(againstAxis);
340
341 MenuItem betweenMenuItem = new MenuItem(MSG.chart_themepanel_area_between());
342 Menu betweenMenu = new Menu();
343 for (int i = 0; i < nThemes; i++) {
344 final Theme theme = themes.getThemeAt(i+1);
345 if (!areAreaCompatible(facetTheme, theme)) {
346 continue;
347 }
348 MenuItem againster = new MenuItem(theme.getDescription());
349 betweenMenu.addItem(againster);
350
351 againster.addClickHandler(new ClickHandler() {
352 public void onClick(MenuItemClickEvent evt) {
353 disable();
354 createAreaArtifact(facetTheme, theme, true);
355 }
356 });
357 }
358 betweenMenu.addItem(createSeparator());
359 betweenMenu.addItem(againstAxis);
360
361 overMenuItem.setSubmenu(overMenu);
362 underMenuItem.setSubmenu(underMenu);
363 betweenMenuItem.setSubmenu(betweenMenu);
364
365 areaMenu.addItem(overMenuItem);
366 areaMenu.addItem(underMenuItem);
367 areaMenu.addItem(betweenMenuItem);
368
369 areaMenuItem.setSubmenu(areaMenu);
370 menu.addItem(areaMenuItem);
371
372 return menu;
373 }
103 } 374 }
104 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 375 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org