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
76 ok.getElement().setId("confirmation.ok");
\r
78 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
\r
79 // Create the 'Cancel' button, along with a listener that hides the
\r
81 // when the button is clicked.
\r
82 final Button cancel = new Button("Cancel", new ClickHandler() {
\r
84 public void onClick(ClickEvent event) {
\r
88 cancel.getElement().setId("confirmation.cancel");
\r
89 buttons.add(cancel);
\r
90 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
\r
91 buttons.setSpacing(8);
\r
92 buttons.setStyleName("gss-warnMessage");
\r
93 outer.setStyleName("gss-warnMessage");
\r
95 outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
\r
96 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
\r
101 * Generate an RPC request to delete a group.
\r
103 * @param userId the ID of the current user
\r
105 private void deleteGroup() {
\r
106 final TreeItem group = GSS.get().getGroups().getCurrent();
\r
107 if (group == null) {
\r
108 GSS.get().displayError("No group was selected!");
\r
111 DeleteCommand dg = new DeleteCommand(((GroupResource)group.getUserObject()).getUri()){
\r
113 public void onComplete() {
\r
114 GSS.get().getGroups().updateGroups();
\r
118 public void onError(Throwable t) {
\r
120 if(t instanceof RestException){
\r
121 int statusCode = ((RestException)t).getHttpStatusCode();
\r
122 if(statusCode == 405)
\r
123 GSS.get().displayError("You don't have the necessary permissions");
\r
124 else if(statusCode == 404)
\r
125 GSS.get().displayError("Group not found");
\r
127 GSS.get().displayError("Unable to delete group:"+((RestException)t).getHttpStatusText());
\r
130 GSS.get().displayError("System error unable to delete group:"+t.getMessage());
\r
133 DeferredCommand.addCommand(dg);
\r
138 protected void onPreviewNativeEvent(NativePreviewEvent preview) {
\r
139 super.onPreviewNativeEvent(preview);
\r
141 NativeEvent evt = preview.getNativeEvent();
\r
142 if (evt.getType().equals("keydown"))
\r
143 // Use the popup's key preview hooks to close the dialog when either
\r
144 // enter or escape is pressed.
\r
145 switch (evt.getKeyCode()) {
\r
146 case KeyCodes.KEY_ENTER:
\r
150 case KeyCodes.KEY_ESCAPE:
\r