root / src / gr / grnet / pithos / web / client / DeleteFolderDialog.java @ f1aabd89
History | View | Annotate | Download (6.6 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 com.google.gwt.core.client.Scheduler; |
38 |
import com.google.gwt.event.dom.client.KeyDownEvent; |
39 |
import com.google.gwt.user.client.Event; |
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; |
43 |
import gr.grnet.pithos.web.client.rest.DeleteCommand; |
44 |
import gr.grnet.pithos.web.client.rest.DeleteRequest; |
45 |
import gr.grnet.pithos.web.client.rest.RestException; |
46 |
import gr.grnet.pithos.web.client.rest.resource.FolderResource; |
47 |
import gr.grnet.pithos.web.client.rest.resource.RestResource; |
48 |
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
49 |
import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource; |
50 |
|
51 |
import com.google.gwt.core.client.GWT; |
52 |
import com.google.gwt.dom.client.NativeEvent; |
53 |
import com.google.gwt.event.dom.client.ClickEvent; |
54 |
import com.google.gwt.event.dom.client.ClickHandler; |
55 |
import com.google.gwt.event.dom.client.KeyCodes; |
56 |
import com.google.gwt.user.client.DeferredCommand; |
57 |
import com.google.gwt.user.client.Event.NativePreviewEvent; |
58 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
59 |
import com.google.gwt.user.client.ui.Button; |
60 |
import com.google.gwt.user.client.ui.DialogBox; |
61 |
import com.google.gwt.user.client.ui.HTML; |
62 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
63 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
64 |
import com.google.gwt.user.client.ui.VerticalPanel; |
65 |
|
66 |
/**
|
67 |
* The 'delete folder' dialog box.
|
68 |
*/
|
69 |
public class DeleteFolderDialog extends DialogBox { |
70 |
|
71 |
private GSS app;
|
72 |
private Folder folder;
|
73 |
|
74 |
/**
|
75 |
* The widget's constructor.
|
76 |
* @param images the supplied images
|
77 |
*/
|
78 |
public DeleteFolderDialog(GSS app, Images images, Folder folder) {
|
79 |
this.app = app;
|
80 |
this.folder = folder;
|
81 |
// Set the dialog's caption.
|
82 |
setText("Confirmation");
|
83 |
setAnimationEnabled(true);
|
84 |
// Create a VerticalPanel to contain the HTML label and the buttons.
|
85 |
VerticalPanel outer = new VerticalPanel();
|
86 |
HorizontalPanel buttons = new HorizontalPanel();
|
87 |
|
88 |
HTML text = new HTML("<table><tr><td rowspan='2'>" + AbstractImagePrototype.create(images.warn()).getHTML() + |
89 |
"</td><td>" + "Are you sure you want to <b>permanently</b> delete folder '" + folder.getName() + |
90 |
"'?</td></tr></table>");
|
91 |
text.setStyleName("pithos-warnMessage");
|
92 |
outer.add(text); |
93 |
|
94 |
// Create the 'Delete' button, along with a listener that hides the dialog
|
95 |
// when the button is clicked and deletes the folder.
|
96 |
Button ok = new Button("Delete", new ClickHandler() { |
97 |
@Override
|
98 |
public void onClick(ClickEvent event) { |
99 |
deleteFolder(); |
100 |
hide(); |
101 |
} |
102 |
}); |
103 |
buttons.add(ok); |
104 |
buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); |
105 |
// Create the 'Cancel' button, along with a listener that hides the
|
106 |
// dialog when the button is clicked.
|
107 |
Button cancel = new Button("Cancel", new ClickHandler() { |
108 |
@Override
|
109 |
public void onClick(ClickEvent event) { |
110 |
hide(); |
111 |
} |
112 |
}); |
113 |
buttons.add(cancel); |
114 |
buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
115 |
buttons.setSpacing(8);
|
116 |
buttons.setStyleName("pithos-warnMessage");
|
117 |
outer.setStyleName("pithos-warnMessage");
|
118 |
outer.add(buttons); |
119 |
outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER); |
120 |
outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); |
121 |
setWidget(outer); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Generate an RPC request to delete a folder.
|
126 |
*
|
127 |
*/
|
128 |
private void deleteFolder() { |
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) { |
134 |
|
135 |
} |
136 |
|
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); |
150 |
} |
151 |
|
152 |
@Override
|
153 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
154 |
super.onPreviewNativeEvent(preview);
|
155 |
|
156 |
NativeEvent evt = preview.getNativeEvent(); |
157 |
if (evt.getType().equals(KeyDownEvent.getType().getName()))
|
158 |
// Use the popup's key preview hooks to close the dialog when either
|
159 |
// enter or escape is pressed.
|
160 |
switch (evt.getKeyCode()) {
|
161 |
case KeyCodes.KEY_ENTER:
|
162 |
hide(); |
163 |
deleteFolder(); |
164 |
break;
|
165 |
case KeyCodes.KEY_ESCAPE:
|
166 |
hide(); |
167 |
break;
|
168 |
} |
169 |
} |
170 |
|
171 |
} |