root / web_client / src / gr / grnet / pithos / web / client / DeleteFolderDialog.java @ 58777026
History | View | Annotate | Download (6.8 kB)
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 |
import gr.grnet.pithos.web.client.MessagePanel.Images; |
38 |
import gr.grnet.pithos.web.client.rest.DeleteCommand; |
39 |
import gr.grnet.pithos.web.client.rest.RestException; |
40 |
import gr.grnet.pithos.web.client.rest.resource.FolderResource; |
41 |
import gr.grnet.pithos.web.client.rest.resource.RestResource; |
42 |
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
43 |
import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource; |
44 |
|
45 |
import com.google.gwt.core.client.GWT; |
46 |
import com.google.gwt.dom.client.NativeEvent; |
47 |
import com.google.gwt.event.dom.client.ClickEvent; |
48 |
import com.google.gwt.event.dom.client.ClickHandler; |
49 |
import com.google.gwt.event.dom.client.KeyCodes; |
50 |
import com.google.gwt.user.client.DeferredCommand; |
51 |
import com.google.gwt.user.client.Event.NativePreviewEvent; |
52 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
53 |
import com.google.gwt.user.client.ui.Button; |
54 |
import com.google.gwt.user.client.ui.DialogBox; |
55 |
import com.google.gwt.user.client.ui.HTML; |
56 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
57 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
58 |
import com.google.gwt.user.client.ui.VerticalPanel; |
59 |
|
60 |
/**
|
61 |
* The 'delete folder' dialog box.
|
62 |
*/
|
63 |
public class DeleteFolderDialog extends DialogBox { |
64 |
|
65 |
/**
|
66 |
* The widget's constructor.
|
67 |
* @param images the supplied images
|
68 |
*/
|
69 |
public DeleteFolderDialog(Images images) {
|
70 |
// Set the dialog's caption.
|
71 |
setText("Confirmation");
|
72 |
setAnimationEnabled(true);
|
73 |
FolderResource folder = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource(); |
74 |
// Create a VerticalPanel to contain the HTML label and the buttons.
|
75 |
VerticalPanel outer = new VerticalPanel();
|
76 |
HorizontalPanel buttons = new HorizontalPanel();
|
77 |
|
78 |
HTML text = new HTML("<table><tr><td rowspan='2'>" + AbstractImagePrototype.create(images.warn()).getHTML() + |
79 |
"</td><td>" + "Are you sure you want to <b>permanently</b> delete folder '" + folder.getName() + |
80 |
"'?</td></tr></table>");
|
81 |
text.setStyleName("pithos-warnMessage");
|
82 |
outer.add(text); |
83 |
|
84 |
// Create the 'Delete' button, along with a listener that hides the dialog
|
85 |
// when the button is clicked and deletes the folder.
|
86 |
Button ok = new Button("Delete", new ClickHandler() { |
87 |
@Override
|
88 |
public void onClick(ClickEvent event) { |
89 |
deleteFolder(); |
90 |
hide(); |
91 |
} |
92 |
}); |
93 |
ok.getElement().setId("confirmation.ok");
|
94 |
buttons.add(ok); |
95 |
buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); |
96 |
// Create the 'Cancel' button, along with a listener that hides the
|
97 |
// dialog when the button is clicked.
|
98 |
Button cancel = new Button("Cancel", new ClickHandler() { |
99 |
@Override
|
100 |
public void onClick(ClickEvent event) { |
101 |
hide(); |
102 |
} |
103 |
}); |
104 |
cancel.getElement().setId("confirmation.cancel");
|
105 |
buttons.add(cancel); |
106 |
buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
107 |
buttons.setSpacing(8);
|
108 |
buttons.setStyleName("pithos-warnMessage");
|
109 |
outer.setStyleName("pithos-warnMessage");
|
110 |
outer.add(buttons); |
111 |
outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER); |
112 |
outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); |
113 |
setWidget(outer); |
114 |
} |
115 |
|
116 |
/**
|
117 |
* Generate an RPC request to delete a folder.
|
118 |
*
|
119 |
* @param userId the ID of the current user
|
120 |
*/
|
121 |
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 |
|
130 |
DeleteCommand df = new DeleteCommand(folder.getUri()){
|
131 |
|
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); |
163 |
} |
164 |
|
165 |
@Override
|
166 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
167 |
super.onPreviewNativeEvent(preview);
|
168 |
|
169 |
NativeEvent evt = preview.getNativeEvent(); |
170 |
if (evt.getType().equals("keydown")) |
171 |
// Use the popup's key preview hooks to close the dialog when either
|
172 |
// enter or escape is pressed.
|
173 |
switch (evt.getKeyCode()) {
|
174 |
case KeyCodes.KEY_ENTER:
|
175 |
hide(); |
176 |
deleteFolder(); |
177 |
break;
|
178 |
case KeyCodes.KEY_ESCAPE:
|
179 |
hide(); |
180 |
break;
|
181 |
} |
182 |
} |
183 |
|
184 |
} |