Revision 816de19f web_client/src/gr/grnet/pithos/web/client/DeleteFileDialog.java
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(); |
Also available in: Unified diff