Revision 26cbae7a
b/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java | ||
---|---|---|
139 | 139 |
pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(this)); |
140 | 140 |
contextMenu.addItem(pasteItem); |
141 | 141 |
|
142 |
MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
|
142 |
MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this, selectedFolder));
|
|
143 | 143 |
contextMenu.addItem(upload); |
144 | 144 |
|
145 | 145 |
MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
... | ... | |
158 | 158 |
copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this)); |
159 | 159 |
contextMenu.addItem(copyItem); |
160 | 160 |
|
161 |
updateItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
|
162 |
contextMenu.addItem(updateItem); |
|
163 |
|
|
164 | 161 |
trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
165 | 162 |
contextMenu.addItem(trashItem); |
166 | 163 |
|
b/web_client/src/gr/grnet/pithos/web/client/FileList.java | ||
---|---|---|
417 | 417 |
|
418 | 418 |
@Override |
419 | 419 |
public void onClick(ClickEvent event) { |
420 |
new UploadFileCommand(null).execute(); |
|
420 |
new UploadFileCommand(null, treeView.getSelection()).execute();
|
|
421 | 421 |
} |
422 | 422 |
}); |
423 | 423 |
HorizontalPanel topPanel = new HorizontalPanel(); |
... | ... | |
435 | 435 |
|
436 | 436 |
@Override |
437 | 437 |
public void onClick(ClickEvent event) { |
438 |
new UploadFileCommand(null).execute(); |
|
438 |
new UploadFileCommand(null, treeView.getSelection()).execute();
|
|
439 | 439 |
} |
440 | 440 |
}); |
441 | 441 |
HorizontalPanel bottomPanel = new HorizontalPanel(); |
b/web_client/src/gr/grnet/pithos/web/client/FileMenu.java | ||
---|---|---|
202 | 202 |
// contextMenu.addItem(newFolderItem); |
203 | 203 |
} |
204 | 204 |
if(uploadVisible){ |
205 |
MenuItem uploadItem = new MenuItem("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
|
|
205 |
MenuItem uploadItem = new MenuItem("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this, null));
|
|
206 | 206 |
contextMenu.addItem(uploadItem); |
207 | 207 |
} |
208 | 208 |
if (downloadVisible) { |
b/web_client/src/gr/grnet/pithos/web/client/FileUploadDialog.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package gr.grnet.pithos.web.client; |
36 | 36 |
|
37 |
import com.google.gwt.core.client.Scheduler; |
|
38 |
import com.google.gwt.http.client.Response; |
|
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; |
|
37 | 42 |
import gr.grnet.pithos.web.client.rest.GetCommand; |
38 | 43 |
import gr.grnet.pithos.web.client.rest.PostCommand; |
44 |
import gr.grnet.pithos.web.client.rest.PutRequest; |
|
39 | 45 |
import gr.grnet.pithos.web.client.rest.RestCommand; |
40 | 46 |
import gr.grnet.pithos.web.client.rest.RestException; |
41 | 47 |
import gr.grnet.pithos.web.client.rest.resource.FileResource; |
... | ... | |
72 | 78 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
73 | 79 |
import com.google.gwt.user.client.ui.Label; |
74 | 80 |
import com.google.gwt.user.client.ui.VerticalPanel; |
81 |
import javax.xml.transform.Templates; |
|
75 | 82 |
|
76 | 83 |
/** |
77 | 84 |
* The 'File upload' dialog box implementation. |
78 | 85 |
*/ |
79 |
public class FileUploadDialog extends DialogBox implements Updateable {
|
|
86 |
public class FileUploadDialog extends DialogBox { |
|
80 | 87 |
|
81 |
protected int prgBarInterval = 1500; |
|
82 |
|
|
83 |
private ProgressBar progressBar; |
|
84 |
|
|
85 |
protected RepeatingTimer repeater = new RepeatingTimer(this, prgBarInterval); |
|
86 |
|
|
87 |
public static final boolean DONE = true; |
|
88 |
public static final boolean DONE = true; |
|
88 | 89 |
|
89 | 90 |
/** |
90 | 91 |
* The Form element that performs the file upload. |
... | ... | |
93 | 94 |
|
94 | 95 |
private final FileUpload upload = new FileUpload(); |
95 | 96 |
|
96 |
protected final Label filenameLabel = new Label("");
|
|
97 |
private final Label filenameLabel = new Label();
|
|
97 | 98 |
|
98 |
protected List<FileResource> files;
|
|
99 |
private final Label foldernameLabel = new Label();
|
|
99 | 100 |
|
100 |
protected boolean cancelEvent = false;
|
|
101 |
private Button submit;
|
|
101 | 102 |
|
102 |
protected String fileNameToUse;
|
|
103 |
protected Folder folder;
|
|
103 | 104 |
|
104 |
protected FolderResource folder;
|
|
105 |
protected GSS app;
|
|
105 | 106 |
|
106 | 107 |
/** |
107 | 108 |
* The widget's constructor. |
... | ... | |
123 | 124 |
"Gears</a><br> for uploading multiple files simultaneously."); |
124 | 125 |
info.addStyleName("pithos-uploadNote"); |
125 | 126 |
panel.add(info); |
126 |
final Hidden date = new Hidden("Date", ""); |
|
127 |
panel.add(date); |
|
128 |
final Hidden auth = new Hidden("Authorization", ""); |
|
129 |
panel.add(auth); |
|
130 |
// Add an informative label with the folder name. |
|
131 |
Object selection = GSS.get().getTreeView().getSelection(); |
|
132 |
folder = ((RestResourceWrapper) selection).getResource(); |
|
127 |
|
|
128 |
final Hidden auth = new Hidden("X-Auth-Token", ""); |
|
129 |
panel.add(auth); |
|
133 | 130 |
upload.setName("file"); |
134 | 131 |
filenameLabel.setText(""); |
135 | 132 |
filenameLabel.setVisible(false); |
136 | 133 |
filenameLabel.setStyleName("props-labels"); |
137 |
HorizontalPanel fileUloadPanel = new HorizontalPanel(); |
|
138 |
fileUloadPanel.add(filenameLabel); |
|
139 |
fileUloadPanel.add(upload); |
|
140 |
upload.getElement().setId("fileUploadDiallog.uploadPanel"); |
|
134 |
HorizontalPanel fileUploadPanel = new HorizontalPanel(); |
|
135 |
fileUploadPanel.add(filenameLabel); |
|
136 |
fileUploadPanel.add(upload); |
|
141 | 137 |
Grid generalTable = new Grid(2, 2); |
142 | 138 |
generalTable.setText(0, 0, "Folder"); |
139 |
generalTable.setWidget(0, 1, foldernameLabel); |
|
143 | 140 |
generalTable.setText(1, 0, "File"); |
144 |
generalTable.setText(0, 1, folder.getName()); |
|
145 |
generalTable.setWidget(1, 1, fileUloadPanel); |
|
141 |
generalTable.setWidget(1, 1, fileUploadPanel); |
|
146 | 142 |
generalTable.getCellFormatter().setStyleName(0, 0, "props-labels"); |
143 |
generalTable.getCellFormatter().setStyleName(0, 1, "props-values"); |
|
147 | 144 |
generalTable.getCellFormatter().setStyleName(1, 0, "props-labels"); |
148 |
generalTable.getCellFormatter().setStyleName(0, 1, "props-values"); |
|
149 | 145 |
generalTable.getCellFormatter().setStyleName(1, 1, "props-values"); |
150 | 146 |
generalTable.setCellSpacing(4); |
151 | 147 |
|
... | ... | |
156 | 152 |
|
157 | 153 |
// Create the 'upload' button, along with a listener that submits the |
158 | 154 |
// form. |
159 |
final Button submit = new Button("Upload", new ClickHandler() {
|
|
155 |
submit = new Button("Upload", new ClickHandler() { |
|
160 | 156 |
@Override |
161 | 157 |
public void onClick(ClickEvent event) { |
162 | 158 |
prepareAndSubmit(); |
163 | 159 |
} |
164 | 160 |
}); |
165 |
submit.getElement().setId("fileUploadDialog.button.upload"); |
|
166 | 161 |
buttons.add(submit); |
167 | 162 |
buttons.setCellHorizontalAlignment(submit, HasHorizontalAlignment.ALIGN_CENTER); |
168 | 163 |
// Create the 'Cancel' button, along with a listener that hides the |
... | ... | |
170 | 165 |
final Button cancel = new Button("Cancel", new ClickHandler() { |
171 | 166 |
@Override |
172 | 167 |
public void onClick(ClickEvent event) { |
173 |
repeater.finish(); |
|
174 | 168 |
hide(); |
175 | 169 |
} |
176 | 170 |
}); |
177 |
cancel.getElement().setId("fileUploadDialog.button.cancel"); |
|
178 | 171 |
buttons.add(cancel); |
179 | 172 |
buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
180 | 173 |
buttons.setSpacing(8); |
181 | 174 |
buttons.addStyleName("pithos-DialogBox"); |
175 |
panel.add(buttons); |
|
176 |
panel.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); |
|
182 | 177 |
|
183 | 178 |
// Add an event handler to the form. |
184 | 179 |
form.addSubmitHandler(new SubmitHandler() { |
185 | 180 |
|
186 | 181 |
@Override |
187 | 182 |
public void onSubmit(SubmitEvent event) { |
188 |
GSS app = GSS.get(); |
|
189 |
// This event is fired just before the form is submitted. We can |
|
190 |
// take this opportunity to perform validation. |
|
191 |
if (upload.getFilename().length() == 0) { |
|
192 |
app.displayError("You must select a file!"); |
|
193 |
event.cancel(); |
|
194 |
hide(); |
|
195 |
} else { |
|
196 |
|
|
197 |
canContinue(); |
|
198 |
GWT.log("Cancel:" + cancelEvent, null); |
|
199 |
if (cancelEvent) { |
|
200 |
cancelEvent = false; |
|
201 |
app.displayError("The specified file name already exists in this folder"); |
|
202 |
event.cancel(); |
|
203 |
hide(); |
|
204 |
} else { |
|
205 |
|
|
206 |
fileNameToUse = getFilename(upload.getFilename()); |
|
207 |
String apath; |
|
208 |
FileResource selectedFile = getFileForName(fileNameToUse); |
|
209 |
if (selectedFile == null ) { |
|
210 |
//we are going to create a file |
|
211 |
apath = folder.getUri(); |
|
212 |
if (!apath.endsWith("/")) |
|
213 |
apath = apath + "/"; |
|
214 |
apath = apath + encodeComponent(fileNameToUse); |
|
215 |
} else |
|
216 |
apath = selectedFile.getUri(); |
|
217 |
form.setAction(apath); |
|
218 |
String dateString = RestCommand.getDate(); |
|
219 |
String resource = apath.substring(app.getApiPath().length() - 1, apath.length()); |
|
220 |
String sig = RestCommand.calculateSig("POST", dateString, resource, RestCommand.base64decode(app.getToken())); |
|
221 |
date.setValue(dateString); |
|
222 |
auth.setValue(app.getCurrentUserResource().getUsername() + " " + sig); |
|
223 |
GWT.log("FolderPATH:" + folder.getUri(), null); |
|
224 |
submit.setEnabled(false); |
|
225 |
upload.setVisible(false); |
|
226 |
filenameLabel.setText(fileNameToUse); |
|
227 |
filenameLabel.setVisible(true); |
|
228 |
repeater.start(); |
|
229 |
progressBar.setVisible(true); |
|
230 |
} |
|
231 |
} |
|
232 |
|
|
183 |
auth.setValue(app.getToken()); //This is done here because the app object is not available in the constructor |
|
233 | 184 |
} |
234 | 185 |
}); |
235 | 186 |
form.addSubmitCompleteHandler(new SubmitCompleteHandler() { |
... | ... | |
244 | 195 |
|
245 | 196 |
// Unfortunately the results are never empty, even in |
246 | 197 |
// the absense of errors, so we have to check for '<pre></pre>'. |
247 |
if (!results.equalsIgnoreCase("<pre></pre>")) { |
|
198 |
if (results != null && !results.equalsIgnoreCase("<pre></pre>")) {
|
|
248 | 199 |
GWT.log(results, null); |
249 |
GSS.get().displayError(results);
|
|
200 |
app.displayError(results);
|
|
250 | 201 |
} |
251 |
progressBar.setProgress(100); |
|
252 |
cancelUpload(); |
|
253 |
GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection()); |
|
254 |
GSS.get().getStatusPanel().updateStats(); |
|
255 |
|
|
202 |
app.updateFolder(folder); |
|
203 |
hide(); |
|
256 | 204 |
} |
257 | 205 |
}); |
258 | 206 |
|
259 | 207 |
|
260 |
panel.add(buttons); |
|
261 |
progressBar = new ProgressBar(50, ProgressBar.SHOW_TIME_REMAINING); |
|
262 |
panel.add(progressBar); |
|
263 |
progressBar.setVisible(false); |
|
264 |
panel.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); |
|
265 |
panel.setCellHorizontalAlignment(progressBar, HasHorizontalAlignment.ALIGN_CENTER); |
|
266 | 208 |
panel.addStyleName("pithos-DialogBox"); |
267 | 209 |
addStyleName("pithos-DialogBox"); |
268 | 210 |
setWidget(form); |
... | ... | |
281 | 223 |
prepareAndSubmit(); |
282 | 224 |
break; |
283 | 225 |
case KeyCodes.KEY_ESCAPE: |
284 |
cancelUpload();
|
|
226 |
hide();
|
|
285 | 227 |
break; |
286 | 228 |
} |
287 | 229 |
} |
288 | 230 |
|
289 |
|
|
290 |
|
|
291 |
/** |
|
292 |
* Cancels the file upload. |
|
293 |
*/ |
|
294 |
private void cancelUpload() { |
|
295 |
repeater.finish(); |
|
296 |
hide(); |
|
297 |
} |
|
298 |
|
|
299 | 231 |
/** |
300 | 232 |
* Make any last minute checks and start the upload. |
301 | 233 |
*/ |
302 |
public void prepareAndSubmit() { |
|
303 |
final String fname = getFilename(upload.getFilename()); |
|
234 |
protected void prepareAndSubmit() { |
|
235 |
if (upload.getFilename().length() == 0) { |
|
236 |
app.displayError("You must select a file!"); |
|
237 |
return; |
|
238 |
} |
|
239 |
final String fname = getFilename(upload.getFilename()); |
|
240 |
String apath = app.getApiPath() + app.getUsername() + folder.getUri() + "/" + fname; |
|
241 |
form.setAction(apath); |
|
242 |
submit.setEnabled(false); |
|
243 |
upload.setVisible(false); |
|
244 |
filenameLabel.setText(fname); |
|
245 |
filenameLabel.setVisible(true); |
|
246 |
|
|
304 | 247 |
if (getFileForName(fname) == null) { |
305 |
//we are going to create a file, so we check to see if there is a trashed file with the same name |
|
306 |
FileResource same = null; |
|
307 |
for (FileResource fres : folder.getFiles()) |
|
308 |
if (fres.isDeleted() && fres.getName().equals(fname)) |
|
309 |
same = fres; |
|
310 |
if (same == null) |
|
311 |
form.submit(); |
|
312 |
else { |
|
313 |
final FileResource sameFile = same; |
|
314 |
GWT.log("Same deleted file", null); |
|
315 |
ConfirmationDialog confirm = new ConfirmationDialog("A file with " + |
|
316 |
"the same name exists in the trash. If you continue,<br/>the trashed " + |
|
317 |
"file '" + fname + "' will be renamed automatically for you.", "Continue") { |
|
318 |
|
|
319 |
@Override |
|
320 |
public void cancel() { |
|
321 |
FileUploadDialog.this.hide(); |
|
322 |
} |
|
323 |
|
|
324 |
@Override |
|
325 |
public void confirm() { |
|
326 |
updateTrashedFile(getBackupFilename(fname), sameFile); |
|
327 |
} |
|
328 |
|
|
329 |
}; |
|
330 |
confirm.center(); |
|
331 |
} |
|
248 |
doUpload(apath); |
|
332 | 249 |
} |
333 | 250 |
else { |
334 | 251 |
// We are going to update an existing file, so show a confirmation dialog. |
... | ... | |
350 | 267 |
} |
351 | 268 |
} |
352 | 269 |
|
353 |
/** |
|
270 |
private void doUpload(String path) { |
|
271 |
PutRequest createFile = new PutRequest(path) { |
|
272 |
@Override |
|
273 |
public void onSuccess(Resource result) { |
|
274 |
form.submit(); |
|
275 |
} |
|
276 |
|
|
277 |
@Override |
|
278 |
public void onError(Throwable t) { |
|
279 |
GWT.log("", t); |
|
280 |
if (t instanceof RestException) { |
|
281 |
app.displayError("Unable to create file:" + ((RestException) t).getHttpStatusText()); |
|
282 |
} |
|
283 |
else |
|
284 |
app.displayError("System error creating file:" + t.getMessage()); |
|
285 |
} |
|
286 |
}; |
|
287 |
createFile.setHeader("X-Auth-Token", app.getToken()); |
|
288 |
createFile.setHeader("Content-Length", "0"); |
|
289 |
Scheduler.get().scheduleDeferred(createFile); |
|
290 |
} |
|
291 |
|
|
292 |
/** |
|
354 | 293 |
* Returns the file name from a potential full path argument. Apparently IE |
355 | 294 |
* insists on sending the full path name of a file when uploading, forcing |
356 | 295 |
* us to trim the extra path info. Since this is only observed on Windows we |
... | ... | |
369 | 308 |
return name.substring(pathSepIndex + 1); |
370 | 309 |
} |
371 | 310 |
|
372 |
/** |
|
373 |
* Check whether the file name exists in selected folder. |
|
374 |
* |
|
375 |
* @return |
|
376 |
*/ |
|
377 |
private boolean canContinue() { |
|
378 |
if (files == null) |
|
379 |
return false; |
|
380 |
String fileName = getFilename(upload.getFilename()); |
|
381 |
if (getFileForName(fileName) == null) { |
|
382 |
// For file creation, check to see if the file already exists. |
|
383 |
GWT.log("filename to upload:" + fileName, null); |
|
384 |
for (FileResource dto : files) { |
|
385 |
GWT.log("Check:" + dto.getName() + "/" + fileName, null); |
|
386 |
if (!dto.isDeleted() && dto.getName().equals(fileName)) { |
|
387 |
cancelEvent = true; |
|
388 |
return true; |
|
389 |
} |
|
390 |
} |
|
391 |
} |
|
392 |
return true; |
|
393 |
} |
|
394 |
|
|
395 |
class RepeatingTimer extends Timer { |
|
396 |
|
|
397 |
private Updateable updateable; |
|
398 |
|
|
399 |
private int interval = 1500; |
|
400 |
|
|
401 |
private boolean running = true; |
|
402 |
|
|
403 |
RepeatingTimer(Updateable _updateable, int _interval) { |
|
404 |
updateable = _updateable; |
|
405 |
interval = _interval; |
|
406 |
} |
|
407 |
|
|
408 |
@Override |
|
409 |
public void run() { |
|
410 |
updateable.update(); |
|
411 |
} |
|
412 |
|
|
413 |
public void start() { |
|
414 |
running = true; |
|
415 |
|
|
416 |
scheduleRepeating(interval); |
|
417 |
} |
|
418 |
|
|
419 |
public void finish() { |
|
420 |
running = false; |
|
421 |
cancel(); |
|
422 |
} |
|
423 |
|
|
424 |
public int getInterval() { |
|
425 |
return interval; |
|
426 |
} |
|
427 |
|
|
428 |
public void setInterval(int anInterval) { |
|
429 |
if (interval != anInterval) { |
|
430 |
interval = anInterval; |
|
431 |
if (running) { |
|
432 |
finish(); |
|
433 |
start(); |
|
434 |
} |
|
435 |
} |
|
436 |
} |
|
437 |
} |
|
438 |
|
|
439 |
@Override |
|
440 |
public void update() { |
|
441 |
String apath = folder.getUri(); |
|
442 |
if (!apath.endsWith("/")) |
|
443 |
apath = apath + "/"; |
|
444 |
apath = apath + encodeComponent(fileNameToUse) + "?progress=" + encodeComponent(fileNameToUse); |
|
445 |
GetCommand eg = new GetCommand<UploadStatusResource>(UploadStatusResource.class, apath, false, null) { |
|
446 |
|
|
447 |
@Override |
|
448 |
public void onComplete() { |
|
449 |
UploadStatusResource res = getResult(); |
|
450 |
progressBar.setProgress(res.percent()); |
|
451 |
} |
|
452 |
|
|
453 |
@Override |
|
454 |
public void onError(Throwable t) { |
|
455 |
GWT.log("", t); |
|
456 |
} |
|
457 |
|
|
458 |
}; |
|
459 |
DeferredCommand.addCommand(eg); |
|
460 |
} |
|
461 |
|
|
462 |
protected String getBackupFilename(String filename) { |
|
463 |
List<FileResource> filesInSameFolder = new ArrayList<FileResource>(); |
|
464 |
for (FileResource deleted : folder.getFiles()) |
|
465 |
if (deleted.isDeleted()) |
|
466 |
filesInSameFolder.add(deleted); |
|
467 |
int i = 1; |
|
468 |
for (FileResource same : filesInSameFolder) |
|
469 |
if (same.getName().startsWith(filename)) { |
|
470 |
String toCheck = same.getName().substring(filename.length(), same.getName().length()); |
|
471 |
if (toCheck.startsWith(" ")) { |
|
472 |
int test = -1; |
|
473 |
try { |
|
474 |
test = Integer.valueOf(toCheck.replace(" ", "")); |
|
475 |
} catch (NumberFormatException e) { |
|
476 |
// Do nothing since string is not a number. |
|
477 |
} |
|
478 |
if (test >= i) |
|
479 |
i = test + 1; |
|
480 |
} |
|
481 |
} |
|
482 |
|
|
483 |
return filename + " " + i; |
|
484 |
} |
|
485 |
|
|
486 |
/** |
|
487 |
* Rename the conflicting trashed file with the supplied new name. |
|
488 |
*/ |
|
489 |
private void updateTrashedFile(String newName, FileResource trashedFile) { |
|
490 |
JSONObject json = new JSONObject(); |
|
491 |
json.put("name", new JSONString(newName)); |
|
492 |
PostCommand cf = new PostCommand(trashedFile.getUri() + "?update=", json.toString(), 200) { |
|
493 |
|
|
494 |
@Override |
|
495 |
public void onComplete() { |
|
496 |
form.submit(); |
|
497 |
} |
|
498 |
|
|
499 |
@Override |
|
500 |
public void onError(Throwable t) { |
|
501 |
GSS app = GSS.get(); |
|
502 |
GWT.log("", t); |
|
503 |
if (t instanceof RestException) { |
|
504 |
int statusCode = ((RestException) t).getHttpStatusCode(); |
|
505 |
if (statusCode == 405) |
|
506 |
app.displayError("You don't have the necessary permissions"); |
|
507 |
else if (statusCode == 404) |
|
508 |
app.displayError("User in permissions does not exist"); |
|
509 |
else if (statusCode == 409) |
|
510 |
app.displayError("A file with the same name already exists"); |
|
511 |
else if (statusCode == 413) |
|
512 |
app.displayError("Your quota has been exceeded"); |
|
513 |
else |
|
514 |
app.displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText()); |
|
515 |
} else |
|
516 |
app.displayError("System error modifying file:" + t.getMessage()); |
|
517 |
} |
|
518 |
|
|
519 |
}; |
|
520 |
DeferredCommand.addCommand(cf); |
|
521 |
} |
|
522 |
|
|
523 |
protected FileResource getFileForName(String name){ |
|
524 |
for (FileResource f : folder.getFiles()) |
|
525 |
if (!f.isDeleted() && f.getName().equals(name)) |
|
311 |
protected File getFileForName(String name){ |
|
312 |
for (File f : folder.getFiles()) |
|
313 |
if (!f.isInTrash() && f.getName().equals(name)) |
|
526 | 314 |
return f; |
527 | 315 |
return null; |
528 | 316 |
} |
529 | 317 |
|
318 |
public void setApp(GSS app) { |
|
319 |
this.app = app; |
|
320 |
} |
|
530 | 321 |
|
531 |
/** |
|
532 |
* Same as URL.encodeComponent, but also |
|
533 |
* encode apostrophe since browsers aren't consistent about it |
|
534 |
* (FF encodes, IE does not). |
|
535 |
*/ |
|
536 |
private String encodeComponent(String decodedURLComponent) { |
|
537 |
String retv = URL.encodeComponent(decodedURLComponent); |
|
538 |
retv = retv.replaceAll("'", "%27"); |
|
539 |
return retv; |
|
540 |
} |
|
541 |
|
|
542 |
/** |
|
543 |
* Modify the files. |
|
544 |
* |
|
545 |
* @param newFiles the files to set |
|
546 |
*/ |
|
547 |
public void setFiles(List<FileResource> newFiles) { |
|
548 |
files = newFiles; |
|
549 |
} |
|
322 |
public void setFolder(Folder folder) { |
|
323 |
this.folder = folder; |
|
324 |
foldernameLabel.setText(folder.getName()); |
|
325 |
} |
|
550 | 326 |
} |
b/web_client/src/gr/grnet/pithos/web/client/FileUploadGearsDialog.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package gr.grnet.pithos.web.client; |
36 | 36 |
|
37 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
|
37 | 38 |
import gr.grnet.pithos.web.client.rest.PostCommand; |
38 | 39 |
import gr.grnet.pithos.web.client.rest.RestCommand; |
39 | 40 |
import gr.grnet.pithos.web.client.rest.RestException; |
40 | 41 |
import gr.grnet.pithos.web.client.rest.resource.FileResource; |
41 |
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
|
42 | 42 |
|
43 | 43 |
import java.util.ArrayList; |
44 | 44 |
import java.util.Arrays; |
... | ... | |
71 | 71 |
/** |
72 | 72 |
* The 'File upload' dialog box implementation with Google Gears support. |
73 | 73 |
*/ |
74 |
public class FileUploadGearsDialog extends FileUploadDialog implements Updateable {
|
|
74 |
public class FileUploadGearsDialog extends FileUploadDialog { |
|
75 | 75 |
|
76 | 76 |
protected final Factory factory = Factory.getInstance(); |
77 | 77 |
|
... | ... | |
97 | 97 |
|
98 | 98 |
private FlexTable generalTable; |
99 | 99 |
|
100 |
private Map<String, FileResource> toRename;
|
|
100 |
private Map<String, gr.grnet.pithos.web.client.foldertree.File> toRename;
|
|
101 | 101 |
|
102 | 102 |
protected List<HttpRequest> requests = new ArrayList<HttpRequest>(); |
103 | 103 |
|
104 | 104 |
private boolean canContinue = true; |
105 | 105 |
|
106 |
protected FileUploadGearsDialog() { |
|
107 |
} |
|
108 |
|
|
106 | 109 |
/** |
107 | 110 |
* The widget's constructor. |
108 | 111 |
*/ |
109 |
public FileUploadGearsDialog() { |
|
112 |
public FileUploadGearsDialog(GSS _app, Folder _folder) { |
|
113 |
this.folder = _folder; |
|
114 |
this.app = _app; |
|
110 | 115 |
// Set the dialog's caption. |
111 | 116 |
setText("File upload"); |
112 | 117 |
setAnimationEnabled(true); |
... | ... | |
117 | 122 |
panel.add(info); |
118 | 123 |
// Add an informative label with the folder name. |
119 | 124 |
Object selection = GSS.get().getTreeView().getSelection(); |
120 |
folder = ((RestResourceWrapper) selection).getResource(); |
|
121 | 125 |
|
122 | 126 |
browse = new Button("Browse..."); |
123 | 127 |
|
... | ... | |
206 | 210 |
hide(); |
207 | 211 |
} |
208 | 212 |
|
209 |
/** |
|
210 |
* Check whether the specified file name exists in the selected folder. |
|
211 |
*/ |
|
212 |
private boolean canContinue(File file) { |
|
213 |
String fileName = getFilename(file.getName()); |
|
214 |
if (getFileForName(fileName) == null) |
|
215 |
// For file creation, check to see if the file already exists. |
|
216 |
for (FileResource fileRes : files) |
|
217 |
if (!fileRes.isDeleted() && fileRes.getName().equals(fileName)) |
|
218 |
return false; |
|
219 |
return true; |
|
220 |
} |
|
221 |
|
|
222 | 213 |
@Override |
223 | 214 |
public void prepareAndSubmit() { |
224 | 215 |
GSS app = GSS.get(); |
... | ... | |
227 | 218 |
hide(); |
228 | 219 |
return; |
229 | 220 |
} |
230 |
for (File file: selectedFiles) |
|
231 |
if (!canContinue(file)) { |
|
232 |
app.displayError("The file name " + file.getName() + |
|
233 |
" already exists in this folder"); |
|
234 |
hide(); |
|
235 |
return; |
|
236 |
} |
|
237 | 221 |
submit.setEnabled(false); |
238 | 222 |
browse.setVisible(false); |
239 | 223 |
List<String> toUpdate = new ArrayList<String>(); |
240 |
toRename = new HashMap<String, FileResource>();
|
|
224 |
toRename = new HashMap<String, gr.grnet.pithos.web.client.foldertree.File>();
|
|
241 | 225 |
for (File file: selectedFiles) { |
242 | 226 |
String fname = getFilename(file.getName()); |
243 | 227 |
if (getFileForName(fname) == null) { |
244 | 228 |
// We are going to create a file, so we check to see if there is a |
245 | 229 |
// trashed file with the same name. |
246 |
FileResource same = null;
|
|
247 |
for (FileResource fres : folder.getFiles())
|
|
248 |
if (fres.isDeleted() && fres.getName().equals(fname))
|
|
230 |
gr.grnet.pithos.web.client.foldertree.File same = null;
|
|
231 |
for (gr.grnet.pithos.web.client.foldertree.File fres : folder.getFiles())
|
|
232 |
if (fres.isInTrash() && fres.getName().equals(fname))
|
|
249 | 233 |
same = fres; |
250 | 234 |
// In that case add it to the list of files to rename. |
251 | 235 |
if (same != null) |
... | ... | |
286 | 270 |
private void confirmRename() { |
287 | 271 |
if (!toRename.isEmpty()) { |
288 | 272 |
StringBuffer sb = new StringBuffer(); |
289 |
for (FileResource file: toRename.values())
|
|
273 |
for (gr.grnet.pithos.web.client.foldertree.File file: toRename.values())
|
|
290 | 274 |
sb.append(file.getName()).append("<br/>"); |
291 | 275 |
ConfirmationDialog confirm = new ConfirmationDialog("Files " + |
292 | 276 |
"with the following names already exist in the trash. If" + |
... | ... | |
454 | 438 |
return retv; |
455 | 439 |
} |
456 | 440 |
|
441 |
protected String getBackupFilename(String filename) { |
|
442 |
List<gr.grnet.pithos.web.client.foldertree.File> filesInSameFolder = new ArrayList<gr.grnet.pithos.web.client.foldertree.File>(); |
|
443 |
for (gr.grnet.pithos.web.client.foldertree.File deleted : folder.getFiles()) |
|
444 |
if (deleted.isInTrash()) |
|
445 |
filesInSameFolder.add(deleted); |
|
446 |
int i = 1; |
|
447 |
for (gr.grnet.pithos.web.client.foldertree.File same : filesInSameFolder) |
|
448 |
if (same.getName().startsWith(filename)) { |
|
449 |
String toCheck = same.getName().substring(filename.length(), same.getName().length()); |
|
450 |
if (toCheck.startsWith(" ")) { |
|
451 |
int test = -1; |
|
452 |
try { |
|
453 |
test = Integer.valueOf(toCheck.replace(" ", "")); |
|
454 |
} catch (NumberFormatException e) { |
|
455 |
// Do nothing since string is not a number. |
|
456 |
} |
|
457 |
if (test >= i) |
|
458 |
i = test + 1; |
|
459 |
} |
|
460 |
} |
|
461 |
|
|
462 |
return filename + " " + i; |
|
463 |
} |
|
457 | 464 |
} |
b/web_client/src/gr/grnet/pithos/web/client/FileUploadGearsIEDialog.java | ||
---|---|---|
48 | 48 |
* The 'File upload' dialog box implementation with Google Gears support |
49 | 49 |
* for IE. |
50 | 50 |
*/ |
51 |
public class FileUploadGearsIEDialog extends FileUploadGearsDialog implements Updateable {
|
|
51 |
public class FileUploadGearsIEDialog extends FileUploadGearsDialog { |
|
52 | 52 |
|
53 | 53 |
/** |
54 | 54 |
* Perform the HTTP request to upload the specified file. |
b/web_client/src/gr/grnet/pithos/web/client/GSS.java | ||
---|---|---|
283 | 283 |
@Override |
284 | 284 |
public void onSelectionChange(SelectionChangeEvent event) { |
285 | 285 |
Folder f = folderTreeSelectionModel.getSelectedObject(); |
286 |
showFiles(f);
|
|
286 |
updateFolder(f);
|
|
287 | 287 |
} |
288 | 288 |
}); |
289 | 289 |
|
... | ... | |
341 | 341 |
}); |
342 | 342 |
} |
343 | 343 |
|
344 |
private void showFiles(Folder f) {
|
|
344 |
public void showFiles(Folder f) {
|
|
345 | 345 |
inner.selectTab(0); |
346 | 346 |
Set<File> files = f.getFiles(); |
347 | 347 |
Iterator<File> iter = files.iterator(); |
/dev/null | ||
---|---|---|
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; |
|
36 |
|
|
37 |
|
|
38 |
public interface Updateable { |
|
39 |
public void update(); |
|
40 |
} |
b/web_client/src/gr/grnet/pithos/web/client/commands/UploadFileCommand.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
import gr.grnet.pithos.web.client.FileUploadDialog; |
38 | 38 |
import gr.grnet.pithos.web.client.GSS; |
39 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
|
39 | 40 |
import gr.grnet.pithos.web.client.rest.GetCommand; |
40 | 41 |
import gr.grnet.pithos.web.client.rest.resource.FileResource; |
41 | 42 |
import gr.grnet.pithos.web.client.rest.resource.FolderResource; |
... | ... | |
58 | 59 |
public class UploadFileCommand implements Command { |
59 | 60 |
|
60 | 61 |
private PopupPanel containerPanel; |
61 |
private List<FileResource> files; |
|
62 | 62 |
|
63 |
public UploadFileCommand(PopupPanel _containerPanel) { |
|
63 |
/* |
|
64 |
* The folder that is the target of the upload |
|
65 |
*/ |
|
66 |
private Folder folder; |
|
67 |
|
|
68 |
public UploadFileCommand(PopupPanel _containerPanel, Folder _folder) { |
|
64 | 69 |
containerPanel = _containerPanel; |
70 |
folder = _folder; |
|
65 | 71 |
} |
66 | 72 |
|
67 | 73 |
@Override |
... | ... | |
75 | 81 |
* Display the 'new file' dialog for uploading a new file to the system. |
76 | 82 |
*/ |
77 | 83 |
private void displayNewFile() { |
78 |
RestResource currentFolder = GSS.get().getTreeView().getSelection(); |
|
79 |
if (currentFolder == null) { |
|
80 |
GSS.get().displayError("You have to select the parent folder first"); |
|
81 |
return; |
|
82 |
} |
|
83 |
getFileList(); |
|
84 |
DeferredCommand.addCommand(new IncrementalCommand() { |
|
85 |
|
|
86 |
@Override |
|
87 |
public boolean execute() { |
|
88 |
boolean res = canContinue(); |
|
89 |
if (res) { |
|
90 |
FileUploadDialog dlg = GWT.create(FileUploadDialog.class); |
|
91 |
dlg.setFiles(files); |
|
92 |
dlg.center(); |
|
93 |
return false; |
|
94 |
} |
|
95 |
return true; |
|
96 |
} |
|
97 |
|
|
98 |
}); |
|
84 |
FileUploadDialog dlg = GWT.create(FileUploadDialog.class); |
|
85 |
dlg.setApp(GSS.get()); |
|
86 |
dlg.setFolder(folder); |
|
87 |
dlg.center(); |
|
99 | 88 |
} |
100 |
|
|
101 |
private boolean canContinue() { |
|
102 |
if (files != null ) |
|
103 |
return true; |
|
104 |
return false; |
|
105 |
} |
|
106 |
|
|
107 |
private void getFileList() { |
|
108 |
GetCommand<FolderResource> eg = new GetCommand<FolderResource>(FolderResource.class,((RestResourceWrapper)GSS.get().getTreeView().getSelection()).getUri(), null){ |
|
109 |
|
|
110 |
@Override |
|
111 |
public void onComplete() { |
|
112 |
files = getResult().getFiles(); |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
public void onError(Throwable t) { |
|
117 |
files = new ArrayList<FileResource>(); |
|
118 |
} |
|
119 |
|
|
120 |
}; |
|
121 |
DeferredCommand.addCommand(eg); |
|
122 |
} |
|
123 |
|
|
124 | 89 |
} |
b/web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java | ||
---|---|---|
212 | 212 |
public Folder getParent() { |
213 | 213 |
return parent; |
214 | 214 |
} |
215 |
|
|
216 |
public String getUri() { |
|
217 |
return "/" + container + (prefix.length() == 0 ? "" : "/" + prefix); |
|
218 |
} |
|
215 | 219 |
} |
b/web_client/src/gr/grnet/pithos/web/client/foldertree/FolderTreeViewModel.java | ||
---|---|---|
116 | 116 |
} |
117 | 117 |
|
118 | 118 |
private void fetchFolder(final Iterator<Folder> iter, final ListDataProvider<Folder> dataProvider, final Set<Folder> folders) { |
119 |
final GSS app = GSS.get(); |
|
119 | 120 |
if (iter.hasNext()) { |
120 | 121 |
final Folder f = iter.next(); |
121 | 122 |
|
122 |
GSS app = GSS.get(); |
|
123 | 123 |
String path = app.getApiPath() + app.getUsername() + "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + f.getPrefix(); |
124 | 124 |
GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, path, f) { |
125 | 125 |
@Override |
... | ... | |
174 | 174 |
GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, path, f) { |
175 | 175 |
@Override |
176 | 176 |
public void onSuccess(Folder result) { |
177 |
app.showFiles(f); |
|
177 | 178 |
Iterator<Folder> iter = result.getSubfolders().iterator(); |
178 | 179 |
fetchFolder(iter, dataProvider, result.getSubfolders()); |
179 | 180 |
} |
Also available in: Unified diff