X-Git-Url: https://code.grnet.gr/git/pithos-web-client/blobdiff_plain/633669253249bdd90fc1dd0f78bfcdcfb674c320..904447e47113602d196ffc436f2b068c923aaeba:/src/gr/grnet/pithos/web/client/DeleteFileDialog.java diff --git a/src/gr/grnet/pithos/web/client/DeleteFileDialog.java b/src/gr/grnet/pithos/web/client/DeleteFileDialog.java index d781b90..9b67a53 100644 --- a/src/gr/grnet/pithos/web/client/DeleteFileDialog.java +++ b/src/gr/grnet/pithos/web/client/DeleteFileDialog.java @@ -34,13 +34,14 @@ */ package gr.grnet.pithos.web.client; +import com.google.gwt.core.client.Scheduler; import gr.grnet.pithos.web.client.MessagePanel.Images; -import gr.grnet.pithos.web.client.rest.DeleteCommand; -import gr.grnet.pithos.web.client.rest.MultipleDeleteCommand; +import gr.grnet.pithos.web.client.foldertree.File; +import gr.grnet.pithos.web.client.foldertree.Resource; +import gr.grnet.pithos.web.client.rest.DeleteRequest; import gr.grnet.pithos.web.client.rest.RestException; -import gr.grnet.pithos.web.client.rest.resource.FileResource; -import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import com.google.gwt.core.client.GWT; @@ -48,9 +49,11 @@ import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.KeyCodes; -import com.google.gwt.user.client.DeferredCommand; +import com.google.gwt.http.client.Response; +import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Event.NativePreviewEvent; import com.google.gwt.user.client.ui.AbstractImagePrototype; +import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.DialogBox; import com.google.gwt.user.client.ui.HTML; @@ -63,141 +66,110 @@ import com.google.gwt.user.client.ui.VerticalPanel; */ public class DeleteFileDialog extends DialogBox { + private List files; + + protected Pithos app; + /** * The widget's constructor. * * @param images the supplied images */ - public DeleteFileDialog(Images images) { + public DeleteFileDialog(Pithos _app, Images images, List _files) { + app = _app; + files = _files; + Anchor close = new Anchor(); + close.addStyleName("close"); + close.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + hide(); + } + }); // Set the dialog's caption. setText("Confirmation"); setAnimationEnabled(true); - Object selection = GSS.get().getCurrentSelection(); + setGlassEnabled(true); + setStyleName("pithos-DialogBox"); // Create a VerticalPanel to contain the label and the buttons. VerticalPanel outer = new VerticalPanel(); - HorizontalPanel buttons = new HorizontalPanel(); + outer.add(close); + + VerticalPanel inner = new VerticalPanel(); + inner.addStyleName("inner"); HTML text; - if (selection instanceof FileResource) - text = new HTML("
" + AbstractImagePrototype.create(images.warn()).getHTML() + "" + "Are you sure you want to permanently delete file '" + ((FileResource) selection).getName() + "'?
"); + if (files.size() == 1) + text = new HTML("
" + AbstractImagePrototype.create(images.warn()).getHTML() + "" + "Are you sure you want to permanently delete file '" + files.get(0).getName() + "'?
"); else text = new HTML("
" + AbstractImagePrototype.create(images.warn()).getHTML() + "" + "Are you sure you want to permanently delete the selected files?
"); text.setStyleName("pithos-warnMessage"); - outer.add(text); + inner.add(text); // Create the 'Delete' button, along with a listener that hides the dialog // when the button is clicked and deletes the file. Button ok = new Button("Delete", new ClickHandler() { @Override - public void onClick(ClickEvent event) { - deleteFile(); + public void onClick(@SuppressWarnings("unused") ClickEvent event) { + deleteFiles(); hide(); } }); - ok.getElement().setId("confirmation.ok"); - buttons.add(ok); - buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); - // Create the 'Cancel' button, along with a listener that hides the - // dialog when the button is clicked. - Button cancel = new Button("Cancel", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - hide(); - } - }); - cancel.getElement().setId("confirmation.cancel"); - buttons.add(cancel); - buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); - buttons.setSpacing(8); - buttons.setStyleName("pithos-warnMessage"); - outer.setStyleName("pithos-warnMessage"); - outer.add(buttons); - outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER); - outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); + ok.addStyleName("button"); + inner.add(ok); + inner.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER); + outer.add(inner); + outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); setWidget(outer); } /** * Generate an RPC request to delete a file. - * - * @param userId the ID of the current user */ - private void deleteFile() { - Object selection = GSS.get().getCurrentSelection(); - if (selection == null) { - GSS.get().displayError("No file was selected"); - return; - } - if (selection instanceof FileResource) { - FileResource file = (FileResource) selection; - - DeleteCommand df = new DeleteCommand(file.getUri()){ + protected void deleteFiles() { + Iterator iter = files.iterator(); + deleteFile(iter); + } + + protected void deleteFile(final Iterator iter) { + if (iter.hasNext()) { + File f = iter.next(); + String path = f.getUri(); + DeleteRequest deleteFile = new DeleteRequest(app.getApiPath(), f.getOwner(), path) { + @Override + public void onSuccess(@SuppressWarnings("unused") Resource result) { + deleteFile(iter); + } + + @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 unable to delete file: "+t.getMessage()); + } @Override - public void onComplete() { - GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection()); - GSS.get().getStatusPanel().updateStats(); + protected void onUnauthorized(Response response) { + app.sessionExpired(); } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - if(t instanceof RestException){ - int statusCode = ((RestException)t).getHttpStatusCode(); - if(statusCode == 405) - GSS.get().displayError("You don't have the necessary permissions"); - else if(statusCode == 404) - GSS.get().displayError("File not found"); - else - GSS.get().displayError("Unable to delete file: "+((RestException)t).getHttpStatusText()); - } - else - GSS.get().displayError("System error unable to delete file: "+t.getMessage()); - } - }; - - DeferredCommand.addCommand(df); - } - else if(selection instanceof List){ - List files = (List) selection; - List fileIds = new ArrayList(); - for(FileResource f : files) - fileIds.add(f.getUri()); - - MultipleDeleteCommand ed = new MultipleDeleteCommand(fileIds.toArray(new String[0])){ - + }; + deleteFile.setHeader("X-Auth-Token", app.getToken()); + Scheduler.get().scheduleDeferred(deleteFile); + } + else { + app.updateFolder(files.get(0).getParent(), true, new Command() { + @Override - public void onComplete() { - GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection()); + public void execute() { + app.updateStatistics(); } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection()); - } - - @Override - public void onError(String path, Throwable t) { - GWT.log("", t); - if(t instanceof RestException){ - int statusCode = ((RestException)t).getHttpStatusCode(); - if(statusCode == 405) - GSS.get().displayError("You don't have the necessary permissions"); - else if(statusCode == 404) - GSS.get().displayError("File not found"); - else - GSS.get().displayError("Unable to delete file:"+((RestException)t).getHttpStatusText()); - } - else - GSS.get().displayError("System error unable to delete file:"+t.getMessage()); - - } - }; - - DeferredCommand.addCommand(ed); - } - } + }); + } + } @Override protected void onPreviewNativeEvent(NativePreviewEvent preview) { @@ -210,7 +182,7 @@ public class DeleteFileDialog extends DialogBox { switch (evt.getKeyCode()) { case KeyCodes.KEY_ENTER: hide(); - deleteFile(); + deleteFiles(); break; case KeyCodes.KEY_ESCAPE: hide();