comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java @ 226:a13382876e5d

The project list is sorted now. flys-client/trunk@1671 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 12 Apr 2011 13:11:46 +0000
parents 9040663aee01
children 924da6695800
comparison
equal deleted inserted replaced
225:9040663aee01 226:a13382876e5d
1 package de.intevation.flys.client.client.ui; 1 package de.intevation.flys.client.client.ui;
2 2
3 import java.util.Date;
4
3 import com.google.gwt.core.client.GWT; 5 import com.google.gwt.core.client.GWT;
6 import com.google.gwt.i18n.client.DateTimeFormat;
4 import com.google.gwt.user.client.rpc.AsyncCallback; 7 import com.google.gwt.user.client.rpc.AsyncCallback;
5 8
9 import com.smartgwt.client.types.Alignment;
10 import com.smartgwt.client.types.ListGridFieldType;
11 import com.smartgwt.client.types.SortDirection;
6 import com.smartgwt.client.util.SC; 12 import com.smartgwt.client.util.SC;
7 import com.smartgwt.client.widgets.Canvas; 13 import com.smartgwt.client.widgets.Canvas;
8 import com.smartgwt.client.widgets.Label; 14 import com.smartgwt.client.widgets.Label;
15 import com.smartgwt.client.widgets.grid.CellFormatter;
9 import com.smartgwt.client.widgets.grid.ListGrid; 16 import com.smartgwt.client.widgets.grid.ListGrid;
10 import com.smartgwt.client.widgets.grid.ListGridField; 17 import com.smartgwt.client.widgets.grid.ListGridField;
11 import com.smartgwt.client.widgets.grid.ListGridRecord; 18 import com.smartgwt.client.widgets.grid.ListGridRecord;
12 import com.smartgwt.client.widgets.grid.events.RowContextClickEvent; 19 import com.smartgwt.client.widgets.grid.events.RowContextClickEvent;
13 import com.smartgwt.client.widgets.grid.events.RowContextClickHandler; 20 import com.smartgwt.client.widgets.grid.events.RowContextClickHandler;
64 */ 71 */
65 public ProjectList(FLYS flys, User user) { 72 public ProjectList(FLYS flys, User user) {
66 this.flys = flys; 73 this.flys = flys;
67 this.user = user; 74 this.user = user;
68 75
69 grid = new CollectionGrid(); 76 grid = new ListGrid();
70 initGrid(); 77 initGrid();
71 init(); 78 init();
72 79
73 updateUserCollections(); 80 updateUserCollections();
74 } 81 }
81 grid.setShowRecordComponentsByCell(true); 88 grid.setShowRecordComponentsByCell(true);
82 grid.setCanRemoveRecords(false); 89 grid.setCanRemoveRecords(false);
83 grid.setShowHeader(false); 90 grid.setShowHeader(false);
84 grid.setWidth100(); 91 grid.setWidth100();
85 grid.setHeight100(); 92 grid.setHeight100();
86 93 grid.setSortDirection(SortDirection.DESCENDING);
87 ListGridField date = new ListGridField("date", "date"); 94 grid.setSortField(0);
88 ListGridField name = new ListGridField("name", "name"); 95
89 96 ListGridField date = buildDateField();
90 date.setWidth(100); 97 ListGridField name = buildNameField();
91 name.setWidth(195);
92 98
93 grid.setFields(date, name); 99 grid.setFields(date, name);
94 100
95 grid.addRowContextClickHandler(new RowContextClickHandler() { 101 grid.addRowContextClickHandler(new RowContextClickHandler() {
96 public void onRowContextClick(RowContextClickEvent event) { 102 public void onRowContextClick(RowContextClickEvent event) {
224 230
225 for (Collection c: collections) { 231 for (Collection c: collections) {
226 grid.addData(new CollectionRecord(c)); 232 grid.addData(new CollectionRecord(c));
227 } 233 }
228 } 234 }
235
236
237 /**
238 * Builds the field in the grid that displays the creation time of a
239 * project.
240 *
241 * @return the grid field.
242 */
243 protected ListGridField buildDateField() {
244 ListGridField date = new ListGridField("creationTime", "creationTime");
245 date.setType(ListGridFieldType.DATE);
246
247 date.setCellFormatter(new CellFormatter() {
248 public String format(Object value, ListGridRecord rec, int r, int c) {
249 if (value == null) {
250 return null;
251 }
252
253 DateTimeFormat dtf = DateTimeFormat.getFormat(
254 messages.datetime_format());
255
256 return dtf.format((Date)value);
257 }
258 });
259
260 date.setWidth(105);
261 date.setAlign(Alignment.LEFT);
262
263 return date;
264 }
265
266
267 /**
268 * Builds the field in the grid that displays the name of a project.
269 *
270 * @return the grid field.
271 */
272 protected ListGridField buildNameField() {
273 ListGridField name = new ListGridField("name", "name");
274 name.setType(ListGridFieldType.TEXT);
275
276 name.setCellFormatter(new CellFormatter() {
277 public String format(Object value, ListGridRecord record, int row, int col) {
278 String n = (String) value;
279 int len = n.length();
280 int sec = len - 15;
281 return n.substring(0, 14) + "..." + n.substring(sec, len-1);
282 }
283 });
284
285 name.setWidth(195);
286 name.setAlign(Alignment.LEFT);
287
288 return name;
289 }
229 } 290 }
230 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 291 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org