Implemented move folder
[pithos] / web_client / src / gr / grnet / pithos / web / client / DeleteFolderDialog.java
index 2c4f7d0..2cdb475 100644 (file)
@@ -1,26 +1,61 @@
 /*\r
- * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.\r
+ * Copyright 2011 GRNET S.A. All rights reserved.\r
  *\r
- * This file is part of GSS.\r
+ * Redistribution and use in source and binary forms, with or\r
+ * without modification, are permitted provided that the following\r
+ * conditions are met:\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
+ *   1. Redistributions of source code must retain the above\r
+ *      copyright notice, this list of conditions and the following\r
+ *      disclaimer.\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
+ *   2. Redistributions in binary form must reproduce the above\r
+ *      copyright notice, this list of conditions and the following\r
+ *      disclaimer in the documentation and/or other materials\r
+ *      provided with the distribution.\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
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR\r
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED\r
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * The views and conclusions contained in the software and\r
+ * documentation are those of the authors and should not be\r
+ * interpreted as representing official policies, either expressed\r
+ * or implied, of GRNET S.A.\r
  */\r
 package gr.grnet.pithos.web.client;\r
 \r
+import com.google.gwt.core.client.Scheduler;\r
+import com.google.gwt.event.dom.client.KeyDownEvent;\r
+import com.google.gwt.http.client.Request;\r
+import com.google.gwt.http.client.RequestBuilder;\r
+import com.google.gwt.http.client.RequestCallback;\r
+import com.google.gwt.http.client.RequestException;\r
+import com.google.gwt.http.client.Response;\r
+import com.google.gwt.json.client.JSONArray;\r
+import com.google.gwt.json.client.JSONObject;\r
+import com.google.gwt.json.client.JSONParser;\r
+import com.google.gwt.json.client.JSONString;\r
+import com.google.gwt.json.client.JSONValue;\r
+import com.google.gwt.user.client.Event;\r
 import gr.grnet.pithos.web.client.MessagePanel.Images;\r
+import gr.grnet.pithos.web.client.foldertree.File;\r
+import gr.grnet.pithos.web.client.foldertree.Folder;\r
+import gr.grnet.pithos.web.client.foldertree.Resource;\r
 import gr.grnet.pithos.web.client.rest.DeleteCommand;\r
+import gr.grnet.pithos.web.client.rest.DeleteRequest;\r
+import gr.grnet.pithos.web.client.rest.GetRequest;\r
 import gr.grnet.pithos.web.client.rest.RestException;\r
+import gr.grnet.pithos.web.client.rest.RestRequestCallback;\r
 import gr.grnet.pithos.web.client.rest.resource.FolderResource;\r
 import gr.grnet.pithos.web.client.rest.resource.RestResource;\r
 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;\r
@@ -40,21 +75,27 @@ import com.google.gwt.user.client.ui.HTML;
 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.VerticalPanel;\r
+import java.util.Iterator;\r
+import java.util.List;\r
 \r
 /**\r
  * The 'delete folder' dialog box.\r
  */\r
 public class DeleteFolderDialog extends DialogBox {\r
 \r
+    private GSS app;\r
+    private Folder folder;\r
+    \r
        /**\r
         * The widget's constructor.\r
         * @param images the supplied images\r
         */\r
-       public DeleteFolderDialog(Images images) {\r
+       public DeleteFolderDialog(GSS _app, Images images, Folder _folder) {\r
+        this.app = _app;\r
+        this.folder = _folder;\r
                // Set the dialog's caption.\r
                setText("Confirmation");\r
                setAnimationEnabled(true);\r
-               FolderResource folder = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();\r
                // Create a VerticalPanel to contain the HTML label and the buttons.\r
                VerticalPanel outer = new VerticalPanel();\r
                HorizontalPanel buttons = new HorizontalPanel();\r
@@ -70,11 +111,10 @@ public class DeleteFolderDialog extends DialogBox {
                Button ok = new Button("Delete", new ClickHandler() {\r
                        @Override\r
                        public void onClick(ClickEvent event) {\r
-                               deleteFolder();\r
+                               app.deleteFolder(folder);\r
                                hide();\r
                        }\r
                });\r
-               ok.getElement().setId("confirmation.ok");\r
                buttons.add(ok);\r
                buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);\r
                // Create the 'Cancel' button, along with a listener that hides the\r
@@ -85,7 +125,6 @@ public class DeleteFolderDialog extends DialogBox {
                                hide();\r
                        }\r
                });\r
-               cancel.getElement().setId("confirmation.cancel");\r
                buttons.add(cancel);\r
                buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
                buttons.setSpacing(8);\r
@@ -97,67 +136,18 @@ public class DeleteFolderDialog extends DialogBox {
                setWidget(outer);\r
        }\r
 \r
-       /**\r
-        * Generate an RPC request to delete a folder.\r
-        *\r
-        * @param userId the ID of the current user\r
-        */\r
-       private void deleteFolder() {\r
-               RestResource folder = GSS.get().getTreeView().getSelection();\r
-               if (folder == null) {\r
-                       GSS.get().displayError("No folder was selected");\r
-                       return;\r
-               }\r
-               if(!(folder instanceof RestResourceWrapper))\r
-                       return;\r
-\r
-               DeleteCommand df = new DeleteCommand(folder.getUri()){\r
-\r
-                       @Override\r
-                       public void onComplete() {\r
-                               FolderResource fres = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();\r
-                               if((RestResourceWrapper) GSS.get().getTreeView().getSelection() instanceof TrashFolderResource)\r
-                                       GSS.get().getTreeView().updateTrashNode();\r
-                               else\r
-                                       GSS.get().getTreeView().updateNodeChildrenForRemove(fres.getParentURI());\r
-                               GSS.get().getTreeView().clearSelection();\r
-                               GSS.get().showFileList(true);\r
-                               \r
-                               GSS.get().getStatusPanel().updateStats();\r
-                       }\r
-\r
-                       @Override\r
-                       public void onError(Throwable t) {\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
-                                       else if(statusCode == 404)\r
-                                               GSS.get().displayError("Folder not found");\r
-                                       else\r
-                                               GSS.get().displayError("Unable to delete folder: "+((RestException)t).getHttpStatusText());\r
-                               }\r
-                               else\r
-                                       GSS.get().displayError("System error unable to delete folder: "+t.getMessage());\r
-                       }\r
-               };\r
-\r
-               DeferredCommand.addCommand(df);\r
-       }\r
-\r
        @Override\r
        protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
                super.onPreviewNativeEvent(preview);\r
 \r
                NativeEvent evt = preview.getNativeEvent();\r
-               if (evt.getType().equals("keydown"))\r
+               if (evt.getType().equals(KeyDownEvent.getType().getName()))\r
                        // Use the popup's key preview hooks to close the dialog when either\r
                        // enter or escape is pressed.\r
                        switch (evt.getKeyCode()) {\r
                                case KeyCodes.KEY_ENTER:\r
                                        hide();\r
-                                       deleteFolder();\r
+                                       app.deleteFolder(folder);\r
                                        break;\r
                                case KeyCodes.KEY_ESCAPE:\r
                                        hide();\r