Added an option for user credentials on user menu
[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.Button;\r
48 import com.google.gwt.user.client.ui.DialogBox;\r
49 import com.google.gwt.user.client.ui.HTML;\r
50 import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
51 import com.google.gwt.user.client.ui.HorizontalPanel;\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                 // Set the dialog's caption.\r
70                 setText("Confirmation");\r
71                 setAnimationEnabled(true);\r
72                 // Create a VerticalPanel to contain the HTML label and the buttons.\r
73                 VerticalPanel outer = new VerticalPanel();\r
74                 HorizontalPanel buttons = new HorizontalPanel();\r
75 \r
76                 HTML text = new HTML("<table><tr><td rowspan='2'>" + AbstractImagePrototype.create(images.warn()).getHTML() +\r
77                                         "</td><td>" + "Are you sure you want to <b>permanently</b> delete folder '" + folder.getName() +\r
78                                         "'?</td></tr></table>");\r
79                 text.setStyleName("pithos-warnMessage");\r
80                 outer.add(text);\r
81 \r
82                 // Create the 'Delete' button, along with a listener that hides the dialog\r
83                 // when the button is clicked and deletes the folder.\r
84                 Button ok = new Button("Delete", new ClickHandler() {\r
85                         @Override\r
86                         public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
87                                 app.deleteFolder(folder);\r
88                                 hide();\r
89                         }\r
90                 });\r
91                 buttons.add(ok);\r
92                 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);\r
93                 // Create the 'Cancel' button, along with a listener that hides the\r
94                 // dialog when the button is clicked.\r
95                 Button cancel = new Button("Cancel", new ClickHandler() {\r
96                         @Override\r
97                         public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
98                                 hide();\r
99                         }\r
100                 });\r
101                 buttons.add(cancel);\r
102                 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
103                 buttons.setSpacing(8);\r
104                 buttons.setStyleName("pithos-warnMessage");\r
105                 outer.setStyleName("pithos-warnMessage");\r
106                 outer.add(buttons);\r
107                 outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);\r
108                 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);\r
109                 setWidget(outer);\r
110         }\r
111 \r
112         @Override\r
113         protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
114                 super.onPreviewNativeEvent(preview);\r
115 \r
116                 NativeEvent evt = preview.getNativeEvent();\r
117                 if (evt.getType().equals(KeyDownEvent.getType().getName()))\r
118                         // Use the popup's key preview hooks to close the dialog when either\r
119                         // enter or escape is pressed.\r
120                         switch (evt.getKeyCode()) {\r
121                                 case KeyCodes.KEY_ENTER:\r
122                                         hide();\r
123                                         app.deleteFolder(folder);\r
124                                         break;\r
125                                 case KeyCodes.KEY_ESCAPE:\r
126                                         hide();\r
127                                         break;\r
128                         }\r
129         }\r
130 \r
131 }\r