commit 0099339a39d93f6fec1b6571eab70560f4654445
Author: Christos Stathis <chstath@ebs.gr>
Date:   Mon Apr 30 15:39:35 2012 +0300

    Added validation to properties dialog (issue #2347)

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