root / web_client / src / gr / grnet / pithos / web / client / DnDFolderPopupMenu.java @ fbff60ff
History | View | Annotate | Download (12.1 kB)
1 |
/*
|
---|---|
2 |
* Copyright (c) 2011 Greek Research and Technology Network
|
3 |
*/
|
4 |
package gr.grnet.pithos.web.client; |
5 |
|
6 |
import gr.grnet.pithos.web.client.foldertree.File; |
7 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
8 |
import gr.grnet.pithos.web.client.rest.MultiplePostCommand; |
9 |
import gr.grnet.pithos.web.client.rest.PostCommand; |
10 |
import gr.grnet.pithos.web.client.rest.RestException; |
11 |
import gr.grnet.pithos.web.client.rest.resource.FileResource; |
12 |
import gr.grnet.pithos.web.client.rest.resource.FolderResource; |
13 |
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
14 |
|
15 |
import java.util.ArrayList; |
16 |
import java.util.List; |
17 |
|
18 |
import com.google.gwt.core.client.GWT; |
19 |
import com.google.gwt.http.client.URL; |
20 |
import com.google.gwt.user.client.Command; |
21 |
import com.google.gwt.user.client.DeferredCommand; |
22 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
23 |
import com.google.gwt.user.client.ui.MenuBar; |
24 |
import com.google.gwt.user.client.ui.PopupPanel; |
25 |
|
26 |
public class DnDFolderPopupMenu extends PopupPanel { |
27 |
|
28 |
public DnDFolderPopupMenu(final CellTreeView.Images newImages, final Folder target, final Object toCopy) { |
29 |
// The popup's constructor's argument is a boolean specifying that it
|
30 |
// auto-close itself when the user clicks outside of it.
|
31 |
super(true); |
32 |
setAnimationEnabled(true);
|
33 |
// A dummy command that we will execute from unimplemented leaves.
|
34 |
final Command cancelCmd = new Command() { |
35 |
|
36 |
@Override
|
37 |
public void execute() { |
38 |
hide(); |
39 |
} |
40 |
}; |
41 |
|
42 |
final MenuBar contextMenu = new MenuBar(true); |
43 |
final CellTreeView folders = GSS.get().getTreeView();
|
44 |
|
45 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Move</span>", true, new Command() { |
46 |
|
47 |
@Override
|
48 |
public void execute() { |
49 |
if (toCopy instanceof Folder) { |
50 |
moveFolder(target, (Folder) toCopy); |
51 |
} |
52 |
else if (toCopy instanceof List) { |
53 |
List<File> files = GSS.get().getFileList().getSelectedFiles(); |
54 |
moveFiles(target, files); |
55 |
} |
56 |
hide(); |
57 |
} |
58 |
}).setVisible(target != null);
|
59 |
|
60 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new Command() { |
61 |
|
62 |
@Override
|
63 |
public void execute() { |
64 |
if (toCopy instanceof Folder) |
65 |
copyFolder(target, (Folder) toCopy); |
66 |
else if (toCopy instanceof List) { |
67 |
List<File> files = GSS.get().getFileList().getSelectedFiles(); |
68 |
copyFiles(target, files); |
69 |
} |
70 |
hide(); |
71 |
} |
72 |
}).setVisible(target != null);
|
73 |
|
74 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.trash()).getHTML() + " Delete (Trash)</span>", true, new Command() { |
75 |
|
76 |
@Override
|
77 |
public void execute() { |
78 |
GWT.log("EXECUTE TRASH:" + toCopy.getClass().getName());
|
79 |
if (toCopy instanceof RestResourceWrapper) { |
80 |
trashFolder(((RestResourceWrapper) toCopy).getResource()); |
81 |
} |
82 |
else if (toCopy instanceof List) { |
83 |
List<File> files = GSS.get().getFileList().getSelectedFiles(); |
84 |
trashFiles(files); |
85 |
} |
86 |
hide(); |
87 |
} |
88 |
}).setVisible(target == null);
|
89 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Cancel</span>", true, cancelCmd); |
90 |
|
91 |
add(contextMenu); |
92 |
} |
93 |
|
94 |
private void copyFolder(final Folder target, Folder toCopy) { |
95 |
// String atarget = target.getUri();
|
96 |
// atarget = atarget.endsWith("/") ? atarget : atarget + '/';
|
97 |
// atarget = atarget + toCopy.getName();
|
98 |
// PostCommand cf = new PostCommand(toCopy.getUri() + "?copy=" + atarget, "", 200) {
|
99 |
//
|
100 |
// @Override
|
101 |
// public void onComplete() {
|
102 |
// GSS.get().getTreeView().updateNodeChildren(new RestResourceWrapper(target));
|
103 |
// GSS.get().getStatusPanel().updateStats();
|
104 |
// }
|
105 |
//
|
106 |
// @Override
|
107 |
// public void onError(Throwable t) {
|
108 |
// GWT.log("", t);
|
109 |
// if (t instanceof RestException) {
|
110 |
// int statusCode = ((RestException) t).getHttpStatusCode();
|
111 |
// if (statusCode == 405)
|
112 |
// GSS.get().displayError("You don't have the necessary permissions");
|
113 |
//
|
114 |
// else if (statusCode == 409)
|
115 |
// GSS.get().displayError("A folder with the same name already exists");
|
116 |
// else if (statusCode == 413)
|
117 |
// GSS.get().displayError("Your quota has been exceeded");
|
118 |
// else
|
119 |
// GSS.get().displayError("Unable to copy folder:" + ((RestException) t).getHttpStatusText());
|
120 |
// }
|
121 |
// else
|
122 |
// GSS.get().displayError("System error copying folder:" + t.getMessage());
|
123 |
// }
|
124 |
// };
|
125 |
// DeferredCommand.addCommand(cf);
|
126 |
} |
127 |
|
128 |
private void moveFolder(final Folder target, final Folder toCopy) { |
129 |
// String atarget = target.getUri();
|
130 |
// atarget = atarget.endsWith("/") ? atarget : atarget + '/';
|
131 |
// atarget = atarget + toCopy.getName();
|
132 |
//
|
133 |
// PostCommand cf = new PostCommand(toCopy.getUri() + "?move=" + atarget, "", 200) {
|
134 |
//
|
135 |
// @Override
|
136 |
// public void onComplete() {
|
137 |
// GWT.log("[MOVE]" + target.getUri() + " " + toCopy.getParentURI());
|
138 |
// GSS.get().getTreeView().updateNodeChildren(new RestResourceWrapper(target));
|
139 |
// GSS.get().getTreeView().updateNodeChildrenForRemove(toCopy.getParentURI());
|
140 |
// GSS.get().getStatusPanel().updateStats();
|
141 |
// }
|
142 |
//
|
143 |
// @Override
|
144 |
// public void onError(Throwable t) {
|
145 |
// GWT.log("", t);
|
146 |
// if (t instanceof RestException) {
|
147 |
// int statusCode = ((RestException) t).getHttpStatusCode();
|
148 |
// if (statusCode == 405)
|
149 |
// GSS.get().displayError("You don't have the necessary permissions");
|
150 |
//
|
151 |
// else if (statusCode == 409)
|
152 |
// GSS.get().displayError("A folder with the same name already exists");
|
153 |
// else if (statusCode == 413)
|
154 |
// GSS.get().displayError("Your quota has been exceeded");
|
155 |
// else
|
156 |
// GSS.get().displayError("Unable to copy folder:" + ((RestException) t).getHttpStatusText());
|
157 |
// }
|
158 |
// else
|
159 |
// GSS.get().displayError("System error copying folder:" + t.getMessage());
|
160 |
// }
|
161 |
// };
|
162 |
// DeferredCommand.addCommand(cf);
|
163 |
} |
164 |
|
165 |
private void copyFiles(final Folder ftarget, List<File> files) { |
166 |
// List<String> fileIds = new ArrayList<String>();
|
167 |
// String target = ftarget.getUri();
|
168 |
// target = target.endsWith("/") ? target : target + '/';
|
169 |
// for (File file : files) {
|
170 |
// String fileTarget = target + URL.encodeComponent(file.getName());
|
171 |
// fileIds.add(file.getUri() + "?copy=" + fileTarget);
|
172 |
// }
|
173 |
// int index = 0;
|
174 |
// executeCopyOrMoveFiles(index, fileIds);
|
175 |
} |
176 |
|
177 |
private void moveFiles(final Folder ftarget, List<File> files) { |
178 |
// List<String> fileIds = new ArrayList<String>();
|
179 |
// String target = ftarget.getUri();
|
180 |
// target = target.endsWith("/") ? target : target + '/';
|
181 |
// for (File file : files) {
|
182 |
// String fileTarget = target + URL.encodeComponent(file.getName());
|
183 |
// fileIds.add(file.getUri() + "?move=" + fileTarget);
|
184 |
// }
|
185 |
// int index = 0;
|
186 |
// executeCopyOrMoveFiles(index, fileIds);
|
187 |
} |
188 |
|
189 |
private void trashFolder(final FolderResource folder) { |
190 |
PostCommand tot = new PostCommand(folder.getUri() + "?trash=", "", 200) { |
191 |
|
192 |
@Override
|
193 |
public void onComplete() { |
194 |
GSS.get().getTreeView().updateNodeChildrenForRemove(folder.getParentURI()); |
195 |
GSS.get().getTreeView().updateTrashNode(); |
196 |
/*for(TreeItem item : items)
|
197 |
GSS.get().getFolders().updateFolder((DnDTreeItem) item);
|
198 |
GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
|
199 |
|
200 |
GSS.get().showFileList(true);
|
201 |
*/
|
202 |
} |
203 |
|
204 |
@Override
|
205 |
public void onError(Throwable t) { |
206 |
GWT.log("", t);
|
207 |
if (t instanceof RestException) { |
208 |
int statusCode = ((RestException) t).getHttpStatusCode();
|
209 |
if (statusCode == 405) |
210 |
GSS.get().displayError("You don't have the necessary permissions");
|
211 |
else if (statusCode == 404) |
212 |
GSS.get().displayError("Folder does not exist");
|
213 |
else
|
214 |
GSS.get().displayError("Unable to trash folder:" + ((RestException) t).getHttpStatusText());
|
215 |
} |
216 |
else
|
217 |
GSS.get().displayError("System error trashing folder:" + t.getMessage());
|
218 |
} |
219 |
}; |
220 |
DeferredCommand.addCommand(tot); |
221 |
} |
222 |
|
223 |
private void trashFiles(List<File> files) { |
224 |
final List<String> fileIds = new ArrayList<String>(); |
225 |
for (File f : files) |
226 |
fileIds.add(f.getUri() + "?trash=");
|
227 |
MultiplePostCommand tot = new MultiplePostCommand(fileIds.toArray(new String[0]), 200) { |
228 |
|
229 |
@Override
|
230 |
public void onComplete() { |
231 |
GSS.get().showFileList(true);
|
232 |
} |
233 |
|
234 |
@Override
|
235 |
public void onError(String p, Throwable t) { |
236 |
GWT.log("", t);
|
237 |
if (t instanceof RestException) { |
238 |
int statusCode = ((RestException) t).getHttpStatusCode();
|
239 |
if (statusCode == 405) |
240 |
GSS.get().displayError("You don't have the necessary permissions");
|
241 |
else if (statusCode == 404) |
242 |
GSS.get().displayError("File does not exist");
|
243 |
else
|
244 |
GSS.get().displayError("Unable to trash file:" + ((RestException) t).getHttpStatusText());
|
245 |
} |
246 |
else
|
247 |
GSS.get().displayError("System error trashing file:" + t.getMessage());
|
248 |
} |
249 |
}; |
250 |
DeferredCommand.addCommand(tot); |
251 |
} |
252 |
|
253 |
private void executeCopyOrMoveFiles(final int index, final List<String> paths) { |
254 |
if (index >= paths.size()) {
|
255 |
GSS.get().showFileList(true);
|
256 |
GSS.get().getStatusPanel().updateStats(); |
257 |
return;
|
258 |
} |
259 |
PostCommand cf = new PostCommand(paths.get(index), "", 200) { |
260 |
|
261 |
@Override
|
262 |
public void onComplete() { |
263 |
executeCopyOrMoveFiles(index + 1, paths);
|
264 |
} |
265 |
|
266 |
@Override
|
267 |
public void onError(Throwable t) { |
268 |
GWT.log("", t);
|
269 |
if (t instanceof RestException) { |
270 |
int statusCode = ((RestException) t).getHttpStatusCode();
|
271 |
if (statusCode == 405) |
272 |
GSS.get().displayError("You don't have the necessary permissions");
|
273 |
else if (statusCode == 404) |
274 |
GSS.get().displayError("File not found");
|
275 |
else if (statusCode == 409) |
276 |
GSS.get().displayError("A file with the same name already exists");
|
277 |
else if (statusCode == 413) |
278 |
GSS.get().displayError("Your quota has been exceeded");
|
279 |
else
|
280 |
GSS.get().displayError("Unable to copy file:" + ((RestException) t).getHttpStatusText());
|
281 |
} |
282 |
else
|
283 |
GSS.get().displayError("System error copying file:" + t.getMessage());
|
284 |
} |
285 |
}; |
286 |
DeferredCommand.addCommand(cf); |
287 |
} |
288 |
} |