fc69ff1f4ce4148c11b89fac25aac67d6a77b9fb
[pithos-web-client] / src / gr / grnet / pithos / web / client / DeleteFolderDialog.java
1 /*\r
2  * Copyright 2011-2012 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 gr.grnet.pithos.web.client.MessagePanel.Images;\r
38 import gr.grnet.pithos.web.client.foldertree.Folder;\r
39 \r
40 import com.google.gwt.dom.client.NativeEvent;\r
41 import com.google.gwt.event.dom.client.ClickEvent;\r
42 import com.google.gwt.event.dom.client.ClickHandler;\r
43 import com.google.gwt.event.dom.client.KeyCodes;\r
44 import com.google.gwt.event.dom.client.KeyDownEvent;\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.VerticalPanel;\r
53 \r
54 /**\r
55  * The 'delete folder' dialog box.\r
56  */\r
57 public class DeleteFolderDialog extends DialogBox {\r
58 \r
59         protected Pithos app;\r
60         protected Folder folder;\r
61     \r
62         /**\r
63          * The widget's constructor.\r
64          * @param images the supplied images\r
65          */\r
66         public DeleteFolderDialog(Pithos _app, Images images, Folder _folder) {\r
67         this.app = _app;\r
68         this.folder = _folder;\r
69 \r
70         Anchor close = new Anchor("close");\r
71                 close.addStyleName("close");\r
72                 close.addClickHandler(new ClickHandler() {\r
73                         \r
74                         @Override\r
75                         public void onClick(ClickEvent event) {\r
76                                 hide();\r
77                         }\r
78                 });\r
79 \r
80                 // Set the dialog's caption.\r
81                 setText("Confirmation");\r
82                 setAnimationEnabled(true);\r
83                 setGlassEnabled(true);\r
84                 setStyleName("pithos-DialogBox");\r
85                 // Create a VerticalPanel to contain the HTML label and the buttons.\r
86                 VerticalPanel outer = new VerticalPanel();\r
87                 outer.add(close);\r
88                 \r
89                 VerticalPanel inner = new VerticalPanel();\r
90                 inner.addStyleName("inner");\r
91 \r
92                 HTML text = new HTML("<table><tr><td rowspan='2'>" + AbstractImagePrototype.create(images.warn()).getHTML() +\r
93                                         "</td><td>" + "Are you sure you want to <b>permanently</b> delete folder '" + folder.getName() +\r
94                                         "'?</td></tr></table>");\r
95                 text.setStyleName("pithos-warnMessage");\r
96                 inner.add(text);\r
97                 inner.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);\r
98 \r
99                 // Create the 'Delete' button, along with a listener that hides the dialog\r
100                 // when the button is clicked and deletes the folder.\r
101                 Button ok = new Button("Delete", new ClickHandler() {\r
102                         @Override\r
103                         public void onClick(ClickEvent event) {\r
104                                 app.deleteFolder(folder, null);\r
105                                 hide();\r
106                         }\r
107                 });\r
108                 ok.addStyleName("button");\r
109                 inner.add(ok);\r
110                 outer.add(inner);\r
111                 outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);\r
112                 setWidget(outer);\r
113         }\r
114 \r
115         @Override\r
116         protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
117                 super.onPreviewNativeEvent(preview);\r
118 \r
119                 NativeEvent evt = preview.getNativeEvent();\r
120                 if (evt.getType().equals(KeyDownEvent.getType().getName()))\r
121                         // Use the popup's key preview hooks to close the dialog when either\r
122                         // enter or escape is pressed.\r
123                         switch (evt.getKeyCode()) {\r
124                                 case KeyCodes.KEY_ENTER:\r
125                                         hide();\r
126                                         app.deleteFolder(folder, null);\r
127                                         break;\r
128                                 case KeyCodes.KEY_ESCAPE:\r
129                                         hide();\r
130                                         break;\r
131                         }\r
132         }\r
133 \r
134 }\r