root / src / gr / grnet / pithos / web / client / DeleteFolderDialog.java @ 28267d27
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 |
setGlassEnabled(true);
|
83 |
setStyleName("pithos-DialogBox");
|
84 |
// Create a VerticalPanel to contain the HTML label and the buttons.
|
85 |
VerticalPanel outer = new VerticalPanel();
|
86 |
outer.add(close); |
87 |
|
88 |
VerticalPanel inner = new VerticalPanel();
|
89 |
inner.addStyleName("inner");
|
90 |
|
91 |
HTML text = new HTML("<table><tr><td rowspan='2'>" + AbstractImagePrototype.create(images.warn()).getHTML() + |
92 |
"</td><td>" + "Are you sure you want to <b>permanently</b> delete folder '" + folder.getName() + |
93 |
"'?</td></tr></table>");
|
94 |
text.setStyleName("pithos-warnMessage");
|
95 |
inner.add(text); |
96 |
inner.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER); |
97 |
|
98 |
// Create the 'Delete' button, along with a listener that hides the dialog
|
99 |
// when the button is clicked and deletes the folder.
|
100 |
Button ok = new Button("Delete", new ClickHandler() { |
101 |
@Override
|
102 |
public void onClick(ClickEvent event) { |
103 |
app.deleteFolder(folder, null);
|
104 |
hide(); |
105 |
} |
106 |
}); |
107 |
ok.addStyleName("button");
|
108 |
inner.add(ok); |
109 |
outer.add(inner); |
110 |
outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
111 |
setWidget(outer); |
112 |
} |
113 |
|
114 |
@Override
|
115 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
116 |
super.onPreviewNativeEvent(preview);
|
117 |
|
118 |
NativeEvent evt = preview.getNativeEvent(); |
119 |
if (evt.getType().equals(KeyDownEvent.getType().getName()))
|
120 |
// Use the popup's key preview hooks to close the dialog when either
|
121 |
// enter or escape is pressed.
|
122 |
switch (evt.getKeyCode()) {
|
123 |
case KeyCodes.KEY_ENTER:
|
124 |
hide(); |
125 |
app.deleteFolder(folder, null);
|
126 |
break;
|
127 |
case KeyCodes.KEY_ESCAPE:
|
128 |
hide(); |
129 |
break;
|
130 |
} |
131 |
} |
132 |
|
133 |
} |