Refresh trash after moving to trash
[pithos-web-client] / src / gr / grnet / pithos / web / client / DeleteFolderDialog.java
1 /*\r
2  * Copyright 2011 GRNET S.A. All rights reserved.\r
3  *\r
4  * Redistribution and use in source and binary forms, with or\r
5  * without modification, are permitted provided that the following\r
6  * conditions are met:\r
7  *\r
8  *   1. Redistributions of source code must retain the above\r
9  *      copyright notice, this list of conditions and the following\r
10  *      disclaimer.\r
11  *\r
12  *   2. Redistributions in binary form must reproduce the above\r
13  *      copyright notice, this list of conditions and the following\r
14  *      disclaimer in the documentation and/or other materials\r
15  *      provided with the distribution.\r
16  *\r
17  * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS\r
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR\r
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
24  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED\r
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
27  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
28  * POSSIBILITY OF SUCH DAMAGE.\r
29  *\r
30  * The views and conclusions contained in the software and\r
31  * documentation are those of the authors and should not be\r
32  * interpreted as representing official policies, either expressed\r
33  * or implied, of GRNET S.A.\r
34  */\r
35 package gr.grnet.pithos.web.client;\r
36 \r
37 import com.google.gwt.event.dom.client.KeyDownEvent;\r
38 import gr.grnet.pithos.web.client.MessagePanel.Images;\r
39 import gr.grnet.pithos.web.client.foldertree.Folder;\r
40 \r
41 import com.google.gwt.dom.client.NativeEvent;\r
42 import com.google.gwt.event.dom.client.ClickEvent;\r
43 import com.google.gwt.event.dom.client.ClickHandler;\r
44 import com.google.gwt.event.dom.client.KeyCodes;\r
45 import com.google.gwt.user.client.Event.NativePreviewEvent;\r
46 import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
47 import com.google.gwt.user.client.ui.Anchor;\r
48 import com.google.gwt.user.client.ui.Button;\r
49 import com.google.gwt.user.client.ui.DialogBox;\r
50 import com.google.gwt.user.client.ui.HTML;\r
51 import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
52 import com.google.gwt.user.client.ui.HorizontalPanel;\r
53 import com.google.gwt.user.client.ui.VerticalPanel;\r
54 \r
55 /**\r
56  * The 'delete folder' dialog box.\r
57  */\r
58 public class DeleteFolderDialog extends DialogBox {\r
59 \r
60         protected Pithos app;\r
61         protected Folder folder;\r
62     \r
63         /**\r
64          * The widget's constructor.\r
65          * @param images the supplied images\r
66          */\r
67         public DeleteFolderDialog(Pithos _app, Images images, Folder _folder) {\r
68         this.app = _app;\r
69         this.folder = _folder;\r
70 \r
71         Anchor close = new Anchor();\r
72                 close.addStyleName("close");\r
73                 close.addClickHandler(new ClickHandler() {\r
74                         \r
75                         @Override\r
76                         public void onClick(ClickEvent event) {\r
77                                 hide();\r
78                         }\r
79                 });\r
80 \r
81                 // Set the dialog's caption.\r
82                 setText("Confirmation");\r
83                 setAnimationEnabled(true);\r
84                 setGlassEnabled(true);\r
85                 setStyleName("pithos-DialogBox");\r
86                 // Create a VerticalPanel to contain the HTML label and the buttons.\r
87                 VerticalPanel outer = new VerticalPanel();\r
88                 outer.add(close);\r
89                 \r
90                 VerticalPanel inner = new VerticalPanel();\r
91                 inner.addStyleName("inner");\r
92 \r
93                 HTML text = new HTML("<table><tr><td rowspan='2'>" + AbstractImagePrototype.create(images.warn()).getHTML() +\r
94                                         "</td><td>" + "Are you sure you want to <b>permanently</b> delete folder '" + folder.getName() +\r
95                                         "'?</td></tr></table>");\r
96                 text.setStyleName("pithos-warnMessage");\r
97                 inner.add(text);\r
98                 inner.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);\r
99 \r
100                 // Create the 'Delete' button, along with a listener that hides the dialog\r
101                 // when the button is clicked and deletes the folder.\r
102                 Button ok = new Button("Delete", new ClickHandler() {\r
103                         @Override\r
104                         public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
105                                 app.deleteFolder(folder);\r
106                                 hide();\r
107                         }\r
108                 });\r
109                 ok.addStyleName("button");\r
110                 inner.add(ok);\r
111                 outer.add(inner);\r
112                 outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);\r
113                 setWidget(outer);\r
114         }\r
115 \r
116         @Override\r
117         protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
118                 super.onPreviewNativeEvent(preview);\r
119 \r
120                 NativeEvent evt = preview.getNativeEvent();\r
121                 if (evt.getType().equals(KeyDownEvent.getType().getName()))\r
122                         // Use the popup's key preview hooks to close the dialog when either\r
123                         // enter or escape is pressed.\r
124                         switch (evt.getKeyCode()) {\r
125                                 case KeyCodes.KEY_ENTER:\r
126                                         hide();\r
127                                         app.deleteFolder(folder);\r
128                                         break;\r
129                                 case KeyCodes.KEY_ESCAPE:\r
130                                         hide();\r
131                                         break;\r
132                         }\r
133         }\r
134 \r
135 }\r