2 * Copyright (c) 2011 Greek Research and Technology Network
\r
4 package gr.grnet.pithos.web.client;
\r
6 import gr.grnet.pithos.web.client.MessagePanel.Images;
\r
7 import gr.grnet.pithos.web.client.rest.DeleteCommand;
\r
8 import gr.grnet.pithos.web.client.rest.RestException;
\r
9 import gr.grnet.pithos.web.client.rest.resource.GroupResource;
\r
11 import com.google.gwt.core.client.GWT;
\r
12 import com.google.gwt.dom.client.NativeEvent;
\r
13 import com.google.gwt.event.dom.client.ClickEvent;
\r
14 import com.google.gwt.event.dom.client.ClickHandler;
\r
15 import com.google.gwt.event.dom.client.KeyCodes;
\r
16 import com.google.gwt.user.client.DeferredCommand;
\r
17 import com.google.gwt.user.client.Event.NativePreviewEvent;
\r
18 import com.google.gwt.user.client.ui.AbstractImagePrototype;
\r
19 import com.google.gwt.user.client.ui.Button;
\r
20 import com.google.gwt.user.client.ui.DialogBox;
\r
21 import com.google.gwt.user.client.ui.HTML;
\r
22 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
23 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
24 import com.google.gwt.user.client.ui.TreeItem;
\r
25 import com.google.gwt.user.client.ui.VerticalPanel;
\r
28 * The 'delete group' dialog box.
\r
30 public class DeleteGroupDialog extends DialogBox {
\r
33 * The widget's constructor.
\r
34 * @param images the supplied images
\r
36 public DeleteGroupDialog(final Images images) {
\r
37 // Use this opportunity to set the dialog's caption.
\r
38 setText("Delete group");
\r
39 setAnimationEnabled(true);
\r
40 final GroupResource group = (GroupResource) GSS.get().getCurrentSelection();
\r
41 // Create a VerticalPanel to contain the 'about' label and the 'OK'
\r
43 final VerticalPanel outer = new VerticalPanel();
\r
44 final HorizontalPanel buttons = new HorizontalPanel();
\r
46 // Create the 'about' text and set a style name so we can style it with
\r
48 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
49 text.setStyleName("pithos-warnMessage");
\r
52 // Create the 'Quit' button, along with a listener that hides the dialog
\r
53 // when the button is clicked and quits the application.
\r
54 final Button ok = new Button("OK", new ClickHandler() {
\r
56 public void onClick(ClickEvent event) {
\r
61 ok.getElement().setId("deleteGroup.button.ok");
\r
63 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
\r
64 // Create the 'Cancel' button, along with a listener that hides the
\r
66 // when the button is clicked.
\r
67 final Button cancel = new Button("Cancel", new ClickHandler() {
\r
69 public void onClick(ClickEvent event) {
\r
73 cancel.getElement().setId("deleteGroup.button.cancel");
\r
74 buttons.add(cancel);
\r
75 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
\r
76 buttons.setSpacing(8);
\r
77 buttons.setStyleName("pithos-warnMessage");
\r
78 outer.setStyleName("pithos-warnMessage");
\r
80 outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
\r
81 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
\r
86 * Generate an RPC request to delete a group.
\r
88 * @param userId the ID of the current user
\r
90 private void deleteGroup() {
\r
91 final TreeItem group = GSS.get().getGroups().getCurrent();
\r
92 if (group == null) {
\r
93 GSS.get().displayError("No group was selected!");
\r
96 DeleteCommand dg = new DeleteCommand(((GroupResource)group.getUserObject()).getUri()){
\r
98 public void onComplete() {
\r
99 GSS.get().getGroups().updateGroups();
\r
103 public void onError(Throwable t) {
\r
105 if(t instanceof RestException){
\r
106 int statusCode = ((RestException)t).getHttpStatusCode();
\r
107 if(statusCode == 405)
\r
108 GSS.get().displayError("You don't have the necessary permissions");
\r
109 else if(statusCode == 404)
\r
110 GSS.get().displayError("Group not found");
\r
112 GSS.get().displayError("Unable to delete group:"+((RestException)t).getHttpStatusText());
\r
115 GSS.get().displayError("System error unable to delete group:"+t.getMessage());
\r
118 DeferredCommand.addCommand(dg);
\r
123 protected void onPreviewNativeEvent(NativePreviewEvent preview) {
\r
124 super.onPreviewNativeEvent(preview);
\r
126 NativeEvent evt = preview.getNativeEvent();
\r
127 if (evt.getType().equals("keydown"))
\r
128 // Use the popup's key preview hooks to close the dialog when either
\r
129 // enter or escape is pressed.
\r
130 switch (evt.getKeyCode()) {
\r
131 case KeyCodes.KEY_ENTER:
\r
135 case KeyCodes.KEY_ESCAPE:
\r