Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (4.9 kB)

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