Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (5.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.foldertree.Folder;
38

    
39
import com.google.gwt.dom.client.NativeEvent;
40
import com.google.gwt.event.dom.client.ClickEvent;
41
import com.google.gwt.event.dom.client.ClickHandler;
42
import com.google.gwt.event.dom.client.KeyCodes;
43
import com.google.gwt.event.dom.client.KeyDownEvent;
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.Anchor;
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.FlexTable;
50
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
51
import com.google.gwt.user.client.ui.TextBox;
52
import com.google.gwt.user.client.ui.VerticalPanel;
53

    
54
/**
55
 * The 'Folder properties' dialog box implementation.
56
 */
57
public class GroupCreateDialog extends DialogBox {
58

    
59
    protected Pithos app;
60

    
61
    private Command callback;
62
    
63
        /**
64
         * The widget that holds the folderName of the folder.
65
         */
66
        TextBox groupName = new TextBox();
67

    
68
        final VerticalPanel inner;
69

    
70
        public GroupCreateDialog(final Pithos app) {
71
                this(app, null);
72
        }
73
        
74
        /**
75
         * The widget's constructor.
76
         */
77
        public GroupCreateDialog(final Pithos app, Command callback) {
78
        this.app = app;
79
        this.callback = callback;
80
        
81
                Anchor close = new Anchor("close");
82
                close.addStyleName("close");
83
                close.addClickHandler(new ClickHandler() {
84
                        
85
                        @Override
86
                        public void onClick(ClickEvent event) {
87
                                hide();
88
                        }
89
                });
90

    
91
                setAnimationEnabled(true);
92
                setGlassEnabled(true);
93
                setStyleName("pithos-DialogBox");
94

    
95
                // Enable IE selection for the dialog (must disable it upon closing it)
96
                Pithos.enableIESelection();
97

    
98
                // Use this opportunity to set the dialog's caption.
99
                setText("Create group");
100

    
101
                // Outer contains inner and buttons
102
                VerticalPanel outer = new VerticalPanel();
103
                outer.add(close);
104
                // Inner contains generalPanel and permPanel
105
                inner = new VerticalPanel();
106
                inner.addStyleName("inner");
107

    
108
                VerticalPanel generalPanel = new VerticalPanel();
109
        FlexTable generalTable = new FlexTable();
110
        generalTable.setText(0, 0, "Name");
111

    
112
        generalTable.setWidget(0, 1, groupName);
113

    
114
        generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
115
        generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
116
        generalTable.setCellSpacing(4);
117
        generalPanel.add(generalTable);
118
        inner.add(generalPanel);
119

    
120
        outer.add(inner);
121

    
122
                // Create the 'Create/Update' button, along with a listener that hides the dialog
123
                // when the button is clicked and quits the application.
124
                String okLabel = "Create";
125
                final Button ok = new Button(okLabel, new ClickHandler() {
126
                        @Override
127
                        public void onClick(ClickEvent event) {
128
                                createGroup();
129
                                closeDialog();
130
                        }
131
                });
132
                ok.addStyleName("button");
133
                outer.add(ok);
134
        outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
135

    
136
        setWidget(outer);
137
        }
138

    
139
        @Override
140
        public void center() {
141
                super.center();
142
                groupName.setFocus(true);
143
        }
144

    
145
        @Override
146
        protected void onPreviewNativeEvent(NativePreviewEvent preview) {
147
                super.onPreviewNativeEvent(preview);
148

    
149
                NativeEvent evt = preview.getNativeEvent();
150
                if (evt.getType().equals(KeyDownEvent.getType().getName()))
151
                        // Use the popup's key preview hooks to close the dialog when either
152
                        // enter or escape is pressed.
153
                        switch (evt.getKeyCode()) {
154
                                case KeyCodes.KEY_ENTER:
155
                                        createGroup();
156
                    closeDialog();
157
                                        break;
158
                                case KeyCodes.KEY_ESCAPE:
159
                                        closeDialog();
160
                                        break;
161
                        }
162
        }
163

    
164

    
165
        /**
166
         * Enables IE selection prevention and hides the dialog
167
         * (we disable the prevention on creation of the dialog)
168
         */
169
        public void closeDialog() {
170
                Pithos.preventIESelection();
171
                hide();
172
                if (callback != null)
173
                        callback.execute();
174
        }
175

    
176
        /**
177
         * Generate an RPC request to create a new folder.
178
         */
179
        void createGroup() {
180
                String name = groupName.getText().trim();
181
                if (name.length() == 0)
182
                        return;
183
                app.addGroup(name);
184
        }
185
}