Revision 4bcf5e39
b/web_client/src/gr/grnet/pithos/web/client/DeleteFolderDialog.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.event.dom.client.KeyDownEvent; |
|
39 |
import com.google.gwt.user.client.Event; |
|
37 | 40 |
import gr.grnet.pithos.web.client.MessagePanel.Images; |
41 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
|
42 |
import gr.grnet.pithos.web.client.foldertree.Resource; |
|
38 | 43 |
import gr.grnet.pithos.web.client.rest.DeleteCommand; |
44 |
import gr.grnet.pithos.web.client.rest.DeleteRequest; |
|
39 | 45 |
import gr.grnet.pithos.web.client.rest.RestException; |
40 | 46 |
import gr.grnet.pithos.web.client.rest.resource.FolderResource; |
41 | 47 |
import gr.grnet.pithos.web.client.rest.resource.RestResource; |
... | ... | |
62 | 68 |
*/ |
63 | 69 |
public class DeleteFolderDialog extends DialogBox { |
64 | 70 |
|
71 |
private GSS app; |
|
72 |
private Folder folder; |
|
73 |
|
|
65 | 74 |
/** |
66 | 75 |
* The widget's constructor. |
67 | 76 |
* @param images the supplied images |
68 | 77 |
*/ |
69 |
public DeleteFolderDialog(Images images) { |
|
78 |
public DeleteFolderDialog(GSS app, Images images, Folder folder) { |
|
79 |
this.app = app; |
|
80 |
this.folder = folder; |
|
70 | 81 |
// Set the dialog's caption. |
71 | 82 |
setText("Confirmation"); |
72 | 83 |
setAnimationEnabled(true); |
73 |
FolderResource folder = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource(); |
|
74 | 84 |
// Create a VerticalPanel to contain the HTML label and the buttons. |
75 | 85 |
VerticalPanel outer = new VerticalPanel(); |
76 | 86 |
HorizontalPanel buttons = new HorizontalPanel(); |
... | ... | |
90 | 100 |
hide(); |
91 | 101 |
} |
92 | 102 |
}); |
93 |
ok.getElement().setId("confirmation.ok"); |
|
94 | 103 |
buttons.add(ok); |
95 | 104 |
buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); |
96 | 105 |
// Create the 'Cancel' button, along with a listener that hides the |
... | ... | |
101 | 110 |
hide(); |
102 | 111 |
} |
103 | 112 |
}); |
104 |
cancel.getElement().setId("confirmation.cancel"); |
|
105 | 113 |
buttons.add(cancel); |
106 | 114 |
buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
107 | 115 |
buttons.setSpacing(8); |
... | ... | |
116 | 124 |
/** |
117 | 125 |
* Generate an RPC request to delete a folder. |
118 | 126 |
* |
119 |
* @param userId the ID of the current user |
|
120 | 127 |
*/ |
121 | 128 |
private void deleteFolder() { |
122 |
RestResource folder = GSS.get().getTreeView().getSelection(); |
|
123 |
if (folder == null) { |
|
124 |
GSS.get().displayError("No folder was selected"); |
|
125 |
return; |
|
126 |
} |
|
127 |
if(!(folder instanceof RestResourceWrapper)) |
|
128 |
return; |
|
129 |
String prefix = folder.getPrefix(); |
|
130 |
String path = app.getApiPath() + app.getUsername() + "/" + folder.getContainer() + (prefix.length() == 0 ? "" : "/" + prefix); |
|
131 |
DeleteRequest deleteFolder = new DeleteRequest(path) { |
|
132 |
@Override |
|
133 |
public void onSuccess(Resource result) { |
|
129 | 134 |
|
130 |
DeleteCommand df = new DeleteCommand(folder.getUri()){
|
|
135 |
}
|
|
131 | 136 |
|
132 |
@Override |
|
133 |
public void onComplete() { |
|
134 |
FolderResource fres = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource(); |
|
135 |
if((RestResourceWrapper) GSS.get().getTreeView().getSelection() instanceof TrashFolderResource) |
|
136 |
GSS.get().getTreeView().updateTrashNode(); |
|
137 |
else |
|
138 |
GSS.get().getTreeView().updateNodeChildrenForRemove(fres.getParentURI()); |
|
139 |
GSS.get().getTreeView().clearSelection(); |
|
140 |
GSS.get().showFileList(true); |
|
141 |
|
|
142 |
GSS.get().getStatusPanel().updateStats(); |
|
143 |
} |
|
144 |
|
|
145 |
@Override |
|
146 |
public void onError(Throwable t) { |
|
147 |
GWT.log("", t); |
|
148 |
if(t instanceof RestException){ |
|
149 |
int statusCode = ((RestException)t).getHttpStatusCode(); |
|
150 |
if(statusCode == 405) |
|
151 |
GSS.get().displayError("You don't have the necessary permissions"); |
|
152 |
else if(statusCode == 404) |
|
153 |
GSS.get().displayError("Folder not found"); |
|
154 |
else |
|
155 |
GSS.get().displayError("Unable to delete folder: "+((RestException)t).getHttpStatusText()); |
|
156 |
} |
|
157 |
else |
|
158 |
GSS.get().displayError("System error unable to delete folder: "+t.getMessage()); |
|
159 |
} |
|
160 |
}; |
|
161 |
|
|
162 |
DeferredCommand.addCommand(df); |
|
137 |
@Override |
|
138 |
public void onError(Throwable t) { |
|
139 |
GWT.log("", t); |
|
140 |
if (t instanceof RestException) { |
|
141 |
int statusCode = ((RestException)t).getHttpStatusCode(); |
|
142 |
app.displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText()); |
|
143 |
} |
|
144 |
else |
|
145 |
GSS.get().displayError("System error unable to delete folder: " + t.getMessage()); |
|
146 |
} |
|
147 |
}; |
|
148 |
deleteFolder.setHeader("X-Auth-Token", app.getToken()); |
|
149 |
Scheduler.get().scheduleDeferred(deleteFolder); |
|
163 | 150 |
} |
164 | 151 |
|
165 | 152 |
@Override |
... | ... | |
167 | 154 |
super.onPreviewNativeEvent(preview); |
168 | 155 |
|
169 | 156 |
NativeEvent evt = preview.getNativeEvent(); |
170 |
if (evt.getType().equals("keydown"))
|
|
157 |
if (evt.getType().equals(KeyDownEvent.getType().getName()))
|
|
171 | 158 |
// Use the popup's key preview hooks to close the dialog when either |
172 | 159 |
// enter or escape is pressed. |
173 | 160 |
switch (evt.getKeyCode()) { |
b/web_client/src/gr/grnet/pithos/web/client/EditMenu.java | ||
---|---|---|
226 | 226 |
contextMenu .addItem(moveToTrashItem) |
227 | 227 |
.setVisible(cutcopyVisible); |
228 | 228 |
|
229 |
MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images)); |
|
229 |
MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images));
|
|
230 | 230 |
deleteItem.getElement().setId("topMenu.edit.delete"); |
231 | 231 |
contextMenu .addItem(deleteItem) |
232 | 232 |
.setVisible(cutcopyVisible); |
b/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java | ||
---|---|---|
149 | 149 |
MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this)); |
150 | 150 |
contextMenu.addItem(restore); |
151 | 151 |
|
152 |
MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images)); |
|
152 |
MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images));
|
|
153 | 153 |
contextMenu.addItem(delete); |
154 | 154 |
} else { |
155 | 155 |
cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this)); |
... | ... | |
164 | 164 |
trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
165 | 165 |
contextMenu.addItem(trashItem); |
166 | 166 |
|
167 |
deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images)); |
|
167 |
deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images));
|
|
168 | 168 |
contextMenu.addItem(deleteItem); |
169 | 169 |
|
170 | 170 |
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/FolderContextMenu.java | ||
---|---|---|
112 | 112 |
MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
113 | 113 |
contextMenu.addItem(moveToTrash); |
114 | 114 |
|
115 |
MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages)); |
|
115 |
MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, folder, newImages));
|
|
116 | 116 |
contextMenu.addItem(delete); |
117 | 117 |
|
118 | 118 |
MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
b/web_client/src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java | ||
---|---|---|
256 | 256 |
app.displayError("System error creating folder:" + t.getMessage()); |
257 | 257 |
} |
258 | 258 |
}; |
259 |
createFolder.setHeader("X-Auth-Token", "0000");
|
|
259 |
createFolder.setHeader("X-Auth-Token", app.getToken());
|
|
260 | 260 |
createFolder.setHeader("Accept", "*/*"); |
261 | 261 |
createFolder.setHeader("Content-Length", "0"); |
262 | 262 |
createFolder.setHeader("Content-Type", "application/folder"); |
b/web_client/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java | ||
---|---|---|
38 | 38 |
import gr.grnet.pithos.web.client.DeleteFolderDialog; |
39 | 39 |
import gr.grnet.pithos.web.client.EditMenu.Images; |
40 | 40 |
import gr.grnet.pithos.web.client.GSS; |
41 |
import gr.grnet.pithos.web.client.foldertree.File; |
|
42 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
|
43 |
import gr.grnet.pithos.web.client.foldertree.Resource; |
|
41 | 44 |
import gr.grnet.pithos.web.client.rest.resource.FileResource; |
42 | 45 |
import gr.grnet.pithos.web.client.rest.resource.GroupUserResource; |
43 | 46 |
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
... | ... | |
57 | 60 |
private PopupPanel containerPanel; |
58 | 61 |
final Images newImages; |
59 | 62 |
|
63 |
private Resource resource; |
|
64 |
|
|
60 | 65 |
/** |
61 | 66 |
* @param _containerPanel |
62 | 67 |
* @param _newImages the images of all the possible delete dialogs |
63 | 68 |
*/ |
64 |
public DeleteCommand( PopupPanel _containerPanel, final Images _newImages ){ |
|
69 |
public DeleteCommand( PopupPanel _containerPanel, Resource resource, final Images _newImages ){
|
|
65 | 70 |
containerPanel = _containerPanel; |
66 |
newImages=_newImages; |
|
71 |
newImages = _newImages; |
|
72 |
this.resource = resource; |
|
67 | 73 |
} |
68 | 74 |
|
69 | 75 |
@Override |
... | ... | |
77 | 83 |
* |
78 | 84 |
*/ |
79 | 85 |
void displayDelete() { |
80 |
Object selection = GSS.get().getCurrentSelection(); |
|
81 |
if (selection == null) |
|
82 |
return; |
|
83 |
GWT.log("selection: " + selection.toString(), null); |
|
84 |
if (selection instanceof RestResourceWrapper) { |
|
85 |
DeleteFolderDialog dlg = new DeleteFolderDialog(newImages); |
|
86 |
if (resource instanceof Folder) { |
|
87 |
DeleteFolderDialog dlg = new DeleteFolderDialog(GSS.get(), newImages, (Folder) resource); |
|
86 | 88 |
dlg.center(); |
87 |
} else if (selection instanceof FileResource || selection instanceof List) {
|
|
89 |
} else if (resource instanceof File) {
|
|
88 | 90 |
DeleteFileDialog dlg = new DeleteFileDialog(newImages); |
89 | 91 |
dlg.center(); |
90 |
} else if (selection instanceof GroupUserResource) { |
|
91 |
// TODO implement user deletion |
|
92 | 92 |
} |
93 | 93 |
} |
94 | 94 |
} |
b/web_client/src/gr/grnet/pithos/web/client/rest/DeleteRequest.java | ||
---|---|---|
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 |
|
|
36 |
package gr.grnet.pithos.web.client.rest; |
|
37 |
|
|
38 |
import com.google.gwt.core.client.Scheduler.ScheduledCommand; |
|
39 |
import com.google.gwt.http.client.Request; |
|
40 |
import com.google.gwt.http.client.RequestBuilder; |
|
41 |
import com.google.gwt.http.client.RequestException; |
|
42 |
import com.google.gwt.http.client.Response; |
|
43 |
import gr.grnet.pithos.web.client.foldertree.Resource; |
|
44 |
import java.util.HashMap; |
|
45 |
import java.util.Map; |
|
46 |
|
|
47 |
/** |
|
48 |
* Created by IntelliJ IDEA. User: chstath Date: 7/5/11 Time: 5:29 PM To change this template use File | Settings | File |
|
49 |
* Templates. |
|
50 |
*/ |
|
51 |
public abstract class DeleteRequest implements ScheduledCommand { |
|
52 |
private String path; |
|
53 |
|
|
54 |
private Map<String, String> headers = new HashMap<String, String>(); |
|
55 |
|
|
56 |
public abstract void onSuccess(Resource result); |
|
57 |
|
|
58 |
public abstract void onError(Throwable t); |
|
59 |
|
|
60 |
public DeleteRequest(String path) { |
|
61 |
this.path = path; |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public void execute() { |
|
66 |
RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, path); |
|
67 |
for (String header : headers.keySet()) { |
|
68 |
builder.setHeader(header, headers.get(header)); |
|
69 |
} |
|
70 |
try { |
|
71 |
builder.sendRequest("", new RestRequestCallback(path, Response.SC_NO_CONTENT) { |
|
72 |
@Override |
|
73 |
public void onSuccess(Resource object) { |
|
74 |
DeleteRequest.this.onSuccess(object); |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
public Resource deserialize(Response response) { |
|
79 |
return Resource.createFromResponse(Resource.class, response, null); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public void onError(Request request, Throwable throwable) { |
|
84 |
DeleteRequest.this.onError(throwable); |
|
85 |
} |
|
86 |
}); |
|
87 |
} |
|
88 |
catch (RequestException e) { |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
public void setHeader(String header, String value) { |
|
93 |
headers.put(header, value); |
|
94 |
} |
|
95 |
} |
b/web_client/src/gr/grnet/pithos/web/client/rest/PutRequest.java | ||
---|---|---|
83 | 83 |
|
84 | 84 |
private String path; |
85 | 85 |
|
86 |
private String username; |
|
87 |
|
|
88 | 86 |
private Map<String, String> headers = new HashMap<String, String>(); |
89 | 87 |
|
90 | 88 |
public abstract void onSuccess(Resource result); |
Also available in: Unified diff