Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / PurgeContainerDialog.java @ 8ddb4627

History | View | Annotate | Download (5.5 kB)

1
/*
2
 * Copyright 2011-2013 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.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;
50

    
51
/**
52
 * The 'Purge Container' dialog box implementation.
53
 */
54
public class PurgeContainerDialog extends DialogBox {
55
    private final Pithos app;
56
    private final Folder container;
57

    
58
    private final CheckBox yesIAgree;
59

    
60
        private final VerticalPanel inner;
61

    
62
        public PurgeContainerDialog(Pithos app, Folder container) {
63
        this.app = app;
64
        this.container = container;
65
        this.yesIAgree =  new CheckBox("I want to purge all contents of " + container.getName());
66

    
67
        this.yesIAgree.setValue(false);
68

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

    
79
                setGlassEnabled(true);
80
                setStyleName("pithos-DialogBox");
81

    
82
                // Enable IE selection for the dialog (must disable it upon closing it)
83
                Pithos.enableIESelection();
84

    
85
                // Use this opportunity to set the dialog's caption.
86
                setText(Const.PurgeContainer(container.getName()));
87

    
88
                // Outer contains inner and buttons
89
                VerticalPanel outer = new VerticalPanel();
90
                outer.add(close);
91
                // Inner contains generalPanel and permPanel
92
                inner = new VerticalPanel();
93
                inner.addStyleName("inner");
94

    
95
                VerticalPanel generalPanel = new VerticalPanel();
96
        FlexTable generalTable = new FlexTable();
97
        generalTable.setText(0, 0, "Are you sure?");
98

    
99
        generalTable.setWidget(0, 1, yesIAgree);
100

    
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);
106

    
107
        outer.add(inner);
108

    
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() {
113
                        @Override
114
                        public void onClick(ClickEvent event) {
115
                purgeContainer();
116
                                closeDialog();
117
                        }
118
                });
119
                ok.addStyleName("button");
120
        ok.setEnabled(false);
121
        ok.setVisible(false);
122
                outer.add(ok);
123

    
124
        this.yesIAgree.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
125
            @Override
126
            public void onValueChange(ValueChangeEvent<Boolean> event) {
127
                ok.setVisible(event.getValue());
128
                ok.setEnabled(event.getValue());
129
            }
130
        });
131

    
132
        outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
133

    
134
        setWidget(outer);
135
        }
136

    
137
        @Override
138
        public void center() {
139
                super.center();
140
        yesIAgree.setFocus(false);
141
        }
142

    
143
        @Override
144
        protected void onPreviewNativeEvent(NativePreviewEvent preview) {
145
                super.onPreviewNativeEvent(preview);
146

    
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:
152
                                        closeDialog();
153
                                        break;
154
                        }
155
        }
156

    
157

    
158
        /**
159
         * Enables IE selection prevention and hides the dialog
160
         * (we disable the prevention on creation of the dialog)
161
         */
162
        public void closeDialog() {
163
                Pithos.preventIESelection();
164
                hide();
165
        }
166

    
167
    private void purgeContainer() {
168
        app.purgeContainer(container);
169
    }
170
}