2 * Copyright 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.client;
21 import gr.ebs.gss.client.rest.PostCommand;
22 import gr.ebs.gss.client.rest.RestException;
24 import com.google.gwt.core.client.GWT;
25 import com.google.gwt.http.client.URL;
26 import com.google.gwt.user.client.DeferredCommand;
27 import com.google.gwt.user.client.ui.Button;
28 import com.google.gwt.user.client.ui.ClickListener;
29 import com.google.gwt.user.client.ui.DialogBox;
30 import com.google.gwt.user.client.ui.Grid;
31 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
32 import com.google.gwt.user.client.ui.HorizontalPanel;
33 import com.google.gwt.user.client.ui.KeyboardListener;
34 import com.google.gwt.user.client.ui.TextBox;
35 import com.google.gwt.user.client.ui.VerticalPanel;
36 import com.google.gwt.user.client.ui.Widget;
41 public class GroupPropertiesDialog extends DialogBox {
44 * The widget that holds the folderName of the folder.
46 private TextBox groupName = new TextBox();
49 * A flag that denotes whether the dialog will be used to create or modify a
52 private final boolean create;
55 * The widget's constructor.
57 * @param _create true if the dialog is displayed for creating a new
58 * sub-folder of the selected folder, false if it is displayed
59 * for modifying the selected folder
61 public GroupPropertiesDialog(final boolean _create) {
62 setAnimationEnabled(true);
64 // Use this opportunity to set the dialog's caption.
66 setText("Create Group");
68 setText("Group properties");
69 final VerticalPanel panel = new VerticalPanel();
71 final Grid generalTable = new Grid(1, 2);
72 generalTable.setText(0, 0, "Group Name");
73 generalTable.setWidget(0, 1, groupName);
74 generalTable.getCellFormatter().setStyleName(0, 0, "props-labels");
75 generalTable.getCellFormatter().setStyleName(0, 1, "props-values");
76 generalTable.setCellSpacing(4);
78 panel.add(generalTable);
79 final HorizontalPanel buttons = new HorizontalPanel();
80 final Button ok = new Button("OK", new ClickListener() {
82 public void onClick(Widget sender) {
83 createGroup(groupName.getText());
88 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
89 // Create the 'Cancel' button, along with a listener that hides the
91 // when the button is clicked.
92 final Button cancel = new Button("Cancel", new ClickListener() {
94 public void onClick(Widget sender) {
99 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
100 buttons.setSpacing(8);
101 buttons.addStyleName("gwt-TabPanelBottom");
103 panel.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
104 //panel.addStyleName("gss-DialogBox");
105 panel.addStyleName("gwt-TabPanelBottom");
106 groupName.setFocus(true);
110 public boolean onKeyDownPreview(final char key, final int modifiers) {
111 // Use the popup's key preview hooks to close the dialog when either
112 // enter or escape is pressed.
114 case KeyboardListener.KEY_ENTER:
116 createGroup( groupName.getText());
118 case KeyboardListener.KEY_ESCAPE:
126 * Generate an RPC request to create a new group.
128 * @param userId the ID of the user whose namespace will be searched for
130 * @param aGroupName the name of the group to create
132 private void createGroup(String aGroupName) {
134 if (aGroupName == null || aGroupName.length() == 0) {
135 GSS.get().displayError("Empty group name!");
138 GWT.log("createGroup(" + aGroupName + ")", null);
139 PostCommand cg = new PostCommand(GSS.get().getCurrentUserResource().getGroupsPath()+"?name="+URL.encodeComponent(aGroupName), "", 201){
142 public void onComplete() {
143 GSS.get().getGroups().updateGroups();
144 GSS.get().showUserList();
148 public void onError(Throwable t) {
150 if(t instanceof RestException){
151 int statusCode = ((RestException)t).getHttpStatusCode();
152 if(statusCode == 405)
153 GSS.get().displayError("You don't have the necessary permissions");
154 else if(statusCode == 404)
155 GSS.get().displayError("Resource does not exist");
156 else if(statusCode == 409)
157 GSS.get().displayError("A group with the same name already exists");
158 else if(statusCode == 413)
159 GSS.get().displayError("Your quota has been exceeded");
161 GSS.get().displayError("Unable to create group:"+((RestException)t).getHttpStatusText());
164 GSS.get().displayError("System error creating group:"+t.getMessage());
167 DeferredCommand.addCommand(cg);