Added validation to properties dialog (issue #2347)
authorChristos Stathis <chstath@ebs.gr>
Mon, 30 Apr 2012 12:39:35 +0000 (15:39 +0300)
committerChristos Stathis <chstath@ebs.gr>
Mon, 30 Apr 2012 12:39:35 +0000 (15:39 +0300)
src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java
src/gr/grnet/pithos/web/client/FilePermissionsDialog.java
src/gr/grnet/pithos/web/client/FilePropertiesDialog.java
src/gr/grnet/pithos/web/client/FilePublishDialog.java
src/gr/grnet/pithos/web/client/FileVersionsDialog.java
src/gr/grnet/pithos/web/client/FilesPropertiesDialog.java

index e3a125c..0c53546 100644 (file)
@@ -67,9 +67,10 @@ public abstract class AbstractPropertiesDialog extends DialogBox {
 \r
        /**\r
         * Accepts any change and updates the file\r
+        * @return \r
         *\r
         */\r
-       protected abstract void accept();\r
+       protected abstract boolean accept();\r
 \r
        @Override\r
        protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
@@ -81,8 +82,9 @@ public abstract class AbstractPropertiesDialog extends DialogBox {
                          // enter or escape is pressed.\r
                          switch (evt.getKeyCode()) {\r
                            case KeyCodes.KEY_ENTER:\r
-                               accept();\r
-                           //$FALL-THROUGH$\r
+                               if (accept())\r
+                                       closeDialog();\r
+                               break;\r
                        case KeyCodes.KEY_ESCAPE:\r
                                closeDialog();\r
                                break;\r
index b3f6159..8fb801a 100644 (file)
@@ -244,8 +244,9 @@ public class FilePermissionsDialog extends AbstractPropertiesDialog {
         *\r
         */\r
        @Override\r
-       protected void accept() {\r
+       protected boolean accept() {\r
         updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", permList.getPermissions());\r
+        return true;\r
        }\r
 \r
        protected void updateMetaData(String api, String owner, final String path, final Map<String, Boolean[]> newPermissions) {\r
index 336a5ee..68bd977 100644 (file)
@@ -112,8 +112,8 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
                final Button ok = new Button("OK", new ClickHandler() {\r
                        @Override\r
                        public void onClick(ClickEvent event) {\r
-                               accept();\r
-                               closeDialog();\r
+                               if (accept())\r
+                                       closeDialog();\r
                        }\r
                });\r
                ok.addStyleName("button");\r
@@ -226,12 +226,15 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
         *\r
         */\r
        @Override\r
-       protected void accept() {\r
+       protected boolean accept() {\r
                String newFilename = null;\r
 \r
                if (!name.getText().trim().equals(file.getName())) {\r
                        newFilename = name.getText().trim();\r
+                       if (newFilename.length() == 0)\r
+                               newFilename = null;\r
                }\r
+               \r
 \r
         final Map<String, String> newMeta = new HashMap<String, String>();\r
         for (int row = 1; row < metaTable.getRowCount(); row++) {\r
@@ -239,6 +242,10 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
                String value = ((TextBox) metaTable.getWidget(row, 1)).getText().trim();\r
                if (key.length() > 0 && value.length() > 0)\r
                        newMeta.put(key, value);\r
+               else if ((key.length() > 0 && value.length() == 0) || (key.length() == 0 && value.length() > 0)) {\r
+                       app.displayError("You have empty keys or values");\r
+                       return false;\r
+               }\r
         }\r
 \r
         if (newFilename != null) {\r
@@ -296,6 +303,7 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
         }\r
         else\r
             updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", newMeta);\r
+        return true;\r
        }\r
 \r
        protected void updateMetaData(String api, String owner, String path, Map<String, String> newMeta) {\r
index ee96121..107b36c 100644 (file)
@@ -221,15 +221,17 @@ public class FilePublishDialog extends AbstractPropertiesDialog {
     }\r
        /**\r
         * Accepts any change and updates the file\r
+        * @return \r
         *\r
         */\r
        @Override\r
-       protected void accept() {\r
+       protected boolean accept() {\r
         Boolean published = null;\r
                if (readForAll.getValue() != file.isPublished())\r
                        if (file.getOwner().equals(app.getUsername()))\r
                 published = readForAll.getValue();\r
         updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", published);\r
+        return true;\r
        }\r
 \r
        protected void updateMetaData(String api, String owner, final String path, final Boolean published) {\r
index e79007c..6229c4b 100644 (file)
@@ -185,10 +185,11 @@ public class FileVersionsDialog extends AbstractPropertiesDialog {
 \r
        /**\r
         * Accepts any change and updates the file\r
+        * @return \r
         *\r
         */\r
        @Override\r
-       protected void accept() {\r
+       protected boolean accept() {\r
         app.updateFolder(file.getParent(), true, new Command() {\r
                        \r
                        @Override\r
@@ -197,5 +198,7 @@ public class FileVersionsDialog extends AbstractPropertiesDialog {
                                        app.updateMySharedRoot();\r
                        }\r
                }, true);\r
+        \r
+        return true;\r
        }\r
 }\r
index a23cd29..72d31e8 100644 (file)
@@ -140,9 +140,11 @@ public class FilesPropertiesDialog extends AbstractPropertiesDialog {
 \r
        /**\r
         * Accepts any change and updates the file\r
+        * @return \r
         *\r
         */\r
        @Override\r
-       protected void accept() {\r
+       protected boolean accept() {\r
+               return true;\r
        }\r
 }\r