6f5464d0f5e43b4f28ccc22a996e13af6337d8d0
[pithos-web-client] / src / gr / grnet / pithos / web / client / DeleteFolderDialog.java
1 /*\r
2  * Copyright 2011-2013 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                 setGlassEnabled(true);\r
83                 setStyleName("pithos-DialogBox");\r
84                 // Create a VerticalPanel to contain the HTML label and the buttons.\r
85                 VerticalPanel outer = new VerticalPanel();\r
86                 outer.add(close);\r
87                 \r
88                 VerticalPanel inner = new VerticalPanel();\r
89                 inner.addStyleName("inner");\r
90 \r
91                 HTML text = new HTML("<table><tr><td rowspan='2'>" + AbstractImagePrototype.create(images.warn()).getHTML() +\r
92                                         "</td><td>" + "Are you sure you want to <b>permanently</b> delete folder '" + folder.getName() +\r
93                                         "'?</td></tr></table>");\r
94                 text.setStyleName("pithos-warnMessage");\r
95                 inner.add(text);\r
96                 inner.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);\r
97 \r
98                 // Create the 'Delete' button, along with a listener that hides the dialog\r
99                 // when the button is clicked and deletes the folder.\r
100                 Button ok = new Button("Delete", new ClickHandler() {\r
101                         @Override\r
102                         public void onClick(ClickEvent event) {\r
103                                 app.deleteFolder(folder, null);\r
104                                 hide();\r
105                         }\r
106                 });\r
107                 ok.addStyleName("button");\r
108                 inner.add(ok);\r
109                 outer.add(inner);\r
110                 outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);\r
111                 setWidget(outer);\r
112         }\r
113 \r
114         @Override\r
115         protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
116                 super.onPreviewNativeEvent(preview);\r
117 \r
118                 NativeEvent evt = preview.getNativeEvent();\r
119                 if (evt.getType().equals(KeyDownEvent.getType().getName()))\r
120                         // Use the popup's key preview hooks to close the dialog when either\r
121                         // enter or escape is pressed.\r
122                         switch (evt.getKeyCode()) {\r
123                                 case KeyCodes.KEY_ENTER:\r
124                                         hide();\r
125                                         app.deleteFolder(folder, null);\r
126                                         break;\r
127                                 case KeyCodes.KEY_ESCAPE:\r
128                                         hide();\r
129                                         break;\r
130                         }\r
131         }\r
132 \r
133 }\r