Revision 816de19f
b/web_client/src/gr/grnet/pithos/web/client/DeleteFileDialog.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package gr.grnet.pithos.web.client; |
36 | 36 |
|
37 |
import com.google.gwt.core.client.Scheduler; |
|
37 | 38 |
import gr.grnet.pithos.web.client.MessagePanel.Images; |
39 |
import gr.grnet.pithos.web.client.foldertree.File; |
|
40 |
import gr.grnet.pithos.web.client.foldertree.Resource; |
|
38 | 41 |
import gr.grnet.pithos.web.client.rest.DeleteCommand; |
42 |
import gr.grnet.pithos.web.client.rest.DeleteRequest; |
|
39 | 43 |
import gr.grnet.pithos.web.client.rest.MultipleDeleteCommand; |
40 | 44 |
import gr.grnet.pithos.web.client.rest.RestException; |
41 | 45 |
import gr.grnet.pithos.web.client.rest.resource.FileResource; |
42 | 46 |
|
43 | 47 |
import java.util.ArrayList; |
48 |
import java.util.Iterator; |
|
44 | 49 |
import java.util.List; |
45 | 50 |
|
46 | 51 |
import com.google.gwt.core.client.GWT; |
... | ... | |
63 | 68 |
*/ |
64 | 69 |
public class DeleteFileDialog extends DialogBox { |
65 | 70 |
|
71 |
private List<File> files; |
|
66 | 72 |
/** |
67 | 73 |
* The widget's constructor. |
68 | 74 |
* |
69 | 75 |
* @param images the supplied images |
70 | 76 |
*/ |
71 |
public DeleteFileDialog(Images images) { |
|
77 |
public DeleteFileDialog(Images images, List<File> _files) { |
|
78 |
files = _files; |
|
72 | 79 |
// Set the dialog's caption. |
73 | 80 |
setText("Confirmation"); |
74 | 81 |
setAnimationEnabled(true); |
75 |
Object selection = GSS.get().getCurrentSelection(); |
|
76 | 82 |
// Create a VerticalPanel to contain the label and the buttons. |
77 | 83 |
VerticalPanel outer = new VerticalPanel(); |
78 | 84 |
HorizontalPanel buttons = new HorizontalPanel(); |
79 | 85 |
|
80 | 86 |
HTML text; |
81 |
if (selection instanceof FileResource)
|
|
82 |
text = new HTML("<table><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + "Are you sure you want to <b>permanently</b> delete file '" + ((FileResource) selection).getName() + "'?</td></tr></table>");
|
|
87 |
if (files.size() == 1)
|
|
88 |
text = new HTML("<table><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + "Are you sure you want to <b>permanently</b> delete file '" + files.get(0).getName() + "'?</td></tr></table>");
|
|
83 | 89 |
else |
84 | 90 |
text = new HTML("<table><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + "Are you sure you want to <b>permanently</b> delete the selected files?</td></tr></table>"); |
85 | 91 |
text.setStyleName("pithos-warnMessage"); |
... | ... | |
90 | 96 |
Button ok = new Button("Delete", new ClickHandler() { |
91 | 97 |
@Override |
92 | 98 |
public void onClick(ClickEvent event) { |
93 |
deleteFile(); |
|
99 |
deleteFiles();
|
|
94 | 100 |
hide(); |
95 | 101 |
} |
96 | 102 |
}); |
... | ... | |
119 | 125 |
|
120 | 126 |
/** |
121 | 127 |
* Generate an RPC request to delete a file. |
122 |
* |
|
123 |
* @param userId the ID of the current user |
|
124 | 128 |
*/ |
125 |
private void deleteFile() { |
|
126 |
Object selection = GSS.get().getCurrentSelection(); |
|
127 |
if (selection == null) { |
|
128 |
GSS.get().displayError("No file was selected"); |
|
129 |
return; |
|
130 |
} |
|
131 |
if (selection instanceof FileResource) { |
|
132 |
FileResource file = (FileResource) selection; |
|
133 |
|
|
134 |
DeleteCommand df = new DeleteCommand(file.getUri()){ |
|
135 |
|
|
136 |
@Override |
|
137 |
public void onComplete() { |
|
138 |
GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection()); |
|
139 |
GSS.get().getStatusPanel().updateStats(); |
|
140 |
} |
|
141 |
|
|
142 |
@Override |
|
143 |
public void onError(Throwable t) { |
|
144 |
GWT.log("", t); |
|
145 |
if(t instanceof RestException){ |
|
146 |
int statusCode = ((RestException)t).getHttpStatusCode(); |
|
147 |
if(statusCode == 405) |
|
148 |
GSS.get().displayError("You don't have the necessary permissions"); |
|
149 |
else if(statusCode == 404) |
|
150 |
GSS.get().displayError("File not found"); |
|
151 |
else |
|
152 |
GSS.get().displayError("Unable to delete file: "+((RestException)t).getHttpStatusText()); |
|
153 |
} |
|
154 |
else |
|
155 |
GSS.get().displayError("System error unable to delete file: "+t.getMessage()); |
|
156 |
} |
|
157 |
}; |
|
158 |
|
|
159 |
DeferredCommand.addCommand(df); |
|
160 |
} |
|
161 |
else if(selection instanceof List){ |
|
162 |
List<FileResource> files = (List<FileResource>) selection; |
|
163 |
List<String> fileIds = new ArrayList<String>(); |
|
164 |
for(FileResource f : files) |
|
165 |
fileIds.add(f.getUri()); |
|
166 |
|
|
167 |
MultipleDeleteCommand ed = new MultipleDeleteCommand(fileIds.toArray(new String[0])){ |
|
168 |
|
|
169 |
@Override |
|
170 |
public void onComplete() { |
|
171 |
GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection()); |
|
172 |
} |
|
173 |
|
|
174 |
@Override |
|
175 |
public void onError(Throwable t) { |
|
176 |
GWT.log("", t); |
|
177 |
GSS.get().getTreeView().updateNode(GSS.get().getTreeView().getSelection()); |
|
178 |
} |
|
179 |
|
|
180 |
@Override |
|
181 |
public void onError(String path, Throwable t) { |
|
182 |
GWT.log("", t); |
|
183 |
if(t instanceof RestException){ |
|
184 |
int statusCode = ((RestException)t).getHttpStatusCode(); |
|
185 |
if(statusCode == 405) |
|
186 |
GSS.get().displayError("You don't have the necessary permissions"); |
|
187 |
else if(statusCode == 404) |
|
188 |
GSS.get().displayError("File not found"); |
|
189 |
else |
|
190 |
GSS.get().displayError("Unable to delete file:"+((RestException)t).getHttpStatusText()); |
|
191 |
} |
|
192 |
else |
|
193 |
GSS.get().displayError("System error unable to delete file:"+t.getMessage()); |
|
194 |
|
|
195 |
} |
|
196 |
}; |
|
197 |
|
|
198 |
DeferredCommand.addCommand(ed); |
|
199 |
} |
|
200 |
} |
|
129 |
private void deleteFiles() { |
|
130 |
Iterator<File> iter = files.iterator(); |
|
131 |
deleteFile(iter); |
|
132 |
} |
|
133 |
|
|
134 |
private void deleteFile(final Iterator<File> iter) { |
|
135 |
if (iter.hasNext()) { |
|
136 |
File f = iter.next(); |
|
137 |
String path = GSS.get().getApiPath() + GSS.get().getUsername() + f.getUri(); |
|
138 |
DeleteRequest deleteFile = new DeleteRequest(path) { |
|
139 |
@Override |
|
140 |
public void onSuccess(Resource result) { |
|
141 |
deleteFile(iter); |
|
142 |
} |
|
143 |
|
|
144 |
@Override |
|
145 |
public void onError(Throwable t) { |
|
146 |
GWT.log("", t); |
|
147 |
if (t instanceof RestException) { |
|
148 |
GSS.get().displayError("Unable to delete file: " + ((RestException) t).getHttpStatusText()); |
|
149 |
} |
|
150 |
else |
|
151 |
GSS.get().displayError("System error unable to delete file: "+t.getMessage()); |
|
152 |
} |
|
153 |
}; |
|
154 |
deleteFile.setHeader("X-Auth-Token", GSS.get().getToken()); |
|
155 |
Scheduler.get().scheduleDeferred(deleteFile); |
|
156 |
} |
|
157 |
else { |
|
158 |
GSS.get().updateFolder(files.get(0).getParent()); |
|
159 |
} |
|
160 |
} |
|
201 | 161 |
|
202 | 162 |
@Override |
203 | 163 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
... | ... | |
210 | 170 |
switch (evt.getKeyCode()) { |
211 | 171 |
case KeyCodes.KEY_ENTER: |
212 | 172 |
hide(); |
213 |
deleteFile(); |
|
173 |
deleteFiles();
|
|
214 | 174 |
break; |
215 | 175 |
case KeyCodes.KEY_ESCAPE: |
216 | 176 |
hide(); |
b/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java | ||
---|---|---|
43 | 43 |
import gr.grnet.pithos.web.client.commands.RestoreTrashCommand; |
44 | 44 |
import gr.grnet.pithos.web.client.commands.ToTrashCommand; |
45 | 45 |
import gr.grnet.pithos.web.client.commands.UploadFileCommand; |
46 |
import gr.grnet.pithos.web.client.foldertree.File; |
|
46 | 47 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
47 | 48 |
import gr.grnet.pithos.web.client.rest.resource.FileResource; |
48 | 49 |
import gr.grnet.pithos.web.client.rest.resource.FolderResource; |
... | ... | |
127 | 128 |
* |
128 | 129 |
* @param newImages the image bundle passed on by the parent object |
129 | 130 |
*/ |
130 |
public FileContextMenu(Images newImages, Folder selectedFolder, boolean isTrash) { |
|
131 |
public FileContextMenu(Images newImages, Folder selectedFolder, List<File> selectedFiles, boolean isTrash) {
|
|
131 | 132 |
// The popup's constructor's argument is a boolean specifying that it |
132 | 133 |
// auto-close itself when the user clicks outside of it. |
133 | 134 |
super(true); |
... | ... | |
161 | 162 |
trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
162 | 163 |
contextMenu.addItem(trashItem); |
163 | 164 |
|
164 |
deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images));
|
|
165 |
deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, selectedFiles, images));
|
|
165 | 166 |
contextMenu.addItem(deleteItem); |
166 | 167 |
|
167 | 168 |
sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1)); |
b/web_client/src/gr/grnet/pithos/web/client/FileList.java | ||
---|---|---|
447 | 447 |
vp.addHandler(new ContextMenuHandler() { |
448 | 448 |
@Override |
449 | 449 |
public void onContextMenu(ContextMenuEvent event) { |
450 |
FileContextMenu contextMenu = new FileContextMenu(images, treeView.getSelection(), false); |
|
450 |
FileContextMenu contextMenu = new FileContextMenu(images, treeView.getSelection(), getSelectedFiles(), false);
|
|
451 | 451 |
int x = event.getNativeEvent().getClientX(); |
452 | 452 |
int y = event.getNativeEvent().getClientY(); |
453 | 453 |
contextMenu.setPopupPosition(x, y); |
b/web_client/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java | ||
---|---|---|
60 | 60 |
private PopupPanel containerPanel; |
61 | 61 |
final Images newImages; |
62 | 62 |
|
63 |
private Resource resource;
|
|
63 |
private Object resource;
|
|
64 | 64 |
|
65 | 65 |
/** |
66 | 66 |
* @param _containerPanel |
67 | 67 |
* @param _newImages the images of all the possible delete dialogs |
68 | 68 |
*/ |
69 |
public DeleteCommand( PopupPanel _containerPanel, Resource resource, final Images _newImages ){
|
|
69 |
public DeleteCommand( PopupPanel _containerPanel, Object resource, final Images _newImages ){
|
|
70 | 70 |
containerPanel = _containerPanel; |
71 | 71 |
newImages = _newImages; |
72 | 72 |
this.resource = resource; |
... | ... | |
86 | 86 |
if (resource instanceof Folder) { |
87 | 87 |
DeleteFolderDialog dlg = new DeleteFolderDialog(GSS.get(), newImages, (Folder) resource); |
88 | 88 |
dlg.center(); |
89 |
} else if (resource instanceof File) {
|
|
90 |
DeleteFileDialog dlg = new DeleteFileDialog(newImages); |
|
89 |
} else if (resource instanceof List) {
|
|
90 |
DeleteFileDialog dlg = new DeleteFileDialog(newImages, (List<File>) resource);
|
|
91 | 91 |
dlg.center(); |
92 | 92 |
} |
93 | 93 |
} |
b/web_client/src/gr/grnet/pithos/web/client/foldertree/File.java | ||
---|---|---|
105 | 105 |
} |
106 | 106 |
|
107 | 107 |
public String getUri() { |
108 |
return path + "/" + name;
|
|
108 |
return "/" + container + "/" + path;
|
|
109 | 109 |
} |
110 | 110 |
|
111 | 111 |
public String getOwner() { |
... | ... | |
187 | 187 |
JSONValue json = JSONParser.parseStrict(response.getText()); |
188 | 188 |
JSONObject o = json.isObject(); |
189 | 189 |
} |
190 |
|
|
191 |
public Folder getParent() { |
|
192 |
return parent; |
|
193 |
} |
|
190 | 194 |
} |
b/web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java | ||
---|---|---|
127 | 127 |
bytesUsed = Long.valueOf(header); |
128 | 128 |
|
129 | 129 |
subfolders.clear(); //This is necessary in case we update a pre-existing Folder so that stale subfolders won't show up |
130 |
files.clear(); |
|
130 | 131 |
JSONValue json = JSONParser.parseStrict(response.getText()); |
131 | 132 |
JSONArray array = json.isArray(); |
132 | 133 |
if (array != null) { |
b/web_client/src/gr/grnet/pithos/web/client/foldertree/FolderTreeViewModel.java | ||
---|---|---|
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 |
app.showFiles(result);
|
|
178 | 178 |
Iterator<Folder> iter = result.getSubfolders().iterator(); |
179 | 179 |
fetchFolder(iter, dataProvider, result.getSubfolders()); |
180 | 180 |
} |
Also available in: Unified diff