2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
\r
4 * This file is part of GSS.
\r
6 * GSS is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * GSS is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
\r
19 package gr.ebs.gss.client;
\r
21 import gr.ebs.gss.client.MessagePanel.Images;
\r
22 import gr.ebs.gss.client.rest.DeleteCommand;
\r
23 import gr.ebs.gss.client.rest.RestException;
\r
24 import gr.ebs.gss.client.rest.resource.GroupResource;
\r
26 import com.google.gwt.core.client.GWT;
\r
27 import com.google.gwt.dom.client.NativeEvent;
\r
28 import com.google.gwt.event.dom.client.ClickEvent;
\r
29 import com.google.gwt.event.dom.client.ClickHandler;
\r
30 import com.google.gwt.event.dom.client.KeyCodes;
\r
31 import com.google.gwt.user.client.DeferredCommand;
\r
32 import com.google.gwt.user.client.Event.NativePreviewEvent;
\r
33 import com.google.gwt.user.client.ui.AbstractImagePrototype;
\r
34 import com.google.gwt.user.client.ui.Button;
\r
35 import com.google.gwt.user.client.ui.DialogBox;
\r
36 import com.google.gwt.user.client.ui.HTML;
\r
37 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
38 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
39 import com.google.gwt.user.client.ui.TreeItem;
\r
40 import com.google.gwt.user.client.ui.VerticalPanel;
\r
43 * The 'delete group' dialog box.
\r
45 public class DeleteGroupDialog extends DialogBox {
\r
48 * The widget's constructor.
\r
49 * @param images the supplied images
\r
51 public DeleteGroupDialog(final Images images) {
\r
52 // Use this opportunity to set the dialog's caption.
\r
53 setText("Delete group");
\r
54 setAnimationEnabled(true);
\r
55 final GroupResource group = (GroupResource) GSS.get().getCurrentSelection();
\r
56 // Create a VerticalPanel to contain the 'about' label and the 'OK'
\r
58 final VerticalPanel outer = new VerticalPanel();
\r
59 final HorizontalPanel buttons = new HorizontalPanel();
\r
61 // Create the 'about' text and set a style name so we can style it with
\r
63 final HTML text = new HTML("<table><tr><td>" + AbstractImagePrototype.create(images.warn()).getHTML() + "</td><td>" + "Are you sure you want to delete group '" + group.getName() + "'?</td></tr></table>");
\r
64 text.setStyleName("gss-warnMessage");
\r
67 // Create the 'Quit' button, along with a listener that hides the dialog
\r
68 // when the button is clicked and quits the application.
\r
69 final Button ok = new Button("OK", new ClickHandler() {
\r
71 public void onClick(ClickEvent event) {
\r
77 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
\r
78 // Create the 'Cancel' button, along with a listener that hides the
\r
80 // when the button is clicked.
\r
81 final Button cancel = new Button("Cancel", new ClickHandler() {
\r
83 public void onClick(ClickEvent event) {
\r
87 buttons.add(cancel);
\r
88 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
\r
89 buttons.setSpacing(8);
\r
90 buttons.setStyleName("gss-warnMessage");
\r
91 outer.setStyleName("gss-warnMessage");
\r
93 outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
\r
94 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
\r
99 * Generate an RPC request to delete a group.
\r
101 * @param userId the ID of the current user
\r
103 private void deleteGroup() {
\r
104 final TreeItem group = GSS.get().getGroups().getCurrent();
\r
105 if (group == null) {
\r
106 GSS.get().displayError("No group was selected!");
\r
109 DeleteCommand dg = new DeleteCommand(((GroupResource)group.getUserObject()).getUri()){
\r
111 public void onComplete() {
\r
112 GSS.get().getGroups().updateGroups();
\r
116 public void onError(Throwable t) {
\r
118 if(t instanceof RestException){
\r
119 int statusCode = ((RestException)t).getHttpStatusCode();
\r
120 if(statusCode == 405)
\r
121 GSS.get().displayError("You don't have the necessary permissions");
\r
122 else if(statusCode == 404)
\r
123 GSS.get().displayError("Group not found");
\r
125 GSS.get().displayError("Unable to delete group:"+((RestException)t).getHttpStatusText());
\r
128 GSS.get().displayError("System error unable to delete group:"+t.getMessage());
\r
131 DeferredCommand.addCommand(dg);
\r
136 protected void onPreviewNativeEvent(NativePreviewEvent preview) {
\r
137 super.onPreviewNativeEvent(preview);
\r
139 NativeEvent evt = preview.getNativeEvent();
\r
140 if (evt.getType().equals("keydown"))
\r
141 // Use the popup's key preview hooks to close the dialog when either
\r
142 // enter or escape is pressed.
\r
143 switch (evt.getKeyCode()) {
\r
144 case KeyCodes.KEY_ENTER:
\r
148 case KeyCodes.KEY_ESCAPE:
\r