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.MultipleDeleteCommand;
\r
24 import gr.ebs.gss.client.rest.RestException;
\r
25 import gr.ebs.gss.client.rest.resource.FileResource;
\r
27 import java.util.ArrayList;
\r
28 import java.util.List;
\r
30 import com.google.gwt.core.client.GWT;
\r
31 import com.google.gwt.user.client.DeferredCommand;
\r
32 import com.google.gwt.user.client.ui.Button;
\r
33 import com.google.gwt.user.client.ui.ClickListener;
\r
34 import com.google.gwt.user.client.ui.DialogBox;
\r
35 import com.google.gwt.user.client.ui.HTML;
\r
36 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
37 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
38 import com.google.gwt.user.client.ui.KeyboardListener;
\r
39 import com.google.gwt.user.client.ui.VerticalPanel;
\r
40 import com.google.gwt.user.client.ui.Widget;
\r
43 * The 'delete file' dialog box.
\r
45 public class DeleteFileDialog extends DialogBox {
\r
48 * The widget's constructor.
\r
50 * @param images the supplied images
\r
52 public DeleteFileDialog(Images images) {
\r
53 // Set the dialog's caption.
\r
54 setText("Confirmation");
\r
55 setAnimationEnabled(true);
\r
56 Object selection = GSS.get().getCurrentSelection();
\r
57 // Create a VerticalPanel to contain the label and the buttons.
\r
58 VerticalPanel outer = new VerticalPanel();
\r
59 HorizontalPanel buttons = new HorizontalPanel();
\r
62 if (selection instanceof FileResource)
\r
63 text = new HTML("<table><tr><td>" + images.warn().getHTML() + "</td><td>" + "Are you sure you want to <b>permanently</b> delete file '" + ((FileResource) selection).getName() + "'?</td></tr></table>");
\r
65 text = new HTML("<table><tr><td>" + images.warn().getHTML() + "</td><td>" + "Are you sure you want to <b>permanently</b> delete the selected files?</td></tr></table>");
\r
66 text.setStyleName("gss-warnMessage");
\r
69 // Create the 'Delete' button, along with a listener that hides the dialog
\r
70 // when the button is clicked and deletes the file.
\r
71 Button ok = new Button("Delete", new ClickListener() {
\r
73 public void onClick(Widget sender) {
\r
79 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
\r
80 // Create the 'Cancel' button, along with a listener that hides the
\r
81 // dialog when the button is clicked.
\r
82 Button cancel = new Button("Cancel", new ClickListener() {
\r
84 public void onClick(Widget sender) {
\r
88 buttons.add(cancel);
\r
89 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
\r
90 buttons.setSpacing(8);
\r
91 buttons.setStyleName("gss-warnMessage");
\r
92 outer.setStyleName("gss-warnMessage");
\r
94 outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
\r
95 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
\r
100 * Generate an RPC request to delete a file.
\r
102 * @param userId the ID of the current user
\r
104 private void deleteFile() {
\r
105 Object selection = GSS.get().getCurrentSelection();
\r
106 if (selection == null) {
\r
107 GSS.get().displayError("No file was selected");
\r
110 if (selection instanceof FileResource) {
\r
111 FileResource file = (FileResource) selection;
\r
113 DeleteCommand df = new DeleteCommand(file.getUri()){
\r
116 public void onComplete() {
\r
117 GSS.get().getFileList().updateFileCache(true, true /*clear selection*/);
\r
118 GSS.get().getStatusPanel().updateStats();
\r
122 public void onError(Throwable t) {
\r
124 if(t instanceof RestException){
\r
125 int statusCode = ((RestException)t).getHttpStatusCode();
\r
126 if(statusCode == 405)
\r
127 GSS.get().displayError("You don't have the necessary permissions");
\r
128 else if(statusCode == 404)
\r
129 GSS.get().displayError("File not found");
\r
131 GSS.get().displayError("Unable to delete file: "+((RestException)t).getHttpStatusText());
\r
134 GSS.get().displayError("System error unable to delete file: "+t.getMessage());
\r
138 DeferredCommand.addCommand(df);
\r
140 else if(selection instanceof List){
\r
141 List<FileResource> files = (List<FileResource>) selection;
\r
142 List<String> fileIds = new ArrayList<String>();
\r
143 for(FileResource f : files)
\r
144 fileIds.add(f.getUri());
\r
146 MultipleDeleteCommand ed = new MultipleDeleteCommand(fileIds.toArray(new String[0])){
\r
149 public void onComplete() {
\r
150 GSS.get().showFileList(true);
\r
154 public void onError(Throwable t) {
\r
156 GSS.get().showFileList(true);
\r
160 public void onError(String path, Throwable t) {
\r
162 if(t instanceof RestException){
\r
163 int statusCode = ((RestException)t).getHttpStatusCode();
\r
164 if(statusCode == 405)
\r
165 GSS.get().displayError("You don't have the necessary permissions");
\r
166 else if(statusCode == 404)
\r
167 GSS.get().displayError("File not found");
\r
169 GSS.get().displayError("Unable to delete file:"+((RestException)t).getHttpStatusText());
\r
172 GSS.get().displayError("System error unable to delete file:"+t.getMessage());
\r
177 DeferredCommand.addCommand(ed);
\r
182 public boolean onKeyDownPreview(final char key, final int modifiers) {
\r
183 // Use the popup's key preview hooks to close the dialog when either
\r
184 // enter or escape is pressed.
\r
186 case KeyboardListener.KEY_ENTER:
\r
190 case KeyboardListener.KEY_ESCAPE:
\r