fixed tree update when moving a node to trash with no children but trashed ones,...
[pithos] / src / gr / ebs / gss / client / FileUploadDialog.java
index 6855e9d..0165141 100644 (file)
@@ -24,6 +24,7 @@ import gr.ebs.gss.client.rest.RestCommand;
 import gr.ebs.gss.client.rest.RestException;
 import gr.ebs.gss.client.rest.resource.FileResource;
 import gr.ebs.gss.client.rest.resource.FolderResource;
+import gr.ebs.gss.client.rest.resource.RestResourceWrapper;
 import gr.ebs.gss.client.rest.resource.UploadStatusResource;
 
 import java.util.ArrayList;
@@ -38,12 +39,16 @@ import com.google.gwt.http.client.URL;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONString;
 import com.google.gwt.user.client.DeferredCommand;
-import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.Event.NativePreviewEvent;
+import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.DialogBox;
 import com.google.gwt.user.client.ui.FileUpload;
 import com.google.gwt.user.client.ui.FormPanel;
+import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
+import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler;
+import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
+import com.google.gwt.user.client.ui.FormPanel.SubmitHandler;
 import com.google.gwt.user.client.ui.Grid;
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
@@ -51,10 +56,6 @@ import com.google.gwt.user.client.ui.Hidden;
 import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.VerticalPanel;
-import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
-import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler;
-import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
-import com.google.gwt.user.client.ui.FormPanel.SubmitHandler;
 
 /**
  * The 'File upload' dialog box implementation.
@@ -86,9 +87,6 @@ public class FileUploadDialog extends DialogBox implements Updateable {
 
        protected FolderResource folder;
 
-       private String fileName;
-
-
        /**
         * The widget's constructor.
         */
@@ -114,8 +112,8 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                final Hidden auth = new Hidden("Authorization", "");
                panel.add(auth);
                // Add an informative label with the folder name.
-               Object selection = GSS.get().getFolders().getCurrent().getUserObject();
-               folder = (FolderResource) selection;
+               Object selection = GSS.get().getTreeView().getSelection();
+               folder = ((RestResourceWrapper) selection).getResource();
                upload.setName("file");
                filenameLabel.setText("");
                filenameLabel.setVisible(false);
@@ -233,7 +231,7 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                                }
                                progressBar.setProgress(100);
                                cancelUpload();
-                               GSS.get().showFileList(true);
+                               GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection());
                                GSS.get().getStatusPanel().updateStats();
 
                        }
@@ -283,36 +281,12 @@ public class FileUploadDialog extends DialogBox implements Updateable {
         * Make any last minute checks and start the upload.
         */
        public void prepareAndSubmit() {
-               fileName = getFilename(upload.getFilename());
-               GSS.get();
-               if(!GSS.isValidResourceName(fileName)){
-                       GWT.log("The upload attemp contains bad elements like slashes.", null);
-                       ConfirmationDialog confirmBox = new ConfirmationDialog("The file you are going to upload" +
-                                       " contains slashes inside its name or the filename should be different than '.' or '..'" +
-                                       " In case you want to continue you should note that the illegal character" +
-                                       " will be automatically replaced with '-' otherwise please press Cancel to rename the file name " +
-                                       " on your own before continuing the upload.", "Illegal Characters found") {
-
-                                       @Override
-                                       public void cancel() {
-                                               FileUploadDialog.this.hide();
-                                       }
-
-                                       @Override
-                                       public void confirm() {
-                                               String name = fileName.replace("/","-");
-                                               fileName = name;
-                                       }
-
-                               };
-                               confirmBox.center();
-
-               }
-               if (getFileForName(fileName) == null) {
+               final String fname = getFilename(upload.getFilename());
+               if (getFileForName(fname) == null) {
                        //we are going to create a file, so we check to see if there is a trashed file with the same name
                        FileResource same = null;
                        for (FileResource fres : folder.getFiles())
-                               if (fres.isDeleted() && fres.getName().equals(fileName))
+                               if (fres.isDeleted() && fres.getName().equals(fname))
                                        same = fres;
                        if (same == null)
                                form.submit();
@@ -321,7 +295,7 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                                GWT.log("Same deleted file", null);
                                ConfirmationDialog confirm = new ConfirmationDialog("A file with " +
                                                "the same name exists in the trash. If you continue,<br/>the trashed " +
-                                               "file  '" + fileName + "' will be renamed automatically for you.", "Continue") {
+                                               "file  '" + fname + "' will be renamed automatically for you.", "Continue") {
 
                                        @Override
                                        public void cancel() {
@@ -330,7 +304,7 @@ public class FileUploadDialog extends DialogBox implements Updateable {
 
                                        @Override
                                        public void confirm() {
-                                               updateTrashedFile(getBackupFilename(fileName), sameFile);
+                                               updateTrashedFile(getBackupFilename(fname), sameFile);
                                        }
 
                                };
@@ -340,7 +314,7 @@ public class FileUploadDialog extends DialogBox implements Updateable {
                else {
                        // We are going to update an existing file, so show a confirmation dialog.
                        ConfirmationDialog confirm = new ConfirmationDialog("Are you sure " +
-                                       "you want to update " + fileName + "?", "Update") {
+                                       "you want to update " + fname + "?", "Update") {
 
                                @Override
                                public void cancel() {