root / src / gr / ebs / gss / client / commands / PasteCommand.java @ 31840568
History | View | Annotate | Download (11.5 kB)
1 | 14ad7326 | pastith | /*
|
---|---|---|---|
2 | 14ad7326 | pastith | * Copyright 2008, 2009 Electronic Business Systems Ltd.
|
3 | 14ad7326 | pastith | *
|
4 | 14ad7326 | pastith | * This file is part of GSS.
|
5 | 14ad7326 | pastith | *
|
6 | 14ad7326 | pastith | * GSS is free software: you can redistribute it and/or modify
|
7 | 14ad7326 | pastith | * it under the terms of the GNU General Public License as published by
|
8 | 14ad7326 | pastith | * the Free Software Foundation, either version 3 of the License, or
|
9 | 14ad7326 | pastith | * (at your option) any later version.
|
10 | 14ad7326 | pastith | *
|
11 | 14ad7326 | pastith | * GSS is distributed in the hope that it will be useful,
|
12 | 14ad7326 | pastith | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 14ad7326 | pastith | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 14ad7326 | pastith | * GNU General Public License for more details.
|
15 | 14ad7326 | pastith | *
|
16 | 14ad7326 | pastith | * You should have received a copy of the GNU General Public License
|
17 | 14ad7326 | pastith | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | 14ad7326 | pastith | */
|
19 | 14ad7326 | pastith | package gr.ebs.gss.client.commands; |
20 | 14ad7326 | pastith | |
21 | 14ad7326 | pastith | import gr.ebs.gss.client.GSS; |
22 | 14ad7326 | pastith | import gr.ebs.gss.client.clipboard.Clipboard; |
23 | 14ad7326 | pastith | import gr.ebs.gss.client.clipboard.ClipboardItem; |
24 | 895035a2 | pastith | import gr.ebs.gss.client.rest.PostCommand; |
25 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.RestException; |
26 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.resource.FileResource; |
27 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.resource.FolderResource; |
28 | 3dfc2d23 | koutsoub | import gr.ebs.gss.client.rest.resource.GroupResource; |
29 | 31840568 | koutsoub | import gr.ebs.gss.client.rest.resource.RestResourceWrapper; |
30 | 14ad7326 | pastith | |
31 | 14ad7326 | pastith | import java.util.ArrayList; |
32 | 14ad7326 | pastith | import java.util.List; |
33 | 14ad7326 | pastith | |
34 | 14ad7326 | pastith | import com.google.gwt.core.client.GWT; |
35 | a52ea5e4 | pastith | import com.google.gwt.http.client.URL; |
36 | 14ad7326 | pastith | import com.google.gwt.user.client.Command; |
37 | a52ea5e4 | pastith | import com.google.gwt.user.client.DeferredCommand; |
38 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.PopupPanel; |
39 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.TreeItem; |
40 | 14ad7326 | pastith | |
41 | 14ad7326 | pastith | /**
|
42 | 14ad7326 | pastith | * @author kman Command for pasting Clipboard contents
|
43 | 14ad7326 | pastith | */
|
44 | 14ad7326 | pastith | public class PasteCommand implements Command { |
45 | 14ad7326 | pastith | |
46 | 14ad7326 | pastith | private PopupPanel containerPanel;
|
47 | 14ad7326 | pastith | |
48 | 14ad7326 | pastith | public PasteCommand(PopupPanel _containerPanel) {
|
49 | 14ad7326 | pastith | containerPanel = _containerPanel; |
50 | 14ad7326 | pastith | } |
51 | 14ad7326 | pastith | |
52 | 023f6f1e | Panagiotis Astithas | @Override
|
53 | 14ad7326 | pastith | public void execute() { |
54 | 14ad7326 | pastith | containerPanel.hide(); |
55 | 14ad7326 | pastith | Object selection = GSS.get().getCurrentSelection();
|
56 | 0336eab9 | koutsoub | if(selection != null && selection instanceof GroupResource){ |
57 | 0336eab9 | koutsoub | final ClipboardItem citem = GSS.get().getClipboard().getItem();
|
58 | 0336eab9 | koutsoub | GroupResource group = (GroupResource) GSS.get().getCurrentSelection(); |
59 | 0336eab9 | koutsoub | if(citem.getUser() != null){ |
60 | 895035a2 | pastith | PostCommand cg = new PostCommand(group.getUri()+"?name="+citem.getUser().getUsername(), "", 201){ |
61 | 0336eab9 | koutsoub | |
62 | 555e8e59 | pastith | @Override
|
63 | 0336eab9 | koutsoub | public void onComplete() { |
64 | 0336eab9 | koutsoub | GSS.get().getGroups().updateGroups(); |
65 | 0336eab9 | koutsoub | GSS.get().showUserList(); |
66 | feeea1cf | Natasa Kapravelou | GSS.get().getClipboard().setItem(null);
|
67 | 0336eab9 | koutsoub | } |
68 | 555e8e59 | pastith | |
69 | 555e8e59 | pastith | @Override
|
70 | 0336eab9 | koutsoub | public void onError(Throwable t) { |
71 | 0336eab9 | koutsoub | GWT.log("", t);
|
72 | 0336eab9 | koutsoub | if(t instanceof RestException){ |
73 | 0336eab9 | koutsoub | int statusCode = ((RestException)t).getHttpStatusCode();
|
74 | 0336eab9 | koutsoub | if(statusCode == 405) |
75 | 0336eab9 | koutsoub | GSS.get().displayError("You don't have the necessary permissions");
|
76 | 0336eab9 | koutsoub | else if(statusCode == 404) |
77 | 0336eab9 | koutsoub | GSS.get().displayError("User does not exist");
|
78 | 0336eab9 | koutsoub | else if(statusCode == 409) |
79 | 0336eab9 | koutsoub | GSS.get().displayError("A user with the same name already exists");
|
80 | 0336eab9 | koutsoub | else if(statusCode == 413) |
81 | 0336eab9 | koutsoub | GSS.get().displayError("Your quota has been exceeded");
|
82 | 0336eab9 | koutsoub | else
|
83 | 0336eab9 | koutsoub | GSS.get().displayError("Unable to add user:"+((RestException)t).getHttpStatusText());
|
84 | 0336eab9 | koutsoub | } |
85 | 0336eab9 | koutsoub | else
|
86 | 0336eab9 | koutsoub | GSS.get().displayError("System error adding user:"+t.getMessage());
|
87 | 0336eab9 | koutsoub | } |
88 | 0336eab9 | koutsoub | }; |
89 | 0336eab9 | koutsoub | DeferredCommand.addCommand(cg); |
90 | 0336eab9 | koutsoub | return;
|
91 | 0336eab9 | koutsoub | } |
92 | 0336eab9 | koutsoub | } |
93 | 0336eab9 | koutsoub | FolderResource selectedFolder = null;
|
94 | 31840568 | koutsoub | if(selection != null && selection instanceof RestResourceWrapper) |
95 | 31840568 | koutsoub | selectedFolder = ((RestResourceWrapper)selection).getResource(); |
96 | 5b09ea6c | koutsoub | //TODO:CELLTREE
|
97 | 5b09ea6c | koutsoub | /*
|
98 | 0336eab9 | koutsoub | else if(GSS.get().getFolders().getCurrent() != null && ((DnDTreeItem)GSS.get().getFolders().getCurrent()).getFolderResource() != null)
|
99 | 0336eab9 | koutsoub | selectedFolder = ((DnDTreeItem)GSS.get().getFolders().getCurrent()).getFolderResource();
|
100 | 5b09ea6c | koutsoub | */
|
101 | 0336eab9 | koutsoub | if (selectedFolder != null) { |
102 | a52ea5e4 | pastith | final ClipboardItem citem = GSS.get().getClipboard().getItem();
|
103 | 31840568 | koutsoub | if (citem != null && citem.getRestResourceWrapper() != null) { |
104 | 555e8e59 | pastith | String target = selectedFolder.getUri();
|
105 | a52ea5e4 | pastith | target = target.endsWith("/") ? target : target + '/'; |
106 | 31840568 | koutsoub | target = target + URL.encodeComponent(citem.getRestResourceWrapper().getResource().getName());
|
107 | a52ea5e4 | pastith | if (citem.getOperation() == Clipboard.COPY) { |
108 | 31840568 | koutsoub | PostCommand cf = new PostCommand(citem.getRestResourceWrapper().getUri() + "?copy=" + target, "", 200) { |
109 | a52ea5e4 | pastith | |
110 | 555e8e59 | pastith | @Override
|
111 | a52ea5e4 | pastith | public void onComplete() { |
112 | 5b09ea6c | koutsoub | //TODO:CELLTREE
|
113 | 5b09ea6c | koutsoub | //GSS.get().getFolders().updateFolder((DnDTreeItem) GSS.get().getFolders().getCurrent());
|
114 | 31840568 | koutsoub | GSS.get().getTreeView().updateNodeChildren(GSS.get().getTreeView().getSelection()); |
115 | 00bf0484 | koutsoub | GSS.get().getStatusPanel().updateStats(); |
116 | feeea1cf | Natasa Kapravelou | GSS.get().getClipboard().setItem(null);
|
117 | a52ea5e4 | pastith | } |
118 | a52ea5e4 | pastith | |
119 | 555e8e59 | pastith | @Override
|
120 | a52ea5e4 | pastith | public void onError(Throwable t) { |
121 | a52ea5e4 | pastith | GWT.log("", t);
|
122 | a52ea5e4 | pastith | if(t instanceof RestException){ |
123 | a52ea5e4 | pastith | int statusCode = ((RestException)t).getHttpStatusCode();
|
124 | a52ea5e4 | pastith | if(statusCode == 405) |
125 | a52ea5e4 | pastith | GSS.get().displayError("You don't have the necessary permissions");
|
126 | a52ea5e4 | pastith | |
127 | a52ea5e4 | pastith | else if(statusCode == 409) |
128 | a52ea5e4 | pastith | GSS.get().displayError("A folder with the same name already exists");
|
129 | a52ea5e4 | pastith | else if(statusCode == 413) |
130 | a52ea5e4 | pastith | GSS.get().displayError("Your quota has been exceeded");
|
131 | a52ea5e4 | pastith | else
|
132 | 8218842e | koutsoub | GSS.get().displayError("Unable to copy folder:"+((RestException)t).getHttpStatusText());
|
133 | a52ea5e4 | pastith | } |
134 | a52ea5e4 | pastith | else
|
135 | a52ea5e4 | pastith | GSS.get().displayError("System error copying folder:"+t.getMessage());
|
136 | a52ea5e4 | pastith | } |
137 | a52ea5e4 | pastith | }; |
138 | a52ea5e4 | pastith | DeferredCommand.addCommand(cf); |
139 | a52ea5e4 | pastith | } else if (citem.getOperation() == Clipboard.CUT) { |
140 | 31840568 | koutsoub | PostCommand cf = new PostCommand(citem.getRestResourceWrapper().getUri() + "?move=" + target, "", 200) { |
141 | a52ea5e4 | pastith | |
142 | 555e8e59 | pastith | @Override
|
143 | a52ea5e4 | pastith | public void onComplete() { |
144 | 5b09ea6c | koutsoub | //TODO:CELLTREE
|
145 | 5b09ea6c | koutsoub | /*
|
146 | 555e8e59 | pastith | List<TreeItem> items = GSS.get().getFolders().getItemsOfTreeForPath(citem.getFolderResource().getUri());
|
147 | a52ea5e4 | pastith | for (TreeItem item : items)
|
148 | a52ea5e4 | pastith | if (item.getParentItem() != null && !item.equals(GSS.get().getFolders().getCurrent()))
|
149 | a52ea5e4 | pastith | GSS.get().getFolders().updateFolder((DnDTreeItem) item.getParentItem());
|
150 | a52ea5e4 | pastith | GSS.get().getFolders().updateFolder((DnDTreeItem) GSS.get().getFolders().getCurrent());
|
151 | 5b09ea6c | koutsoub | */
|
152 | 31840568 | koutsoub | GSS.get().getTreeView().updateNodeChildren(GSS.get().getTreeView().getSelection()); |
153 | 31840568 | koutsoub | GSS.get().getTreeView().updateNodeChildren(citem.getRestResourceWrapper().getResource().getParentURI()); |
154 | feeea1cf | Natasa Kapravelou | GSS.get().getStatusPanel().updateStats(); |
155 | feeea1cf | Natasa Kapravelou | GSS.get().getClipboard().setItem(null);
|
156 | a52ea5e4 | pastith | } |
157 | a52ea5e4 | pastith | |
158 | 555e8e59 | pastith | @Override
|
159 | a52ea5e4 | pastith | public void onError(Throwable t) { |
160 | a52ea5e4 | pastith | GWT.log("", t);
|
161 | a52ea5e4 | pastith | if(t instanceof RestException){ |
162 | a52ea5e4 | pastith | int statusCode = ((RestException)t).getHttpStatusCode();
|
163 | a52ea5e4 | pastith | if(statusCode == 405) |
164 | a52ea5e4 | pastith | GSS.get().displayError("You don't have the necessary permissions");
|
165 | a52ea5e4 | pastith | else if(statusCode == 409) |
166 | a52ea5e4 | pastith | GSS.get().displayError("A folder with the same name already exists");
|
167 | a52ea5e4 | pastith | else if(statusCode == 413) |
168 | a52ea5e4 | pastith | GSS.get().displayError("Your quota has been exceeded");
|
169 | a52ea5e4 | pastith | else
|
170 | 8218842e | koutsoub | GSS.get().displayError("Unable to move folder:"+((RestException)t).getHttpStatusText());
|
171 | a52ea5e4 | pastith | } |
172 | a52ea5e4 | pastith | else
|
173 | a52ea5e4 | pastith | GSS.get().displayError("System error moving folder:"+t.getMessage());
|
174 | a52ea5e4 | pastith | } |
175 | a52ea5e4 | pastith | }; |
176 | a52ea5e4 | pastith | DeferredCommand.addCommand(cf); |
177 | a52ea5e4 | pastith | } |
178 | a52ea5e4 | pastith | return;
|
179 | a52ea5e4 | pastith | } else if (citem != null && citem.getFile() != null) { |
180 | 555e8e59 | pastith | String target = selectedFolder.getUri();
|
181 | a52ea5e4 | pastith | target = target.endsWith("/") ? target : target + '/'; |
182 | a52ea5e4 | pastith | target = target + URL.encodeComponent(citem.getFile().getName());
|
183 | a52ea5e4 | pastith | if (citem.getOperation() == Clipboard.COPY) { |
184 | 895035a2 | pastith | PostCommand cf = new PostCommand(citem.getFile().getUri() + "?copy=" + target, "", 200) { |
185 | a52ea5e4 | pastith | |
186 | 555e8e59 | pastith | @Override
|
187 | a52ea5e4 | pastith | public void onComplete() { |
188 | a52ea5e4 | pastith | GSS.get().showFileList(true);
|
189 | 00bf0484 | koutsoub | GSS.get().getStatusPanel().updateStats(); |
190 | feeea1cf | Natasa Kapravelou | GSS.get().getClipboard().setItem(null);
|
191 | a52ea5e4 | pastith | } |
192 | a52ea5e4 | pastith | |
193 | 555e8e59 | pastith | @Override
|
194 | a52ea5e4 | pastith | public void onError(Throwable t) { |
195 | a52ea5e4 | pastith | GWT.log("", t);
|
196 | a52ea5e4 | pastith | if(t instanceof RestException){ |
197 | a52ea5e4 | pastith | int statusCode = ((RestException)t).getHttpStatusCode();
|
198 | a52ea5e4 | pastith | if(statusCode == 405) |
199 | a52ea5e4 | pastith | GSS.get().displayError("You don't have the necessary permissions");
|
200 | a52ea5e4 | pastith | else if(statusCode == 404) |
201 | a52ea5e4 | pastith | GSS.get().displayError("File not found");
|
202 | a52ea5e4 | pastith | else if(statusCode == 409) |
203 | a52ea5e4 | pastith | GSS.get().displayError("A file with the same name already exists");
|
204 | a52ea5e4 | pastith | else if(statusCode == 413) |
205 | a52ea5e4 | pastith | GSS.get().displayError("Your quota has been exceeded");
|
206 | a52ea5e4 | pastith | else
|
207 | 8218842e | koutsoub | GSS.get().displayError("Unable to copy file:"+((RestException)t).getHttpStatusText());
|
208 | a52ea5e4 | pastith | } |
209 | a52ea5e4 | pastith | else
|
210 | a52ea5e4 | pastith | GSS.get().displayError("System error copying file:"+t.getMessage());
|
211 | a52ea5e4 | pastith | } |
212 | a52ea5e4 | pastith | }; |
213 | a52ea5e4 | pastith | DeferredCommand.addCommand(cf); |
214 | a52ea5e4 | pastith | } else if (citem.getOperation() == Clipboard.CUT) { |
215 | 895035a2 | pastith | PostCommand cf = new PostCommand(citem.getFile().getUri() + "?move=" + target, "", 200) { |
216 | a52ea5e4 | pastith | |
217 | 555e8e59 | pastith | @Override
|
218 | a52ea5e4 | pastith | public void onComplete() { |
219 | a52ea5e4 | pastith | GSS.get().showFileList(true);
|
220 | 2bbcce54 | Fotis Stamatelopoulos | GSS.get().getStatusPanel().updateStats(); |
221 | feeea1cf | Natasa Kapravelou | GSS.get().getClipboard().setItem(null);
|
222 | a52ea5e4 | pastith | } |
223 | a52ea5e4 | pastith | |
224 | 555e8e59 | pastith | @Override
|
225 | a52ea5e4 | pastith | public void onError(Throwable t) { |
226 | a52ea5e4 | pastith | GWT.log("", t);
|
227 | a52ea5e4 | pastith | if(t instanceof RestException){ |
228 | a52ea5e4 | pastith | int statusCode = ((RestException)t).getHttpStatusCode();
|
229 | a52ea5e4 | pastith | if(statusCode == 405) |
230 | a52ea5e4 | pastith | GSS.get().displayError("You don't have the necessary permissions");
|
231 | a52ea5e4 | pastith | else if(statusCode == 404) |
232 | a52ea5e4 | pastith | GSS.get().displayError("File not found");
|
233 | a52ea5e4 | pastith | else if(statusCode == 409) |
234 | a52ea5e4 | pastith | GSS.get().displayError("A file with the same name already exists");
|
235 | a52ea5e4 | pastith | else if(statusCode == 413) |
236 | a52ea5e4 | pastith | GSS.get().displayError("Your quota has been exceeded");
|
237 | a52ea5e4 | pastith | else
|
238 | 8218842e | koutsoub | GSS.get().displayError("Unable to copy file:"+((RestException)t).getHttpStatusText());
|
239 | a52ea5e4 | pastith | } |
240 | a52ea5e4 | pastith | else
|
241 | a52ea5e4 | pastith | GSS.get().displayError("System error copying file:"+t.getMessage());
|
242 | a52ea5e4 | pastith | } |
243 | a52ea5e4 | pastith | }; |
244 | a52ea5e4 | pastith | DeferredCommand.addCommand(cf); |
245 | a52ea5e4 | pastith | } |
246 | a52ea5e4 | pastith | return;
|
247 | a52ea5e4 | pastith | } else if (citem != null && citem.getFiles() != null) { |
248 | a52ea5e4 | pastith | List<FileResource> res = citem.getFiles();
|
249 | a52ea5e4 | pastith | List<String> fileIds = new ArrayList<String>(); |
250 | 555e8e59 | pastith | String target = selectedFolder.getUri();
|
251 | a52ea5e4 | pastith | target = target.endsWith("/") ? target : target + '/'; |
252 | a52ea5e4 | pastith | |
253 | a52ea5e4 | pastith | if (citem.getOperation() == Clipboard.COPY) { |
254 | a52ea5e4 | pastith | for (FileResource fileResource : res) {
|
255 | a52ea5e4 | pastith | String fileTarget = target + fileResource.getName();
|
256 | 555e8e59 | pastith | fileIds.add(fileResource.getUri() + "?copy=" + fileTarget);
|
257 | a52ea5e4 | pastith | } |
258 | a52ea5e4 | pastith | int index = 0; |
259 | a52ea5e4 | pastith | executeCopyOrMove(index, fileIds); |
260 | a52ea5e4 | pastith | |
261 | a52ea5e4 | pastith | } else if (citem.getOperation() == Clipboard.CUT) { |
262 | a52ea5e4 | pastith | for (FileResource fileResource : res) {
|
263 | a52ea5e4 | pastith | String fileTarget = target + fileResource.getName();
|
264 | 555e8e59 | pastith | fileIds.add(fileResource.getUri() + "?move=" + fileTarget);
|
265 | a52ea5e4 | pastith | } |
266 | feeea1cf | Natasa Kapravelou | int index = 0; |
267 | a52ea5e4 | pastith | executeCopyOrMove(index, fileIds); |
268 | a52ea5e4 | pastith | } |
269 | a52ea5e4 | pastith | return;
|
270 | 14ad7326 | pastith | } |
271 | a52ea5e4 | pastith | } |
272 | 14ad7326 | pastith | } |
273 | 14ad7326 | pastith | |
274 | a52ea5e4 | pastith | private void executeCopyOrMove(final int index, final List<String> paths){ |
275 | a52ea5e4 | pastith | if(index >= paths.size()){
|
276 | a52ea5e4 | pastith | GSS.get().showFileList(true);
|
277 | 00bf0484 | koutsoub | GSS.get().getStatusPanel().updateStats(); |
278 | feeea1cf | Natasa Kapravelou | GSS.get().getClipboard().setItem(null);
|
279 | 14ad7326 | pastith | return;
|
280 | 14ad7326 | pastith | } |
281 | 895035a2 | pastith | PostCommand cf = new PostCommand(paths.get(index), "", 200) { |
282 | 555e8e59 | pastith | |
283 | a52ea5e4 | pastith | @Override
|
284 | a52ea5e4 | pastith | public void onComplete() { |
285 | a52ea5e4 | pastith | executeCopyOrMove(index+1, paths);
|
286 | 14ad7326 | pastith | } |
287 | 14ad7326 | pastith | |
288 | a52ea5e4 | pastith | @Override
|
289 | a52ea5e4 | pastith | public void onError(Throwable t) { |
290 | a52ea5e4 | pastith | GWT.log("", t);
|
291 | a52ea5e4 | pastith | if(t instanceof RestException){ |
292 | a52ea5e4 | pastith | int statusCode = ((RestException)t).getHttpStatusCode();
|
293 | a52ea5e4 | pastith | if(statusCode == 405) |
294 | a52ea5e4 | pastith | GSS.get().displayError("You don't have the necessary permissions");
|
295 | a52ea5e4 | pastith | else if(statusCode == 404) |
296 | a52ea5e4 | pastith | GSS.get().displayError("File not found");
|
297 | a52ea5e4 | pastith | else if(statusCode == 409) |
298 | a52ea5e4 | pastith | GSS.get().displayError("A file with the same name already exists");
|
299 | a52ea5e4 | pastith | else if(statusCode == 413) |
300 | a52ea5e4 | pastith | GSS.get().displayError("Your quota has been exceeded");
|
301 | a52ea5e4 | pastith | else
|
302 | 8218842e | koutsoub | GSS.get().displayError("Unable to copy file:"+((RestException)t).getHttpStatusText());
|
303 | a52ea5e4 | pastith | } |
304 | 14ad7326 | pastith | else
|
305 | a52ea5e4 | pastith | GSS.get().displayError("System error copying file:"+t.getMessage());
|
306 | 14ad7326 | pastith | } |
307 | a52ea5e4 | pastith | }; |
308 | a52ea5e4 | pastith | DeferredCommand.addCommand(cf); |
309 | 14ad7326 | pastith | } |
310 | 14ad7326 | pastith | } |