Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / DeleteFolderDialog.java @ cb1f6cdb

History | View | Annotate | Download (4.7 kB)

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