comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ThemePanel.java @ 9416:05405292a7ca

Navigationtheme panel now shows themes of dWt and WQ charts grayed out, if the current station is outside the valid range of the theme.
author gernotbelger
date Thu, 16 Aug 2018 16:28:03 +0200
parents 5e38e2924c07
children cff7636035ce
comparison
equal deleted inserted replaced
9415:9744ce3c3853 9416:05405292a7ca
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.client.client.ui; 9 package org.dive4elements.river.client.client.ui;
10 10
11 import com.google.gwt.core.client.GWT; 11 import java.util.ArrayList;
12 import com.google.gwt.user.client.rpc.AsyncCallback; 12 import java.util.List;
13
14 import com.smartgwt.client.util.BooleanCallback;
15 import com.smartgwt.client.util.SC;
16 import com.smartgwt.client.widgets.Canvas;
17 import com.smartgwt.client.widgets.grid.ListGrid;
18 import com.smartgwt.client.widgets.grid.ListGridRecord;
19 import com.smartgwt.client.widgets.grid.events.EditCompleteEvent;
20 import com.smartgwt.client.widgets.grid.events.EditCompleteHandler;
21 import com.smartgwt.client.widgets.grid.events.RowContextClickEvent;
22 import com.smartgwt.client.widgets.grid.events.RowContextClickHandler;
23 import com.smartgwt.client.widgets.menu.Menu;
24 import com.smartgwt.client.widgets.menu.MenuItem;
25 import com.smartgwt.client.widgets.menu.events.ClickHandler;
26 import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
27 13
28 import org.dive4elements.river.client.client.Config; 14 import org.dive4elements.river.client.client.Config;
29 import org.dive4elements.river.client.client.FLYSConstants; 15 import org.dive4elements.river.client.client.FLYSConstants;
30 import org.dive4elements.river.client.client.event.HasOutputParameterChangeHandlers; 16 import org.dive4elements.river.client.client.event.HasOutputParameterChangeHandlers;
31 import org.dive4elements.river.client.client.event.HasRedrawRequestHandlers; 17 import org.dive4elements.river.client.client.event.HasRedrawRequestHandlers;
45 import org.dive4elements.river.client.shared.model.FacetRecord; 31 import org.dive4elements.river.client.shared.model.FacetRecord;
46 import org.dive4elements.river.client.shared.model.OutputMode; 32 import org.dive4elements.river.client.shared.model.OutputMode;
47 import org.dive4elements.river.client.shared.model.Theme; 33 import org.dive4elements.river.client.shared.model.Theme;
48 import org.dive4elements.river.client.shared.model.ThemeList; 34 import org.dive4elements.river.client.shared.model.ThemeList;
49 35
50 import java.util.ArrayList; 36 import com.google.gwt.core.client.GWT;
51 import java.util.List; 37 import com.google.gwt.user.client.rpc.AsyncCallback;
38 import com.smartgwt.client.util.BooleanCallback;
39 import com.smartgwt.client.util.SC;
40 import com.smartgwt.client.widgets.Canvas;
41 import com.smartgwt.client.widgets.grid.ListGrid;
42 import com.smartgwt.client.widgets.grid.ListGridRecord;
43 import com.smartgwt.client.widgets.grid.events.EditCompleteEvent;
44 import com.smartgwt.client.widgets.grid.events.EditCompleteHandler;
45 import com.smartgwt.client.widgets.grid.events.RowContextClickEvent;
46 import com.smartgwt.client.widgets.grid.events.RowContextClickHandler;
47 import com.smartgwt.client.widgets.menu.Menu;
48 import com.smartgwt.client.widgets.menu.MenuItem;
49 import com.smartgwt.client.widgets.menu.events.ClickHandler;
50 import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
52 51
53 /** 52 /**
54 * ThemePanel on the left in CollectionView. 53 * ThemePanel on the left in CollectionView.
55 * Contains control widgets for "themes", which are plotted in 54 * Contains control widgets for "themes", which are plotted in
56 * a diagram (chart). 55 * a diagram (chart).
57 * 56 *
58 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 57 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
59 */ 58 */
60 public abstract class ThemePanel 59 public abstract class ThemePanel extends Canvas implements OnMoveHandler, EditCompleteHandler, HasOutputParameterChangeHandlers, HasRedrawRequestHandlers {
61 extends Canvas 60
62 implements OnMoveHandler, 61 private final CollectionAttributeServiceAsync updater = GWT.create(CollectionAttributeService.class);
63 EditCompleteHandler,
64 HasOutputParameterChangeHandlers,
65 HasRedrawRequestHandlers
66 {
67 protected CollectionAttributeServiceAsync updater =
68 GWT.create(CollectionAttributeService.class);
69 62
70 /** The service used to get collection item attributes. */ 63 /** The service used to get collection item attributes. */
71 protected CollectionItemAttributeServiceAsync itemAttributeService = 64 private final CollectionItemAttributeServiceAsync itemAttributeService = GWT.create(CollectionItemAttributeService.class);
72 GWT.create(CollectionItemAttributeService.class);
73 65
74 /** i18ner. */ 66 /** i18ner. */
75 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); 67 protected final FLYSConstants MSG = GWT.create(FLYSConstants.class);
76 68
77 /** List of OutParameterChangedHandler. */ 69 /** List of OutParameterChangedHandler. */
78 protected List<OutputParameterChangeHandler> outHandlers; 70 private final List<OutputParameterChangeHandler> outHandlers;
79 71
80 /** List of ChartShallRedrawHandler. */ 72 /** List of ChartShallRedrawHandler. */
81 protected List<RedrawRequestHandler> redrawRequestHandlers; 73 protected final List<RedrawRequestHandler> redrawRequestHandlers;
82 74
83 protected OutputMode mode; 75 protected final OutputMode mode;
84 76
85 protected ThemeNavigationPanel navigation; 77 protected final ThemeNavigationPanel navigation;
86 protected ListGrid list; 78
87 79 protected final ListGrid list;
88 /** The collection view*/ 80
81 /** The collection view */
89 protected CollectionView view; 82 protected CollectionView view;
90 83
84 private final IThemeRecordHandler recordHandler;
85
91 /** 86 /**
92 * Setup Grid, navigation bar. 87 * Setup Grid, navigation bar.
93 * @param collection Collection for which to show themes. 88 *
94 */ 89 * @param collection
95 public ThemePanel( 90 * Collection for which to show themes.
96 OutputMode mode, 91 */
97 CollectionView view 92 public ThemePanel(final OutputMode mode, final CollectionView view, final IThemeRecordHandler recordHandler) {
98 ) { 93 this.mode = mode;
99 this.mode = mode; 94 this.recordHandler = recordHandler;
100 this.list = createGrid(); 95 this.list = createGrid();
101 this.view = view; 96 this.view = view;
102 list.addRowContextClickHandler(new RowContextClickHandler() { 97
103 @Override 98 this.list.addRowContextClickHandler(new RowContextClickHandler() {
104 public void onRowContextClick(RowContextClickEvent event) { 99 @Override
105 ListGridRecord[] records = list.getSelectedRecords(); 100 public void onRowContextClick(final RowContextClickEvent event) {
101 final ListGridRecord[] records = ThemePanel.this.list.getSelectedRecords();
106 102
107 Menu menu = null; 103 Menu menu = null;
108 104
109 if (records == null || records.length == 0) { 105 if (records == null || records.length == 0) {
110 return; 106 return;
111 } 107 } else if (records.length == 1) {
112 else if (records.length == 1) {
113 menu = getSingleContextMenu(records); 108 menu = getSingleContextMenu(records);
114 } 109 } else if (records.length > 1) {
115 else if (records.length > 1) {
116 menu = getMultiContextMenu(records); 110 menu = getMultiContextMenu(records);
117 } 111 }
118 112
119 if (menu != null) { 113 if (menu != null) {
120 list.setContextMenu(menu); 114 ThemePanel.this.list.setContextMenu(menu);
121 menu.showContextMenu(); 115 menu.showContextMenu();
122 116
123 event.cancel(); 117 event.cancel();
124 } 118 }
125 } 119 }
126 }); 120 });
127 121
128 this.redrawRequestHandlers = new ArrayList<RedrawRequestHandler>(); 122 this.redrawRequestHandlers = new ArrayList<RedrawRequestHandler>();
129 this.outHandlers = new ArrayList<OutputParameterChangeHandler>(); 123 this.outHandlers = new ArrayList<OutputParameterChangeHandler>();
130 this.navigation = new ThemeNavigationPanel(); 124 this.navigation = new ThemeNavigationPanel();
131 this.navigation.addOnMoveHandler(this); 125 this.navigation.addOnMoveHandler(this);
132 126
133 this.setShowResizeBar(true); 127 this.setShowResizeBar(true);
134 } 128 }
135 129
136
137 public abstract void activateTheme(Theme theme, boolean active); 130 public abstract void activateTheme(Theme theme, boolean active);
138
139 131
140 /** 132 /**
141 * Replace the current collection with a new one. <b>NOTE: this operation 133 * Replace the current collection with a new one. <b>NOTE: this operation
142 * triggers updateGrid() which modifies the themes in the grid.</b> 134 * triggers updateGrid() which modifies the themes in the grid.</b>
143 * 135 *
144 * @param collection The new collection object. 136 * @param collection
145 */ 137 * The new collection object.
146 protected void setCollection(Collection collection) { 138 */
139 protected void setCollection(final Collection collection) {
147 // Set collection of view, but do not trigger event shooting. 140 // Set collection of view, but do not trigger event shooting.
148 this.view.setCollection(collection, true); 141 this.view.setCollection(collection, true);
149 142
150 updateGrid(); 143 updateGrid();
151 } 144 }
152 145
153
154 /** Get Collection. */ 146 /** Get Collection. */
155 public Collection getCollection() { 147 public Collection getCollection() {
156 return view.getCollection(); 148 return this.view.getCollection();
157 } 149 }
158
159 150
160 /** 151 /**
161 * Returns the ThemeList of the current collection and output mode. 152 * Returns the ThemeList of the current collection and output mode.
162 * 153 *
163 * @return the current ThemeList. 154 * @return the current ThemeList.
164 */ 155 */
165 public ThemeList getThemeList() { 156 public ThemeList getThemeList() {
166 return getCollection().getThemeList(mode.getName()); 157 return getCollection().getThemeList(this.mode.getName());
167 } 158 }
168 159
169 public ListGridRecord[] getSelectedRecords() { 160 public ListGridRecord[] getSelectedRecords() {
170 return list.getSelectedRecords(); 161 return this.list.getSelectedRecords();
171 } 162 }
172 163
173 /** 164 /**
174 * Registers a new OutputParameterChangeHandler. 165 * Registers a new OutputParameterChangeHandler.
175 * 166 *
176 * @param h The new handler. 167 * @param h
168 * The new handler.
177 */ 169 */
178 @Override 170 @Override
179 public void addOutputParameterChangeHandler(OutputParameterChangeHandler h){ 171 public void addOutputParameterChangeHandler(final OutputParameterChangeHandler h) {
180 if (h != null) { 172 if (h != null) {
181 outHandlers.add(h); 173 this.outHandlers.add(h);
182 } 174 }
183 } 175 }
184
185 176
186 /** 177 /**
187 * Registers a RedrawRequestHandler. 178 * Registers a RedrawRequestHandler.
188 * 179 *
189 * @param h The new handler. 180 * @param h
181 * The new handler.
190 */ 182 */
191 @Override 183 @Override
192 public void addRedrawRequestHandler(RedrawRequestHandler h){ 184 public void addRedrawRequestHandler(final RedrawRequestHandler h) {
193 if (h != null) { 185 if (h != null) {
194 redrawRequestHandlers.add(h); 186 this.redrawRequestHandlers.add(h);
195 } 187 }
196 } 188 }
197
198 189
199 /** 190 /**
200 * Request a redraw of e.g. a Chart. 191 * Request a redraw of e.g. a Chart.
201 */ 192 */
202 final public void requestRedraw() { 193 final public void requestRedraw() {
203 for (RedrawRequestHandler handler: redrawRequestHandlers) { 194 for (final RedrawRequestHandler handler : this.redrawRequestHandlers) {
204 handler.onRedrawRequest(new RedrawRequestEvent(Type.DEFAULT)); 195 handler.onRedrawRequest(new RedrawRequestEvent(Type.DEFAULT));
205 } 196 }
206 } 197 }
207
208 198
209 /** 199 /**
210 * Called when the attribution of an output changed. It informs the 200 * Called when the attribution of an output changed. It informs the
211 * registered handlers about the changes. 201 * registered handlers about the changes.
212 */ 202 */
213 protected void fireOutputParameterChanged() { 203 protected void fireOutputParameterChanged() {
214 OutputParameterChangeEvent evt = new OutputParameterChangeEvent(); 204 final OutputParameterChangeEvent evt = new OutputParameterChangeEvent();
215 205
216 for (OutputParameterChangeHandler handler: outHandlers) { 206 for (final OutputParameterChangeHandler handler : this.outHandlers) {
217 handler.onOutputParameterChanged(evt); 207 handler.onOutputParameterChanged(evt);
218 } 208 }
219 } 209 }
220 210
221
222 /** Registers the CollectionView associated to this ThemePanel. */ 211 /** Registers the CollectionView associated to this ThemePanel. */
223 public void setCollectionView(CollectionView view) { 212 public void setCollectionView(final CollectionView view) {
224 this.view = view; 213 this.view = view;
225 } 214 }
226
227 215
228 /** 216 /**
229 * This method is used to clear the current theme grid and add new updated 217 * This method is used to clear the current theme grid and add new updated
230 * data. 218 * data.
231 */ 219 */
232 protected void updateGrid() { 220 protected void updateGrid() {
233 GWT.log("ThemePanel.updateGrid"); 221 GWT.log("ThemePanel.updateGrid");
234 222
235 ListGridRecord[] selected = list.getSelectedRecords(); 223 final ListGridRecord[] selected = this.list.getSelectedRecords();
236 224
237 clearGrid(); 225 clearGrid();
238 226
239 ThemeList themeList = getThemeList(); 227 final ThemeList themeList = getThemeList();
240 228
241 if (themeList == null) { 229 if (themeList == null) {
242 GWT.log("ERROR: No theme list."); 230 GWT.log("ERROR: No theme list.");
243 return; 231 return;
244 } 232 }
245 233
246 int count = themeList.getThemeCount(); 234 final int count = themeList.getThemeCount();
247 235
248 for (int i = 1; i <= count; i++) { 236 for (int i = 1; i <= count; i++) {
249 Theme theme = themeList.getThemeAt(i); 237 final Theme theme = themeList.getThemeAt(i);
250 238
251 if (theme == null) { 239 if (theme == null) {
252 continue; 240 continue;
253 } 241 }
254 242
258 246
259 if (theme.getVisible() == 0) { 247 if (theme.getVisible() == 0) {
260 continue; 248 continue;
261 } 249 }
262 250
263 FacetRecord newRecord = createRecord(theme); 251 final FacetRecord newRecord = createRecord(theme);
264 addFacetRecord(newRecord); 252 addFacetRecord(newRecord);
265 253
266 String newArtifact = theme.getArtifact(); 254 final String newArtifact = theme.getArtifact();
267 String newFacet = theme.getFacet(); 255 final String newFacet = theme.getFacet();
268 int newIndex = theme.getIndex(); 256 final int newIndex = theme.getIndex();
269 257
270 for (ListGridRecord r: selected) { 258 for (final ListGridRecord r : selected) {
271 FacetRecord sel = (FacetRecord) r; 259 final FacetRecord sel = (FacetRecord) r;
272 Theme oldTheme = sel.getTheme(); 260 final Theme oldTheme = sel.getTheme();
273 261
274 if (oldTheme.getArtifact().equals(newArtifact) 262 if (oldTheme.getArtifact().equals(newArtifact) && oldTheme.getFacet().equals(newFacet) && oldTheme.getIndex() == newIndex) {
275 && oldTheme.getFacet().equals(newFacet) 263 this.list.selectRecord(newRecord);
276 && oldTheme.getIndex() == newIndex) {
277 list.selectRecord(newRecord);
278 } 264 }
279 } 265 }
280 } 266 }
281 267
268 updateThemes();
269
282 fireOutputParameterChanged(); 270 fireOutputParameterChanged();
283 } 271 }
284 272
285
286 /** Adds given Record to the list (table). */ 273 /** Adds given Record to the list (table). */
287 protected void addFacetRecord(FacetRecord rec) { 274 protected void addFacetRecord(final FacetRecord rec) {
288 list.addData(rec); 275 this.list.addData(rec);
289 } 276 }
290
291 277
292 /** Create a FacetRecord that wraps given theme. */ 278 /** Create a FacetRecord that wraps given theme. */
293 protected FacetRecord createRecord(Theme theme) { 279 protected final FacetRecord createRecord(final Theme theme) {
294 return new FacetRecord(theme); 280 return new FacetRecord(theme);
295 } 281 }
296
297 282
298 /** 283 /**
299 * This method triggers the CollectionAttributeService. Based on the current 284 * This method triggers the CollectionAttributeService. Based on the current
300 * collectin settings, the attribute of the collection is modified or not. 285 * collectin settings, the attribute of the collection is modified or not.
301 * But in every case, we will get a new collection object - which might be 286 * But in every case, we will get a new collection object - which might be
302 * the same as the current one. 287 * the same as the current one.
303 */ 288 */
304 public void updateCollection() { 289 public void updateCollection() {
305 final Config config = Config.getInstance(); 290 final Config config = Config.getInstance();
306 final String loc = config.getLocale(); 291 final String loc = config.getLocale();
307 292
308 GWT.log("ThemePanel.updateCollection via RPC now"); 293 GWT.log("ThemePanel.updateCollection via RPC now");
309 294
310 // Don't forget to enable the panel after the request has finished! 295 // Don't forget to enable the panel after the request has finished!
311 disable(); 296 disable();
312 297
313 updater.update(getCollection(), loc, new AsyncCallback<Collection>() { 298 this.updater.update(getCollection(), loc, new AsyncCallback<Collection>() {
314 @Override 299 @Override
315 public void onFailure(Throwable caught) { 300 public void onFailure(final Throwable caught) {
316 GWT.log("Could not update collection attributes."); 301 GWT.log("Could not update collection attributes.");
317 SC.warn(MSG.getString(caught.getMessage())); 302 SC.warn(ThemePanel.this.MSG.getString(caught.getMessage()));
318 303
319 enable(); 304 enable();
320 } 305 }
321 306
322 307 @Override
323 @Override 308 public void onSuccess(final Collection collection) {
324 public void onSuccess(Collection collection) {
325 setCollection(collection); 309 setCollection(collection);
326 310
327 enable(); 311 enable();
328 } 312 }
329 }); 313 });
330 } 314 }
331 315
332
333 /** 316 /**
334 * Create and configure the Grid to display. 317 * Create and configure the Grid to display.
335 */ 318 */
336 protected ListGrid createGrid() { 319 protected ListGrid createGrid() {
337 ListGrid grid = createNewGrid(); 320 final ListGrid grid = new ListGrid();
338 grid.setLeaveScrollbarGap(false); 321 grid.setLeaveScrollbarGap(false);
339 322
340 return grid; 323 return grid;
341 } 324 }
342 325
343
344 protected ListGrid createNewGrid() {
345 return new ListGrid();
346 }
347
348
349 /** 326 /**
350 * A method that removes all records from theme grid. 327 * A method that removes all records from theme grid.
351 */ 328 */
352 protected void clearGrid() { 329 protected void clearGrid() {
353 ListGridRecord[] records = list.getRecords(); 330 final ListGridRecord[] records = this.list.getRecords();
354 331
355 if (records == null || records.length == 0) { 332 if (records == null || records.length == 0) {
356 return; 333 return;
357 } 334 }
358 335
359 for (ListGridRecord record: records) { 336 for (final ListGridRecord record : records) {
360 list.removeData(record); 337 this.list.removeData(record);
361 } 338 }
362 } 339 }
363 340
364 /** Return 'separator'- menu-item. */ 341 /** Return 'separator'- menu-item. */
365 protected MenuItem createSeparator() { 342 protected MenuItem createSeparator() {
366 MenuItem separator = new MenuItem(); 343 final MenuItem separator = new MenuItem();
367 separator.setIsSeparator(true); 344 separator.setIsSeparator(true);
368 return separator; 345 return separator;
369 } 346 }
370 347
371
372 /** 348 /**
373 * Get the context menu for a (right mouse button)click on a single item. 349 * Get the context menu for a (right mouse button)click on a single item.
374 */ 350 */
375 protected Menu getSingleContextMenu(final ListGridRecord[] records) { 351 protected Menu getSingleContextMenu(final ListGridRecord[] records) {
376 Menu menu = new Menu(); 352 final Menu menu = new Menu();
377 353
378 menu.addItem(createActivateItem(records)); 354 menu.addItem(createActivateItem(records));
379 menu.addItem(createDeactivateItem(records)); 355 menu.addItem(createDeactivateItem(records));
380 menu.addItem(createRemoveItem(records)); 356 menu.addItem(createRemoveItem(records));
381 menu.addItem(createSeparator()); 357 menu.addItem(createSeparator());
382 menu.addItem(createPropertiesItem(records)); 358 menu.addItem(createPropertiesItem(records));
383 359
384 return menu; 360 return menu;
385 } 361 }
386 362
387
388 protected Menu getMultiContextMenu(final ListGridRecord[] records) { 363 protected Menu getMultiContextMenu(final ListGridRecord[] records) {
389 Menu menu = new Menu(); 364 final Menu menu = new Menu();
390 365
391 menu.addItem(createActivateItem(records)); 366 menu.addItem(createActivateItem(records));
392 menu.addItem(createDeactivateItem(records)); 367 menu.addItem(createDeactivateItem(records));
393 menu.addItem(createRemoveItem(records)); 368 menu.addItem(createRemoveItem(records));
394 369
395 return menu; 370 return menu;
396 } 371 }
397 372
398
399 /** The properties menu item (opens style editor on click). */ 373 /** The properties menu item (opens style editor on click). */
400 protected MenuItem createPropertiesItem(final ListGridRecord[] records) { 374 protected MenuItem createPropertiesItem(final ListGridRecord[] records) {
401 MenuItem properties = new MenuItem(MSG.properties()); 375 final MenuItem properties = new MenuItem(this.MSG.properties());
402 376
403 properties.addClickHandler(new ClickHandler() { 377 properties.addClickHandler(new ClickHandler() {
404 @Override 378 @Override
405 public void onClick(MenuItemClickEvent evt) { 379 public void onClick(final MenuItemClickEvent evt) {
406 GWT.log("clicked properties"); 380 GWT.log("clicked properties");
407 for (ListGridRecord record: records) { 381 for (final ListGridRecord record : records) {
408 openStyleEditor((FacetRecord) record); 382 openStyleEditor((FacetRecord) record);
409 } 383 }
410 } 384 }
411 }); 385 });
412 386
413 return properties; 387 return properties;
414 } 388 }
415 389
416
417 protected MenuItem createActivateItem(final ListGridRecord[] records) { 390 protected MenuItem createActivateItem(final ListGridRecord[] records) {
418 MenuItem activate = new MenuItem(MSG.activateTheme()); 391 final MenuItem activate = new MenuItem(this.MSG.activateTheme());
419 392
420 activate.addClickHandler(new ClickHandler() { 393 activate.addClickHandler(new ClickHandler() {
421 @Override 394 @Override
422 public void onClick(MenuItemClickEvent evt) { 395 public void onClick(final MenuItemClickEvent evt) {
423 for (ListGridRecord record: records) { 396 for (final ListGridRecord record : records) {
424 FacetRecord facet = (FacetRecord) record; 397 final FacetRecord facet = (FacetRecord) record;
425 activateTheme(facet.getTheme(), true); 398 activateTheme(facet.getTheme(), true);
426 } 399 }
427 400
428 updateCollection(); 401 updateCollection();
429 } 402 }
430 }); 403 });
431 404
432 return activate; 405 return activate;
433 } 406 }
434 407
435
436 protected MenuItem createDeactivateItem(final ListGridRecord[] records) { 408 protected MenuItem createDeactivateItem(final ListGridRecord[] records) {
437 MenuItem deactivate = new MenuItem(MSG.deactivateTheme()); 409 final MenuItem deactivate = new MenuItem(this.MSG.deactivateTheme());
438 410
439 deactivate.addClickHandler(new ClickHandler() { 411 deactivate.addClickHandler(new ClickHandler() {
440 @Override 412 @Override
441 public void onClick(MenuItemClickEvent evt) { 413 public void onClick(final MenuItemClickEvent evt) {
442 for (ListGridRecord record: records) { 414 for (final ListGridRecord record : records) {
443 FacetRecord facet = (FacetRecord) record; 415 final FacetRecord facet = (FacetRecord) record;
444 activateTheme(facet.getTheme(), false); 416 activateTheme(facet.getTheme(), false);
445 } 417 }
446 418
447 updateCollection(); 419 updateCollection();
448 } 420 }
449 }); 421 });
450 422
451 return deactivate; 423 return deactivate;
452 } 424 }
453 425
454
455 /** Remove given themes (not asking for confirmation). */ 426 /** Remove given themes (not asking for confirmation). */
456 protected void removeThemes(final ListGridRecord[] records) { 427 protected void removeThemes(final ListGridRecord[] records) {
457 for (ListGridRecord record: records) { 428 for (final ListGridRecord record : records) {
458 FacetRecord facet = (FacetRecord) record; 429 final FacetRecord facet = (FacetRecord) record;
459 Theme theme = facet.getTheme(); 430 final Theme theme = facet.getTheme();
460 theme.setVisible(0); 431 theme.setVisible(0);
461 theme.setActive(0); 432 theme.setActive(0);
462 updateCollection(); 433 updateCollection();
463 } 434 }
464 } 435 }
465 436
466
467 /** Create menu item for removing theme(s). Will ask for confirmation. */ 437 /** Create menu item for removing theme(s). Will ask for confirmation. */
468 protected MenuItem createRemoveItem(final ListGridRecord[] records) { 438 protected MenuItem createRemoveItem(final ListGridRecord[] records) {
469 MenuItem remove = new MenuItem(MSG.removeTheme()); 439 final MenuItem remove = new MenuItem(this.MSG.removeTheme());
470 440
471 remove.addClickHandler(new ClickHandler() { 441 remove.addClickHandler(new ClickHandler() {
472 @Override 442 @Override
473 public void onClick(MenuItemClickEvent evt) { 443 public void onClick(final MenuItemClickEvent evt) {
474 SC.ask(MSG.askThemeRemove(), new BooleanCallback() { 444 SC.ask(ThemePanel.this.MSG.askThemeRemove(), new BooleanCallback() {
475 @Override 445 @Override
476 public void execute(Boolean value) { 446 public void execute(final Boolean value) {
477 if (value) { 447 if (value) {
478 removeThemes(records); 448 removeThemes(records);
479 } 449 }
480 } 450 }
481 }); 451 });
483 }); 453 });
484 454
485 return remove; 455 return remove;
486 } 456 }
487 457
488
489 /** 458 /**
490 * This method is called after a cell in the theme grid has been modified. 459 * This method is called after a cell in the theme grid has been modified.
491 * 460 *
492 * @param event The event that stores information about the modified record. 461 * @param event
462 * The event that stores information about the modified record.
493 */ 463 */
494 @Override 464 @Override
495 public void onEditComplete(EditCompleteEvent event) { 465 public void onEditComplete(final EditCompleteEvent event) {
496 GWT.log("Edited record."); 466 GWT.log("Edited record.");
497 467
498 int row = event.getRowNum(); 468 final int row = event.getRowNum();
499 FacetRecord rec = (FacetRecord) list.getRecord(row); 469 final FacetRecord rec = (FacetRecord) this.list.getRecord(row);
500 470
501 Theme theme = rec.getTheme(); 471 final Theme theme = rec.getTheme();
502 472
503 theme.setDescription(rec.getName()); 473 theme.setDescription(rec.getName());
504 activateTheme(theme, rec.getActive()); 474 activateTheme(theme, rec.getActive());
505 475
506 updateCollection(); 476 updateCollection();
507 } 477 }
508 478
509
510 /** 479 /**
511 * This method should be defined in subclasses that wants to listen to this 480 * This method should be defined in subclasses that wants to listen to this
512 * event. 481 * event.
513 * 482 *
514 * @param theme The theme that is moved. 483 * @param theme
515 * @param oldIdx The index of the theme before it was moved. 484 * The theme that is moved.
516 * @param newIdx The index of the theme after it was moved. 485 * @param oldIdx
517 */ 486 * The index of the theme before it was moved.
518 protected void fireThemeMoved(Theme theme, int oldIdx, int newIdx) { 487 * @param newIdx
488 * The index of the theme after it was moved.
489 */
490 protected void fireThemeMoved(final Theme theme, final int oldIdx, final int newIdx) {
519 // Do nothing 491 // Do nothing
520 } 492 }
521 493
522
523 @Override 494 @Override
524 public void onMove(OnMoveEvent event) { 495 public void onMove(final OnMoveEvent event) {
525 int type = event.getType(); 496 final int type = event.getType();
526 497
527 GWT.log("ThemePanel.onMove: " + type); 498 GWT.log("ThemePanel.onMove: " + type);
528 499
529 ListGridRecord[] records = list.getSelectedRecords(); 500 final ListGridRecord[] records = this.list.getSelectedRecords();
530 501
531 if (records == null || records.length == 0) { 502 if (records == null || records.length == 0) {
532 GWT.log("ThemePanel.onMove: No records selected."); 503 GWT.log("ThemePanel.onMove: No records selected.");
533 return; 504 return;
534 } 505 }
535 506
536 switch (type) { 507 switch (type) {
537 case 0: moveRecordsTop(records); break; 508 case 0:
538 case 1: moveRecordsUp(records); break; 509 moveRecordsTop(records);
539 case 2: moveRecordsDown(records); break; 510 break;
540 case 3: moveRecordsBottom(records); break; 511 case 1:
512 moveRecordsUp(records);
513 break;
514 case 2:
515 moveRecordsDown(records);
516 break;
517 case 3:
518 moveRecordsBottom(records);
519 break;
541 } 520 }
542 521
543 updateCollection(); 522 updateCollection();
544 } 523 }
545 524
546
547 /** 525 /**
548 * Moves the selected grid records (themes) to the top of the grid. 526 * Moves the selected grid records (themes) to the top of the grid.
549 * 527 *
550 * @param records The selected themes in the list. Null not permitted. 528 * @param records
551 */ 529 * The selected themes in the list. Null not permitted.
552 protected void moveRecordsTop(ListGridRecord[] records) { 530 */
553 ThemeList themeList = getThemeList(); 531 protected void moveRecordsTop(final ListGridRecord[] records) {
532 final ThemeList themeList = getThemeList();
554 533
555 int idx = 1; 534 int idx = 1;
556 535
557 for (ListGridRecord record: records) { 536 for (final ListGridRecord record : records) {
558 Theme theme = ((FacetRecord) record).getTheme(); 537 final Theme theme = ((FacetRecord) record).getTheme();
559 fireThemeMoved(theme, theme.getPosition(), idx); 538 fireThemeMoved(theme, theme.getPosition(), idx);
560 themeList.setThemePosition(theme, idx++); 539 themeList.setThemePosition(theme, idx++);
561 } 540 }
562 541
563 updateGrid(); 542 updateGrid();
564 } 543 }
565 544
566
567 /** 545 /**
568 * Moves the selected grid records (themes) one step up. 546 * Moves the selected grid records (themes) one step up.
569 * 547 *
570 * @param records The selected themes in the list. Null not permitted. 548 * @param records
571 */ 549 * The selected themes in the list. Null not permitted.
572 protected void moveRecordsUp(ListGridRecord[] records) { 550 */
573 ThemeList themeList = getThemeList(); 551 protected void moveRecordsUp(final ListGridRecord[] records) {
574 552 final ThemeList themeList = getThemeList();
575 int[] newPos = new int[records.length]; 553
576 554 final int[] newPos = new int[records.length];
577 for (int i = 0; i < records.length ; i++) { 555
578 Theme theme = ((FacetRecord) records[i]).getTheme(); 556 for (int i = 0; i < records.length; i++) {
579 newPos[i] = theme.getPosition() - 1; 557 final Theme theme = ((FacetRecord) records[i]).getTheme();
580 } 558 newPos[i] = theme.getPosition() - 1;
581 559 }
582 for (int i = 0; i < records.length ; i++) { 560
583 Theme theme = ((FacetRecord) records[i]).getTheme(); 561 for (int i = 0; i < records.length; i++) {
562 final Theme theme = ((FacetRecord) records[i]).getTheme();
584 fireThemeMoved(theme, theme.getPosition(), newPos[i]); 563 fireThemeMoved(theme, theme.getPosition(), newPos[i]);
585 themeList.setThemePosition(theme, newPos[i]); 564 themeList.setThemePosition(theme, newPos[i]);
586 } 565 }
587 566
588 updateGrid(); 567 updateGrid();
589 } 568 }
590 569
591
592 /** 570 /**
593 * Moves the selected grid records (themes) one step down. 571 * Moves the selected grid records (themes) one step down.
594 * 572 *
595 * @param records The selected themes in the list. Null not permitted. 573 * @param records
596 */ 574 * The selected themes in the list. Null not permitted.
597 protected void moveRecordsDown(ListGridRecord[] records) { 575 */
598 ThemeList themeList = getThemeList(); 576 protected void moveRecordsDown(final ListGridRecord[] records) {
599 577 final ThemeList themeList = getThemeList();
600 int[] newPos = new int[records.length]; 578
601 579 final int[] newPos = new int[records.length];
602 for (int i = records.length-1; i >= 0; i--) { 580
603 Theme theme = ((FacetRecord) records[i]).getTheme(); 581 for (int i = records.length - 1; i >= 0; i--) {
604 newPos[i] = theme.getPosition()+1; 582 final Theme theme = ((FacetRecord) records[i]).getTheme();
605 } 583 newPos[i] = theme.getPosition() + 1;
606 584 }
607 for (int i = records.length-1; i >= 0; i--) { 585
608 Theme theme = ((FacetRecord) records[i]).getTheme(); 586 for (int i = records.length - 1; i >= 0; i--) {
587 final Theme theme = ((FacetRecord) records[i]).getTheme();
609 fireThemeMoved(theme, theme.getPosition(), newPos[i]); 588 fireThemeMoved(theme, theme.getPosition(), newPos[i]);
610 themeList.setThemePosition(theme, newPos[i]); 589 themeList.setThemePosition(theme, newPos[i]);
611 } 590 }
612 591
613 updateGrid(); 592 updateGrid();
614 } 593 }
615 594
616
617 /** 595 /**
618 * Moves the selected grid records (themes) to the bottom of the grid. 596 * Moves the selected grid records (themes) to the bottom of the grid.
619 * 597 *
620 * @param records The selected themes in the list. Null not permitted. 598 * @param records
621 */ 599 * The selected themes in the list. Null not permitted.
622 protected void moveRecordsBottom(ListGridRecord[] records) { 600 */
623 ThemeList themeList = getThemeList(); 601 protected void moveRecordsBottom(final ListGridRecord[] records) {
602 final ThemeList themeList = getThemeList();
624 603
625 int idx = themeList.getThemeCount(); 604 int idx = themeList.getThemeCount();
626 605
627 for (int i = records.length-1; i >= 0; i--) { 606 for (int i = records.length - 1; i >= 0; i--) {
628 Theme theme = ((FacetRecord) records[i]).getTheme(); 607 final Theme theme = ((FacetRecord) records[i]).getTheme();
629 fireThemeMoved(theme, theme.getPosition(), idx); 608 fireThemeMoved(theme, theme.getPosition(), idx);
630 themeList.setThemePosition(theme, idx--); 609 themeList.setThemePosition(theme, idx--);
631 } 610 }
632 611
633 updateGrid(); 612 updateGrid();
634 } 613 }
635 614
636
637 protected void openStyleEditor(final FacetRecord record) { 615 protected void openStyleEditor(final FacetRecord record) {
638 Config config = Config.getInstance(); 616 final Config config = Config.getInstance();
639 String locale = config.getLocale(); 617 final String locale = config.getLocale();
640 618
641 String artifact = record.getTheme().getArtifact(); 619 final String artifact = record.getTheme().getArtifact();
642 620
643 itemAttributeService.getCollectionItemAttribute( 621 this.itemAttributeService.getCollectionItemAttribute(this.getCollection(), artifact, locale, new AsyncCallback<CollectionItemAttribute>() {
644 this.getCollection(), 622 @Override
645 artifact, 623 public void onFailure(final Throwable caught) {
646 locale, 624 SC.warn(ThemePanel.this.MSG.getString(caught.getMessage()));
647 new AsyncCallback<CollectionItemAttribute>() { 625 }
648 @Override 626
649 public void onFailure (Throwable caught) { 627 @Override
650 SC.warn(MSG.getString(caught.getMessage())); 628 public void onSuccess(final CollectionItemAttribute cia) {
651 } 629 GWT.log("Successfully loaded collectionitem attributes.");
652 @Override 630 showStyleEditor(cia, record);
653 public void onSuccess(CollectionItemAttribute cia) { 631 }
654 GWT.log("Successfully loaded collectionitem attributes."); 632 });
655 showStyleEditor(cia, record); 633 }
656 } 634
657 }); 635 protected void showStyleEditor(final CollectionItemAttribute cia, final FacetRecord record) {
658 } 636 final StyleEditorWindow win = new StyleEditorWindow(getCollection(), cia, record);
659
660
661 protected void showStyleEditor(
662 CollectionItemAttribute cia,
663 FacetRecord record)
664 {
665 StyleEditorWindow win = new StyleEditorWindow(
666 getCollection(),
667 cia,
668 record);
669 win.setThemePanel(this); 637 win.setThemePanel(this);
670 win.centerInPage(); 638 win.centerInPage();
671 win.show(); 639 win.show();
672 } 640 }
673 641
674
675 /** Get OutputMode of this Panel. */ 642 /** Get OutputMode of this Panel. */
676 public OutputMode getMode() { 643 public OutputMode getMode() {
677 return this.mode; 644 return this.mode;
678 } 645 }
646
647 public void updateThemes() {
648
649 final ListGridRecord[] records = this.list.getRecords();
650 for (final ListGridRecord record : records) {
651 final FacetRecord facetRecord = (FacetRecord) record;
652
653 this.recordHandler.handle(facetRecord);
654 }
655
656 this.list.markForRedraw();
657 }
679 } 658 }
680 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org