Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (4.9 kB)

1
/*
2
 * Copyright 2011 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 com.google.gwt.event.dom.client.KeyDownEvent;
38
import gr.grnet.pithos.web.client.MessagePanel.Images;
39
import gr.grnet.pithos.web.client.foldertree.Folder;
40

    
41
import com.google.gwt.dom.client.NativeEvent;
42
import com.google.gwt.event.dom.client.ClickEvent;
43
import com.google.gwt.event.dom.client.ClickHandler;
44
import com.google.gwt.event.dom.client.KeyCodes;
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.Button;
48
import com.google.gwt.user.client.ui.DialogBox;
49
import com.google.gwt.user.client.ui.HTML;
50
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
51
import com.google.gwt.user.client.ui.HorizontalPanel;
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
    private Pithos app;
60
    private 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
                // Set the dialog's caption.
70
                setText("Confirmation");
71
                setAnimationEnabled(true);
72
                // Create a VerticalPanel to contain the HTML label and the buttons.
73
                VerticalPanel outer = new VerticalPanel();
74
                HorizontalPanel buttons = new HorizontalPanel();
75

    
76
                HTML text = new HTML("<table><tr><td rowspan='2'>" + AbstractImagePrototype.create(images.warn()).getHTML() +
77
                                        "</td><td>" + "Are you sure you want to <b>permanently</b> delete folder '" + folder.getName() +
78
                                        "'?</td></tr></table>");
79
                text.setStyleName("pithos-warnMessage");
80
                outer.add(text);
81

    
82
                // Create the 'Delete' button, along with a listener that hides the dialog
83
                // when the button is clicked and deletes the folder.
84
                Button ok = new Button("Delete", new ClickHandler() {
85
                        @Override
86
                        public void onClick(ClickEvent event) {
87
                                app.deleteFolder(folder);
88
                                hide();
89
                        }
90
                });
91
                buttons.add(ok);
92
                buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
93
                // Create the 'Cancel' button, along with a listener that hides the
94
                // dialog when the button is clicked.
95
                Button cancel = new Button("Cancel", new ClickHandler() {
96
                        @Override
97
                        public void onClick(ClickEvent event) {
98
                                hide();
99
                        }
100
                });
101
                buttons.add(cancel);
102
                buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
103
                buttons.setSpacing(8);
104
                buttons.setStyleName("pithos-warnMessage");
105
                outer.setStyleName("pithos-warnMessage");
106
                outer.add(buttons);
107
                outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
108
                outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
109
                setWidget(outer);
110
        }
111

    
112
        @Override
113
        protected void onPreviewNativeEvent(NativePreviewEvent preview) {
114
                super.onPreviewNativeEvent(preview);
115

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

    
131
}