root / web_client / src / gr / grnet / pithos / web / client / commands / ToTrashCommand.java @ 7529fcd7
History | View | Annotate | Download (4.3 kB)
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 |
package gr.grnet.pithos.web.client.commands; |
36 |
|
37 |
import com.google.gwt.core.client.Scheduler; |
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; |
42 |
import gr.grnet.pithos.web.client.rest.MultiplePostCommand; |
43 |
import gr.grnet.pithos.web.client.rest.PostCommand; |
44 |
import gr.grnet.pithos.web.client.rest.PostRequest; |
45 |
import gr.grnet.pithos.web.client.rest.RestException; |
46 |
import gr.grnet.pithos.web.client.rest.resource.FileResource; |
47 |
import gr.grnet.pithos.web.client.rest.resource.FolderResource; |
48 |
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
49 |
|
50 |
import java.util.ArrayList; |
51 |
import java.util.Iterator; |
52 |
import java.util.List; |
53 |
|
54 |
|
55 |
import com.google.gwt.core.client.GWT; |
56 |
import com.google.gwt.user.client.Command; |
57 |
import com.google.gwt.user.client.DeferredCommand; |
58 |
import com.google.gwt.user.client.ui.PopupPanel; |
59 |
|
60 |
/**
|
61 |
*
|
62 |
* Move file or folder to trash.
|
63 |
*
|
64 |
*
|
65 |
*/
|
66 |
public class ToTrashCommand implements Command{ |
67 |
private PopupPanel containerPanel;
|
68 |
private GSS app;
|
69 |
private Object resource; |
70 |
|
71 |
public ToTrashCommand(GSS _app, PopupPanel _containerPanel, Object _resource){ |
72 |
containerPanel = _containerPanel; |
73 |
app = _app; |
74 |
resource = _resource; |
75 |
} |
76 |
|
77 |
@Override
|
78 |
public void execute() { |
79 |
containerPanel.hide(); |
80 |
if (resource instanceof List) { |
81 |
Iterator<File> iter = ((List<File>) resource).iterator(); |
82 |
deleteFiles(iter); |
83 |
} |
84 |
else if (resource instanceof Folder) { |
85 |
|
86 |
} |
87 |
} |
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 |
} |
117 |
} |