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.MessagePanel.Images;
22 import gr.ebs.gss.client.rest.DeleteCommand;
23 import gr.ebs.gss.client.rest.RestException;
24 import gr.ebs.gss.client.rest.resource.GroupResource;
25 import gr.ebs.gss.client.rest.resource.GroupUserResource;
27 import com.google.gwt.core.client.GWT;
28 import com.google.gwt.user.client.DeferredCommand;
29 import com.google.gwt.user.client.ui.Button;
30 import com.google.gwt.user.client.ui.ClickListener;
31 import com.google.gwt.user.client.ui.DialogBox;
32 import com.google.gwt.user.client.ui.HTML;
33 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
34 import com.google.gwt.user.client.ui.HorizontalPanel;
35 import com.google.gwt.user.client.ui.KeyboardListener;
36 import com.google.gwt.user.client.ui.TreeItem;
37 import com.google.gwt.user.client.ui.VerticalPanel;
38 import com.google.gwt.user.client.ui.Widget;
45 public class DeleteUserDialog extends DialogBox {
48 * The widget's constructor.
49 * @param images the supplied images
51 public DeleteUserDialog(final Images images) {
52 // Use this opportunity to set the dialog's caption.
53 setText("Delete user");
54 setAnimationEnabled(true);
55 final GroupUserResource group = (GroupUserResource) GSS.get().getCurrentSelection();
56 // Create a VerticalPanel to contain the 'about' label and the 'OK'
58 final VerticalPanel outer = new VerticalPanel();
59 final HorizontalPanel buttons = new HorizontalPanel();
61 // Create the 'about' text and set a style name so we can style it with
63 final HTML text = new HTML("<table><tr><td>" + images.warn().getHTML() + "</td><td>" + "Are you sure you want to remove user '" + group.getName() + "'?</td></tr></table>");
64 text.setStyleName("gss-warnMessage");
67 // Create the 'Quit' button, along with a listener that hides the dialog
68 // when the button is clicked and quits the application.
69 final Button ok = new Button("OK", new ClickListener() {
71 public void onClick(Widget sender) {
77 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
78 // Create the 'Cancel' button, along with a listener that hides the
80 // when the button is clicked.
81 final Button cancel = new Button("Cancel", new ClickListener() {
83 public void onClick(Widget sender) {
88 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
89 buttons.setSpacing(8);
90 buttons.setStyleName("gss-warnMessage");
91 outer.setStyleName("gss-warnMessage");
93 outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
94 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
99 * Generate an RPC request to delete a group.
101 * @param userId the ID of the current user
103 private void deleteUser() {
104 final TreeItem user = GSS.get().getGroups().getCurrent();
105 final TreeItem group = user.getParentItem();
107 GSS.get().displayError("No user was selected!");
110 final GroupResource groupR = (GroupResource) group.getUserObject();
111 final GroupUserResource memberR = (GroupUserResource) user.getUserObject();
112 DeleteCommand du = new DeleteCommand(memberR.getUri()){
114 public void onComplete() {
115 GSS.get().getGroups().updateGroups();
118 public void onError(Throwable t) {
120 if(t instanceof RestException){
121 int statusCode = ((RestException)t).getHttpStatusCode();
122 if(statusCode == 405)
123 GSS.get().displayError("You don't have the necessary permissions");
124 else if(statusCode == 404)
125 GSS.get().displayError("User not found");
127 GSS.get().displayError("Unable to delete user:"+((RestException)t).getHttpStatusText());
130 GSS.get().displayError("System error unable to delete user:"+t.getMessage());
133 DeferredCommand.addCommand(du);
140 * @see com.google.gwt.user.client.ui.PopupPanel#onKeyDownPreview(char, int)
142 public boolean onKeyDownPreview(final char key, final int modifiers) {
143 // Use the popup's key preview hooks to close the dialog when either
144 // enter or escape is pressed.
146 case KeyboardListener.KEY_ENTER:
150 case KeyboardListener.KEY_ESCAPE: