ignore case when examining the file extension for guessing the mime-type
[pithos] / src / gr / ebs / gss / client / FileUploadDialog.java
index 044eb0e..fbcbffa 100644 (file)
@@ -44,6 +44,7 @@ import com.google.gwt.user.client.ui.FormPanel;
 import com.google.gwt.user.client.ui.FormSubmitCompleteEvent;\r
 import com.google.gwt.user.client.ui.FormSubmitEvent;\r
 import com.google.gwt.user.client.ui.Grid;\r
+import com.google.gwt.user.client.ui.HTML;\r
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
 import com.google.gwt.user.client.ui.Hidden;\r
 import com.google.gwt.user.client.ui.HorizontalPanel;\r
@@ -59,7 +60,7 @@ public class FileUploadDialog extends DialogBox implements Updateable {
 \r
        protected int prgBarInterval = 1500;\r
 \r
-       protected ProgressBar progressBar;\r
+       private ProgressBar progressBar;\r
 \r
        protected RepeatingTimer repeater = new RepeatingTimer(this, prgBarInterval);\r
 \r
@@ -97,6 +98,11 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                // Create a panel to hold all of the form widgets.\r
                VerticalPanel panel = new VerticalPanel();\r
                form.setWidget(panel);\r
+               final HTML info = new HTML("You may select a file to upload. Install" +\r
+                               " <a href='http://gears.google.com/' target='_blank'>Google " +\r
+                               "Gears</a><br> for uploading multiple files simultaneously.");\r
+               info.addStyleName("gss-uploadNote");\r
+               panel.add(info);\r
                final Hidden date = new Hidden("Date", "");\r
                panel.add(date);\r
                final Hidden auth = new Hidden("Authorization", "");\r
@@ -214,8 +220,7 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                                        GSS.get().displayError(results);\r
                                }\r
                                progressBar.setProgress(100);\r
-                               repeater.finish();\r
-                               hide();\r
+                               cancelUpload();\r
                                GSS.get().showFileList(true);\r
                                GSS.get().getStatusPanel().updateStats();\r
                        }\r
@@ -241,16 +246,25 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                                prepareAndSubmit();\r
                                break;\r
                        case KeyboardListener.KEY_ESCAPE:\r
-                               repeater.finish();\r
-                               hide();\r
+                               cancelUpload();\r
                                break;\r
                }\r
 \r
                return true;\r
        }\r
 \r
+       /**\r
+        * Cancels the file upload.\r
+        */\r
+       private void cancelUpload() {\r
+               repeater.finish();\r
+               hide();\r
+       }\r
 \r
-       public void prepareAndSubmit(){\r
+       /**\r
+        * Make any last minute checks and start the upload.\r
+        */\r
+       public void prepareAndSubmit() {\r
                final String fname = getFilename(upload.getFilename());\r
                if (getFileForName(fname) == null) {\r
                        //we are going to create a file, so we check to see if there is a trashed file with the same name\r
@@ -436,7 +450,10 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                return filename + " " + i;\r
        }\r
 \r
-       protected void updateTrashedFile(String newName, FileResource trashedFile) {\r
+       /**\r
+        * Rename the conflicting trashed file with the supplied new name.\r
+        */\r
+       private void updateTrashedFile(String newName, FileResource trashedFile) {\r
                JSONObject json = new JSONObject();\r
                json.put("name", new JSONString(newName));\r
                PostCommand cf = new PostCommand(trashedFile.getUri() + "?update=", json.toString(), 200) {\r
@@ -448,21 +465,22 @@ public class FileUploadDialog extends DialogBox implements Updateable {
 \r
                        @Override\r
                        public void onError(Throwable t) {\r
+                               GSS app = GSS.get();\r
                                GWT.log("", t);\r
                                if (t instanceof RestException) {\r
                                        int statusCode = ((RestException) t).getHttpStatusCode();\r
                                        if (statusCode == 405)\r
-                                               GSS.get().displayError("You don't have the necessary permissions");\r
+                                               app.displayError("You don't have the necessary permissions");\r
                                        else if (statusCode == 404)\r
-                                               GSS.get().displayError("User in permissions does not exist");\r
+                                               app.displayError("User in permissions does not exist");\r
                                        else if (statusCode == 409)\r
-                                               GSS.get().displayError("A file with the same name already exists");\r
+                                               app.displayError("A file with the same name already exists");\r
                                        else if (statusCode == 413)\r
-                                               GSS.get().displayError("Your quota has been exceeded");\r
+                                               app.displayError("Your quota has been exceeded");\r
                                        else\r
-                                               GSS.get().displayError("Unable to modify file:" +((RestException)t).getHttpStatusText());\r
+                                               app.displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());\r
                                } else\r
-                                       GSS.get().displayError("System error modifying file:" + t.getMessage());\r
+                                       app.displayError("System error modifying file:" + t.getMessage());\r
                        }\r
 \r
                };\r
@@ -481,11 +499,8 @@ public class FileUploadDialog extends DialogBox implements Updateable {
         * Same as URL.encodeComponent, but also\r
         * encode apostrophe since browsers aren't consistent about it\r
         * (FF encodes, IE does not).\r
-        *\r
-        * @param decodedURLComponent\r
-        * @return\r
         */\r
-       protected String encodeComponent(String decodedURLComponent) {\r
+       private String encodeComponent(String decodedURLComponent) {\r
                String retv = URL.encodeComponent(decodedURLComponent);\r
                retv = retv.replaceAll("'", "%27");\r
                return retv;\r