First rough implementation of the file upload functionality using Google Gears. Multi...
authorPanagiotis Astithas <pastith@gmail.com>
Fri, 12 Jun 2009 15:02:21 +0000 (18:02 +0300)
committerPanagiotis Astithas <pastith@gmail.com>
Fri, 12 Jun 2009 15:02:21 +0000 (18:02 +0300)
13 files changed:
.classpath
build.xml
lib/gwt-gears.jar [new file with mode: 0644]
src/gr/ebs/gss/GSS.gwt.xml
src/gr/ebs/gss/client/ConfirmationDialog.java
src/gr/ebs/gss/client/FileContextMenu.java
src/gr/ebs/gss/client/FileMenu.java
src/gr/ebs/gss/client/FilePropertiesDialog.java
src/gr/ebs/gss/client/FileUploadDialog.java
src/gr/ebs/gss/client/FileUploadGearsDialog.java [new file with mode: 0644]
src/gr/ebs/gss/client/FolderContextMenu.java
src/gr/ebs/gss/client/MessagePanel.java
src/gr/ebs/gss/client/commands/UploadFileCommand.java

index c47e930..3452093 100644 (file)
@@ -24,5 +24,6 @@
                        <attribute name="javadoc_location" value="http://commons.apache.org/configuration/apidocs/"/>
                </attributes>
        </classpathentry>
+       <classpathentry kind="lib" path="lib/gwt-gears.jar"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index f68cf20..8963f14 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -96,6 +96,7 @@
                <pathelement location="${ear.lib.dir}/commons-lang.jar"/>
                <pathelement location="${junit.path}/junit.jar"/>
                <pathelement location="${basedir}/lib/gwt-dnd-2.5.6.jar"/>
+               <pathelement location="${basedir}/lib/gwt-gears.jar"/>
        </path>
 
        <target name="install" description="Installs the configuration files of the application server">
diff --git a/lib/gwt-gears.jar b/lib/gwt-gears.jar
new file mode 100644 (file)
index 0000000..8001532
Binary files /dev/null and b/lib/gwt-gears.jar differ
index 596e98d..4263f0e 100644 (file)
@@ -2,6 +2,9 @@
 
        <!-- Inherit the core Web Toolkit stuff.                  -->
        <inherits name='com.google.gwt.user.User' />
+       <!-- Inherit the default GWT style sheet -->
+       <!--  inherits name="com.google.gwt.user.theme.standard.Standard"/-->
+       <inherits name="com.google.gwt.gears.Gears"/>
        <inherits name='com.allen_sauer.gwt.dnd.gwt-dnd' />
        <inherits name="com.google.gwt.http.HTTP"/>
        <inherits name="com.google.gwt.json.JSON"/>
@@ -9,5 +12,9 @@
        <entry-point class='gr.ebs.gss.client.GSS' />
        <stylesheet src='gss.css' />
        <!-- <set-property name="user.agent" value="gecko" /> --> 
-         
+       <!-- Rebind the file upload dialog if Gears is installed -->
+       <replace-with class="gr.ebs.gss.client.FileUploadGearsDialog">
+               <when-type-is class="gr.ebs.gss.client.FileUploadDialog"/>
+               <when-property-is name="gears.installed" value="true"/>
+       </replace-with>   
 </module>
index 2c737b1..e87d688 100644 (file)
@@ -18,8 +18,6 @@
  */
 package gr.ebs.gss.client;
 
-import gr.ebs.gss.client.MessagePanel.Images;
-
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.ClickListener;
 import com.google.gwt.user.client.ui.DialogBox;
@@ -41,11 +39,10 @@ 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(Images images, String message, String buttonLabel) {
+       public ConfirmationDialog(String message, String buttonLabel) {
                // Set the dialog's caption.
                setText("Confirmation");
                setAnimationEnabled(true);
@@ -53,7 +50,7 @@ public abstract class ConfirmationDialog extends DialogBox {
                VerticalPanel outer = new VerticalPanel();
                HorizontalPanel buttons = new HorizontalPanel();
 
-               HTML text = new HTML("<table><tr><td rowspan='2'>" + images.warn().getHTML() +
+               HTML text = new HTML("<table><tr><td rowspan='2'>" + MessagePanel.images.warn().getHTML() +
                                        "</td><td>" + message + "</td></tr></table>");
                text.setStyleName("gss-warnMessage");
                outer.add(text);
index faa9696..5568625 100644 (file)
@@ -121,14 +121,14 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
                        contextMenu.addItem(pasteItem);
                        if (GSS.get().getFolders().getCurrent() != null)
                                if (GSS.get().getFolders().isFileItem(GSS.get().getFolders().getCurrent()))
-                                       contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, images));
+                                       contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
                                else if (GSS.get().getFolders().isMySharedItem(GSS.get().getFolders().getCurrent()) || GSS      .get()
                                                                                                                                                                                                                        .getFolders()
                                                                                                                                                                                                                        .isOthersSharedItem(GSS .get()
                                                                                                                                                                                                                                                                        .getFolders()
                                                                                                                                                                                                                                                                        .getCurrent()))
                                        if(GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource)
-                                               contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, images));
+                                               contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
                        contextMenu.addItem("<span>" + images.refresh().getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
                } else if (isTrash) {
                        contextMenu.addItem("<span>" + newImages.versions().getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(this));
@@ -147,7 +147,7 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
                        cutItem = new MenuItem("<span>" + newImages.cut().getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
                        copyItem = new MenuItem("<span>" + newImages.copy().getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
 
-                       updateItem = new MenuItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, images));
+                       updateItem = new MenuItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
 
                        trashItem = new MenuItem("<span>" + newImages.emptyTrash().getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
                        deleteItem = new MenuItem("<span>" + newImages.delete().getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images));
index 23aa254..636f411 100644 (file)
@@ -146,7 +146,7 @@ public class FileMenu extends PopupPanel implements ClickListener {
                boolean downloadVisible = GSS.get().getCurrentSelection() != null && GSS.get().getCurrentSelection() instanceof FileResource;\r
                boolean propertiesNotVisible = selectedItem != null && (folders.isTrash(selectedItem) || folders.isMyShares(selectedItem) || folders.isOthersShared(selectedItem) || selectedItem.getUserObject() instanceof GroupUserResource);\r
                contextMenu.addItem("<span>" + images.folderNew().getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));\r
-               contextMenu.addItem("<span>" + images.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, images));\r
+               contextMenu.addItem("<span>" + images.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));\r
                if (downloadVisible) {\r
                        String[] link = {"", ""};\r
                        createDownloadLink(link);\r
index bc62883..24ea140 100644 (file)
@@ -325,12 +325,14 @@ public class FilePropertiesDialog extends DialogBox {
                Button removeVersionsButton = new Button(images.delete().getHTML(), new ClickListener() {\r
 \r
                        public void onClick(Widget sender) {\r
-                               ConfirmationDialog confirm = new ConfirmationDialog(images,"Really remove all previous versions?","Remove"){\r
+                               ConfirmationDialog confirm = new ConfirmationDialog("Really " +\r
+                                               "remove all previous versions?", "Remove") {\r
 \r
+                                       @Override\r
                                        public void cancel() {\r
                                        }\r
 \r
-\r
+                                       @Override\r
                                        public void confirm() {\r
                                                FilePropertiesDialog.this.closeDialog();\r
                                                removeAllOldVersions();\r
@@ -364,6 +366,7 @@ public class FilePropertiesDialog extends DialogBox {
        private void updateTags() {\r
                GetCommand<TagsResource> tc = new GetCommand<TagsResource>(TagsResource.class, GSS.get().getCurrentUserResource().getTagsPath()) {\r
 \r
+                       @Override\r
                        public void onComplete() {\r
                                allTagsContent.clear();\r
                                TagsResource tagr = getResult();\r
@@ -465,10 +468,12 @@ public class FilePropertiesDialog extends DialogBox {
                }\r
                PostCommand cf = new PostCommand(file.getUri() + "?update=", jsonString, 200) {\r
 \r
+                       @Override\r
                        public void onComplete() {\r
                                GSS.get().getFileList().updateFileCache(true, false /* do not clear selected file*/);\r
                        }\r
 \r
+                       @Override\r
                        public void onError(Throwable t) {\r
                                GWT.log("", t);\r
                                if (t instanceof RestException) {\r
@@ -498,10 +503,12 @@ public class FilePropertiesDialog extends DialogBox {
                GWT.log(json.toString(), null);\r
                PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {\r
 \r
+                       @Override\r
                        public void onComplete() {\r
                                toggleVersioned(true);\r
                        }\r
 \r
+                       @Override\r
                        public void onError(Throwable t) {\r
                                GWT.log("", t);\r
                                if (t instanceof RestException) {\r
@@ -529,10 +536,12 @@ public class FilePropertiesDialog extends DialogBox {
                GWT.log(json.toString(), null);\r
                PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {\r
 \r
+                       @Override\r
                        public void onComplete() {\r
                                GSS.get().getFileList().updateFileCache(true, false /* do not clear selected file*/);\r
                        }\r
 \r
+                       @Override\r
                        public void onError(Throwable t) {\r
                                GWT.log("", t);\r
                                if (t instanceof RestException) {\r
index 6062bbd..044eb0e 100644 (file)
@@ -18,7 +18,6 @@
  */\r
 package gr.ebs.gss.client;\r
 \r
-import gr.ebs.gss.client.FileMenu.Images;\r
 import gr.ebs.gss.client.rest.GetCommand;\r
 import gr.ebs.gss.client.rest.PostCommand;\r
 import gr.ebs.gss.client.rest.RestCommand;\r
@@ -58,40 +57,35 @@ import com.google.gwt.user.client.ui.Widget;
  */\r
 public class FileUploadDialog extends DialogBox implements Updateable {\r
 \r
-       private int prgBarInterval = 1500;\r
+       protected int prgBarInterval = 1500;\r
 \r
-       private ProgressBar progressBar;\r
+       protected ProgressBar progressBar;\r
 \r
-       private RepeatingTimer repeater = new RepeatingTimer(this, prgBarInterval);\r
+       protected RepeatingTimer repeater = new RepeatingTimer(this, prgBarInterval);\r
 \r
        public static final boolean DONE = true;\r
 \r
        /**\r
         * The Form element that performs the file upload.\r
         */\r
-       final FormPanel form = new FormPanel();\r
+       private final FormPanel form = new FormPanel();\r
 \r
-       final FileUpload upload = new FileUpload();\r
+       private final FileUpload upload = new FileUpload();\r
 \r
-       final Label filenameLabel = new Label("");\r
+       protected final Label filenameLabel = new Label("");\r
 \r
-       private List<FileResource> files;\r
+       protected List<FileResource> files;\r
 \r
-       boolean cancelEvent = false;\r
+       protected boolean cancelEvent = false;\r
 \r
-       private String fileNameToUse;\r
+       protected String fileNameToUse;\r
 \r
-       final FolderResource folder;\r
-       final Images images;\r
+       protected FolderResource folder;\r
 \r
        /**\r
         * The widget's constructor.\r
-        * @param _images\r
-        * @param _files\r
         */\r
-       public FileUploadDialog(final Images _images, List<FileResource> _files) {\r
-               images = _images;\r
-               files = _files;\r
+       public FileUploadDialog() {\r
                // Set the dialog's caption.\r
                setText("File upload");\r
                setAnimationEnabled(true);\r
@@ -269,9 +263,9 @@ 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 " +\r
+                               ConfirmationDialog confirm = new ConfirmationDialog("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
+                                               "file  '" + fname + "' will be renamed automatically for you.", "Continue") {\r
 \r
                                        @Override\r
                                        public void cancel() {\r
@@ -289,8 +283,8 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                }\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 " +\r
-                                       "you want to update " + fname + "?", "Update"){\r
+                       ConfirmationDialog confirm = new ConfirmationDialog("Are you sure " +\r
+                                       "you want to update " + fname + "?", "Update") {\r
 \r
                                @Override\r
                                public void cancel() {\r
@@ -316,7 +310,7 @@ public class FileUploadDialog extends DialogBox implements Updateable {
         * @param name the potentially full path name of a file\r
         * @return the file name without extra path information\r
         */\r
-       private String getFilename(String name) {\r
+       protected String getFilename(String name) {\r
                int pathSepIndex = name.lastIndexOf("\\");\r
                if (pathSepIndex == -1) {\r
                        pathSepIndex = name.lastIndexOf("/");\r
@@ -412,14 +406,13 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                        @Override\r
                        public void onError(Throwable t) {\r
                                GWT.log("", t);\r
-\r
                        }\r
 \r
                };\r
                DeferredCommand.addCommand(eg);\r
        }\r
 \r
-       private String getBackupFilename(String filename) {\r
+       protected String getBackupFilename(String filename) {\r
                List<FileResource> filesInSameFolder = new ArrayList<FileResource>();\r
                for (FileResource deleted : folder.getFiles())\r
                        if (deleted.isDeleted())\r
@@ -443,7 +436,7 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                return filename + " " + i;\r
        }\r
 \r
-       private void updateTrashedFile(String newName, FileResource trashedFile) {\r
+       protected 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
@@ -476,7 +469,7 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                DeferredCommand.addCommand(cf);\r
        }\r
 \r
-       private FileResource getFileForName(String name){\r
+       protected FileResource getFileForName(String name){\r
                for (FileResource f : folder.getFiles())\r
                        if (!f.isDeleted() && f.getName().equals(name))\r
                                return f;\r
@@ -492,9 +485,18 @@ public class FileUploadDialog extends DialogBox implements Updateable {
         * @param decodedURLComponent\r
         * @return\r
         */\r
-       private String encodeComponent(String decodedURLComponent) {\r
+       protected String encodeComponent(String decodedURLComponent) {\r
                String retv = URL.encodeComponent(decodedURLComponent);\r
                retv = retv.replaceAll("'", "%27");\r
                return retv;\r
        }\r
+\r
+       /**\r
+        * Modify the files.\r
+        *\r
+        * @param newFiles the files to set\r
+        */\r
+       public void setFiles(List<FileResource> newFiles) {\r
+               files = newFiles;\r
+       }\r
 }\r
diff --git a/src/gr/ebs/gss/client/FileUploadGearsDialog.java b/src/gr/ebs/gss/client/FileUploadGearsDialog.java
new file mode 100644 (file)
index 0000000..ac2f86c
--- /dev/null
@@ -0,0 +1,313 @@
+/*\r
+ * Copyright 2009 Electronic Business Systems Ltd.\r
+ *\r
+ * This file is part of GSS.\r
+ *\r
+ * GSS is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * GSS is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with GSS.  If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package gr.ebs.gss.client;\r
+\r
+import gr.ebs.gss.client.rest.RestCommand;\r
+import gr.ebs.gss.client.rest.resource.FileResource;\r
+import gr.ebs.gss.client.rest.resource.FolderResource;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.List;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.gears.client.Factory;\r
+import com.google.gwt.gears.client.desktop.Desktop;\r
+import com.google.gwt.gears.client.desktop.File;\r
+import com.google.gwt.gears.client.desktop.OpenFilesHandler;\r
+import com.google.gwt.gears.client.httprequest.HttpRequest;\r
+import com.google.gwt.gears.client.httprequest.ProgressEvent;\r
+import com.google.gwt.gears.client.httprequest.ProgressHandler;\r
+import com.google.gwt.gears.client.httprequest.RequestCallback;\r
+import com.google.gwt.user.client.Command;\r
+import com.google.gwt.user.client.DeferredCommand;\r
+import com.google.gwt.user.client.ui.Button;\r
+import com.google.gwt.user.client.ui.ClickListener;\r
+import com.google.gwt.user.client.ui.Grid;\r
+import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
+import com.google.gwt.user.client.ui.HorizontalPanel;\r
+import com.google.gwt.user.client.ui.TextBox;\r
+import com.google.gwt.user.client.ui.VerticalPanel;\r
+import com.google.gwt.user.client.ui.Widget;\r
+\r
+/**\r
+ * The 'File upload' dialog box implementation with Google Gears support.\r
+ */\r
+public class FileUploadGearsDialog extends FileUploadDialog implements Updateable {\r
+\r
+       private final Factory factory = Factory.getInstance();\r
+\r
+       private List<File> selectedFiles = new ArrayList<File>();\r
+\r
+       private TextBox selected;\r
+\r
+       /**\r
+        * The widget's constructor.\r
+        */\r
+       public FileUploadGearsDialog() {\r
+               // Set the dialog's caption.\r
+               setText("File upload");\r
+               setAnimationEnabled(true);\r
+               // Create a panel to hold all of the dialog widgets.\r
+               VerticalPanel panel = new VerticalPanel();\r
+               // Add an informative label with the folder name.\r
+               Object selection = GSS.get().getFolders().getCurrent().getUserObject();\r
+               folder = (FolderResource) selection;\r
+               filenameLabel.setText("");\r
+               filenameLabel.setVisible(false);\r
+               filenameLabel.setStyleName("props-labels");\r
+\r
+               final Button browse = new Button("Browse...");\r
+\r
+               selected = new TextBox();\r
+               selected.setEnabled(false);\r
+\r
+               HorizontalPanel fileUploadPanel = new HorizontalPanel();\r
+               fileUploadPanel.add(filenameLabel);\r
+               fileUploadPanel.add(selected);\r
+               fileUploadPanel.add(browse);\r
+\r
+               Grid generalTable = new Grid(2, 2);\r
+               generalTable.setText(0, 0, "Folder");\r
+               generalTable.setText(1, 0, "File");\r
+               generalTable.setText(0, 1, folder.getName());\r
+               generalTable.setWidget(1, 1, fileUploadPanel);\r
+               generalTable.getCellFormatter().setStyleName(0, 0, "props-labels");\r
+               generalTable.getCellFormatter().setStyleName(1, 0, "props-labels");\r
+               generalTable.getCellFormatter().setStyleName(0, 1, "props-values");\r
+               generalTable.getCellFormatter().setStyleName(1, 1, "props-values");\r
+               generalTable.setCellSpacing(4);\r
+\r
+               panel.add(generalTable);\r
+\r
+               // Create a panel to hold the buttons.\r
+               HorizontalPanel buttons = new HorizontalPanel();\r
+\r
+               // Create the 'upload' button, along with a listener that submits the\r
+               // form.\r
+               final Button submit = new Button("Upload");\r
+               submit.addClickListener(new ClickListener() {\r
+\r
+                       public void onClick(Widget sender) {\r
+                               GSS app = GSS.get();\r
+                               if (selectedFiles.size() == 0) {\r
+                                       app.displayError("You must select a file!");\r
+                                       hide();\r
+                                       return;\r
+                               }\r
+                               for(File file: selectedFiles)\r
+                                       if (!canContinue(file)) {\r
+                                               app.displayError("The specified file name already exists in this folder");\r
+                                               hide();\r
+                                               return;\r
+                                       }\r
+                               submit.setEnabled(false);\r
+                               browse.setVisible(false);\r
+                               prepareAndSubmit();\r
+                       }\r
+               });\r
+               submit.setEnabled(false);\r
+               buttons.add(submit);\r
+               buttons.setCellHorizontalAlignment(submit, HasHorizontalAlignment.ALIGN_CENTER);\r
+               // Create the 'Cancel' button, along with a listener that hides the\r
+               // dialog when the button is clicked.\r
+               Button cancel = new Button("Cancel", new ClickListener() {\r
+\r
+                       public void onClick(Widget sender) {\r
+                               hide();\r
+                       }\r
+               });\r
+               buttons.add(cancel);\r
+               buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
+               buttons.setSpacing(8);\r
+               buttons.addStyleName("gss-DialogBox");\r
+\r
+               browse.addClickListener(new ClickListener() {\r
+                       public void onClick(Widget sender) {\r
+                               Desktop desktop = factory.createDesktop();\r
+                               desktop.openFiles(new OpenFilesHandler() {\r
+\r
+                                       public void onOpenFiles(OpenFilesEvent event) {\r
+                                               selectedFiles.addAll(Arrays.asList(event.getFiles()));\r
+                                               selected.setText(selectedFiles.get(0).getName());\r
+                                               submit.setEnabled(true);\r
+                                       }\r
+                               });\r
+                       }\r
+               });\r
+\r
+               panel.add(buttons);\r
+               progressBar = new ProgressBar(50, ProgressBar.SHOW_TIME_REMAINING);\r
+               panel.add(progressBar);\r
+               progressBar.setVisible(false);\r
+               panel.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);\r
+               panel.setCellHorizontalAlignment(progressBar, HasHorizontalAlignment.ALIGN_CENTER);\r
+               panel.addStyleName("gss-DialogBox");\r
+               addStyleName("gss-DialogBox");\r
+               setWidget(panel);\r
+       }\r
+\r
+       /**\r
+        * Check whether the specified file name exists in the selected folder.\r
+        */\r
+       private boolean canContinue(File file) {\r
+               String fileName = getFilename(file.getName());\r
+               if (getFileForName(fileName) == null)\r
+                       // For file creation, check to see if the file already exists.\r
+                       for (FileResource fileRes : files)\r
+                               if (!fileRes.isDeleted() && fileRes.getName().equals(fileName))\r
+                                       return false;\r
+               return true;\r
+       }\r
+\r
+       @Override\r
+       public void prepareAndSubmit(){\r
+               final String fname = getFilename(selectedFiles.get(0).getName());\r
+               if (getFileForName(fname) == null) {\r
+                       // We are going to create a file, so we check to see if there is a\r
+                       // trashed file with the same name.\r
+                       FileResource same = null;\r
+                       for (FileResource fres : folder.getFiles())\r
+                               if (fres.isDeleted() && fres.getName().equals(fname))\r
+                                       same = fres;\r
+                       if (same == null)\r
+                               uploadFiles();\r
+                       else {\r
+                               final FileResource sameFile = same;\r
+                               GWT.log("Same deleted file", null);\r
+                               ConfirmationDialog confirm = new ConfirmationDialog("A file " +\r
+                                               "with the same name exists in the trash. If you " +\r
+                                               "continue,<br/>the trashed file  '" + fname +\r
+                                               "' will be renamed automatically for you.", "Continue") {\r
+\r
+                                       @Override\r
+                                       public void cancel() {\r
+                                               FileUploadGearsDialog.this.hide();\r
+                                       }\r
+\r
+                                       @Override\r
+                                       public void confirm() {\r
+                                               updateTrashedFile(getBackupFilename(fname), sameFile);\r
+                                       }\r
+\r
+                               };\r
+                               confirm.center();\r
+                       }\r
+               }\r
+               else {\r
+                       // We are going to update an existing file, so show a confirmation dialog.\r
+                       ConfirmationDialog confirm = new ConfirmationDialog("Are you sure " +\r
+                                       "you want to update " + fname + "?", "Update"){\r
+\r
+                               @Override\r
+                               public void cancel() {\r
+                                       FileUploadGearsDialog.this.hide();\r
+                               }\r
+\r
+                               @Override\r
+                               public void confirm() {\r
+                                       uploadFiles();\r
+                               }\r
+\r
+                       };\r
+                       confirm.center();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Schedule the PUT requests to upload the files.\r
+        */\r
+       private void uploadFiles() {\r
+               for (final File file: selectedFiles)\r
+                       DeferredCommand.addCommand(new Command() {\r
+                               public void execute() {\r
+                                       doPut(file);\r
+                               }\r
+                       });\r
+       }\r
+\r
+       /**\r
+        * Perform the HTTP PUT requests to upload the specified file.\r
+        */\r
+       protected void doPut(final File file) {\r
+               GSS app = GSS.get();\r
+               HttpRequest request = factory.createHttpRequest();\r
+               String method = "PUT";\r
+\r
+               fileNameToUse = getFilename(file.getName());\r
+               selected.setVisible(false);\r
+               filenameLabel.setText(fileNameToUse);\r
+               filenameLabel.setVisible(true);\r
+               progressBar.setVisible(true);\r
+\r
+               String path;\r
+               FileResource selectedResource = getFileForName(fileNameToUse);\r
+               if (selectedResource == null ) {\r
+                       // We are going to create a file.\r
+                       path = folder.getUri();\r
+                       if (!path.endsWith("/"))\r
+                               path = path + "/";\r
+                       path = path + encodeComponent(fileNameToUse);\r
+               } else\r
+                       path = selectedResource.getUri();\r
+\r
+               String token = app.getToken();\r
+               String resource = path.substring(app.getApiPath().length()-1, path.length());\r
+               String date = RestCommand.getDate();\r
+               String sig = RestCommand.calculateSig(method, date, resource, RestCommand.base64decode(token));\r
+               request.open(method, path);\r
+               request.setRequestHeader("X-GSS-Date", date);\r
+               request.setRequestHeader("Authorization", app.getCurrentUserResource().getUsername() + " " + sig);\r
+               request.setRequestHeader("Accept", "application/json; charset=utf-8");\r
+               request.setCallback(new RequestCallback() {\r
+                       public void onResponseReceived(HttpRequest req) {\r
+                               switch(req.getStatus()) {\r
+                                       case 201: // Created falls through to updated.\r
+                                       case 204:\r
+                                               selectedFiles.remove(file);\r
+                                               finish();\r
+                                               break;\r
+                                       case 403:\r
+                                               SessionExpiredDialog dlg = new SessionExpiredDialog();\r
+                                               dlg.center();\r
+                                               break;\r
+                                       default:\r
+                                               DisplayHelper.log(req.getStatus() + ":" + req.getStatusText());\r
+                               }\r
+                       }\r
+               });\r
+               request.getUpload().setProgressHandler(new ProgressHandler() {\r
+                       public void onProgress(ProgressEvent event) {\r
+                               double pcnt = (double) event.getLoaded() / event.getTotal();\r
+                               progressBar.setProgress((int) Math.floor(pcnt * 100));\r
+                       }\r
+               });\r
+               request.send(file.getBlob());\r
+       }\r
+\r
+       /**\r
+        * Perform the final actions after the files are uploaded.\r
+        */\r
+       private void finish() {\r
+               if (!selectedFiles.isEmpty()) return;\r
+               hide();\r
+               GSS.get().showFileList(true);\r
+               GSS.get().getStatusPanel().updateStats();\r
+       }\r
+}\r
index 247fe24..e61114c 100644 (file)
@@ -87,7 +87,7 @@ public class FolderContextMenu extends PopupPanel {
                        }
                        else if(folders.isFileItem(selectedItem)){
                                contextMenu.addItem("<span>" + newImages.folderNew().getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
-                               contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, images));
+                               contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
                                boolean notRootFolder = !folders.getRootItem().equals(selectedItem);
                                if (notRootFolder) {
                                        // do not show the copy & cut option for the user's root folder
@@ -106,7 +106,7 @@ public class FolderContextMenu extends PopupPanel {
                        }
                        else if(!folders.isMyShares(selectedItem) && folders.isMySharedItem(selectedItem)){
                                contextMenu.addItem("<span>" + newImages.folderNew().getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
-                               contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, images));
+                               contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
                                contextMenu.addItem("<span>" + newImages.cut().getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
                                contextMenu.addItem("<span>" + newImages.copy().getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
                                contextMenu.addItem(pasteItem);
@@ -117,7 +117,7 @@ public class FolderContextMenu extends PopupPanel {
                        }
                        else if(!folders.isOthersShared(selectedItem) && folders.isOthersSharedItem(selectedItem) && !(GSS.get().getCurrentSelection() instanceof OtherUserResource)){
                                contextMenu.addItem("<span>" + newImages.folderNew().getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
-                               contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, images));
+                               contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
                                contextMenu.addItem("<span>" + newImages.copy().getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
                                contextMenu.addItem(pasteItem);
                                contextMenu.addItem("<span>" + images.refresh().getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
index 3a058ad..4bce80e 100644 (file)
@@ -55,7 +55,7 @@ public class MessagePanel extends Composite {
        /**\r
         * The widget's images.\r
         */\r
-       private Images images;\r
+       public static Images images;\r
 \r
        /**\r
         * The system message to be displayed.\r
index de3619f..0a7db54 100644 (file)
@@ -20,7 +20,6 @@ package gr.ebs.gss.client.commands;
 
 import gr.ebs.gss.client.FileUploadDialog;
 import gr.ebs.gss.client.GSS;
-import gr.ebs.gss.client.FileMenu.Images;
 import gr.ebs.gss.client.rest.GetCommand;
 import gr.ebs.gss.client.rest.resource.FileResource;
 import gr.ebs.gss.client.rest.resource.FolderResource;
@@ -28,6 +27,7 @@ import gr.ebs.gss.client.rest.resource.FolderResource;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.DeferredCommand;
 import com.google.gwt.user.client.IncrementalCommand;
@@ -42,12 +42,9 @@ import com.google.gwt.user.client.ui.TreeItem;
 public class UploadFileCommand implements Command {
 
        private PopupPanel containerPanel;
-       final Images newImages;
-       List<FileResource> files;
-       boolean monitorCall = false;
+       private List<FileResource> files;
 
-       public UploadFileCommand(PopupPanel _containerPanel, final Images images) {
-               newImages = images;
+       public UploadFileCommand(PopupPanel _containerPanel) {
                containerPanel = _containerPanel;
        }
 
@@ -59,7 +56,7 @@ public class UploadFileCommand implements Command {
        /**
         * Display the 'new file' dialog for uploading a new file to the system.
         */
-       void displayNewFile() {
+       private void displayNewFile() {
                TreeItem currentFolder = GSS.get().getFolders().getCurrent();
                if (currentFolder == null) {
                        GSS.get().displayError("You have to select the parent folder first");
@@ -71,7 +68,8 @@ public class UploadFileCommand implements Command {
                        public boolean execute() {
                                boolean res = canContinue();
                                if (res) {
-                                       FileUploadDialog dlg = new FileUploadDialog(newImages, files);
+                                       FileUploadDialog dlg = GWT.create(FileUploadDialog.class);
+                                       dlg.setFiles(files);
                                        dlg.center();
                                        return false;
                                }