Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (4.7 kB)

1
/*
2
 * Copyright 2011-2012 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35
package gr.grnet.pithos.web.client;
36

    
37
import gr.grnet.pithos.web.client.MessagePanel.Images;
38
import gr.grnet.pithos.web.client.foldertree.Folder;
39

    
40
import com.google.gwt.dom.client.NativeEvent;
41
import com.google.gwt.event.dom.client.ClickEvent;
42
import com.google.gwt.event.dom.client.ClickHandler;
43
import com.google.gwt.event.dom.client.KeyCodes;
44
import com.google.gwt.event.dom.client.KeyDownEvent;
45
import com.google.gwt.user.client.Event.NativePreviewEvent;
46
import com.google.gwt.user.client.ui.AbstractImagePrototype;
47
import com.google.gwt.user.client.ui.Anchor;
48
import com.google.gwt.user.client.ui.Button;
49
import com.google.gwt.user.client.ui.DialogBox;
50
import com.google.gwt.user.client.ui.HTML;
51
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
52
import com.google.gwt.user.client.ui.VerticalPanel;
53

    
54
/**
55
 * The 'delete folder' dialog box.
56
 */
57
public class DeleteFolderDialog extends DialogBox {
58

    
59
        protected Pithos app;
60
        protected Folder folder;
61
    
62
        /**
63
         * The widget's constructor.
64
         * @param images the supplied images
65
         */
66
        public DeleteFolderDialog(Pithos _app, Images images, Folder _folder) {
67
        this.app = _app;
68
        this.folder = _folder;
69

    
70
        Anchor close = new Anchor("close");
71
                close.addStyleName("close");
72
                close.addClickHandler(new ClickHandler() {
73
                        
74
                        @Override
75
                        public void onClick(ClickEvent event) {
76
                                hide();
77
                        }
78
                });
79

    
80
                // Set the dialog's caption.
81
                setText("Confirmation");
82
                setAnimationEnabled(true);
83
                setGlassEnabled(true);
84
                setStyleName("pithos-DialogBox");
85
                // Create a VerticalPanel to contain the HTML label and the buttons.
86
                VerticalPanel outer = new VerticalPanel();
87
                outer.add(close);
88
                
89
                VerticalPanel inner = new VerticalPanel();
90
                inner.addStyleName("inner");
91

    
92
                HTML text = new HTML("<table><tr><td rowspan='2'>" + AbstractImagePrototype.create(images.warn()).getHTML() +
93
                                        "</td><td>" + "Are you sure you want to <b>permanently</b> delete folder '" + folder.getName() +
94
                                        "'?</td></tr></table>");
95
                text.setStyleName("pithos-warnMessage");
96
                inner.add(text);
97
                inner.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
98

    
99
                // Create the 'Delete' button, along with a listener that hides the dialog
100
                // when the button is clicked and deletes the folder.
101
                Button ok = new Button("Delete", new ClickHandler() {
102
                        @Override
103
                        public void onClick(ClickEvent event) {
104
                                app.deleteFolder(folder, null);
105
                                hide();
106
                        }
107
                });
108
                ok.addStyleName("button");
109
                inner.add(ok);
110
                outer.add(inner);
111
                outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
112
                setWidget(outer);
113
        }
114

    
115
        @Override
116
        protected void onPreviewNativeEvent(NativePreviewEvent preview) {
117
                super.onPreviewNativeEvent(preview);
118

    
119
                NativeEvent evt = preview.getNativeEvent();
120
                if (evt.getType().equals(KeyDownEvent.getType().getName()))
121
                        // Use the popup's key preview hooks to close the dialog when either
122
                        // enter or escape is pressed.
123
                        switch (evt.getKeyCode()) {
124
                                case KeyCodes.KEY_ENTER:
125
                                        hide();
126
                                        app.deleteFolder(folder, null);
127
                                        break;
128
                                case KeyCodes.KEY_ESCAPE:
129
                                        hide();
130
                                        break;
131
                        }
132
        }
133

    
134
}