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