Implemeted empty trash with the new API call
[pithos-web-client] / src / gr / grnet / pithos / web / client / commands / EmptyTrashCommand.java
index 27a60e8..71fbff0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
 package gr.grnet.pithos.web.client.commands;
 
 import gr.grnet.pithos.web.client.Pithos;
-import gr.grnet.pithos.web.client.rest.DeleteCommand;
+import gr.grnet.pithos.web.client.foldertree.File;
+import gr.grnet.pithos.web.client.foldertree.Folder;
+import gr.grnet.pithos.web.client.foldertree.Resource;
+import gr.grnet.pithos.web.client.rest.DeleteRequest;
+import gr.grnet.pithos.web.client.rest.GetRequest;
 import gr.grnet.pithos.web.client.rest.RestException;
 
+import java.util.Iterator;
+
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.http.client.Response;
+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.PopupPanel;
 
 
@@ -50,7 +58,7 @@ import com.google.gwt.user.client.ui.PopupPanel;
 public class EmptyTrashCommand implements Command{
        private PopupPanel containerPanel;
 
-    private Pithos app;
+    Pithos app;
 
        public EmptyTrashCommand(Pithos _app, PopupPanel _containerPanel){
         app = _app;
@@ -59,32 +67,9 @@ public class EmptyTrashCommand implements Command{
 
        @Override
        public void execute() {
-               containerPanel.hide();
-               DeleteCommand df = new DeleteCommand(app, app.getTreeView().getTrash().getUri()){
-
-                       @Override
-                       public void onComplete() {
-                               app.getTreeView().updateTrashNode();
-                               app.showFileList(true);
-                       }
-
-                       @Override
-                       public void onError(Throwable t) {
-                               GWT.log("", t);
-                               if(t instanceof RestException){
-                                       int statusCode = ((RestException)t).getHttpStatusCode();
-                                       if(statusCode == 405)
-                                               app.displayError("You don't have the necessary permissions");
-                                       else if(statusCode == 404)
-                                               app.displayError("Resource does not exist");
-                                       else
-                                               app.displayError("Unable to empty trash:"+((RestException)t).getHttpStatusText());
-                               }
-                               else
-                                       app.displayError("System error emptying trash:"+t.getMessage());
-                       }
-               };
-               DeferredCommand.addCommand(df);
+               if (containerPanel != null)
+                       containerPanel.hide();
+               
+               app.emptyTrash();
        }
-
 }