2 * Copyright 2011 GRNET S.A. All rights reserved.
\r
4 * Redistribution and use in source and binary forms, with or
\r
5 * without modification, are permitted provided that the following
\r
6 * conditions are met:
\r
8 * 1. Redistributions of source code must retain the above
\r
9 * copyright notice, this list of conditions and the following
\r
12 * 2. Redistributions in binary form must reproduce the above
\r
13 * copyright notice, this list of conditions and the following
\r
14 * disclaimer in the documentation and/or other materials
\r
15 * provided with the distribution.
\r
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
\r
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
\r
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
\r
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
\r
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
28 * POSSIBILITY OF SUCH DAMAGE.
\r
30 * The views and conclusions contained in the software and
\r
31 * documentation are those of the authors and should not be
\r
32 * interpreted as representing official policies, either expressed
\r
33 * or implied, of GRNET S.A.
\r
35 package gr.grnet.pithos.web.client;
\r
37 import gr.grnet.pithos.web.client.MessagePanel.Images;
\r
38 import gr.grnet.pithos.web.client.rest.DeleteCommand;
\r
39 import gr.grnet.pithos.web.client.rest.RestException;
\r
40 import gr.grnet.pithos.web.client.rest.resource.FolderResource;
\r
41 import gr.grnet.pithos.web.client.rest.resource.RestResource;
\r
42 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
\r
43 import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;
\r
45 import com.google.gwt.core.client.GWT;
\r
46 import com.google.gwt.dom.client.NativeEvent;
\r
47 import com.google.gwt.event.dom.client.ClickEvent;
\r
48 import com.google.gwt.event.dom.client.ClickHandler;
\r
49 import com.google.gwt.event.dom.client.KeyCodes;
\r
50 import com.google.gwt.user.client.DeferredCommand;
\r
51 import com.google.gwt.user.client.Event.NativePreviewEvent;
\r
52 import com.google.gwt.user.client.ui.AbstractImagePrototype;
\r
53 import com.google.gwt.user.client.ui.Button;
\r
54 import com.google.gwt.user.client.ui.DialogBox;
\r
55 import com.google.gwt.user.client.ui.HTML;
\r
56 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
57 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
58 import com.google.gwt.user.client.ui.VerticalPanel;
\r
61 * The 'delete folder' dialog box.
\r
63 public class DeleteFolderDialog extends DialogBox {
\r
66 * The widget's constructor.
\r
67 * @param images the supplied images
\r
69 public DeleteFolderDialog(Images images) {
\r
70 // Set the dialog's caption.
\r
71 setText("Confirmation");
\r
72 setAnimationEnabled(true);
\r
73 FolderResource folder = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();
\r
74 // Create a VerticalPanel to contain the HTML label and the buttons.
\r
75 VerticalPanel outer = new VerticalPanel();
\r
76 HorizontalPanel buttons = new HorizontalPanel();
\r
78 HTML text = new HTML("<table><tr><td rowspan='2'>" + AbstractImagePrototype.create(images.warn()).getHTML() +
\r
79 "</td><td>" + "Are you sure you want to <b>permanently</b> delete folder '" + folder.getName() +
\r
80 "'?</td></tr></table>");
\r
81 text.setStyleName("pithos-warnMessage");
\r
84 // Create the 'Delete' button, along with a listener that hides the dialog
\r
85 // when the button is clicked and deletes the folder.
\r
86 Button ok = new Button("Delete", new ClickHandler() {
\r
88 public void onClick(ClickEvent event) {
\r
93 ok.getElement().setId("confirmation.ok");
\r
95 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
\r
96 // Create the 'Cancel' button, along with a listener that hides the
\r
97 // dialog when the button is clicked.
\r
98 Button cancel = new Button("Cancel", new ClickHandler() {
\r
100 public void onClick(ClickEvent event) {
\r
104 cancel.getElement().setId("confirmation.cancel");
\r
105 buttons.add(cancel);
\r
106 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
\r
107 buttons.setSpacing(8);
\r
108 buttons.setStyleName("pithos-warnMessage");
\r
109 outer.setStyleName("pithos-warnMessage");
\r
110 outer.add(buttons);
\r
111 outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
\r
112 outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
\r
117 * Generate an RPC request to delete a folder.
\r
119 * @param userId the ID of the current user
\r
121 private void deleteFolder() {
\r
122 RestResource folder = GSS.get().getTreeView().getSelection();
\r
123 if (folder == null) {
\r
124 GSS.get().displayError("No folder was selected");
\r
127 if(!(folder instanceof RestResourceWrapper))
\r
130 DeleteCommand df = new DeleteCommand(folder.getUri()){
\r
133 public void onComplete() {
\r
134 FolderResource fres = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();
\r
135 if((RestResourceWrapper) GSS.get().getTreeView().getSelection() instanceof TrashFolderResource)
\r
136 GSS.get().getTreeView().updateTrashNode();
\r
138 GSS.get().getTreeView().updateNodeChildrenForRemove(fres.getParentURI());
\r
139 GSS.get().getTreeView().clearSelection();
\r
140 GSS.get().showFileList(true);
\r
142 GSS.get().getStatusPanel().updateStats();
\r
146 public void onError(Throwable t) {
\r
148 if(t instanceof RestException){
\r
149 int statusCode = ((RestException)t).getHttpStatusCode();
\r
150 if(statusCode == 405)
\r
151 GSS.get().displayError("You don't have the necessary permissions");
\r
152 else if(statusCode == 404)
\r
153 GSS.get().displayError("Folder not found");
\r
155 GSS.get().displayError("Unable to delete folder: "+((RestException)t).getHttpStatusText());
\r
158 GSS.get().displayError("System error unable to delete folder: "+t.getMessage());
\r
162 DeferredCommand.addCommand(df);
\r
166 protected void onPreviewNativeEvent(NativePreviewEvent preview) {
\r
167 super.onPreviewNativeEvent(preview);
\r
169 NativeEvent evt = preview.getNativeEvent();
\r
170 if (evt.getType().equals("keydown"))
\r
171 // Use the popup's key preview hooks to close the dialog when either
\r
172 // enter or escape is pressed.
\r
173 switch (evt.getKeyCode()) {
\r
174 case KeyCodes.KEY_ENTER:
\r
178 case KeyCodes.KEY_ESCAPE:
\r