Revision 7529fcd7

b/web_client/src/gr/grnet/pithos/web/client/EditMenu.java
216 216
		pasteItem.getElement().setId("topMenu.edit.paste");
217 217
		if (GSS.get().getClipboard().getItem() != null)
218 218
    		contextMenu.addItem(pasteItem);
219
		MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
219
		MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(GSS.get(), this, null));
220 220
		moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash");
221 221
		contextMenu	.addItem(moveToTrashItem)
222 222
					.setVisible(cutcopyVisible);
b/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java
159 159
			copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(GSS.get(), this, selectedFiles));
160 160
            contextMenu.addItem(copyItem);
161 161

  
162
			trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
162
			trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(GSS.get(), this, selectedFiles));
163 163
            contextMenu.addItem(trashItem);
164 164

  
165 165
			deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, selectedFiles, images));
b/web_client/src/gr/grnet/pithos/web/client/FolderContextMenu.java
109 109
        contextMenu.addItem(pasteItem);
110 110

  
111 111
        // do not show delete options for the user's root folder
112
        MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
112
        MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(GSS.get(), this, folder));
113 113
        contextMenu.addItem(moveToTrash);
114 114

  
115 115
        MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, folder, newImages));
b/web_client/src/gr/grnet/pithos/web/client/commands/ToTrashCommand.java
34 34
 */
35 35
package gr.grnet.pithos.web.client.commands;
36 36

  
37
import com.google.gwt.core.client.Scheduler;
37 38
import gr.grnet.pithos.web.client.GSS;
39
import gr.grnet.pithos.web.client.foldertree.File;
40
import gr.grnet.pithos.web.client.foldertree.Folder;
41
import gr.grnet.pithos.web.client.foldertree.Resource;
38 42
import gr.grnet.pithos.web.client.rest.MultiplePostCommand;
39 43
import gr.grnet.pithos.web.client.rest.PostCommand;
44
import gr.grnet.pithos.web.client.rest.PostRequest;
40 45
import gr.grnet.pithos.web.client.rest.RestException;
41 46
import gr.grnet.pithos.web.client.rest.resource.FileResource;
42 47
import gr.grnet.pithos.web.client.rest.resource.FolderResource;
43 48
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
44 49

  
45 50
import java.util.ArrayList;
51
import java.util.Iterator;
46 52
import java.util.List;
47 53

  
48 54

  
......
59 65
 */
60 66
public class ToTrashCommand implements Command{
61 67
	private PopupPanel containerPanel;
68
    private GSS app;
69
    private Object resource;
62 70

  
63
	public ToTrashCommand(PopupPanel _containerPanel){
71
	public ToTrashCommand(GSS _app, PopupPanel _containerPanel, Object _resource){
64 72
		containerPanel = _containerPanel;
73
        app = _app;
74
        resource = _resource;
65 75
	}
66 76

  
67 77
	@Override
68 78
	public void execute() {
69 79
		containerPanel.hide();
70
		Object selection = GSS.get().getCurrentSelection();
71
		if (selection == null)
72
			return;
73
		GWT.log("selection: " + selection.toString(), null);
74
		if (selection instanceof RestResourceWrapper) {
75
			FolderResource fdto = ((RestResourceWrapper) selection).getResource();
76
			PostCommand tot = new PostCommand(fdto.getUri()+"?trash=","",200){
80
        if (resource instanceof List) {
81
            Iterator<File> iter = ((List<File>) resource).iterator();
82
            deleteFiles(iter);
83
        }
84
        else if (resource instanceof Folder) {
77 85

  
78
				@Override
79
				public void onComplete() {
80
					//TODO:CELLTREE
81
					/*
82
					TreeItem folder = GSS.get().getFolders().getCurrent();
83
					if(folder.getParentItem() != null){
84
						GSS.get().getFolders().select(folder.getParentItem());
85
						GSS.get().getFolders().updateFolder((DnDTreeItem) folder.getParentItem());
86
					}
87
					GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
88
					*/
89
					FolderResource fres = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();
90
					GSS.get().getTreeView().updateNodeChildrenForRemove(fres.getParentURI());
91
					GSS.get().getTreeView().clearSelection();
92
					//GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getTrash());
93
					GSS.get().getTreeView().updateTrashNode();
94
					GSS.get().showFileList(true);
95
				}
96

  
97
				@Override
98
				public void onError(Throwable t) {
99
					GWT.log("", t);
100
					if(t instanceof RestException){
101
						int statusCode = ((RestException)t).getHttpStatusCode();
102
						if(statusCode == 405)
103
							GSS.get().displayError("You don't have the necessary permissions");
104
						else if(statusCode == 404)
105
							GSS.get().displayError("Folder does not exist");
106
						else
107
							GSS.get().displayError("Unable to trash folder:"+((RestException)t).getHttpStatusText());
108
					}
109
					else
110
						GSS.get().displayError("System error trashing folder:"+t.getMessage());
111
				}
112
			};
113
			DeferredCommand.addCommand(tot);
114
		} else if (selection instanceof FileResource) {
115
			FileResource fdto = (FileResource) selection;
116
			PostCommand tot = new PostCommand(fdto.getUri()+"?trash=","",200){
117

  
118
				@Override
119
				public void onComplete() {
120
					GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection());
121
				}
122

  
123
				@Override
124
				public void onError(Throwable t) {
125
					GWT.log("", t);
126
					if(t instanceof RestException){
127
						int statusCode = ((RestException)t).getHttpStatusCode();
128
						if(statusCode == 405)
129
							GSS.get().displayError("You don't have the necessary permissions");
130
						else if(statusCode == 404)
131
							GSS.get().displayError("File does not exist");
132
						else
133
							GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
134
					}
135
					else
136
						GSS.get().displayError("System error trashing file:"+t.getMessage());
137
				}
138
			};
139
			DeferredCommand.addCommand(tot);
140

  
141
		}
142
		else if (selection instanceof List) {
143
			List<FileResource> fdtos = (List<FileResource>) selection;
144
			final List<String> fileIds = new ArrayList<String>();
145
			for(FileResource f : fdtos)
146
				fileIds.add(f.getUri()+"?trash=");
147
			MultiplePostCommand tot = new MultiplePostCommand(fileIds.toArray(new String[0]),200){
148

  
149
				@Override
150
				public void onComplete() {
151
					GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection());
152
				}
153

  
154
				@Override
155
				public void onError(String p, Throwable t) {
156
					GWT.log("", t);
157
					if(t instanceof RestException){
158
						int statusCode = ((RestException)t).getHttpStatusCode();
159
						if(statusCode == 405)
160
							GSS.get().displayError("You don't have the necessary permissions");
161
						else if(statusCode == 404)
162
							GSS.get().displayError("File does not exist");
163
						else
164
							GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
165
					}
166
					else
167
						GSS.get().displayError("System error trashing file:"+t.getMessage());
168
				}
169
			};
170
			DeferredCommand.addCommand(tot);
171
		}
86
        }
172 87
	}
173 88

  
89
    private void deleteFiles(final Iterator<File> iter) {
90
        if (iter.hasNext()) {
91
            File file = iter.next();
92
            String path = app.getApiPath() + app.getUsername() + file.getUri() + "?update=";
93
            PostRequest trashFile = new PostRequest(path) {
94
                @Override
95
                public void onSuccess(Resource result) {
96
                    deleteFiles(iter);
97
                }
98

  
99
                @Override
100
                public void onError(Throwable t) {
101
                    GWT.log("", t);
102
                    if (t instanceof RestException) {
103
                        GSS.get().displayError("Unable to move file to trash: " + ((RestException) t).getHttpStatusText());
104
                    }
105
                    else
106
                        GSS.get().displayError("System error unable to move file to trash: "+t.getMessage());
107
                }
108
            };
109
            trashFile.setHeader("X-Auth-Token", app.getToken());
110
            trashFile.setHeader("X-Object-Meta-Trash", "true");
111
            Scheduler.get().scheduleDeferred(trashFile);
112
        }
113
        else {
114
            app.get().updateFolder(((List<File>) resource).get(0).getParent());
115
        }
116
    }
174 117
}
b/web_client/src/gr/grnet/pithos/web/client/rest/PostRequest.java
1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35

  
36
package gr.grnet.pithos.web.client.rest;
37

  
38
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
39
import com.google.gwt.http.client.Request;
40
import com.google.gwt.http.client.RequestBuilder;
41
import com.google.gwt.http.client.RequestException;
42
import com.google.gwt.http.client.Response;
43
import gr.grnet.pithos.web.client.foldertree.Resource;
44
import java.util.HashMap;
45
import java.util.Map;
46

  
47
public abstract class PostRequest implements ScheduledCommand {
48

  
49
    private String path;
50

  
51
    private Map<String, String> headers = new HashMap<String, String>();
52

  
53
    public abstract void onSuccess(Resource result);
54

  
55
    public abstract void onError(Throwable t);
56

  
57
    public PostRequest(String path) {
58
        this.path = path;
59
    }
60

  
61
    @Override
62
    public void execute() {
63
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, path);
64
        for (String header : headers.keySet()) {
65
            builder.setHeader(header, headers.get(header));
66
        }
67
        try {
68
            builder.sendRequest("", new RestRequestCallback(path, Response.SC_ACCEPTED) {
69
                @Override
70
                public void onSuccess(Resource object) {
71
                    PostRequest.this.onSuccess(object);
72
                }
73

  
74
                @Override
75
                public Resource deserialize(Response response) {
76
                    return Resource.createFromResponse(Resource.class, response, null);
77
                }
78

  
79
                @Override
80
                public void onError(Request request, Throwable throwable) {
81
                    PostRequest.this.onError(throwable);
82
                }
83
            });
84
        }
85
        catch (RequestException e) {
86
        }
87
    }
88

  
89
    public void setHeader(String header, String value) {
90
        headers.put(header, value);
91
    }
92
}

Also available in: Unified diff