/*
- * 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 java.util.Iterator;
-
import gr.grnet.pithos.web.client.Pithos;
import gr.grnet.pithos.web.client.foldertree.File;
import gr.grnet.pithos.web.client.foldertree.Folder;
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;
if (containerPanel != null)
containerPanel.hide();
- final Folder trash = app.getAccount().getTrash();
- if (trash != null) {
- Iterator<File> iter = trash.getFiles().iterator();
- deleteFile(iter, new Command() {
-
- @Override
- public void execute() {
- Iterator<Folder> iter2 = trash.getSubfolders().iterator();
- deleteSubfolder(iter2, new Command() {
-
- @Override
- public void execute() {
- app.updateTrash(true, new Command() {
-
- @Override
- public void execute() {
- app.updateStatistics();
- }
- });
- }
- });
- }
- });
- }
- }
-
- protected void deleteSubfolder(final Iterator<Folder> iter2, final Command callback) {
- if (iter2.hasNext()) {
- final Folder f = iter2.next();
- GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwner(), "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()), f) {
-
- @Override
- public void onSuccess(final Folder _f) {
- Iterator<File> iter3 = _f.getFiles().iterator();
- deleteFile(iter3, new Command() {
-
- @Override
- public void execute() {
- Iterator<Folder> iter4 = _f.getSubfolders().iterator();
- deleteSubfolder(iter4, new Command() {
-
- @Override
- public void execute() {
- String path = _f.getUri();
- DeleteRequest deleteF = new DeleteRequest(app.getApiPath(), _f.getOwner(), path) {
-
- @Override
- public void onSuccess(@SuppressWarnings("unused") Resource result) {
- deleteSubfolder(iter2, callback);
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- if (t instanceof RestException) {
- app.displayError("Unable to delete file:" + ((RestException) t).getHttpStatusText());
- }
- else
- app.displayError("System error deleting file:" + t.getMessage());
- }
-
- @Override
- protected void onUnauthorized(Response response) {
- app.sessionExpired();
- }
- };
- deleteF.setHeader("X-Auth-Token", app.getToken());
- Scheduler.get().scheduleDeferred(deleteF);
- }
- });
- }
- });
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- if (t instanceof RestException) {
- app.displayError("Unable to get folder: " + ((RestException) t).getHttpStatusText());
- }
- else
- app.displayError("System error getting folder: " + t.getMessage());
- }
-
- @Override
- protected void onUnauthorized(Response response) {
- app.sessionExpired();
- }
- };
- getFolder.setHeader("X-Auth-Token", app.getToken());
- Scheduler.get().scheduleDeferred(getFolder);
- }
- else {
- if (callback != null)
- callback.execute();
- }
- }
-
- void deleteFile(final Iterator<File> iter, final Command callback) {
- if (iter.hasNext()) {
- File f = iter.next();
- String path = f.getUri();
- DeleteRequest deleteF = new DeleteRequest(app.getApiPath(), f.getOwner(), path) {
-
- @Override
- public void onSuccess(@SuppressWarnings("unused") Resource result) {
- deleteFile(iter, callback);
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- if (t instanceof RestException) {
- app.displayError("Unable to delete file:" + ((RestException) t).getHttpStatusText());
- }
- else
- app.displayError("System error deleting file:" + t.getMessage());
- }
-
- @Override
- protected void onUnauthorized(Response response) {
- app.sessionExpired();
- }
- };
- deleteF.setHeader("X-Auth-Token", app.getToken());
- Scheduler.get().scheduleDeferred(deleteF);
- }
- else {
- if (callback != null)
- callback.execute();
- }
+ app.emptyTrash();
}
}