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