X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/587770261820e8b4f34a50db1304b028b9c668c7..49df7570ecab2c6e0693affcbf27e752199828e4:/web_client/src/gr/grnet/pithos/web/client/GSS.java diff --git a/web_client/src/gr/grnet/pithos/web/client/GSS.java b/web_client/src/gr/grnet/pithos/web/client/GSS.java index 762d99f..e952aa2 100644 --- a/web_client/src/gr/grnet/pithos/web/client/GSS.java +++ b/web_client/src/gr/grnet/pithos/web/client/GSS.java @@ -36,19 +36,26 @@ package gr.grnet.pithos.web.client; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.event.dom.client.ContextMenuEvent; -import com.google.gwt.event.dom.client.ContextMenuHandler; -import com.google.gwt.event.shared.GwtEvent; -import com.google.gwt.event.shared.GwtEvent.Type; +import com.google.gwt.http.client.Request; +import com.google.gwt.http.client.RequestBuilder; +import com.google.gwt.http.client.RequestCallback; +import com.google.gwt.http.client.RequestException; +import com.google.gwt.http.client.Response; +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONParser; +import com.google.gwt.json.client.JSONString; +import com.google.gwt.json.client.JSONValue; import com.google.gwt.view.client.SelectionChangeEvent; import com.google.gwt.view.client.SingleSelectionModel; -import gr.grnet.pithos.web.client.clipboard.Clipboard; import gr.grnet.pithos.web.client.commands.GetUserCommand; import gr.grnet.pithos.web.client.foldertree.AccountResource; import gr.grnet.pithos.web.client.foldertree.File; import gr.grnet.pithos.web.client.foldertree.Folder; import gr.grnet.pithos.web.client.foldertree.FolderTreeView; import gr.grnet.pithos.web.client.foldertree.FolderTreeViewModel; +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 gr.grnet.pithos.web.client.rest.resource.FileResource; @@ -77,7 +84,6 @@ import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.resources.client.ImageResource; import com.google.gwt.user.client.Cookies; -import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.History; import com.google.gwt.user.client.Window; @@ -120,6 +126,10 @@ public class GSS implements EntryPoint, ResizeHandler { return account; } + public void updateFolder(Folder f) { + folderTreeView.updateFolder(f); + } + /** * An aggregate image bundle that pulls together all the images for this * application into a single bundle. @@ -279,7 +289,7 @@ public class GSS implements EntryPoint, ResizeHandler { @Override public void onSelectionChange(SelectionChangeEvent event) { Folder f = folderTreeSelectionModel.getSelectedObject(); - showFiles(f); + updateFolder(f); } }); @@ -337,7 +347,7 @@ public class GSS implements EntryPoint, ResizeHandler { }); } - private void showFiles(Folder f) { + public void showFiles(Folder f) { inner.selectTab(0); Set files = f.getFiles(); Iterator iter = files.iterator(); @@ -796,4 +806,112 @@ public class GSS implements EntryPoint, ResizeHandler { } } + + public void deleteFolder(final Folder folder) { + String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + folder.getPrefix(); + RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path); + builder.setHeader("If-Modified-Since", "0"); + builder.setHeader("X-Auth-Token", getToken()); + try { + builder.sendRequest("", new RequestCallback() { + @Override + public void onResponseReceived(Request request, Response response) { + if (response.getStatusCode() == Response.SC_OK) { + JSONValue json = JSONParser.parseStrict(response.getText()); + JSONArray array = json.isArray(); + int i = 0; + if (array != null) { + deleteObject(folder, i, array); + } + } + } + + @Override + public void onError(Request request, Throwable exception) { + GSS.get().displayError("System error unable to delete folder: " + exception.getMessage()); + } + }); + } + catch (RequestException e) { + } + } + + public void deleteObject(final Folder folder, final int i, final JSONArray array) { + if (i < array.size()) { + JSONObject o = array.get(i).isObject(); + if (o != null && !o.containsKey("subdir")) { + JSONString name = o.get("name").isString(); + String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "/" + name.stringValue(); + DeleteRequest delete = new DeleteRequest(path) { + @Override + public void onSuccess(Resource result) { + deleteObject(folder, i + 1, array); + } + + @Override + public void onError(Throwable t) { + GWT.log("", t); + GSS.get().displayError("System error unable to delete folder: " + t.getMessage()); + } + }; + delete.setHeader("X-Auth-Token", getToken()); + Scheduler.get().scheduleDeferred(delete); + } + else { + String subdir = o.get("subdir").isString().stringValue(); + subdir = subdir.substring(0, subdir.length() - 1); + String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + subdir; + RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path); + builder.setHeader("If-Modified-Since", "0"); + builder.setHeader("X-Auth-Token", getToken()); + try { + builder.sendRequest("", new RequestCallback() { + @Override + public void onResponseReceived(Request request, Response response) { + if (response.getStatusCode() == Response.SC_OK) { + JSONValue json = JSONParser.parseStrict(response.getText()); + JSONArray array2 = json.isArray(); + if (array2 != null) { + int l = array.size(); + for (int j=0; j