commit f1aabd8999c734bfa6c43df49518bf7156ed4161
Author: Christos Stathis <chstath@ebs.gr>
Date:   Tue Jul 5 17:48:07 2011 +0300

    Implemented folder deletion (without refresh yet)

diff --git a/src/gr/grnet/pithos/web/client/DeleteFolderDialog.java b/src/gr/grnet/pithos/web/client/DeleteFolderDialog.java
index 9c0bf21..d930bbe 100644
--- a/src/gr/grnet/pithos/web/client/DeleteFolderDialog.java
+++ b/src/gr/grnet/pithos/web/client/DeleteFolderDialog.java
@@ -34,8 +34,14 @@
  */
 package gr.grnet.pithos.web.client;
 
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.event.dom.client.KeyDownEvent;
+import com.google.gwt.user.client.Event;
 import gr.grnet.pithos.web.client.MessagePanel.Images;
+import gr.grnet.pithos.web.client.foldertree.Folder;
+import gr.grnet.pithos.web.client.foldertree.Resource;
 import gr.grnet.pithos.web.client.rest.DeleteCommand;
+import gr.grnet.pithos.web.client.rest.DeleteRequest;
 import gr.grnet.pithos.web.client.rest.RestException;
 import gr.grnet.pithos.web.client.rest.resource.FolderResource;
 import gr.grnet.pithos.web.client.rest.resource.RestResource;
@@ -62,15 +68,19 @@ import com.google.gwt.user.client.ui.VerticalPanel;
  */
 public class DeleteFolderDialog extends DialogBox {
 
+    private GSS app;
+    private Folder folder;
+    
 	/**
 	 * The widget's constructor.
 	 * @param images the supplied images
 	 */
-	public DeleteFolderDialog(Images images) {
+	public DeleteFolderDialog(GSS app, Images images, Folder folder) {
+        this.app = app;
+        this.folder = folder;
 		// Set the dialog's caption.
 		setText("Confirmation");
 		setAnimationEnabled(true);
-		FolderResource folder = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();
 		// Create a VerticalPanel to contain the HTML label and the buttons.
 		VerticalPanel outer = new VerticalPanel();
 		HorizontalPanel buttons = new HorizontalPanel();
@@ -90,7 +100,6 @@ public class DeleteFolderDialog extends DialogBox {
 				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
@@ -101,7 +110,6 @@ public class DeleteFolderDialog extends DialogBox {
 				hide();
 			}
 		});
-		cancel.getElement().setId("confirmation.cancel");
 		buttons.add(cancel);
 		buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
 		buttons.setSpacing(8);
@@ -116,50 +124,29 @@ public class DeleteFolderDialog extends DialogBox {
 	/**
 	 * Generate an RPC request to delete a folder.
 	 *
-	 * @param userId the ID of the current user
 	 */
 	private void deleteFolder() {
-		RestResource folder = GSS.get().getTreeView().getSelection();
-		if (folder == null) {
-			GSS.get().displayError("No folder was selected");
-			return;
-		}
-		if(!(folder instanceof RestResourceWrapper))
-			return;
+        String prefix = folder.getPrefix();
+        String path = app.getApiPath() + app.getUsername() + "/" + folder.getContainer() + (prefix.length() == 0 ? "" : "/" + prefix);
+        DeleteRequest deleteFolder = new DeleteRequest(path) {
+            @Override
+            public void onSuccess(Resource result) {
 
-		DeleteCommand df = new DeleteCommand(folder.getUri()){
+            }
 
-			@Override
-			public void onComplete() {
-				FolderResource fres = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();
-				if((RestResourceWrapper) GSS.get().getTreeView().getSelection() instanceof TrashFolderResource)
-					GSS.get().getTreeView().updateTrashNode();
-				else
-					GSS.get().getTreeView().updateNodeChildrenForRemove(fres.getParentURI());
-				GSS.get().getTreeView().clearSelection();
-				GSS.get().showFileList(true);
-				
-				GSS.get().getStatusPanel().updateStats();
-			}
-
-			@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("Folder not found");
-					else
-						GSS.get().displayError("Unable to delete folder: "+((RestException)t).getHttpStatusText());
-				}
-				else
-					GSS.get().displayError("System error unable to delete folder: "+t.getMessage());
-			}
-		};
-
-		DeferredCommand.addCommand(df);
+            @Override
+            public void onError(Throwable t) {
+                GWT.log("", t);
+                if (t instanceof RestException) {
+                    int statusCode = ((RestException)t).getHttpStatusCode();
+                    app.displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText());
+                }
+                else
+                    GSS.get().displayError("System error unable to delete folder: " + t.getMessage());
+            }
+        };
+        deleteFolder.setHeader("X-Auth-Token", app.getToken());
+        Scheduler.get().scheduleDeferred(deleteFolder);
 	}
 
 	@Override
@@ -167,7 +154,7 @@ public class DeleteFolderDialog extends DialogBox {
 		super.onPreviewNativeEvent(preview);
 
 		NativeEvent evt = preview.getNativeEvent();
-		if (evt.getType().equals("keydown"))
+		if (evt.getType().equals(KeyDownEvent.getType().getName()))
 			// Use the popup's key preview hooks to close the dialog when either
 			// enter or escape is pressed.
 			switch (evt.getKeyCode()) {
diff --git a/src/gr/grnet/pithos/web/client/EditMenu.java b/src/gr/grnet/pithos/web/client/EditMenu.java
index 6688f70..9e4e2d4 100644
--- a/src/gr/grnet/pithos/web/client/EditMenu.java
+++ b/src/gr/grnet/pithos/web/client/EditMenu.java
@@ -226,7 +226,7 @@ public class EditMenu extends PopupPanel implements ClickHandler {
 		contextMenu	.addItem(moveToTrashItem)
 					.setVisible(cutcopyVisible);
 		
-		MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images));
+		MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, null, images));
 		deleteItem.getElement().setId("topMenu.edit.delete");
 		contextMenu	.addItem(deleteItem)
 					.setVisible(cutcopyVisible);
diff --git a/src/gr/grnet/pithos/web/client/FileContextMenu.java b/src/gr/grnet/pithos/web/client/FileContextMenu.java
index a01d220..8f91fbe 100644
--- a/src/gr/grnet/pithos/web/client/FileContextMenu.java
+++ b/src/gr/grnet/pithos/web/client/FileContextMenu.java
@@ -149,7 +149,7 @@ public class FileContextMenu extends PopupPanel {
 			MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(this));
 			contextMenu.addItem(restore);
 
-			MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images));
+			MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, null, images));
 			contextMenu.addItem(delete);
 		} else {
 			cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
@@ -164,7 +164,7 @@ public class FileContextMenu extends PopupPanel {
 			trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
             contextMenu.addItem(trashItem);
 
-			deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images));
+			deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, null, images));
             contextMenu.addItem(deleteItem);
 
 			sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
diff --git a/src/gr/grnet/pithos/web/client/FolderContextMenu.java b/src/gr/grnet/pithos/web/client/FolderContextMenu.java
index 4a77f38..aaee292 100644
--- a/src/gr/grnet/pithos/web/client/FolderContextMenu.java
+++ b/src/gr/grnet/pithos/web/client/FolderContextMenu.java
@@ -112,7 +112,7 @@ public class FolderContextMenu extends PopupPanel {
         MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
         contextMenu.addItem(moveToTrash);
 
-        MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
+        MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, folder, newImages));
         contextMenu.addItem(delete);
 
         MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
diff --git a/src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java b/src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java
index 63d24d2..0f026c9 100644
--- a/src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java
+++ b/src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java
@@ -256,7 +256,7 @@ public class FolderPropertiesDialog extends DialogBox {
 					app.displayError("System error creating folder:" + t.getMessage());
             }
         };
-        createFolder.setHeader("X-Auth-Token", "0000");
+        createFolder.setHeader("X-Auth-Token", app.getToken());
         createFolder.setHeader("Accept", "*/*");
         createFolder.setHeader("Content-Length", "0");
         createFolder.setHeader("Content-Type", "application/folder");
diff --git a/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java b/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java
index f286e9f..2c45ddd 100644
--- a/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java
+++ b/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java
@@ -38,6 +38,9 @@ import gr.grnet.pithos.web.client.DeleteFileDialog;
 import gr.grnet.pithos.web.client.DeleteFolderDialog;
 import gr.grnet.pithos.web.client.EditMenu.Images;
 import gr.grnet.pithos.web.client.GSS;
+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.resource.FileResource;
 import gr.grnet.pithos.web.client.rest.resource.GroupUserResource;
 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
@@ -57,13 +60,16 @@ public class DeleteCommand implements Command{
 	private PopupPanel containerPanel;
 	final Images newImages;
 
+    private Resource resource;
+
 	/**
 	 * @param _containerPanel
 	 * @param _newImages the images of all the possible delete dialogs
 	 */
-	public DeleteCommand( PopupPanel _containerPanel, final Images _newImages ){
+	public DeleteCommand( PopupPanel _containerPanel, Resource resource, final Images _newImages ){
 		containerPanel = _containerPanel;
-		newImages=_newImages;
+		newImages = _newImages;
+        this.resource = resource;
 	}
 
 	@Override
@@ -77,18 +83,12 @@ public class DeleteCommand implements Command{
 	 *
 	 */
 	void displayDelete() {
-		Object selection = GSS.get().getCurrentSelection();
-		if (selection == null)
-			return;
-		GWT.log("selection: " + selection.toString(), null);
-		if (selection instanceof RestResourceWrapper) {
-			DeleteFolderDialog dlg = new DeleteFolderDialog(newImages);
+		if (resource instanceof Folder) {
+			DeleteFolderDialog dlg = new DeleteFolderDialog(GSS.get(), newImages, (Folder) resource);
 			dlg.center();
-		} else if (selection instanceof FileResource || selection instanceof List) {
+		} else if (resource instanceof File) {
 			DeleteFileDialog dlg = new DeleteFileDialog(newImages);
 			dlg.center();
-		} else if (selection instanceof GroupUserResource) {
-			// TODO implement user deletion
 		}
     }
 }
diff --git a/src/gr/grnet/pithos/web/client/rest/DeleteRequest.java b/src/gr/grnet/pithos/web/client/rest/DeleteRequest.java
new file mode 100644
index 0000000..8082de9
--- /dev/null
+++ b/src/gr/grnet/pithos/web/client/rest/DeleteRequest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.rest;
+
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
+import com.google.gwt.http.client.Request;
+import com.google.gwt.http.client.RequestBuilder;
+import com.google.gwt.http.client.RequestException;
+import com.google.gwt.http.client.Response;
+import gr.grnet.pithos.web.client.foldertree.Resource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA. User: chstath Date: 7/5/11 Time: 5:29 PM To change this template use File | Settings | File
+ * Templates.
+ */
+public abstract class DeleteRequest implements ScheduledCommand {
+    private String path;
+
+    private Map<String, String> headers = new HashMap<String, String>();
+
+    public abstract void onSuccess(Resource result);
+
+    public abstract void onError(Throwable t);
+
+    public DeleteRequest(String path) {
+        this.path = path;
+    }
+
+    @Override
+    public void execute() {
+        RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, path);
+        for (String header : headers.keySet()) {
+            builder.setHeader(header, headers.get(header));
+        }
+        try {
+            builder.sendRequest("", new RestRequestCallback(path, Response.SC_NO_CONTENT) {
+                @Override
+                public void onSuccess(Resource object) {
+                    DeleteRequest.this.onSuccess(object);
+                }
+
+                @Override
+                public Resource deserialize(Response response) {
+                    return Resource.createFromResponse(Resource.class, response, null);
+                }
+
+                @Override
+                public void onError(Request request, Throwable throwable) {
+                    DeleteRequest.this.onError(throwable);
+                }
+            });
+        }
+        catch (RequestException e) {
+        }
+    }
+
+    public void setHeader(String header, String value) {
+        headers.put(header, value);
+    }
+}
diff --git a/src/gr/grnet/pithos/web/client/rest/PutRequest.java b/src/gr/grnet/pithos/web/client/rest/PutRequest.java
index b7ceb3a..ee50142 100644
--- a/src/gr/grnet/pithos/web/client/rest/PutRequest.java
+++ b/src/gr/grnet/pithos/web/client/rest/PutRequest.java
@@ -83,8 +83,6 @@ public abstract class PutRequest implements ScheduledCommand {
 
     private String path;
 
-    private String username;
-
     private Map<String, String> headers = new HashMap<String, String>();
 
     public abstract void onSuccess(Resource result);
