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.FolderResource;
\r
25 import gr.ebs.gss.client.rest.resource.RestResource;
\r
27 import com.google.gwt.core.client.GWT;
\r
28 import com.google.gwt.dom.client.NativeEvent;
\r
29 import com.google.gwt.event.dom.client.ClickEvent;
\r
30 import com.google.gwt.event.dom.client.ClickHandler;
\r
31 import com.google.gwt.event.dom.client.KeyCodes;
\r
32 import com.google.gwt.user.client.DeferredCommand;
\r
33 import com.google.gwt.user.client.Event.NativePreviewEvent;
\r
34 import com.google.gwt.user.client.ui.AbstractImagePrototype;
\r
35 import com.google.gwt.user.client.ui.Button;
\r
36 import com.google.gwt.user.client.ui.DialogBox;
\r
37 import com.google.gwt.user.client.ui.HTML;
\r
38 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
39 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
40 import com.google.gwt.user.client.ui.VerticalPanel;
\r
43 * The 'delete folder' dialog box.
\r
45 public class DeleteFolderDialog extends DialogBox {
\r
48 * The widget's constructor.
\r
49 * @param images the supplied images
\r
51 public DeleteFolderDialog(Images images) {
\r
52 // Set the dialog's caption.
\r
53 setText("Confirmation");
\r
54 setAnimationEnabled(true);
\r
55 FolderResource folder = (FolderResource) GSS.get().getCurrentSelection();
\r
56 // Create a VerticalPanel to contain the HTML label and the buttons.
\r
57 VerticalPanel outer = new VerticalPanel();
\r
58 HorizontalPanel buttons = new HorizontalPanel();
\r
60 HTML text = new HTML("<table><tr><td rowspan='2'>" + AbstractImagePrototype.create(images.warn()).getHTML() +
\r
61 "</td><td>" + "Are you sure you want to <b>permanently</b> delete folder '" + folder.getName() +
\r
62 "'?</td></tr></table>");
\r
63 text.setStyleName("gss-warnMessage");
\r
66 // Create the 'Delete' button, along with a listener that hides the dialog
\r
67 // when the button is clicked and deletes the folder.
\r
68 Button ok = new Button("Delete", new ClickHandler() {
\r
70 public void onClick(ClickEvent event) {
\r
76 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
\r
77 // Create the 'Cancel' button, along with a listener that hides the
\r
78 // dialog when the button is clicked.
\r
79 Button cancel = new Button("Cancel", new ClickHandler() {
\r
81 public void onClick(ClickEvent event) {
\r
85 buttons.add(cancel);
\r
86 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
\r
87 buttons.setSpacing(8);
\r
88 buttons.setStyleName("gss-warnMessage");
\r
89 outer.setStyleName("gss-warnMessage");
\r
91 outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
\r
92 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
\r
97 * Generate an RPC request to delete a folder.
\r
99 * @param userId the ID of the current user
\r
101 private void deleteFolder() {
\r
102 RestResource folder = GSS.get().getTreeView().getSelection();
\r
103 if (folder == null) {
\r
104 GSS.get().displayError("No folder was selected");
\r
107 if(!(folder instanceof FolderResource))
\r
110 DeleteCommand df = new DeleteCommand(folder.getUri()){
\r
113 public void onComplete() {
\r
115 TreeItem curFolder = GSS.get().getFolders().getCurrent();
\r
116 if(curFolder.getParentItem() != null){
\r
117 GSS.get().getFolders().select(curFolder.getParentItem());
\r
118 GSS.get().getFolders().updateFolder((DnDTreeItem) curFolder.getParentItem());
\r
120 FolderResource fres = (FolderResource) GSS.get().getTreeView().getSelection();
\r
121 GSS.get().getTreeView().updateNodeChildren(fres.getParentURI());
\r
122 GSS.get().showFileList(true);
\r
123 GSS.get().getStatusPanel().updateStats();
\r
127 public void onError(Throwable t) {
\r
129 if(t instanceof RestException){
\r
130 int statusCode = ((RestException)t).getHttpStatusCode();
\r
131 if(statusCode == 405)
\r
132 GSS.get().displayError("You don't have the necessary permissions");
\r
133 else if(statusCode == 404)
\r
134 GSS.get().displayError("Folder not found");
\r
136 GSS.get().displayError("Unable to delete folder: "+((RestException)t).getHttpStatusText());
\r
139 GSS.get().displayError("System error unable to delete folder: "+t.getMessage());
\r
143 DeferredCommand.addCommand(df);
\r
147 protected void onPreviewNativeEvent(NativePreviewEvent preview) {
\r
148 super.onPreviewNativeEvent(preview);
\r
150 NativeEvent evt = preview.getNativeEvent();
\r
151 if (evt.getType().equals("keydown"))
\r
152 // Use the popup's key preview hooks to close the dialog when either
\r
153 // enter or escape is pressed.
\r
154 switch (evt.getKeyCode()) {
\r
155 case KeyCodes.KEY_ENTER:
\r
159 case KeyCodes.KEY_ESCAPE:
\r