2 * Copyright 2011-2013 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
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.
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.
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.
35 package gr.grnet.pithos.web.client;
37 import com.google.gwt.dom.client.NativeEvent;
38 import com.google.gwt.event.dom.client.ClickEvent;
39 import com.google.gwt.event.dom.client.ClickHandler;
40 import com.google.gwt.event.dom.client.KeyCodes;
41 import com.google.gwt.event.dom.client.KeyDownEvent;
42 import com.google.gwt.event.logical.shared.ValueChangeEvent;
43 import com.google.gwt.event.logical.shared.ValueChangeHandler;
44 import com.google.gwt.user.client.Command;
45 import com.google.gwt.user.client.Event.NativePreviewEvent;
46 import com.google.gwt.user.client.ui.*;
47 import gr.grnet.pithos.web.client.commands.AddUserCommand;
48 import gr.grnet.pithos.web.client.foldertree.Folder;
49 import gr.grnet.pithos.web.client.grouptree.Group;
52 * The 'Purge Container' dialog box implementation.
54 public class PurgeContainerDialog extends DialogBox {
55 private final Pithos app;
56 private final Folder container;
58 private final CheckBox yesIAgree;
60 private final VerticalPanel inner;
62 public PurgeContainerDialog(Pithos app, Folder container) {
64 this.container = container;
65 this.yesIAgree = new CheckBox("I want to purge all contents of " + container.getName());
67 this.yesIAgree.setValue(false);
69 Anchor close = new Anchor("close");
70 close.addStyleName("close");
71 close.addClickHandler(new ClickHandler() {
74 public void onClick(ClickEvent event) {
79 setGlassEnabled(true);
80 setStyleName("pithos-DialogBox");
82 // Enable IE selection for the dialog (must disable it upon closing it)
83 Pithos.enableIESelection();
85 // Use this opportunity to set the dialog's caption.
86 setText(Const.PurgeContainer(container.getName()));
88 // Outer contains inner and buttons
89 VerticalPanel outer = new VerticalPanel();
91 // Inner contains generalPanel and permPanel
92 inner = new VerticalPanel();
93 inner.addStyleName("inner");
95 VerticalPanel generalPanel = new VerticalPanel();
96 FlexTable generalTable = new FlexTable();
97 generalTable.setText(0, 0, "Are you sure?");
99 generalTable.setWidget(0, 1, yesIAgree);
101 generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
102 generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
103 generalTable.setCellSpacing(4);
104 generalPanel.add(generalTable);
105 inner.add(generalPanel);
109 // Create the 'Create/Update' button, along with a listener that hides the dialog
110 // when the button is clicked and quits the application.
111 String okLabel = "Purge Container";
112 final Button ok = new Button(okLabel, new ClickHandler() {
114 public void onClick(ClickEvent event) {
119 ok.addStyleName("button");
120 ok.setEnabled(false);
121 ok.setVisible(false);
124 this.yesIAgree.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
126 public void onValueChange(ValueChangeEvent<Boolean> event) {
127 ok.setVisible(event.getValue());
128 ok.setEnabled(event.getValue());
132 outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
138 public void center() {
140 yesIAgree.setFocus(false);
144 protected void onPreviewNativeEvent(NativePreviewEvent preview) {
145 super.onPreviewNativeEvent(preview);
147 NativeEvent evt = preview.getNativeEvent();
148 if (evt.getType().equals(KeyDownEvent.getType().getName()))
149 // Exit the dialog on Escape
150 switch (evt.getKeyCode()) {
151 case KeyCodes.KEY_ESCAPE:
159 * Enables IE selection prevention and hides the dialog
160 * (we disable the prevention on creation of the dialog)
162 public void closeDialog() {
163 Pithos.preventIESelection();
167 private void purgeContainer() {
168 app.purgeContainer(container);