Revision 53f8abed
b/src/gr/grnet/pithos/web/client/AddUserDialog.java | ||
---|---|---|
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.Resource; |
|
38 |
import gr.grnet.pithos.web.client.grouptree.Group; |
|
39 |
import gr.grnet.pithos.web.client.rest.PostRequest; |
|
40 |
import gr.grnet.pithos.web.client.rest.RestException; |
|
41 |
|
|
42 |
import com.google.gwt.core.client.GWT; |
|
43 |
import com.google.gwt.core.client.Scheduler; |
|
44 |
import com.google.gwt.dom.client.NativeEvent; |
|
45 |
import com.google.gwt.event.dom.client.ClickEvent; |
|
46 |
import com.google.gwt.event.dom.client.ClickHandler; |
|
47 |
import com.google.gwt.event.dom.client.KeyCodes; |
|
48 |
import com.google.gwt.event.dom.client.KeyDownEvent; |
|
49 |
import com.google.gwt.http.client.Response; |
|
50 |
import com.google.gwt.http.client.URL; |
|
51 |
import com.google.gwt.user.client.Event.NativePreviewEvent; |
|
52 |
import com.google.gwt.user.client.ui.Anchor; |
|
53 |
import com.google.gwt.user.client.ui.Button; |
|
54 |
import com.google.gwt.user.client.ui.DialogBox; |
|
55 |
import com.google.gwt.user.client.ui.FlexTable; |
|
56 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
|
57 |
import com.google.gwt.user.client.ui.TextBox; |
|
58 |
import com.google.gwt.user.client.ui.VerticalPanel; |
|
59 |
|
|
60 |
/** |
|
61 |
* The 'Folder properties' dialog box implementation. |
|
62 |
*/ |
|
63 |
public class AddUserDialog extends DialogBox { |
|
64 |
|
|
65 |
protected Pithos app; |
|
66 |
|
|
67 |
Group group; |
|
68 |
/** |
|
69 |
* The widget that holds the folderName of the folder. |
|
70 |
*/ |
|
71 |
TextBox userName = new TextBox(); |
|
72 |
|
|
73 |
final VerticalPanel inner; |
|
74 |
|
|
75 |
/** |
|
76 |
* The widget's constructor. |
|
77 |
*/ |
|
78 |
public AddUserDialog(final Pithos app, Group _group) { |
|
79 |
this.app = app; |
|
80 |
this.group = _group; |
|
81 |
|
|
82 |
Anchor close = new Anchor(); |
|
83 |
close.addStyleName("close"); |
|
84 |
close.addClickHandler(new ClickHandler() { |
|
85 |
|
|
86 |
@Override |
|
87 |
public void onClick(ClickEvent event) { |
|
88 |
hide(); |
|
89 |
} |
|
90 |
}); |
|
91 |
|
|
92 |
setAnimationEnabled(true); |
|
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("Add user"); |
|
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, "Username"); |
|
112 |
|
|
113 |
generalTable.setWidget(0, 1, userName); |
|
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 |
addUser(); |
|
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 |
userName.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 |
addUser(); |
|
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 |
} |
|
174 |
|
|
175 |
/** |
|
176 |
* Generate an RPC request to create a new folder. |
|
177 |
*/ |
|
178 |
void addUser() { |
|
179 |
String name = userName.getText().trim(); |
|
180 |
if (name.length() == 0) |
|
181 |
return; |
|
182 |
group.addMember(name); |
|
183 |
String path = "?update="; |
|
184 |
PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) { |
|
185 |
|
|
186 |
@Override |
|
187 |
public void onSuccess(Resource result) { |
|
188 |
app.updateGroupNode(group); |
|
189 |
} |
|
190 |
|
|
191 |
@Override |
|
192 |
public void onError(Throwable t) { |
|
193 |
GWT.log("", t); |
|
194 |
app.setError(t); |
|
195 |
if (t instanceof RestException) { |
|
196 |
app.displayError("Unable to update group:" + ((RestException) t).getHttpStatusText()); |
|
197 |
} |
|
198 |
else |
|
199 |
app.displayError("System error updating group:" + t.getMessage()); |
|
200 |
} |
|
201 |
|
|
202 |
@Override |
|
203 |
protected void onUnauthorized(Response response) { |
|
204 |
app.sessionExpired(); |
|
205 |
} |
|
206 |
}; |
|
207 |
updateGroup.setHeader("X-Auth-Token", app.getToken()); |
|
208 |
String groupMembers = ""; |
|
209 |
for (String u : group.getMembers()) |
|
210 |
groupMembers += (URL.encodePathSegment(u) + ","); |
|
211 |
updateGroup.setHeader("X-Account-Group-" + URL.encodePathSegment(group.getName()), groupMembers); |
|
212 |
Scheduler.get().scheduleDeferred(updateGroup); |
|
213 |
} |
|
214 |
} |
b/src/gr/grnet/pithos/web/client/GroupCreateDialog.java | ||
---|---|---|
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.Event.NativePreviewEvent; |
|
45 |
import com.google.gwt.user.client.ui.Anchor; |
|
46 |
import com.google.gwt.user.client.ui.Button; |
|
47 |
import com.google.gwt.user.client.ui.DialogBox; |
|
48 |
import com.google.gwt.user.client.ui.FlexTable; |
|
49 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
|
50 |
import com.google.gwt.user.client.ui.TextBox; |
|
51 |
import com.google.gwt.user.client.ui.VerticalPanel; |
|
52 |
|
|
53 |
/** |
|
54 |
* The 'Folder properties' dialog box implementation. |
|
55 |
*/ |
|
56 |
public class GroupCreateDialog extends DialogBox { |
|
57 |
|
|
58 |
protected Pithos app; |
|
59 |
|
|
60 |
/** |
|
61 |
* The widget that holds the folderName of the folder. |
|
62 |
*/ |
|
63 |
TextBox groupName = new TextBox(); |
|
64 |
|
|
65 |
final VerticalPanel inner; |
|
66 |
|
|
67 |
/** |
|
68 |
* The widget's constructor. |
|
69 |
*/ |
|
70 |
public GroupCreateDialog(final Pithos app) { |
|
71 |
this.app = app; |
|
72 |
Anchor close = new Anchor(); |
|
73 |
close.addStyleName("close"); |
|
74 |
close.addClickHandler(new ClickHandler() { |
|
75 |
|
|
76 |
@Override |
|
77 |
public void onClick(ClickEvent event) { |
|
78 |
hide(); |
|
79 |
} |
|
80 |
}); |
|
81 |
|
|
82 |
setAnimationEnabled(true); |
|
83 |
setGlassEnabled(true); |
|
84 |
setStyleName("pithos-DialogBox"); |
|
85 |
|
|
86 |
// Enable IE selection for the dialog (must disable it upon closing it) |
|
87 |
Pithos.enableIESelection(); |
|
88 |
|
|
89 |
// Use this opportunity to set the dialog's caption. |
|
90 |
setText("Create group"); |
|
91 |
|
|
92 |
// Outer contains inner and buttons |
|
93 |
VerticalPanel outer = new VerticalPanel(); |
|
94 |
outer.add(close); |
|
95 |
// Inner contains generalPanel and permPanel |
|
96 |
inner = new VerticalPanel(); |
|
97 |
inner.addStyleName("inner"); |
|
98 |
|
|
99 |
VerticalPanel generalPanel = new VerticalPanel(); |
|
100 |
FlexTable generalTable = new FlexTable(); |
|
101 |
generalTable.setText(0, 0, "Name"); |
|
102 |
|
|
103 |
generalTable.setWidget(0, 1, groupName); |
|
104 |
|
|
105 |
generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); |
|
106 |
generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); |
|
107 |
generalTable.setCellSpacing(4); |
|
108 |
generalPanel.add(generalTable); |
|
109 |
inner.add(generalPanel); |
|
110 |
|
|
111 |
outer.add(inner); |
|
112 |
|
|
113 |
// Create the 'Create/Update' button, along with a listener that hides the dialog |
|
114 |
// when the button is clicked and quits the application. |
|
115 |
String okLabel = "Create"; |
|
116 |
final Button ok = new Button(okLabel, new ClickHandler() { |
|
117 |
@Override |
|
118 |
public void onClick(ClickEvent event) { |
|
119 |
createGroup(); |
|
120 |
closeDialog(); |
|
121 |
} |
|
122 |
}); |
|
123 |
ok.addStyleName("button"); |
|
124 |
outer.add(ok); |
|
125 |
outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
|
126 |
|
|
127 |
setWidget(outer); |
|
128 |
} |
|
129 |
|
|
130 |
@Override |
|
131 |
public void center() { |
|
132 |
super.center(); |
|
133 |
groupName.setFocus(true); |
|
134 |
} |
|
135 |
|
|
136 |
@Override |
|
137 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
|
138 |
super.onPreviewNativeEvent(preview); |
|
139 |
|
|
140 |
NativeEvent evt = preview.getNativeEvent(); |
|
141 |
if (evt.getType().equals(KeyDownEvent.getType().getName())) |
|
142 |
// Use the popup's key preview hooks to close the dialog when either |
|
143 |
// enter or escape is pressed. |
|
144 |
switch (evt.getKeyCode()) { |
|
145 |
case KeyCodes.KEY_ENTER: |
|
146 |
createGroup(); |
|
147 |
closeDialog(); |
|
148 |
break; |
|
149 |
case KeyCodes.KEY_ESCAPE: |
|
150 |
closeDialog(); |
|
151 |
break; |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
|
|
156 |
/** |
|
157 |
* Enables IE selection prevention and hides the dialog |
|
158 |
* (we disable the prevention on creation of the dialog) |
|
159 |
*/ |
|
160 |
public void closeDialog() { |
|
161 |
Pithos.preventIESelection(); |
|
162 |
hide(); |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Generate an RPC request to create a new folder. |
|
167 |
*/ |
|
168 |
private void createGroup() { |
|
169 |
String name = groupName.getText().trim(); |
|
170 |
if (name.length() == 0) |
|
171 |
return; |
|
172 |
app.addGroup(name); |
|
173 |
} |
|
174 |
} |
b/src/gr/grnet/pithos/web/client/commands/AddUserCommand.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package gr.grnet.pithos.web.client.commands; |
36 | 36 |
|
37 |
import gr.grnet.pithos.web.client.AddUserDialog; |
|
37 | 38 |
import gr.grnet.pithos.web.client.Pithos; |
38 | 39 |
import gr.grnet.pithos.web.client.foldertree.Resource; |
39 | 40 |
import gr.grnet.pithos.web.client.grouptree.Group; |
... | ... | |
72 | 73 |
public void execute() { |
73 | 74 |
if (containerPanel != null) |
74 | 75 |
containerPanel.hide(); |
75 |
String username = Window.prompt("Enter username:", ""); |
|
76 |
if (username != null && username.length() > 0) { |
|
77 |
group.addMember(username); |
|
78 |
String path = "?update="; |
|
79 |
PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) { |
|
80 |
|
|
81 |
@Override |
|
82 |
public void onSuccess(Resource result) { |
|
83 |
app.updateGroupNode(group); |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public void onError(Throwable t) { |
|
88 |
GWT.log("", t); |
|
89 |
app.setError(t); |
|
90 |
if (t instanceof RestException) { |
|
91 |
app.displayError("Unable to update group:" + ((RestException) t).getHttpStatusText()); |
|
92 |
} |
|
93 |
else |
|
94 |
app.displayError("System error updating group:" + t.getMessage()); |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
protected void onUnauthorized(Response response) { |
|
99 |
app.sessionExpired(); |
|
100 |
} |
|
101 |
}; |
|
102 |
updateGroup.setHeader("X-Auth-Token", app.getToken()); |
|
103 |
String groupMembers = ""; |
|
104 |
for (String u : group.getMembers()) |
|
105 |
groupMembers += (URL.encodePathSegment(u) + ","); |
|
106 |
updateGroup.setHeader("X-Account-Group-" + URL.encodePathSegment(group.getName()), groupMembers); |
|
107 |
Scheduler.get().scheduleDeferred(updateGroup); |
|
108 |
} |
|
76 |
AddUserDialog dlg = new AddUserDialog(app, group); |
|
77 |
dlg.center(); |
|
109 | 78 |
} |
110 | 79 |
} |
b/src/gr/grnet/pithos/web/client/commands/CreateGroupCommand.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package gr.grnet.pithos.web.client.commands; |
36 | 36 |
|
37 |
import gr.grnet.pithos.web.client.GroupCreateDialog; |
|
37 | 38 |
import gr.grnet.pithos.web.client.Pithos; |
38 | 39 |
|
39 | 40 |
import com.google.gwt.user.client.Command; |
... | ... | |
61 | 62 |
public void execute() { |
62 | 63 |
if (containerPanel != null) |
63 | 64 |
containerPanel.hide(); |
64 |
String groupname = Window.prompt("Enter group name:", ""); |
|
65 |
if (groupname != null && groupname.length() > 0) { |
|
66 |
app.addGroup(groupname); |
|
67 |
} |
|
65 |
GroupCreateDialog dlg = new GroupCreateDialog(app); |
|
66 |
dlg.center(); |
|
68 | 67 |
} |
69 | 68 |
} |
Also available in: Unified diff