diff 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
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Tue Apr 12 11:01:09 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Tue Apr 12 13:11:46 2011 +0000
@@ -1,11 +1,18 @@
 package de.intevation.flys.client.client.ui;
 
+import java.util.Date;
+
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.DateTimeFormat;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.types.SortDirection;
 import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.grid.CellFormatter;
 import com.smartgwt.client.widgets.grid.ListGrid;
 import com.smartgwt.client.widgets.grid.ListGridField;
 import com.smartgwt.client.widgets.grid.ListGridRecord;
@@ -66,7 +73,7 @@
         this.flys = flys;
         this.user = user;
 
-        grid = new CollectionGrid();
+        grid = new ListGrid();
         initGrid();
         init();
 
@@ -83,12 +90,11 @@
         grid.setShowHeader(false);
         grid.setWidth100();
         grid.setHeight100();
+        grid.setSortDirection(SortDirection.DESCENDING);
+        grid.setSortField(0);
 
-        ListGridField date = new ListGridField("date", "date");
-        ListGridField name = new ListGridField("name", "name");
-
-        date.setWidth(100);
-        name.setWidth(195);
+        ListGridField date = buildDateField();
+        ListGridField name = buildNameField();
 
         grid.setFields(date, name);
 
@@ -226,5 +232,60 @@
             grid.addData(new CollectionRecord(c));
         }
     }
+
+
+    /**
+     * Builds the field in the grid that displays the creation time of a
+     * project.
+     *
+     * @return the grid field.
+     */
+    protected ListGridField buildDateField() {
+        ListGridField date = new ListGridField("creationTime", "creationTime");
+        date.setType(ListGridFieldType.DATE);
+
+        date.setCellFormatter(new CellFormatter() {
+            public String format(Object value, ListGridRecord rec, int r, int c) {
+                if (value == null) {
+                    return null;
+                }
+
+                DateTimeFormat dtf = DateTimeFormat.getFormat(
+                    messages.datetime_format());
+
+                return dtf.format((Date)value);
+            }
+        });
+
+        date.setWidth(105);
+        date.setAlign(Alignment.LEFT);
+
+        return date;
+    }
+
+
+    /**
+     * Builds the field in the grid that displays the name of a project.
+     *
+     * @return the grid field.
+     */
+    protected ListGridField buildNameField() {
+        ListGridField name = new ListGridField("name", "name");
+        name.setType(ListGridFieldType.TEXT);
+
+        name.setCellFormatter(new CellFormatter() {
+            public String format(Object value, ListGridRecord record, int row, int col) {
+                String n = (String) value;
+                int len  = n.length();
+                int sec  = len - 15;
+                return n.substring(0, 14) + "..." + n.substring(sec, len-1);
+            }
+        });
+
+        name.setWidth(195);
+        name.setAlign(Alignment.LEFT);
+
+        return name;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org