diff flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java @ 613:471ca61b83b5

#165 Set the max length of project names to 50 characters. flys-client/trunk@2228 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 24 Jun 2011 11:19:35 +0000
parents ee40f86dd009
children e14dc5fed6bb
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Fri Jun 24 09:53:25 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Fri Jun 24 11:19:35 2011 +0000
@@ -76,6 +76,9 @@
     /** The initial width of this panel.*/
     public static final int MIN_WIDTH = 300;
 
+    /** The max length for new project names.*/
+    public static final int MAX_NAME_LENGTH = 50;
+
     public static final String COLUMN_DATE_WIDTH = "100px";
 
     public static final String COLUMN_TITLE_WIDTH = "*";
@@ -321,6 +324,21 @@
         Map newValues = event.getNewValues();
         String name   = (String) newValues.get("name");
 
+        int maxLength = getMaxNameLength();
+        int length    = name != null ? name.length() : 0;
+
+        if (length <= 0 || length > maxLength) {
+            String msg = messages.project_name_too_long();
+            msg        = msg.replace("$LEN", String.valueOf(maxLength));
+            SC.warn(msg);
+
+            ListGridRecord[] rs = grid.getRecords();
+            rs[row] = (ListGridRecord) event.getOldRecord();
+            grid.setRecords(rs);
+
+            return;
+        }
+
         c.setName(name);
         updateCollectionName(c);
     }
@@ -481,6 +499,11 @@
     }
 
 
+    public int getMaxNameLength() {
+        return MAX_NAME_LENGTH;
+    }
+
+
     /**
      * Builds the field in the grid that displays the creation time of a
      * project.

http://dive4elements.wald.intevation.org