root / src / gr / grnet / pithos / web / client / GroupCreateDialog.java @ 28267d27
History | View | Annotate | Download (5.9 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.commands.AddUserCommand; |
38 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
39 |
import gr.grnet.pithos.web.client.grouptree.Group; |
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.event.dom.client.KeyDownEvent; |
46 |
import com.google.gwt.user.client.Command; |
47 |
import com.google.gwt.user.client.Event.NativePreviewEvent; |
48 |
import com.google.gwt.user.client.ui.Anchor; |
49 |
import com.google.gwt.user.client.ui.Button; |
50 |
import com.google.gwt.user.client.ui.DialogBox; |
51 |
import com.google.gwt.user.client.ui.FlexTable; |
52 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
53 |
import com.google.gwt.user.client.ui.TextBox; |
54 |
import com.google.gwt.user.client.ui.VerticalPanel; |
55 |
|
56 |
/**
|
57 |
* The 'Folder properties' dialog box implementation.
|
58 |
*/
|
59 |
public class GroupCreateDialog extends DialogBox { |
60 |
|
61 |
protected Pithos app;
|
62 |
|
63 |
private Command callback;
|
64 |
|
65 |
/**
|
66 |
* The widget that holds the folderName of the folder.
|
67 |
*/
|
68 |
TextBox groupName = new TextBox();
|
69 |
|
70 |
final VerticalPanel inner;
|
71 |
|
72 |
public GroupCreateDialog(final Pithos app) { |
73 |
this(app, null); |
74 |
} |
75 |
|
76 |
/**
|
77 |
* The widget's constructor.
|
78 |
*/
|
79 |
public GroupCreateDialog(final Pithos app, Command callback) { |
80 |
this.app = app;
|
81 |
this.callback = callback;
|
82 |
|
83 |
Anchor close = new Anchor("close"); |
84 |
close.addStyleName("close");
|
85 |
close.addClickHandler(new ClickHandler() {
|
86 |
|
87 |
@Override
|
88 |
public void onClick(ClickEvent event) { |
89 |
hide(); |
90 |
} |
91 |
}); |
92 |
|
93 |
setGlassEnabled(true);
|
94 |
setStyleName("pithos-DialogBox");
|
95 |
|
96 |
// Enable IE selection for the dialog (must disable it upon closing it)
|
97 |
Pithos.enableIESelection(); |
98 |
|
99 |
// Use this opportunity to set the dialog's caption.
|
100 |
setText("Create group");
|
101 |
|
102 |
// Outer contains inner and buttons
|
103 |
VerticalPanel outer = new VerticalPanel();
|
104 |
outer.add(close); |
105 |
// Inner contains generalPanel and permPanel
|
106 |
inner = new VerticalPanel();
|
107 |
inner.addStyleName("inner");
|
108 |
|
109 |
VerticalPanel generalPanel = new VerticalPanel();
|
110 |
FlexTable generalTable = new FlexTable();
|
111 |
generalTable.setText(0, 0, "Name"); |
112 |
|
113 |
generalTable.setWidget(0, 1, groupName); |
114 |
|
115 |
generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); |
116 |
generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); |
117 |
generalTable.setCellSpacing(4);
|
118 |
generalPanel.add(generalTable); |
119 |
inner.add(generalPanel); |
120 |
|
121 |
outer.add(inner); |
122 |
|
123 |
// Create the 'Create/Update' button, along with a listener that hides the dialog
|
124 |
// when the button is clicked and quits the application.
|
125 |
String okLabel = "Create"; |
126 |
final Button ok = new Button(okLabel, new ClickHandler() { |
127 |
@Override
|
128 |
public void onClick(ClickEvent event) { |
129 |
createGroup(); |
130 |
closeDialog(); |
131 |
} |
132 |
}); |
133 |
ok.addStyleName("button");
|
134 |
outer.add(ok); |
135 |
outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
136 |
|
137 |
setWidget(outer); |
138 |
} |
139 |
|
140 |
@Override
|
141 |
public void center() { |
142 |
super.center();
|
143 |
groupName.setFocus(true);
|
144 |
} |
145 |
|
146 |
@Override
|
147 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
148 |
super.onPreviewNativeEvent(preview);
|
149 |
|
150 |
NativeEvent evt = preview.getNativeEvent(); |
151 |
if (evt.getType().equals(KeyDownEvent.getType().getName()))
|
152 |
// Use the popup's key preview hooks to close the dialog when either
|
153 |
// enter or escape is pressed.
|
154 |
switch (evt.getKeyCode()) {
|
155 |
case KeyCodes.KEY_ENTER:
|
156 |
createGroup(); |
157 |
closeDialog(); |
158 |
break;
|
159 |
case KeyCodes.KEY_ESCAPE:
|
160 |
closeDialog(); |
161 |
break;
|
162 |
} |
163 |
} |
164 |
|
165 |
|
166 |
/**
|
167 |
* Enables IE selection prevention and hides the dialog
|
168 |
* (we disable the prevention on creation of the dialog)
|
169 |
*/
|
170 |
public void closeDialog() { |
171 |
Pithos.preventIESelection(); |
172 |
hide(); |
173 |
if (callback != null) |
174 |
callback.execute(); |
175 |
} |
176 |
|
177 |
/**
|
178 |
* Generate an RPC request to create a new folder.
|
179 |
*/
|
180 |
void createGroup() {
|
181 |
String name = groupName.getText().trim();
|
182 |
if (name.length() == 0) |
183 |
return;
|
184 |
Group group = app.addGroup(name);
|
185 |
|
186 |
new AddUserCommand(app, null, group).execute(); |
187 |
} |
188 |
} |