comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java @ 1309:a95e82d6bcc1

Refactored the code to create a context menu and a style editor so that it is also available for maps. flys-client/trunk@2943 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 12 Oct 2011 08:53:17 +0000
parents 84c50f1d939b
children c4c957a9c092
comparison
equal deleted inserted replaced
1308:d194bee456d3 1309:a95e82d6bcc1
10 import com.smartgwt.client.widgets.Canvas; 10 import com.smartgwt.client.widgets.Canvas;
11 import com.smartgwt.client.widgets.grid.ListGrid; 11 import com.smartgwt.client.widgets.grid.ListGrid;
12 import com.smartgwt.client.widgets.grid.ListGridRecord; 12 import com.smartgwt.client.widgets.grid.ListGridRecord;
13 import com.smartgwt.client.widgets.grid.events.EditCompleteEvent; 13 import com.smartgwt.client.widgets.grid.events.EditCompleteEvent;
14 import com.smartgwt.client.widgets.grid.events.EditCompleteHandler; 14 import com.smartgwt.client.widgets.grid.events.EditCompleteHandler;
15 import com.smartgwt.client.widgets.grid.events.RowContextClickEvent;
16 import com.smartgwt.client.widgets.grid.events.RowContextClickHandler;
17 import com.smartgwt.client.widgets.menu.Menu;
18 import com.smartgwt.client.widgets.menu.MenuItem;
19 import com.smartgwt.client.widgets.menu.events.ClickHandler;
20 import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
15 21
16 import de.intevation.flys.client.shared.model.Collection; 22 import de.intevation.flys.client.shared.model.Collection;
23 import de.intevation.flys.client.shared.model.CollectionItemAttribute;
17 import de.intevation.flys.client.shared.model.FacetRecord; 24 import de.intevation.flys.client.shared.model.FacetRecord;
18 import de.intevation.flys.client.shared.model.OutputMode; 25 import de.intevation.flys.client.shared.model.OutputMode;
19 import de.intevation.flys.client.shared.model.Theme; 26 import de.intevation.flys.client.shared.model.Theme;
20 import de.intevation.flys.client.shared.model.ThemeList; 27 import de.intevation.flys.client.shared.model.ThemeList;
21 28
30 import de.intevation.flys.client.client.event.RedrawRequestHandler; 37 import de.intevation.flys.client.client.event.RedrawRequestHandler;
31 import de.intevation.flys.client.client.event.RedrawRequestEvent; 38 import de.intevation.flys.client.client.event.RedrawRequestEvent;
32 import de.intevation.flys.client.client.event.RedrawRequestEvent.Type; 39 import de.intevation.flys.client.client.event.RedrawRequestEvent.Type;
33 import de.intevation.flys.client.client.services.CollectionAttributeService; 40 import de.intevation.flys.client.client.services.CollectionAttributeService;
34 import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; 41 import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync;
42 import de.intevation.flys.client.client.services.CollectionItemAttributeService;
43 import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync;
35 44
36 45
37 public abstract class ThemePanel 46 public abstract class ThemePanel
38 extends Canvas 47 extends Canvas
39 implements OnMoveHandler, 48 implements OnMoveHandler,
42 HasRedrawRequestHandlers 51 HasRedrawRequestHandlers
43 { 52 {
44 protected CollectionAttributeServiceAsync updater = 53 protected CollectionAttributeServiceAsync updater =
45 GWT.create(CollectionAttributeService.class); 54 GWT.create(CollectionAttributeService.class);
46 55
56 /** The service used to get collection item attributes. */
57 protected CollectionItemAttributeServiceAsync itemAttributeService =
58 GWT.create(CollectionItemAttributeService.class);
59
47 private FLYSConstants MSG = GWT.create(FLYSConstants.class); 60 private FLYSConstants MSG = GWT.create(FLYSConstants.class);
48 61
49 /** List of OutParameterChangedHandler. */ 62 /** List of OutParameterChangedHandler. */
50 protected List<OutputParameterChangeHandler> outHandlers; 63 protected List<OutputParameterChangeHandler> outHandlers;
51 /** List of ChartShallRedrawHandler. */ 64 /** List of ChartShallRedrawHandler. */
55 protected OutputMode mode; 68 protected OutputMode mode;
56 69
57 protected ThemeNavigationPanel navigation; 70 protected ThemeNavigationPanel navigation;
58 protected ListGrid list; 71 protected ListGrid list;
59 72
73 /** The collection view*/
74 protected CollectionView view;
75
60 76
61 /** 77 /**
62 * Setup Grid, navigation bar. 78 * Setup Grid, navigation bar.
63 * @param collection Collection for which to show themes. 79 * @param collection Collection for which to show themes.
64 */ 80 */
145 handler.onOutputParameterChanged(evt); 161 handler.onOutputParameterChanged(evt);
146 } 162 }
147 } 163 }
148 164
149 165
166 public void setCollectionView(CollectionView view) {
167 this.view = view;
168 }
169
170
150 /** 171 /**
151 * This method is used to clear the current theme grid and add new updated 172 * This method is used to clear the current theme grid and add new updated
152 * data. 173 * data.
153 */ 174 */
154 protected void updateGrid() { 175 protected void updateGrid() {
215 236
216 /** 237 /**
217 * Create and configure the Grid to display. 238 * Create and configure the Grid to display.
218 */ 239 */
219 protected ListGrid createGrid() { 240 protected ListGrid createGrid() {
220 return new ListGrid(); 241 ListGrid grid = new ListGrid();
242 grid.addRowContextClickHandler(new RowContextClickHandler() {
243 public void onRowContextClick(RowContextClickEvent event) {
244 ListGridRecord[] records = list.getSelection();
245
246 Menu menu = null;
247
248 if (records == null || records.length == 0) {
249 return;
250 }
251 else if (records.length == 1) {
252 menu = getSingleContextMenu(records);
253 }
254 else if (records.length > 1) {
255 menu = getMultiContextMenu(records);
256 }
257
258 if (menu != null) {
259 list.setContextMenu(menu);
260 menu.showContextMenu();
261
262 event.cancel();
263 }
264 }
265 });
266
267 return grid;
221 } 268 }
222 269
223 270
224 /** 271 /**
225 * A method that removes all records from theme grid. 272 * A method that removes all records from theme grid.
232 } 279 }
233 280
234 for (ListGridRecord record: records) { 281 for (ListGridRecord record: records) {
235 list.removeData(record); 282 list.removeData(record);
236 } 283 }
284 }
285
286
287 protected Menu getSingleContextMenu(final ListGridRecord[] records) {
288 Menu menu = new Menu();
289
290 menu.addItem(createActivateItem(records));
291 menu.addItem(createDeactivateItem(records));
292 menu.addItem(createRemoveItem(records));
293 menu.addItem(createPropertiesItem(records));
294
295 return menu;
296 }
297
298
299 protected Menu getMultiContextMenu(final ListGridRecord[] records) {
300 Menu menu = new Menu();
301
302 menu.addItem(createActivateItem(records));
303 menu.addItem(createDeactivateItem(records));
304 menu.addItem(createRemoveItem(records));
305
306 return menu;
307 }
308
309
310 protected MenuItem createPropertiesItem(final ListGridRecord[] records) {
311 MenuItem properties = new MenuItem(MSG.properties());
312
313 properties.addClickHandler(new ClickHandler() {
314 public void onClick(MenuItemClickEvent evt) {
315 GWT.log("clicked properties");
316 for (ListGridRecord record: records) {
317 openStyleEditor((FacetRecord) record);
318 }
319 }
320 });
321
322 return properties;
323 }
324
325
326 protected MenuItem createActivateItem(final ListGridRecord[] records) {
327 MenuItem activate = new MenuItem(MSG.activateTheme());
328
329 activate.addClickHandler(new ClickHandler() {
330 public void onClick(MenuItemClickEvent evt) {
331 for (ListGridRecord record: records) {
332 FacetRecord facet = (FacetRecord) record;
333 activateTheme(facet.getTheme(), true);
334 }
335
336 updateCollection();
337 }
338 });
339
340 return activate;
341 }
342
343
344 protected MenuItem createDeactivateItem(final ListGridRecord[] records) {
345 MenuItem deactivate = new MenuItem(MSG.deactivateTheme());
346
347 deactivate.addClickHandler(new ClickHandler() {
348 public void onClick(MenuItemClickEvent evt) {
349 for (ListGridRecord record: records) {
350 FacetRecord facet = (FacetRecord) record;
351 activateTheme(facet.getTheme(), false);
352 }
353
354 updateCollection();
355 }
356 });
357
358 return deactivate;
359 }
360
361
362 protected MenuItem createRemoveItem(final ListGridRecord[] records) {
363 MenuItem remove = new MenuItem(MSG.removeTheme());
364
365 remove.addClickHandler(new ClickHandler() {
366 public void onClick(MenuItemClickEvent evt) {
367 SC.warn("Currently not implemented");
368
369 for (ListGridRecord record: records) {
370 FacetRecord facet = (FacetRecord) record;
371 }
372 }
373 });
374
375 return remove;
237 } 376 }
238 377
239 378
240 /** 379 /**
241 * This method is called after a cell in the theme grid has been modified. 380 * This method is called after a cell in the theme grid has been modified.
378 themeList.setThemePosition(theme, idx--); 517 themeList.setThemePosition(theme, idx--);
379 } 518 }
380 519
381 updateGrid(); 520 updateGrid();
382 } 521 }
522
523
524 protected void openStyleEditor(final FacetRecord record) {
525 Config config = Config.getInstance();
526 String url = config.getServerUrl();
527 String locale = config.getLocale();
528
529 String artifact = record.getTheme().getArtifact();
530
531 itemAttributeService.getCollectionItemAttribute(
532 this.collection,
533 artifact,
534 url,
535 locale,
536 new AsyncCallback<CollectionItemAttribute>() {
537 public void onFailure (Throwable caught) {
538 GWT.log("Could not get Collection item attributes.");
539 }
540 public void onSuccess(CollectionItemAttribute cia) {
541 GWT.log("Successfully loaded collectionitem attributes.");
542 StyleEditorWindow win = new StyleEditorWindow(
543 collection,
544 cia,
545 record);
546 win.setCollectionView(view);
547 win.show();
548 }
549 });
550 }
383 } 551 }
384 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 552 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org