comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java @ 597:14e5e51a7de4

Improved the project list - listeners are notified after setting the name and ttl of a project. flys-client/trunk@2199 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 22 Jun 2011 10:14:57 +0000
parents 53ad6dd2cb2b
children 031357c3e23e
comparison
equal deleted inserted replaced
596:3f094045d512 597:14e5e51a7de4
1 package de.intevation.flys.client.client.ui; 1 package de.intevation.flys.client.client.ui;
2 2
3 import java.util.Date; 3 import java.util.Date;
4 import java.util.Map;
4 5
5 import com.google.gwt.core.client.GWT; 6 import com.google.gwt.core.client.GWT;
6 import com.google.gwt.i18n.client.DateTimeFormat; 7 import com.google.gwt.i18n.client.DateTimeFormat;
7 import com.google.gwt.user.client.Timer; 8 import com.google.gwt.user.client.Timer;
8 import com.google.gwt.user.client.rpc.AsyncCallback; 9 import com.google.gwt.user.client.rpc.AsyncCallback;
9 10
10 import com.smartgwt.client.types.Alignment; 11 import com.smartgwt.client.types.Alignment;
12 import com.smartgwt.client.types.ListGridEditEvent;
11 import com.smartgwt.client.types.ListGridFieldType; 13 import com.smartgwt.client.types.ListGridFieldType;
12 import com.smartgwt.client.types.SortDirection; 14 import com.smartgwt.client.types.SortDirection;
13 import com.smartgwt.client.util.SC; 15 import com.smartgwt.client.util.SC;
14 import com.smartgwt.client.widgets.Canvas; 16 import com.smartgwt.client.widgets.Canvas;
15 import com.smartgwt.client.widgets.Label; 17 import com.smartgwt.client.widgets.Label;
16 import com.smartgwt.client.widgets.grid.CellFormatter; 18 import com.smartgwt.client.widgets.grid.CellFormatter;
17 import com.smartgwt.client.widgets.grid.ListGrid; 19 import com.smartgwt.client.widgets.grid.ListGrid;
18 import com.smartgwt.client.widgets.grid.ListGridField; 20 import com.smartgwt.client.widgets.grid.ListGridField;
19 import com.smartgwt.client.widgets.grid.ListGridRecord; 21 import com.smartgwt.client.widgets.grid.ListGridRecord;
22 import com.smartgwt.client.widgets.grid.events.CellClickEvent;
23 import com.smartgwt.client.widgets.grid.events.CellClickHandler;
20 import com.smartgwt.client.widgets.grid.events.CellDoubleClickEvent; 24 import com.smartgwt.client.widgets.grid.events.CellDoubleClickEvent;
21 import com.smartgwt.client.widgets.grid.events.CellDoubleClickHandler; 25 import com.smartgwt.client.widgets.grid.events.CellDoubleClickHandler;
26 import com.smartgwt.client.widgets.grid.events.EditCompleteEvent;
27 import com.smartgwt.client.widgets.grid.events.EditCompleteHandler;
22 import com.smartgwt.client.widgets.grid.events.RowContextClickEvent; 28 import com.smartgwt.client.widgets.grid.events.RowContextClickEvent;
23 import com.smartgwt.client.widgets.grid.events.RowContextClickHandler; 29 import com.smartgwt.client.widgets.grid.events.RowContextClickHandler;
24 import com.smartgwt.client.widgets.layout.VLayout; 30 import com.smartgwt.client.widgets.layout.VLayout;
25 import com.smartgwt.client.widgets.menu.Menu; 31 import com.smartgwt.client.widgets.menu.Menu;
26 import com.smartgwt.client.widgets.menu.MenuItem; 32 import com.smartgwt.client.widgets.menu.MenuItem;
46 * 52 *
47 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 53 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
48 */ 54 */
49 public class ProjectList 55 public class ProjectList
50 extends VLayout 56 extends VLayout
51 implements CollectionChangeHandler 57 implements CollectionChangeHandler, EditCompleteHandler
52 { 58 {
53 /** Interval to refresh the user's projects.*/ 59 /** Interval to refresh the user's projects.*/
54 public static final int UPDATE_INTERVAL = 30000; 60 public static final int UPDATE_INTERVAL = 30000;
55 61
56 /** Min Interval to refresh the user's projects.*/ 62 /** Min Interval to refresh the user's projects.*/
84 90
85 grid = new ListGrid(); 91 grid = new ListGrid();
86 initGrid(); 92 initGrid();
87 init(); 93 init();
88 initTimer(); 94 initTimer();
95
96 grid.addEditCompleteHandler(this);
89 97
90 updateUserCollections(); 98 updateUserCollections();
91 } 99 }
92 100
93 101
100 grid.setShowHeader(false); 108 grid.setShowHeader(false);
101 grid.setWidth100(); 109 grid.setWidth100();
102 grid.setHeight100(); 110 grid.setHeight100();
103 grid.setSortDirection(SortDirection.DESCENDING); 111 grid.setSortDirection(SortDirection.DESCENDING);
104 grid.setSortField(0); 112 grid.setSortField(0);
113 grid.setCanEdit(false);
114 grid.setEditByCell(true);
115 grid.setEditEvent(ListGridEditEvent.NONE);
105 116
106 ListGridField date = buildDateField(); 117 ListGridField date = buildDateField();
107 ListGridField name = buildNameField(); 118 ListGridField name = buildNameField();
108 ListGridField fav = buildFavoriteField(); 119 ListGridField fav = buildFavoriteField();
109 120
110 grid.setFields(date, name, fav); 121 grid.setFields(date, name, fav);
111 122
123 // add a handler to set / unset the favorite state of a project
124 grid.addCellClickHandler(new CellClickHandler() {
125 public void onCellClick(CellClickEvent event) {
126 if (event.getColNum() != 2) {
127 return;
128 }
129
130 CollectionRecord r = (CollectionRecord) event.getRecord();
131 Collection c = r.getCollection();
132
133 c.setTTL(c.getTTL() == 0 ? -1 : 0);
134 updateCollectionTTL(c);
135 }
136 });
137
138 // add a handler to open a project
112 grid.addCellDoubleClickHandler(new CellDoubleClickHandler() { 139 grid.addCellDoubleClickHandler(new CellDoubleClickHandler() {
113 public void onCellDoubleClick(CellDoubleClickEvent e) { 140 public void onCellDoubleClick(CellDoubleClickEvent e) {
114 CollectionRecord record = (CollectionRecord) e.getRecord(); 141 CollectionRecord record = (CollectionRecord) e.getRecord();
115 String uuid = record != null 142 String uuid = record != null
116 ? record.getCollection().identifier() 143 ? record.getCollection().identifier()
117 : ""; 144 : "";
118 getFlys().openProject(uuid); 145 getFlys().openProject(uuid);
119 } 146 }
120 }); 147 });
121 148
149 // add a handler to open a context menu
122 grid.addRowContextClickHandler(new RowContextClickHandler() { 150 grid.addRowContextClickHandler(new RowContextClickHandler() {
123 public void onRowContextClick(RowContextClickEvent event) { 151 public void onRowContextClick(RowContextClickEvent event) {
124 CollectionRecord record = (CollectionRecord) event.getRecord(); 152 CollectionRecord record = (CollectionRecord) event.getRecord();
125 153
126 Menu menu = createContextMenu(record); 154 Menu menu = createContextMenu(record);
184 public void onClick(MenuItemClickEvent evt) { 212 public void onClick(MenuItemClickEvent evt) {
185 SC.warn("Removing projects is not implemented."); 213 SC.warn("Removing projects is not implemented.");
186 } 214 }
187 }); 215 });
188 216
217 MenuItem rename = new MenuItem(messages.rename_project());
218 rename.addClickHandler(new ClickHandler() {
219 public void onClick(MenuItemClickEvent evt) {
220 int row = grid.getRecordIndex(record);
221 grid.startEditing(row, 1, false);
222 }
223 });
224
189 menu.addItem(open); 225 menu.addItem(open);
190 menu.addItem(del); 226 menu.addItem(del);
227 menu.addItem(rename);
191 228
192 return menu; 229 return menu;
193 } 230 }
194 231
195 232
231 updateUserCollections(); 268 updateUserCollections();
232 } 269 }
233 } 270 }
234 271
235 272
273 public void onEditComplete(EditCompleteEvent event) {
274 if (event.getColNum() != 1) {
275 return;
276 }
277
278 int row = event.getRowNum();
279
280 CollectionRecord r = (CollectionRecord) grid.getRecord(row);
281 Collection c = r.getCollection();
282
283 Map newValues = event.getNewValues();
284 String name = (String) newValues.get("name");
285
286 c.setName(name);
287
288 updateCollectionName(c);
289 }
290
291
292 /**
293 * Set the name of the collection <i>c</i> to a new value. If the update
294 * process succeeded, the project list is refreshed.
295 *
296 * @param c The Collection with a new name.
297 */
298 protected void updateCollectionName(Collection c) {
299 if (c == null) {
300 return;
301 }
302
303 GWT.log("Update Collection name: " + c.identifier());
304 GWT.log("=> New name = " + c.getName());
305
306 // TODO IMPLEMENT ME
307 }
308
309
310 /**
311 * Set the ttl of the collection <i>c</i> to a new value. If the update
312 * process succeeded, the project list is refreshed.
313 *
314 * @param c The Collection with a new ttl.
315 */
316 protected void updateCollectionTTL(Collection c) {
317 if (c == null) {
318 return;
319 }
320
321 GWT.log("Update Collection TTL: " + c.identifier());
322 GWT.log("=> New ttl = " + c.getTTL());
323
324 // TODO IMPLEMENT ME
325 }
326
327
236 protected void updateUserCollections() { 328 protected void updateUserCollections() {
237 GWT.log("==> ProjectList updates user collections!"); 329 GWT.log("==> ProjectList updates user collections!");
238 330
239 Config config = Config.getInstance(); 331 Config config = Config.getInstance();
240 String url = config.getServerUrl(); 332 String url = config.getServerUrl();
288 * @return the grid field. 380 * @return the grid field.
289 */ 381 */
290 protected ListGridField buildDateField() { 382 protected ListGridField buildDateField() {
291 ListGridField date = new ListGridField("creationTime", "creationTime"); 383 ListGridField date = new ListGridField("creationTime", "creationTime");
292 date.setType(ListGridFieldType.DATE); 384 date.setType(ListGridFieldType.DATE);
385 date.setCanEdit(false);
293 386
294 date.setCellFormatter(new CellFormatter() { 387 date.setCellFormatter(new CellFormatter() {
295 public String format(Object value, ListGridRecord rec, int r, int c) { 388 public String format(Object value, ListGridRecord rec, int r, int c) {
296 if (value == null) { 389 if (value == null) {
297 return null; 390 return null;
323 name.setCellFormatter(new CellFormatter() { 416 name.setCellFormatter(new CellFormatter() {
324 public String format(Object value, ListGridRecord record, int row, int col) { 417 public String format(Object value, ListGridRecord record, int row, int col) {
325 String n = (String) value; 418 String n = (String) value;
326 int len = n.length(); 419 int len = n.length();
327 420
328 if (len < 30) { 421 if (len < 26) {
329 return n; 422 return n;
330 } 423 }
331 424
332 int sec = len - 15; 425 int sec = len - 13;
333 return n.substring(0, 14) + "..." + n.substring(sec, len-1); 426 return n.substring(0, 12) + "..." + n.substring(sec, len-1);
334 } 427 }
335 }); 428 });
336 429
337 name.setWidth(165); 430 name.setWidth(165);
338 name.setAlign(Alignment.LEFT); 431 name.setAlign(Alignment.LEFT);
347 String base = GWT.getHostPageBaseURL(); 440 String base = GWT.getHostPageBaseURL();
348 fav.setImageURLPrefix(base + "images/"); 441 fav.setImageURLPrefix(base + "images/");
349 fav.setImageURLSuffix(".png"); 442 fav.setImageURLSuffix(".png");
350 fav.setWidth(30); 443 fav.setWidth(30);
351 fav.setAlign(Alignment.RIGHT); 444 fav.setAlign(Alignment.RIGHT);
445 fav.setCanEdit(false);
352 446
353 return fav; 447 return fav;
354 } 448 }
355 } 449 }
356 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 450 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org