Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / DeleteFolderDialog.java @ a60ea262

History | View | Annotate | Download (5.6 kB)

1 14ad7326 pastith
/*
2 14ad7326 pastith
 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
3 14ad7326 pastith
 *
4 14ad7326 pastith
 * This file is part of GSS.
5 14ad7326 pastith
 *
6 14ad7326 pastith
 * GSS is free software: you can redistribute it and/or modify
7 14ad7326 pastith
 * it under the terms of the GNU General Public License as published by
8 14ad7326 pastith
 * the Free Software Foundation, either version 3 of the License, or
9 14ad7326 pastith
 * (at your option) any later version.
10 14ad7326 pastith
 *
11 14ad7326 pastith
 * GSS is distributed in the hope that it will be useful,
12 14ad7326 pastith
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 14ad7326 pastith
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14ad7326 pastith
 * GNU General Public License for more details.
15 14ad7326 pastith
 *
16 14ad7326 pastith
 * You should have received a copy of the GNU General Public License
17 14ad7326 pastith
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18 14ad7326 pastith
 */
19 14ad7326 pastith
package gr.ebs.gss.client;
20 14ad7326 pastith
21 14ad7326 pastith
import gr.ebs.gss.client.MessagePanel.Images;
22 a52ea5e4 pastith
import gr.ebs.gss.client.dnd.DnDTreeItem;
23 895035a2 pastith
import gr.ebs.gss.client.rest.DeleteCommand;
24 a52ea5e4 pastith
import gr.ebs.gss.client.rest.RestException;
25 a52ea5e4 pastith
import gr.ebs.gss.client.rest.resource.FolderResource;
26 14ad7326 pastith
27 14ad7326 pastith
import com.google.gwt.core.client.GWT;
28 afd3a0ef Giannis Koutsoubos
import com.google.gwt.dom.client.NativeEvent;
29 afd3a0ef Giannis Koutsoubos
import com.google.gwt.event.dom.client.ClickEvent;
30 afd3a0ef Giannis Koutsoubos
import com.google.gwt.event.dom.client.ClickHandler;
31 afd3a0ef Giannis Koutsoubos
import com.google.gwt.event.dom.client.KeyCodes;
32 a52ea5e4 pastith
import com.google.gwt.user.client.DeferredCommand;
33 afd3a0ef Giannis Koutsoubos
import com.google.gwt.user.client.Event.NativePreviewEvent;
34 afd3a0ef Giannis Koutsoubos
import com.google.gwt.user.client.ui.AbstractImagePrototype;
35 14ad7326 pastith
import com.google.gwt.user.client.ui.Button;
36 14ad7326 pastith
import com.google.gwt.user.client.ui.DialogBox;
37 14ad7326 pastith
import com.google.gwt.user.client.ui.HTML;
38 14ad7326 pastith
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
39 14ad7326 pastith
import com.google.gwt.user.client.ui.HorizontalPanel;
40 14ad7326 pastith
import com.google.gwt.user.client.ui.TreeItem;
41 14ad7326 pastith
import com.google.gwt.user.client.ui.VerticalPanel;
42 14ad7326 pastith
43 14ad7326 pastith
/**
44 14ad7326 pastith
 * The 'delete folder' dialog box.
45 14ad7326 pastith
 */
46 14ad7326 pastith
public class DeleteFolderDialog extends DialogBox {
47 14ad7326 pastith
48 14ad7326 pastith
        /**
49 14ad7326 pastith
         * The widget's constructor.
50 14ad7326 pastith
         * @param images the supplied images
51 14ad7326 pastith
         */
52 d2c63e7e pastith
        public DeleteFolderDialog(Images images) {
53 d2c63e7e pastith
                // Set the dialog's caption.
54 d2c63e7e pastith
                setText("Confirmation");
55 14ad7326 pastith
                setAnimationEnabled(true);
56 d2c63e7e pastith
                FolderResource folder = (FolderResource) GSS.get().getCurrentSelection();
57 d2c63e7e pastith
                // Create a VerticalPanel to contain the HTML label and the buttons.
58 d2c63e7e pastith
                VerticalPanel outer = new VerticalPanel();
59 d2c63e7e pastith
                HorizontalPanel buttons = new HorizontalPanel();
60 d2c63e7e pastith
61 afd3a0ef Giannis Koutsoubos
                HTML text = new HTML("<table><tr><td rowspan='2'>" + AbstractImagePrototype.create(images.warn()).getHTML() +
62 d2c63e7e pastith
                                        "</td><td>" + "Are you sure you want to <b>permanently</b> delete folder '" + folder.getName() +
63 d2c63e7e pastith
                                        "'?</td></tr></table>");
64 14ad7326 pastith
                text.setStyleName("gss-warnMessage");
65 14ad7326 pastith
                outer.add(text);
66 14ad7326 pastith
67 d2c63e7e pastith
                // Create the 'Delete' button, along with a listener that hides the dialog
68 d2c63e7e pastith
                // when the button is clicked and deletes the folder.
69 afd3a0ef Giannis Koutsoubos
                Button ok = new Button("Delete", new ClickHandler() {
70 afd3a0ef Giannis Koutsoubos
                        @Override
71 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
72 a52ea5e4 pastith
                                deleteFolder();
73 14ad7326 pastith
                                hide();
74 14ad7326 pastith
                        }
75 14ad7326 pastith
                });
76 14ad7326 pastith
                buttons.add(ok);
77 14ad7326 pastith
                buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
78 14ad7326 pastith
                // Create the 'Cancel' button, along with a listener that hides the
79 d2c63e7e pastith
                // dialog when the button is clicked.
80 afd3a0ef Giannis Koutsoubos
                Button cancel = new Button("Cancel", new ClickHandler() {
81 afd3a0ef Giannis Koutsoubos
                        @Override
82 afd3a0ef Giannis Koutsoubos
                        public void onClick(ClickEvent event) {
83 14ad7326 pastith
                                hide();
84 14ad7326 pastith
                        }
85 14ad7326 pastith
                });
86 14ad7326 pastith
                buttons.add(cancel);
87 14ad7326 pastith
                buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);
88 14ad7326 pastith
                buttons.setSpacing(8);
89 14ad7326 pastith
                buttons.setStyleName("gss-warnMessage");
90 14ad7326 pastith
                outer.setStyleName("gss-warnMessage");
91 14ad7326 pastith
                outer.add(buttons);
92 14ad7326 pastith
                outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER);
93 14ad7326 pastith
                outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);
94 14ad7326 pastith
                setWidget(outer);
95 14ad7326 pastith
        }
96 14ad7326 pastith
97 14ad7326 pastith
        /**
98 14ad7326 pastith
         * Generate an RPC request to delete a folder.
99 14ad7326 pastith
         *
100 14ad7326 pastith
         * @param userId the ID of the current user
101 14ad7326 pastith
         */
102 a52ea5e4 pastith
        private void deleteFolder() {
103 a52ea5e4 pastith
104 d2c63e7e pastith
                DnDTreeItem folder = (DnDTreeItem) GSS.get().getFolders().getCurrent();
105 14ad7326 pastith
                if (folder == null) {
106 d2c63e7e pastith
                        GSS.get().displayError("No folder was selected");
107 14ad7326 pastith
                        return;
108 14ad7326 pastith
                }
109 a52ea5e4 pastith
                if(folder.getFolderResource() == null)
110 a52ea5e4 pastith
                        return;
111 d2c63e7e pastith
112 895035a2 pastith
                DeleteCommand df = new DeleteCommand(folder.getFolderResource().getUri()){
113 d2c63e7e pastith
114 a52ea5e4 pastith
                        @Override
115 a52ea5e4 pastith
                        public void onComplete() {
116 d2c63e7e pastith
                                TreeItem curFolder = GSS.get().getFolders().getCurrent();
117 fb1560b1 koutsoub
                                if(curFolder.getParentItem() != null){
118 fb1560b1 koutsoub
                                        GSS.get().getFolders().select(curFolder.getParentItem());
119 fb1560b1 koutsoub
                                        GSS.get().getFolders().updateFolder((DnDTreeItem) curFolder.getParentItem());
120 fb1560b1 koutsoub
                                }
121 fb1560b1 koutsoub
                                GSS.get().showFileList(true);
122 44a544a5 Fotis Stamatelopoulos
                                GSS.get().getStatusPanel().updateStats();
123 14ad7326 pastith
                        }
124 d2c63e7e pastith
125 d2c63e7e pastith
                        @Override
126 a52ea5e4 pastith
                        public void onError(Throwable t) {
127 a52ea5e4 pastith
                                GWT.log("", t);
128 a52ea5e4 pastith
                                if(t instanceof RestException){
129 a52ea5e4 pastith
                                        int statusCode = ((RestException)t).getHttpStatusCode();
130 a52ea5e4 pastith
                                        if(statusCode == 405)
131 a52ea5e4 pastith
                                                GSS.get().displayError("You don't have the necessary permissions");
132 a52ea5e4 pastith
                                        else if(statusCode == 404)
133 a52ea5e4 pastith
                                                GSS.get().displayError("Folder not found");
134 a52ea5e4 pastith
                                        else
135 d2c63e7e pastith
                                                GSS.get().displayError("Unable to delete folder: "+((RestException)t).getHttpStatusText());
136 a52ea5e4 pastith
                                }
137 14ad7326 pastith
                                else
138 d2c63e7e pastith
                                        GSS.get().displayError("System error unable to delete folder: "+t.getMessage());
139 14ad7326 pastith
                        }
140 a52ea5e4 pastith
                };
141 a52ea5e4 pastith
142 d2c63e7e pastith
                DeferredCommand.addCommand(df);
143 14ad7326 pastith
        }
144 14ad7326 pastith
145 d2c63e7e pastith
        @Override
146 afd3a0ef Giannis Koutsoubos
        protected void onPreviewNativeEvent(NativePreviewEvent preview) {
147 afd3a0ef Giannis Koutsoubos
                super.onPreviewNativeEvent(preview);
148 afd3a0ef Giannis Koutsoubos
149 afd3a0ef Giannis Koutsoubos
                NativeEvent evt = preview.getNativeEvent();
150 afd3a0ef Giannis Koutsoubos
                if (evt.getType().equals("keydown"))
151 afd3a0ef Giannis Koutsoubos
                        // Use the popup's key preview hooks to close the dialog when either
152 afd3a0ef Giannis Koutsoubos
                        // enter or escape is pressed.
153 afd3a0ef Giannis Koutsoubos
                        switch (evt.getKeyCode()) {
154 afd3a0ef Giannis Koutsoubos
                                case KeyCodes.KEY_ENTER:
155 afd3a0ef Giannis Koutsoubos
                                        hide();
156 afd3a0ef Giannis Koutsoubos
                                        deleteFolder();
157 afd3a0ef Giannis Koutsoubos
                                        break;
158 afd3a0ef Giannis Koutsoubos
                                case KeyCodes.KEY_ESCAPE:
159 afd3a0ef Giannis Koutsoubos
                                        hide();
160 afd3a0ef Giannis Koutsoubos
                                        break;
161 afd3a0ef Giannis Koutsoubos
                        }
162 14ad7326 pastith
        }
163 14ad7326 pastith
164 14ad7326 pastith
}