root / src / gr / ebs / gss / client / GroupPropertiesDialog.java @ 783db80b
History | View | Annotate | Download (5.7 kB)
1 | 14ad7326 | pastith | /*
|
---|---|---|---|
2 | 14ad7326 | pastith | * Copyright 2008, 2009 Electronic Business Systems Ltd.
|
3 | 14ad7326 | pastith | *
|
4 | 14ad7326 | pastith | * This file is part of GSS.
|
5 | 14ad7326 | pastith | *
|
6 | 14ad7326 | pastith | * GSS is free software: you can redistribute it and/or modify
|
7 | 14ad7326 | pastith | * it under the terms of the GNU General Public License as published by
|
8 | 14ad7326 | pastith | * the Free Software Foundation, either version 3 of the License, or
|
9 | 14ad7326 | pastith | * (at your option) any later version.
|
10 | 14ad7326 | pastith | *
|
11 | 14ad7326 | pastith | * GSS is distributed in the hope that it will be useful,
|
12 | 14ad7326 | pastith | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 14ad7326 | pastith | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 14ad7326 | pastith | * GNU General Public License for more details.
|
15 | 14ad7326 | pastith | *
|
16 | 14ad7326 | pastith | * You should have received a copy of the GNU General Public License
|
17 | 14ad7326 | pastith | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | 14ad7326 | pastith | */
|
19 | 14ad7326 | pastith | package gr.ebs.gss.client; |
20 | 14ad7326 | pastith | |
21 | 895035a2 | pastith | import gr.ebs.gss.client.rest.PostCommand; |
22 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.RestException; |
23 | 14ad7326 | pastith | |
24 | 14ad7326 | pastith | import com.google.gwt.core.client.GWT; |
25 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.dom.client.NativeEvent; |
26 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.event.dom.client.ClickEvent; |
27 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.event.dom.client.ClickHandler; |
28 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.event.dom.client.KeyCodes; |
29 | f6d2577e | droutsis | import com.google.gwt.http.client.URL; |
30 | a52ea5e4 | pastith | import com.google.gwt.user.client.DeferredCommand; |
31 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.user.client.Event.NativePreviewEvent; |
32 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.Button; |
33 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.DialogBox; |
34 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.Grid; |
35 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
36 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.HorizontalPanel; |
37 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.TextBox; |
38 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.VerticalPanel; |
39 | 14ad7326 | pastith | |
40 | 14ad7326 | pastith | /**
|
41 | 14ad7326 | pastith | * @author kman
|
42 | 14ad7326 | pastith | */
|
43 | 14ad7326 | pastith | public class GroupPropertiesDialog extends DialogBox { |
44 | 14ad7326 | pastith | |
45 | 14ad7326 | pastith | /**
|
46 | 14ad7326 | pastith | * The widget that holds the folderName of the folder.
|
47 | 14ad7326 | pastith | */
|
48 | 14ad7326 | pastith | private TextBox groupName = new TextBox(); |
49 | 14ad7326 | pastith | |
50 | 14ad7326 | pastith | /**
|
51 | 14ad7326 | pastith | * A flag that denotes whether the dialog will be used to create or modify a
|
52 | 14ad7326 | pastith | * folder.
|
53 | 14ad7326 | pastith | */
|
54 | 14ad7326 | pastith | private final boolean create; |
55 | 14ad7326 | pastith | |
56 | 14ad7326 | pastith | /**
|
57 | 14ad7326 | pastith | * The widget's constructor.
|
58 | 14ad7326 | pastith | *
|
59 | 14ad7326 | pastith | * @param _create true if the dialog is displayed for creating a new
|
60 | 14ad7326 | pastith | * sub-folder of the selected folder, false if it is displayed
|
61 | 14ad7326 | pastith | * for modifying the selected folder
|
62 | 14ad7326 | pastith | */
|
63 | 41d05cc8 | pastith | public GroupPropertiesDialog(final boolean _create) { |
64 | 14ad7326 | pastith | setAnimationEnabled(true);
|
65 | 14ad7326 | pastith | create = _create; |
66 | 14ad7326 | pastith | // Use this opportunity to set the dialog's caption.
|
67 | 14ad7326 | pastith | if (create)
|
68 | 14ad7326 | pastith | setText("Create Group");
|
69 | 14ad7326 | pastith | else
|
70 | 14ad7326 | pastith | setText("Group properties");
|
71 | 14ad7326 | pastith | final VerticalPanel panel = new VerticalPanel(); |
72 | 14ad7326 | pastith | setWidget(panel); |
73 | 14ad7326 | pastith | final Grid generalTable = new Grid(1, 2); |
74 | 14ad7326 | pastith | generalTable.setText(0, 0, "Group Name"); |
75 | 14ad7326 | pastith | generalTable.setWidget(0, 1, groupName); |
76 | 14ad7326 | pastith | generalTable.getCellFormatter().setStyleName(0, 0, "props-labels"); |
77 | 14ad7326 | pastith | generalTable.getCellFormatter().setStyleName(0, 1, "props-values"); |
78 | 14ad7326 | pastith | generalTable.setCellSpacing(4);
|
79 | 14ad7326 | pastith | |
80 | 14ad7326 | pastith | panel.add(generalTable); |
81 | 14ad7326 | pastith | final HorizontalPanel buttons = new HorizontalPanel(); |
82 | afd3a0ef | Giannis Koutsoubos | final Button ok = new Button("OK", new ClickHandler() { |
83 | afd3a0ef | Giannis Koutsoubos | @Override
|
84 | afd3a0ef | Giannis Koutsoubos | public void onClick(ClickEvent event) { |
85 | a52ea5e4 | pastith | createGroup(groupName.getText()); |
86 | 14ad7326 | pastith | hide(); |
87 | 14ad7326 | pastith | } |
88 | 14ad7326 | pastith | }); |
89 | 14ad7326 | pastith | buttons.add(ok); |
90 | 14ad7326 | pastith | buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); |
91 | 14ad7326 | pastith | // Create the 'Cancel' button, along with a listener that hides the
|
92 | 14ad7326 | pastith | // dialog
|
93 | 14ad7326 | pastith | // when the button is clicked.
|
94 | afd3a0ef | Giannis Koutsoubos | final Button cancel = new Button("Cancel", new ClickHandler() { |
95 | afd3a0ef | Giannis Koutsoubos | @Override
|
96 | afd3a0ef | Giannis Koutsoubos | public void onClick(ClickEvent event) { |
97 | 14ad7326 | pastith | hide(); |
98 | 14ad7326 | pastith | } |
99 | 14ad7326 | pastith | }); |
100 | 14ad7326 | pastith | buttons.add(cancel); |
101 | 14ad7326 | pastith | buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
102 | 14ad7326 | pastith | buttons.setSpacing(8);
|
103 | 5c6b2883 | Panagiotis Astithas | buttons.addStyleName("gss-TabPanelBottom");
|
104 | 14ad7326 | pastith | panel.add(buttons); |
105 | 14ad7326 | pastith | panel.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); |
106 | 14ad7326 | pastith | //panel.addStyleName("gss-DialogBox");
|
107 | ba484b3c | Natasa Kapravelou | panel.addStyleName("gss-TabPanelBottom");
|
108 | ba484b3c | Natasa Kapravelou | } |
109 | ba484b3c | Natasa Kapravelou | @Override
|
110 | ba484b3c | Natasa Kapravelou | public void center() { |
111 | ba484b3c | Natasa Kapravelou | super.center();
|
112 | 14ad7326 | pastith | groupName.setFocus(true);
|
113 | 14ad7326 | pastith | } |
114 | 14ad7326 | pastith | |
115 | 41d05cc8 | pastith | @Override
|
116 | afd3a0ef | Giannis Koutsoubos | protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
117 | afd3a0ef | Giannis Koutsoubos | super.onPreviewNativeEvent(preview);
|
118 | 14ad7326 | pastith | |
119 | afd3a0ef | Giannis Koutsoubos | NativeEvent evt = preview.getNativeEvent(); |
120 | afd3a0ef | Giannis Koutsoubos | if (evt.getType().equals("keydown")) |
121 | afd3a0ef | Giannis Koutsoubos | // Use the popup's key preview hooks to close the dialog when either
|
122 | afd3a0ef | Giannis Koutsoubos | // enter or escape is pressed.
|
123 | afd3a0ef | Giannis Koutsoubos | switch (evt.getKeyCode()) {
|
124 | afd3a0ef | Giannis Koutsoubos | case KeyCodes.KEY_ENTER:
|
125 | afd3a0ef | Giannis Koutsoubos | hide(); |
126 | afd3a0ef | Giannis Koutsoubos | createGroup( groupName.getText()); |
127 | afd3a0ef | Giannis Koutsoubos | break;
|
128 | afd3a0ef | Giannis Koutsoubos | case KeyCodes.KEY_ESCAPE:
|
129 | afd3a0ef | Giannis Koutsoubos | hide(); |
130 | afd3a0ef | Giannis Koutsoubos | break;
|
131 | afd3a0ef | Giannis Koutsoubos | } |
132 | 14ad7326 | pastith | } |
133 | afd3a0ef | Giannis Koutsoubos | |
134 | afd3a0ef | Giannis Koutsoubos | |
135 | 14ad7326 | pastith | /**
|
136 | 14ad7326 | pastith | * Generate an RPC request to create a new group.
|
137 | 14ad7326 | pastith | *
|
138 | 14ad7326 | pastith | * @param userId the ID of the user whose namespace will be searched for
|
139 | 14ad7326 | pastith | * groups
|
140 | 41d05cc8 | pastith | * @param aGroupName the name of the group to create
|
141 | 14ad7326 | pastith | */
|
142 | 41d05cc8 | pastith | private void createGroup(String aGroupName) { |
143 | a52ea5e4 | pastith | |
144 | 41d05cc8 | pastith | if (aGroupName == null || aGroupName.length() == 0) { |
145 | 14ad7326 | pastith | GSS.get().displayError("Empty group name!");
|
146 | 14ad7326 | pastith | return;
|
147 | 14ad7326 | pastith | } |
148 | 41d05cc8 | pastith | GWT.log("createGroup(" + aGroupName + ")", null); |
149 | f6d2577e | droutsis | PostCommand cg = new PostCommand(GSS.get().getCurrentUserResource().getGroupsPath()+"?name="+URL.encodeComponent(aGroupName), "", 201){ |
150 | 14ad7326 | pastith | |
151 | 41d05cc8 | pastith | @Override
|
152 | a52ea5e4 | pastith | public void onComplete() { |
153 | a52ea5e4 | pastith | GSS.get().getGroups().updateGroups(); |
154 | 14ad7326 | pastith | GSS.get().showUserList(); |
155 | 14ad7326 | pastith | } |
156 | 14ad7326 | pastith | |
157 | 41d05cc8 | pastith | @Override
|
158 | a52ea5e4 | pastith | public void onError(Throwable t) { |
159 | a52ea5e4 | pastith | GWT.log("", t);
|
160 | a52ea5e4 | pastith | if(t instanceof RestException){ |
161 | a52ea5e4 | pastith | int statusCode = ((RestException)t).getHttpStatusCode();
|
162 | a52ea5e4 | pastith | if(statusCode == 405) |
163 | a52ea5e4 | pastith | GSS.get().displayError("You don't have the necessary permissions");
|
164 | a52ea5e4 | pastith | else if(statusCode == 404) |
165 | a52ea5e4 | pastith | GSS.get().displayError("Resource does not exist");
|
166 | a52ea5e4 | pastith | else if(statusCode == 409) |
167 | a52ea5e4 | pastith | GSS.get().displayError("A group with the same name already exists");
|
168 | a52ea5e4 | pastith | else if(statusCode == 413) |
169 | a52ea5e4 | pastith | GSS.get().displayError("Your quota has been exceeded");
|
170 | a52ea5e4 | pastith | else
|
171 | e08c358f | koutsoub | GSS.get().displayError("Unable to create group:"+((RestException)t).getHttpStatusText());
|
172 | a52ea5e4 | pastith | } |
173 | 14ad7326 | pastith | else
|
174 | a52ea5e4 | pastith | GSS.get().displayError("System error creating group:"+t.getMessage());
|
175 | 14ad7326 | pastith | } |
176 | a52ea5e4 | pastith | }; |
177 | a52ea5e4 | pastith | DeferredCommand.addCommand(cg); |
178 | a52ea5e4 | pastith | |
179 | 14ad7326 | pastith | } |
180 | 14ad7326 | pastith | } |