Clarify the confirmation message, fix warnings and cleanup code a bit. Also, generali...
authorpastith <devnull@localhost>
Thu, 19 Mar 2009 11:48:06 +0000 (11:48 +0000)
committerpastith <devnull@localhost>
Thu, 19 Mar 2009 11:48:06 +0000 (11:48 +0000)
gss/src/gr/ebs/gss/client/ConfirmationDialog.java
gss/src/gr/ebs/gss/client/FileUploadDialog.java

index 185f1ea..2c737b1 100644 (file)
@@ -32,34 +32,35 @@ import com.google.gwt.user.client.ui.Widget;
 
 
 /**
- * @author kman
+ * A dialog for requesting confirmation from the user.
  *
+ * @author kman
  */
 public abstract class ConfirmationDialog extends DialogBox {
 
        /**
         * The widget's constructor.
+        *
         * @param images the supplied images
+        * @param message the message to display
+        * @param buttonLabel the label of the confirmation button
         */
-       public ConfirmationDialog(final Images images, String message) {
-               // Use this opportunity to set the dialog's caption.
-               setText("Update File Warning");
+       public ConfirmationDialog(Images images, String message, String buttonLabel) {
+               // Set the dialog's caption.
+               setText("Confirmation");
                setAnimationEnabled(true);
-               // Create a VerticalPanel to contain the 'about' label and the 'OK'
-               // button.
-               final VerticalPanel outer = new VerticalPanel();
-               final HorizontalPanel buttons = new HorizontalPanel();
+               // Create a VerticalPanel to contain the label and the buttons.
+               VerticalPanel outer = new VerticalPanel();
+               HorizontalPanel buttons = new HorizontalPanel();
 
-               // Create the 'about' text and set a style name so we can style it with
-               // CSS.
-               final HTML text = new HTML("<table><tr><td rowspan='2'>" + images.warn().getHTML() +
+               HTML text = new HTML("<table><tr><td rowspan='2'>" + images.warn().getHTML() +
                                        "</td><td>" + message + "</td></tr></table>");
                text.setStyleName("gss-warnMessage");
                outer.add(text);
 
-               // Create the 'Quit' button, along with a listener that hides the dialog
-               // when the button is clicked and quits the application.
-               final Button ok = new Button("Update File", new ClickListener() {
+               // Create the 'Update' button, along with a listener that hides the dialog
+               // when the button is clicked and renames the file.
+               Button ok = new Button(buttonLabel, new ClickListener() {
 
                        public void onClick(Widget sender) {
                                confirm();
@@ -69,9 +70,8 @@ public abstract class ConfirmationDialog extends DialogBox {
                buttons.add(ok);
                buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
                // Create the 'Cancel' button, along with a listener that hides the
-               // dialog
-               // when the button is clicked.
-               final Button cancel = new Button("Cancel", new ClickListener() {
+               // dialog when the button is clicked.
+               Button cancel = new Button("Cancel", new ClickListener() {
 
                        public void onClick(Widget sender) {
                                hide();
@@ -89,13 +89,7 @@ public abstract class ConfirmationDialog extends DialogBox {
                setWidget(outer);
        }
 
-
-
-       /*
-        * (non-Javadoc)
-        *
-        * @see com.google.gwt.user.client.ui.PopupPanel#onKeyDownPreview(char, int)
-        */
+       @Override
        public boolean onKeyDownPreview(final char key, final int modifiers) {
                // Use the popup's key preview hooks to close the dialog when either
                // enter or escape is pressed.
@@ -109,7 +103,6 @@ public abstract class ConfirmationDialog extends DialogBox {
                                cancel();
                                break;
                }
-
                return true;
        }
 
index 417fe7c..da9f7f9 100644 (file)
@@ -83,6 +83,7 @@ public class FileUploadDialog extends DialogBox implements Updateable {
 \r
        /**\r
         * The widget's constructor.\r
+        * @param _images\r
         * @param _files\r
         */\r
        public FileUploadDialog(final Images _images, List<FileResource> _files) {\r
@@ -259,34 +260,35 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                        else {\r
                                final FileResource sameFile = same;\r
                                GWT.log("Same deleted file", null);\r
-                               ConfirmationDialog confirm = new ConfirmationDialog(images,"A file with the same name exists in trash. <br/>if you continue trashed file  "+fname+" will be renamed?"){\r
-\r
+                               ConfirmationDialog confirm = new ConfirmationDialog(images, "A file with " +\r
+                                               "the same name exists in the trash. If you continue,<br/>the trashed " +\r
+                                               "file  '" + fname + "' will be renamed automatically for you.", "Continue"){\r
 \r
+                                       @Override\r
                                        public void cancel() {\r
                                                FileUploadDialog.this.hide();\r
                                        }\r
 \r
-\r
+                                       @Override\r
                                        public void confirm() {\r
                                                updateTrashedFile(getBackupFilename(fname), sameFile);\r
                                        }\r
 \r
                                };\r
                                confirm.center();\r
-\r
-\r
                        }\r
                }\r
                else {\r
-                       //we are going to update an existing file so show a confirmation dialog\r
-                       ConfirmationDialog confirm = new ConfirmationDialog(images,"Are you sure you want to update "+fname+"?"){\r
-\r
+                       // We are going to update an existing file, so show a confirmation dialog.\r
+                       ConfirmationDialog confirm = new ConfirmationDialog(images, "Are you sure " +\r
+                                       "you want to update " + fname + "?", "Update"){\r
 \r
+                               @Override\r
                                public void cancel() {\r
                                        FileUploadDialog.this.hide();\r
                                }\r
 \r
-\r
+                               @Override\r
                                public void confirm() {\r
                                        form.submit();\r
                                }\r
@@ -295,6 +297,7 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                        confirm.center();\r
                }\r
        }\r
+\r
        /**\r
         * Returns the file name from a potential full path argument. Apparently IE\r
         * insists on sending the full path name of a file when uploading, forcing\r
@@ -314,13 +317,17 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                return name.substring(pathSepIndex + 1);\r
        }\r
 \r
-       // Check whether the file name exists in selected folder\r
+       /**\r
+        * Check whether the file name exists in selected folder.\r
+        *\r
+        * @return\r
+        */\r
        private boolean canContinue() {\r
                if (files == null)\r
                        return false;\r
                String fileName = getFilename(upload.getFilename());\r
                if (getFileForName(fileName) == null) {\r
-                       // file creation so check to see if file already exists\r
+                       // For file creation, check to see if the file already exists.\r
                        GWT.log("filename to upload:" + fileName, null);\r
                        for (FileResource dto : files) {\r
                                GWT.log("Check:" + dto.getName() + "/" + fileName, null);\r
@@ -330,17 +337,6 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                                }\r
                        }\r
                }\r
-\r
-               /*\r
-               Object selection = GSS.get().getFolders().getCurrent().getUserObject();\r
-\r
-               FolderResource folder = (FolderResource) selection;\r
-               for (FolderResource dto : folder.get())\r
-                       if (dto.getName().equals(fileName)) {\r
-                               cancelEvent = true;\r
-                               return true;\r
-                       }\r
-                       */\r
                return true;\r
        }\r
 \r
@@ -398,11 +394,13 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                apath = apath + URL.encodeComponent(fileNameToUse) + "?progress=" + fileNameToUse;\r
                ExecuteGet eg = new ExecuteGet<UploadStatusResource>(UploadStatusResource.class, apath, false) {\r
 \r
+                       @Override\r
                        public void onComplete() {\r
                                UploadStatusResource res = getResult();\r
                                progressBar.setProgress(res.percent());\r
                        }\r
 \r
+                       @Override\r
                        public void onError(Throwable t) {\r
                                GWT.log("", t);\r
 \r
@@ -410,7 +408,6 @@ public class FileUploadDialog extends DialogBox implements Updateable {
 \r
                };\r
                DeferredCommand.addCommand(eg);\r
-\r
        }\r
 \r
        private String getBackupFilename(String filename) {\r
@@ -419,7 +416,6 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                        if (deleted.isDeleted())\r
                                filesInSameFolder.add(deleted);\r
                int i = 1;\r
-               String filenameToCheck = filename;\r
                for (FileResource same : filesInSameFolder)\r
                        if (same.getName().startsWith(filename)) {\r
                                String toCheck = same.getName().substring(filename.length(), same.getName().length());\r
@@ -428,7 +424,7 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                                        try {\r
                                                test = Integer.valueOf(toCheck.replace(" ", ""));\r
                                        } catch (NumberFormatException e) {\r
-                                               //do nothing since string is not a number\r
+                                               // Do nothing since string is not a number.\r
                                        }\r
                                        if (test >= i)\r
                                                i = test + 1;\r
@@ -443,10 +439,12 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                json.put("name", new JSONString(newName));\r
                ExecutePost cf = new ExecutePost(trashedFile.getPath() + "?update=", json.toString(), 200) {\r
 \r
+                       @Override\r
                        public void onComplete() {\r
                                form.submit();\r
                        }\r
 \r
+                       @Override\r
                        public void onError(Throwable t) {\r
                                GWT.log("", t);\r
                                if (t instanceof RestException) {\r
@@ -474,6 +472,5 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                        if (!f.isDeleted() && f.getName().equals(name))\r
                                return f;\r
                return null;\r
-\r
        }\r
 }\r