changeset 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 3f094045d512
children 031357c3e23e
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java
diffstat 8 files changed, 137 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Jun 22 08:06:19 2011 +0000
+++ b/flys-client/ChangeLog	Wed Jun 22 10:14:57 2011 +0000
@@ -1,3 +1,22 @@
+2011-06-22  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java,
+	  src/main/java/de/intevation/flys/client/shared/model/Collection.java:
+	  There are setter methods for 'name' and 'ttl' now. The project list
+	  requires this to set those attribute to a new value.
+
+	* src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.java:
+	  Added strings for the project list's context menu item "rename project".
+
+	* src/main/java/de/intevation/flys/client/client/ui/ProjectList.java:
+	  Added a context menu item to rename the selected project and listeners
+	  to trigger setting 'name' and 'ttl' to a new value.
+
+	  TODO: We still need to write RPC services to update those values!
+
 2011-06-22  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Wed Jun 22 08:06:19 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Wed Jun 22 10:14:57 2011 +0000
@@ -22,6 +22,8 @@
 
     String delete_project();
 
+    String rename_project();
+
     String manage_projects();
 
     String logout();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Wed Jun 22 08:06:19 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Wed Jun 22 10:14:57 2011 +0000
@@ -6,6 +6,7 @@
 projects = Projects
 open_project = Open Project
 delete_project = Delete Project
+rename_project = Rename Project
 manage_projects = Manage Projects
 switch_language = German
 info = Info
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Wed Jun 22 08:06:19 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Wed Jun 22 10:14:57 2011 +0000
@@ -4,8 +4,9 @@
 guest = Gast
 logout = Abmelden
 projects = Projekte
-open_project = Projekt \u00d6ffnen
+open_project = Projekt \u00f6ffnen
 delete_project = Projekt l\u00f6schen
+rename_project = Projekt umbenennen
 manage_projects = Projekte verwalten
 switch_language = Englisch
 info = Info
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Wed Jun 22 08:06:19 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Wed Jun 22 10:14:57 2011 +0000
@@ -6,6 +6,7 @@
 projects = Projects
 open_project = Open Project
 delete_project = Delete Project
+rename_project = Rename Project
 manage_projects = Manage Projects
 switch_language = German
 info = Info
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Wed Jun 22 08:06:19 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Wed Jun 22 10:14:57 2011 +0000
@@ -1,6 +1,7 @@
 package de.intevation.flys.client.client.ui;
 
 import java.util.Date;
+import java.util.Map;
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.i18n.client.DateTimeFormat;
@@ -8,6 +9,7 @@
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.ListGridEditEvent;
 import com.smartgwt.client.types.ListGridFieldType;
 import com.smartgwt.client.types.SortDirection;
 import com.smartgwt.client.util.SC;
@@ -17,8 +19,12 @@
 import com.smartgwt.client.widgets.grid.ListGrid;
 import com.smartgwt.client.widgets.grid.ListGridField;
 import com.smartgwt.client.widgets.grid.ListGridRecord;
+import com.smartgwt.client.widgets.grid.events.CellClickEvent;
+import com.smartgwt.client.widgets.grid.events.CellClickHandler;
 import com.smartgwt.client.widgets.grid.events.CellDoubleClickEvent;
 import com.smartgwt.client.widgets.grid.events.CellDoubleClickHandler;
+import com.smartgwt.client.widgets.grid.events.EditCompleteEvent;
+import com.smartgwt.client.widgets.grid.events.EditCompleteHandler;
 import com.smartgwt.client.widgets.grid.events.RowContextClickEvent;
 import com.smartgwt.client.widgets.grid.events.RowContextClickHandler;
 import com.smartgwt.client.widgets.layout.VLayout;
@@ -48,7 +54,7 @@
  */
 public class ProjectList
 extends      VLayout
-implements   CollectionChangeHandler
+implements   CollectionChangeHandler, EditCompleteHandler
 {
     /** Interval to refresh the user's projects.*/
     public static final int UPDATE_INTERVAL = 30000;
@@ -87,6 +93,8 @@
         init();
         initTimer();
 
+        grid.addEditCompleteHandler(this);
+
         updateUserCollections();
     }
 
@@ -102,6 +110,9 @@
         grid.setHeight100();
         grid.setSortDirection(SortDirection.DESCENDING);
         grid.setSortField(0);
+        grid.setCanEdit(false);
+        grid.setEditByCell(true);
+        grid.setEditEvent(ListGridEditEvent.NONE);
 
         ListGridField date = buildDateField();
         ListGridField name = buildNameField();
@@ -109,6 +120,22 @@
 
         grid.setFields(date, name, fav);
 
+        // add a handler to set / unset the favorite state of a project
+        grid.addCellClickHandler(new CellClickHandler() {
+            public void onCellClick(CellClickEvent event) {
+                if (event.getColNum() != 2) {
+                    return;
+                }
+
+                CollectionRecord r = (CollectionRecord) event.getRecord();
+                Collection       c = r.getCollection();
+
+                c.setTTL(c.getTTL() == 0 ? -1 : 0);
+                updateCollectionTTL(c);
+            }
+        });
+
+        // add a handler to open a project
         grid.addCellDoubleClickHandler(new CellDoubleClickHandler() {
             public void onCellDoubleClick(CellDoubleClickEvent e) {
                 CollectionRecord record = (CollectionRecord) e.getRecord();
@@ -119,6 +146,7 @@
             }
         });
 
+        // add a handler to open a context menu
         grid.addRowContextClickHandler(new RowContextClickHandler() {
             public void onRowContextClick(RowContextClickEvent event) {
                 CollectionRecord record = (CollectionRecord) event.getRecord();
@@ -186,8 +214,17 @@
             }
         });
 
+        MenuItem rename = new MenuItem(messages.rename_project());
+        rename.addClickHandler(new ClickHandler() {
+            public void onClick(MenuItemClickEvent evt) {
+                int row = grid.getRecordIndex(record);
+                grid.startEditing(row, 1, false);
+            }
+        });
+
         menu.addItem(open);
         menu.addItem(del);
+        menu.addItem(rename);
 
         return menu;
     }
@@ -233,6 +270,61 @@
     }
 
 
+    public void onEditComplete(EditCompleteEvent event) {
+        if (event.getColNum() != 1) {
+            return;
+        }
+
+        int row = event.getRowNum();
+
+        CollectionRecord r = (CollectionRecord) grid.getRecord(row);
+        Collection       c = r.getCollection();
+
+        Map newValues = event.getNewValues();
+        String name   = (String) newValues.get("name");
+
+        c.setName(name);
+
+        updateCollectionName(c);
+    }
+
+
+    /**
+     * Set the name of the collection <i>c</i> to a new value. If the update
+     * process succeeded, the project list is refreshed.
+     *
+     * @param c The Collection with a new name.
+     */
+    protected void updateCollectionName(Collection c) {
+        if (c == null) {
+            return;
+        }
+
+        GWT.log("Update Collection name: " + c.identifier());
+        GWT.log("=> New name = " + c.getName());
+
+        // TODO IMPLEMENT ME
+    }
+
+
+    /**
+     * Set the ttl of the collection <i>c</i> to a new value. If the update
+     * process succeeded, the project list is refreshed.
+     *
+     * @param c The Collection with a new ttl.
+     */
+    protected void updateCollectionTTL(Collection c) {
+        if (c == null) {
+            return;
+        }
+
+        GWT.log("Update Collection TTL: " + c.identifier());
+        GWT.log("=> New ttl = " + c.getTTL());
+
+        // TODO IMPLEMENT ME
+    }
+
+
     protected void updateUserCollections() {
         GWT.log("==> ProjectList updates user collections!");
 
@@ -290,6 +382,7 @@
     protected ListGridField buildDateField() {
         ListGridField date = new ListGridField("creationTime", "creationTime");
         date.setType(ListGridFieldType.DATE);
+        date.setCanEdit(false);
 
         date.setCellFormatter(new CellFormatter() {
             public String format(Object value, ListGridRecord rec, int r, int c) {
@@ -325,12 +418,12 @@
                 String n = (String) value;
                 int len  = n.length();
 
-                if (len < 30) {
+                if (len < 26) {
                     return n;
                 }
 
-                int sec  = len - 15;
-                return n.substring(0, 14) + "..." + n.substring(sec, len-1);
+                int sec  = len - 13;
+                return n.substring(0, 12) + "..." + n.substring(sec, len-1);
             }
         });
 
@@ -349,6 +442,7 @@
         fav.setImageURLSuffix(".png");
         fav.setWidth(30);
         fav.setAlign(Alignment.RIGHT);
+        fav.setCanEdit(false);
 
         return fav;
     }
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java	Wed Jun 22 08:06:19 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Collection.java	Wed Jun 22 10:14:57 2011 +0000
@@ -16,12 +16,16 @@
 
     public String getName();
 
+    public void setName(String name);
+
     public Date getCreationTime();
 
     public Date getLastAccess();
 
     public long getTTL();
 
+    public void setTTL(long ttl);
+
     public void addItem(CollectionItem item);
 
     public int getItemLength();
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java	Wed Jun 22 08:06:19 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java	Wed Jun 22 10:14:57 2011 +0000
@@ -110,11 +110,21 @@
     }
 
 
+    public void setTTL(long ttl) {
+        this.ttl = ttl;
+    }
+
+
     public String getName() {
         return name;
     }
 
 
+    public void setName(String name) {
+        this.name = name;
+    }
+
+
     public void addItem(CollectionItem item) {
         if (item != null) {
             items.add(item);

http://dive4elements.wald.intevation.org