Removed all static references to the Pithos class
[pithos-web-client] / src / gr / grnet / pithos / web / client / DnDFolderPopupMenu.java
index 9b22f37..65052e1 100644 (file)
@@ -1,5 +1,36 @@
 /*
- *  Copyright (c) 2011 Greek Research and Technology Network
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
  */
 package gr.grnet.pithos.web.client;
 
@@ -8,7 +39,6 @@ import gr.grnet.pithos.web.client.foldertree.Folder;
 import gr.grnet.pithos.web.client.rest.MultiplePostCommand;
 import gr.grnet.pithos.web.client.rest.PostCommand;
 import gr.grnet.pithos.web.client.rest.RestException;
-import gr.grnet.pithos.web.client.rest.resource.FileResource;
 import gr.grnet.pithos.web.client.rest.resource.FolderResource;
 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
 
@@ -16,7 +46,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import com.google.gwt.core.client.GWT;
-import com.google.gwt.http.client.URL;
 import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.DeferredCommand;
 import com.google.gwt.user.client.ui.AbstractImagePrototype;
@@ -25,10 +54,13 @@ import com.google.gwt.user.client.ui.PopupPanel;
 
 public class DnDFolderPopupMenu extends PopupPanel {
 
-    public DnDFolderPopupMenu(final CellTreeView.Images newImages, final Folder target, final Object toCopy) {
+    private Pithos app;
+
+    public DnDFolderPopupMenu(Pithos _app, final CellTreeView.Images newImages, final Folder target, final Object toCopy) {
         // The popup's constructor's argument is a boolean specifying that it
         // auto-close itself when the user clicks outside of it.
         super(true);
+        app = _app;
         setAnimationEnabled(true);
         // A dummy command that we will execute from unimplemented leaves.
         final Command cancelCmd = new Command() {
@@ -40,7 +72,7 @@ public class DnDFolderPopupMenu extends PopupPanel {
         };
 
         final MenuBar contextMenu = new MenuBar(true);
-        final CellTreeView folders = GSS.get().getTreeView();
+        final CellTreeView folders = app.getTreeView();
 
         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Move</span>", true, new Command() {
 
@@ -50,7 +82,7 @@ public class DnDFolderPopupMenu extends PopupPanel {
                     moveFolder(target, (Folder) toCopy);
                 }
                 else if (toCopy instanceof List) {
-                    List<File> files = GSS.get().getFileList().getSelectedFiles();
+                    List<File> files = app.getFileList().getSelectedFiles();
                     moveFiles(target, files);
                 }
                 hide();
@@ -64,7 +96,7 @@ public class DnDFolderPopupMenu extends PopupPanel {
                 if (toCopy instanceof Folder)
                     copyFolder(target, (Folder) toCopy);
                 else if (toCopy instanceof List) {
-                    List<File> files = GSS.get().getFileList().getSelectedFiles();
+                    List<File> files = app.getFileList().getSelectedFiles();
                     copyFiles(target, files);
                 }
                 hide();
@@ -80,7 +112,7 @@ public class DnDFolderPopupMenu extends PopupPanel {
                     trashFolder(((RestResourceWrapper) toCopy).getResource());
                 }
                 else if (toCopy instanceof List) {
-                    List<File> files = GSS.get().getFileList().getSelectedFiles();
+                    List<File> files = app.getFileList().getSelectedFiles();
                     trashFiles(files);
                 }
                 hide();
@@ -99,8 +131,8 @@ public class DnDFolderPopupMenu extends PopupPanel {
 //
 //            @Override
 //            public void onComplete() {
-//                GSS.get().getTreeView().updateNodeChildren(new RestResourceWrapper(target));
-//                GSS.get().getStatusPanel().updateStats();
+//                app.getTreeView().updateNodeChildren(new RestResourceWrapper(target));
+//                app.getStatusPanel().updateStats();
 //            }
 //
 //            @Override
@@ -109,17 +141,17 @@ public class DnDFolderPopupMenu extends PopupPanel {
 //                if (t instanceof RestException) {
 //                    int statusCode = ((RestException) t).getHttpStatusCode();
 //                    if (statusCode == 405)
-//                        GSS.get().displayError("You don't have the necessary permissions");
+//                        app.displayError("You don't have the necessary permissions");
 //
 //                    else if (statusCode == 409)
-//                        GSS.get().displayError("A folder with the same name already exists");
+//                        app.displayError("A folder with the same name already exists");
 //                    else if (statusCode == 413)
-//                        GSS.get().displayError("Your quota has been exceeded");
+//                        app.displayError("Your quota has been exceeded");
 //                    else
-//                        GSS.get().displayError("Unable to copy folder:" + ((RestException) t).getHttpStatusText());
+//                        app.displayError("Unable to copy folder:" + ((RestException) t).getHttpStatusText());
 //                }
 //                else
-//                    GSS.get().displayError("System error copying folder:" + t.getMessage());
+//                    app.displayError("System error copying folder:" + t.getMessage());
 //            }
 //        };
 //        DeferredCommand.addCommand(cf);
@@ -135,9 +167,9 @@ public class DnDFolderPopupMenu extends PopupPanel {
 //            @Override
 //            public void onComplete() {
 //                GWT.log("[MOVE]" + target.getUri() + "   " + toCopy.getParentURI());
-//                GSS.get().getTreeView().updateNodeChildren(new RestResourceWrapper(target));
-//                GSS.get().getTreeView().updateNodeChildrenForRemove(toCopy.getParentURI());
-//                GSS.get().getStatusPanel().updateStats();
+//                app.getTreeView().updateNodeChildren(new RestResourceWrapper(target));
+//                app.getTreeView().updateNodeChildrenForRemove(toCopy.getParentURI());
+//                app.getStatusPanel().updateStats();
 //            }
 //
 //            @Override
@@ -146,17 +178,17 @@ public class DnDFolderPopupMenu extends PopupPanel {
 //                if (t instanceof RestException) {
 //                    int statusCode = ((RestException) t).getHttpStatusCode();
 //                    if (statusCode == 405)
-//                        GSS.get().displayError("You don't have the necessary permissions");
+//                        app.displayError("You don't have the necessary permissions");
 //
 //                    else if (statusCode == 409)
-//                        GSS.get().displayError("A folder with the same name already exists");
+//                        app.displayError("A folder with the same name already exists");
 //                    else if (statusCode == 413)
-//                        GSS.get().displayError("Your quota has been exceeded");
+//                        app.displayError("Your quota has been exceeded");
 //                    else
-//                        GSS.get().displayError("Unable to copy folder:" + ((RestException) t).getHttpStatusText());
+//                        app.displayError("Unable to copy folder:" + ((RestException) t).getHttpStatusText());
 //                }
 //                else
-//                    GSS.get().displayError("System error copying folder:" + t.getMessage());
+//                    app.displayError("System error copying folder:" + t.getMessage());
 //            }
 //        };
 //        DeferredCommand.addCommand(cf);
@@ -187,17 +219,17 @@ public class DnDFolderPopupMenu extends PopupPanel {
     }
 
     private void trashFolder(final FolderResource folder) {
-        PostCommand tot = new PostCommand(folder.getUri() + "?trash=", "", 200) {
+        PostCommand tot = new PostCommand(app, folder.getUri() + "?trash=", "", 200) {
 
             @Override
             public void onComplete() {
-                GSS.get().getTreeView().updateNodeChildrenForRemove(folder.getParentURI());
-                GSS.get().getTreeView().updateTrashNode();
+                app.getTreeView().updateNodeChildrenForRemove(folder.getParentURI());
+                app.getTreeView().updateTrashNode();
                 /*for(TreeItem item : items)
-                        GSS.get().getFolders().updateFolder((DnDTreeItem) item);
-                GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
+                        app.getFolders().updateFolder((DnDTreeItem) item);
+                app.getFolders().update(app.getFolders().getTrashItem());
 
-                GSS.get().showFileList(true);
+                app.showFileList(true);
                 */
             }
 
@@ -207,14 +239,14 @@ public class DnDFolderPopupMenu extends PopupPanel {
                 if (t instanceof RestException) {
                     int statusCode = ((RestException) t).getHttpStatusCode();
                     if (statusCode == 405)
-                        GSS.get().displayError("You don't have the necessary permissions");
+                        app.displayError("You don't have the necessary permissions");
                     else if (statusCode == 404)
-                        GSS.get().displayError("Folder does not exist");
+                        app.displayError("Folder does not exist");
                     else
-                        GSS.get().displayError("Unable to trash folder:" + ((RestException) t).getHttpStatusText());
+                        app.displayError("Unable to trash folder:" + ((RestException) t).getHttpStatusText());
                 }
                 else
-                    GSS.get().displayError("System error trashing folder:" + t.getMessage());
+                    app.displayError("System error trashing folder:" + t.getMessage());
             }
         };
         DeferredCommand.addCommand(tot);
@@ -224,11 +256,11 @@ public class DnDFolderPopupMenu extends PopupPanel {
         final List<String> fileIds = new ArrayList<String>();
         for (File f : files)
             fileIds.add(f.getUri() + "?trash=");
-        MultiplePostCommand tot = new MultiplePostCommand(fileIds.toArray(new String[0]), 200) {
+        MultiplePostCommand tot = new MultiplePostCommand(app, fileIds.toArray(new String[0]), 200) {
 
             @Override
             public void onComplete() {
-                GSS.get().showFileList(true);
+                app.showFileList(true);
             }
 
             @Override
@@ -237,14 +269,14 @@ public class DnDFolderPopupMenu extends PopupPanel {
                 if (t instanceof RestException) {
                     int statusCode = ((RestException) t).getHttpStatusCode();
                     if (statusCode == 405)
-                        GSS.get().displayError("You don't have the necessary permissions");
+                        app.displayError("You don't have the necessary permissions");
                     else if (statusCode == 404)
-                        GSS.get().displayError("File does not exist");
+                        app.displayError("File does not exist");
                     else
-                        GSS.get().displayError("Unable to trash file:" + ((RestException) t).getHttpStatusText());
+                        app.displayError("Unable to trash file:" + ((RestException) t).getHttpStatusText());
                 }
                 else
-                    GSS.get().displayError("System error trashing file:" + t.getMessage());
+                    app.displayError("System error trashing file:" + t.getMessage());
             }
         };
         DeferredCommand.addCommand(tot);
@@ -252,11 +284,11 @@ public class DnDFolderPopupMenu extends PopupPanel {
 
     private void executeCopyOrMoveFiles(final int index, final List<String> paths) {
         if (index >= paths.size()) {
-            GSS.get().showFileList(true);
-            GSS.get().getStatusPanel().updateStats();
+            app.showFileList(true);
+            app.getStatusPanel().updateStats();
             return;
         }
-        PostCommand cf = new PostCommand(paths.get(index), "", 200) {
+        PostCommand cf = new PostCommand(app, paths.get(index), "", 200) {
 
             @Override
             public void onComplete() {
@@ -269,18 +301,18 @@ public class DnDFolderPopupMenu extends PopupPanel {
                 if (t instanceof RestException) {
                     int statusCode = ((RestException) t).getHttpStatusCode();
                     if (statusCode == 405)
-                        GSS.get().displayError("You don't have the necessary permissions");
+                        app.displayError("You don't have the necessary permissions");
                     else if (statusCode == 404)
-                        GSS.get().displayError("File not found");
+                        app.displayError("File not found");
                     else if (statusCode == 409)
-                        GSS.get().displayError("A file with the same name already exists");
+                        app.displayError("A file with the same name already exists");
                     else if (statusCode == 413)
-                        GSS.get().displayError("Your quota has been exceeded");
+                        app.displayError("Your quota has been exceeded");
                     else
-                        GSS.get().displayError("Unable to copy file:" + ((RestException) t).getHttpStatusText());
+                        app.displayError("Unable to copy file:" + ((RestException) t).getHttpStatusText());
                 }
                 else
-                    GSS.get().displayError("System error copying file:" + t.getMessage());
+                    app.displayError("System error copying file:" + t.getMessage());
             }
         };
         DeferredCommand.addCommand(cf);