Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / FolderPropertiesDialog.java @ 969a4d94

History | View | Annotate | Download (17.8 kB)

1 a57faaf0 Christos Stathis
/*
2 63366925 Christos Stathis
 * Copyright 2011 GRNET S.A. All rights reserved.
3 63366925 Christos Stathis
 *
4 63366925 Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 63366925 Christos Stathis
 * without modification, are permitted provided that the following
6 63366925 Christos Stathis
 * conditions are met:
7 63366925 Christos Stathis
 *
8 63366925 Christos Stathis
 *   1. Redistributions of source code must retain the above
9 63366925 Christos Stathis
 *      copyright notice, this list of conditions and the following
10 63366925 Christos Stathis
 *      disclaimer.
11 63366925 Christos Stathis
 *
12 63366925 Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 63366925 Christos Stathis
 *      copyright notice, this list of conditions and the following
14 63366925 Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 63366925 Christos Stathis
 *      provided with the distribution.
16 63366925 Christos Stathis
 *
17 63366925 Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 63366925 Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 63366925 Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 63366925 Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 63366925 Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 63366925 Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 63366925 Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 63366925 Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 63366925 Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 63366925 Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 63366925 Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 63366925 Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 63366925 Christos Stathis
 *
30 63366925 Christos Stathis
 * The views and conclusions contained in the software and
31 63366925 Christos Stathis
 * documentation are those of the authors and should not be
32 63366925 Christos Stathis
 * interpreted as representing official policies, either expressed
33 63366925 Christos Stathis
 * or implied, of GRNET S.A.
34 a57faaf0 Christos Stathis
 */
35 a57faaf0 Christos Stathis
package gr.grnet.pithos.web.client;
36 a57faaf0 Christos Stathis
37 b651e67f Christos Stathis
import com.google.gwt.core.client.Scheduler;
38 447407c8 Christos Stathis
import com.google.gwt.event.dom.client.KeyDownEvent;
39 d6be39da Christos Stathis
import com.google.gwt.user.client.Command;
40 d6be39da Christos Stathis
import gr.grnet.pithos.web.client.foldertree.File;
41 447407c8 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Folder;
42 b651e67f Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Resource;
43 5ebc9312 Christos Stathis
import gr.grnet.pithos.web.client.rest.PostRequest;
44 b651e67f Christos Stathis
import gr.grnet.pithos.web.client.rest.PutRequest;
45 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.rest.RestException;
46 a57faaf0 Christos Stathis
47 a57faaf0 Christos Stathis
import com.google.gwt.core.client.GWT;
48 a57faaf0 Christos Stathis
import com.google.gwt.dom.client.NativeEvent;
49 a57faaf0 Christos Stathis
import com.google.gwt.event.dom.client.ClickEvent;
50 a57faaf0 Christos Stathis
import com.google.gwt.event.dom.client.ClickHandler;
51 a57faaf0 Christos Stathis
import com.google.gwt.event.dom.client.KeyCodes;
52 f1b24b82 Christos Stathis
import com.google.gwt.http.client.Response;
53 a57faaf0 Christos Stathis
import com.google.gwt.i18n.client.DateTimeFormat;
54 a57faaf0 Christos Stathis
import com.google.gwt.user.client.Event.NativePreviewEvent;
55 4420a247 Christos Stathis
import com.google.gwt.user.client.ui.Anchor;
56 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.Button;
57 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.DecoratedTabPanel;
58 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.DialogBox;
59 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.FlexTable;
60 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
61 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.HorizontalPanel;
62 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.TabPanel;
63 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.TextBox;
64 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.VerticalPanel;
65 d6be39da Christos Stathis
import java.util.Iterator;
66 5ebc9312 Christos Stathis
import java.util.Map;
67 a57faaf0 Christos Stathis
68 a57faaf0 Christos Stathis
/**
69 a57faaf0 Christos Stathis
 * The 'Folder properties' dialog box implementation.
70 a57faaf0 Christos Stathis
 */
71 a57faaf0 Christos Stathis
public class FolderPropertiesDialog extends DialogBox {
72 a57faaf0 Christos Stathis
73 7811b9d1 Christos Stathis
    protected Pithos app;
74 b651e67f Christos Stathis
75 a57faaf0 Christos Stathis
        /**
76 a57faaf0 Christos Stathis
         * The widget that holds the folderName of the folder.
77 a57faaf0 Christos Stathis
         */
78 a57faaf0 Christos Stathis
        private TextBox folderName = new TextBox();
79 a57faaf0 Christos Stathis
80 a57faaf0 Christos Stathis
        /**
81 a57faaf0 Christos Stathis
         * A flag that denotes whether the dialog will be used to create or modify a
82 a57faaf0 Christos Stathis
         * folder.
83 a57faaf0 Christos Stathis
         */
84 a57faaf0 Christos Stathis
        private final boolean create;
85 a57faaf0 Christos Stathis
86 7811b9d1 Christos Stathis
        protected PermissionsList permList;
87 ecf95c9e Christos Stathis
88 447407c8 Christos Stathis
        final Folder folder;
89 a57faaf0 Christos Stathis
90 a57faaf0 Christos Stathis
        final TabPanel inner;
91 a57faaf0 Christos Stathis
92 a57faaf0 Christos Stathis
        /**
93 a57faaf0 Christos Stathis
         * The widget's constructor.
94 a57faaf0 Christos Stathis
         */
95 ecf95c9e Christos Stathis
        public FolderPropertiesDialog(final Pithos app, boolean _create,  Folder selected) {
96 b651e67f Christos Stathis
        this.app = app;
97 4420a247 Christos Stathis
                Anchor close = new Anchor();
98 4420a247 Christos Stathis
                close.addStyleName("close");
99 4420a247 Christos Stathis
                close.addClickHandler(new ClickHandler() {
100 4420a247 Christos Stathis
                        
101 4420a247 Christos Stathis
                        @Override
102 4420a247 Christos Stathis
                        public void onClick(ClickEvent event) {
103 4420a247 Christos Stathis
                                hide();
104 4420a247 Christos Stathis
                        }
105 4420a247 Christos Stathis
                });
106 4420a247 Christos Stathis
107 a57faaf0 Christos Stathis
                setAnimationEnabled(true);
108 4420a247 Christos Stathis
                setGlassEnabled(true);
109 4420a247 Christos Stathis
                setStyleName("pithos-DialogBox");
110 a57faaf0 Christos Stathis
111 a57faaf0 Christos Stathis
                // Enable IE selection for the dialog (must disable it upon closing it)
112 7811b9d1 Christos Stathis
                Pithos.enableIESelection();
113 a57faaf0 Christos Stathis
114 a57faaf0 Christos Stathis
                create = _create;
115 a57faaf0 Christos Stathis
                
116 447407c8 Christos Stathis
                folder = selected;
117 a57faaf0 Christos Stathis
118 a57faaf0 Christos Stathis
                // Use this opportunity to set the dialog's caption.
119 a57faaf0 Christos Stathis
                if (create)
120 a57faaf0 Christos Stathis
                        setText("Create folder");
121 a57faaf0 Christos Stathis
                else
122 a57faaf0 Christos Stathis
                        setText("Folder properties");
123 a57faaf0 Christos Stathis
124 a57faaf0 Christos Stathis
                // Outer contains inner and buttons
125 a57faaf0 Christos Stathis
                VerticalPanel outer = new VerticalPanel();
126 4420a247 Christos Stathis
                outer.add(close);
127 a57faaf0 Christos Stathis
                // Inner contains generalPanel and permPanel
128 a57faaf0 Christos Stathis
                inner = new DecoratedTabPanel();
129 a57faaf0 Christos Stathis
                inner.setAnimationEnabled(true);
130 4420a247 Christos Stathis
                inner.addStyleName("inner");
131 4420a247 Christos Stathis
                inner.getDeckPanel().addStyleName("pithos-TabPanelBottom");
132 ecf95c9e Christos Stathis
133 a57faaf0 Christos Stathis
                VerticalPanel generalPanel = new VerticalPanel();
134 ecf95c9e Christos Stathis
        FlexTable generalTable = new FlexTable();
135 ecf95c9e Christos Stathis
        generalTable.setText(0, 0, "Name");
136 ecf95c9e Christos Stathis
        generalTable.setText(1, 0, "Parent");
137 ecf95c9e Christos Stathis
        generalTable.setText(2, 0, "Creator");
138 ecf95c9e Christos Stathis
        generalTable.setText(3, 0, "Last modified");
139 ecf95c9e Christos Stathis
        folderName.setText(create ? "" : folder.getName());
140 4fe76337 Christos Stathis
        folderName.setReadOnly(folder.isContainer() && !create);
141 ecf95c9e Christos Stathis
        generalTable.setWidget(0, 1, folderName);
142 ecf95c9e Christos Stathis
143 ecf95c9e Christos Stathis
        if (create)
144 ecf95c9e Christos Stathis
            generalTable.setText(1, 1, folder.getName());
145 ecf95c9e Christos Stathis
        else
146 ecf95c9e Christos Stathis
            generalTable.setText(1, 1, folder.getPrefix());
147 ecf95c9e Christos Stathis
        generalTable.setText(2, 1, "");
148 ecf95c9e Christos Stathis
        DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
149 ecf95c9e Christos Stathis
        if(folder.getLastModified() != null)
150 ecf95c9e Christos Stathis
            generalTable.setText(3, 1, formatter.format(folder.getLastModified()));
151 ecf95c9e Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
152 ecf95c9e Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
153 ecf95c9e Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
154 ecf95c9e Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");
155 ecf95c9e Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
156 ecf95c9e Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
157 ecf95c9e Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
158 ecf95c9e Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");
159 ecf95c9e Christos Stathis
        generalTable.setCellSpacing(4);
160 ecf95c9e Christos Stathis
        generalPanel.add(generalTable);
161 ecf95c9e Christos Stathis
        inner.add(generalPanel, "General");
162 ecf95c9e Christos Stathis
163 ecf95c9e Christos Stathis
        VerticalPanel permPanel = new VerticalPanel();
164 ecf95c9e Christos Stathis
        FilePropertiesDialog.Images images = GWT.create(FilePropertiesDialog.Images.class);
165 ecf95c9e Christos Stathis
        boolean permsReadonly = folder.getInheritedPermissionsFrom() != null || folder.existChildrenPermissions();
166 ecf95c9e Christos Stathis
        permList = new PermissionsList(images, folder.getPermissions(), folder.getOwner(), permsReadonly);
167 ecf95c9e Christos Stathis
        permPanel.add(permList);
168 ecf95c9e Christos Stathis
169 ecf95c9e Christos Stathis
        if (!permsReadonly) {
170 ecf95c9e Christos Stathis
            HorizontalPanel permButtons = new HorizontalPanel();
171 ecf95c9e Christos Stathis
            Button add = new Button("Add Group", new ClickHandler() {
172 ecf95c9e Christos Stathis
                @Override
173 7811b9d1 Christos Stathis
                public void onClick(@SuppressWarnings("unused") ClickEvent event) {
174 ecf95c9e Christos Stathis
                    PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false);
175 ecf95c9e Christos Stathis
                    dlg.center();
176 ecf95c9e Christos Stathis
                }
177 ecf95c9e Christos Stathis
            });
178 969a4d94 Christos Stathis
            add.addStyleName("button");
179 ecf95c9e Christos Stathis
            permButtons.add(add);
180 ecf95c9e Christos Stathis
            permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);
181 ecf95c9e Christos Stathis
182 ecf95c9e Christos Stathis
            Button addUser = new Button("Add User", new ClickHandler() {
183 ecf95c9e Christos Stathis
                @Override
184 7811b9d1 Christos Stathis
                public void onClick(@SuppressWarnings("unused") ClickEvent event) {
185 ecf95c9e Christos Stathis
                    PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true);
186 ecf95c9e Christos Stathis
                    dlg.center();
187 ecf95c9e Christos Stathis
                }
188 ecf95c9e Christos Stathis
            });
189 969a4d94 Christos Stathis
            addUser.addStyleName("button");
190 ecf95c9e Christos Stathis
            permButtons.add(addUser);
191 ecf95c9e Christos Stathis
            permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);
192 ecf95c9e Christos Stathis
            permButtons.setSpacing(8);
193 ecf95c9e Christos Stathis
            permPanel.add(permButtons);
194 ecf95c9e Christos Stathis
        }
195 ecf95c9e Christos Stathis
196 ecf95c9e Christos Stathis
        if (!create)
197 ecf95c9e Christos Stathis
            inner.add(permPanel, "Sharing");
198 ecf95c9e Christos Stathis
        inner.selectTab(0);
199 ecf95c9e Christos Stathis
200 ecf95c9e Christos Stathis
        outer.add(inner);
201 ecf95c9e Christos Stathis
202 a57faaf0 Christos Stathis
                // Create the 'Create/Update' button, along with a listener that hides the dialog
203 a57faaf0 Christos Stathis
                // when the button is clicked and quits the application.
204 a57faaf0 Christos Stathis
                String okLabel;
205 a57faaf0 Christos Stathis
                if (create)
206 a57faaf0 Christos Stathis
                        okLabel = "Create";
207 a57faaf0 Christos Stathis
                else
208 a57faaf0 Christos Stathis
                        okLabel = "Update";
209 a57faaf0 Christos Stathis
                Button ok = new Button(okLabel, new ClickHandler() {
210 a57faaf0 Christos Stathis
                        @Override
211 7811b9d1 Christos Stathis
                        public void onClick(@SuppressWarnings("unused") ClickEvent event) {
212 447407c8 Christos Stathis
                                createOrUpdateFolder();
213 447407c8 Christos Stathis
                                closeDialog();
214 a57faaf0 Christos Stathis
                        }
215 a57faaf0 Christos Stathis
                });
216 4420a247 Christos Stathis
                ok.addStyleName("button");
217 4420a247 Christos Stathis
                outer.add(ok);
218 4420a247 Christos Stathis
        outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
219 a57faaf0 Christos Stathis
220 ecf95c9e Christos Stathis
        setWidget(outer);
221 a57faaf0 Christos Stathis
        }
222 a57faaf0 Christos Stathis
223 a57faaf0 Christos Stathis
        @Override
224 a57faaf0 Christos Stathis
        public void center() {
225 a57faaf0 Christos Stathis
                super.center();
226 a57faaf0 Christos Stathis
                folderName.setFocus(true);
227 a57faaf0 Christos Stathis
        }
228 a57faaf0 Christos Stathis
229 a57faaf0 Christos Stathis
        @Override
230 a57faaf0 Christos Stathis
        protected void onPreviewNativeEvent(NativePreviewEvent preview) {
231 a57faaf0 Christos Stathis
                super.onPreviewNativeEvent(preview);
232 a57faaf0 Christos Stathis
233 a57faaf0 Christos Stathis
                NativeEvent evt = preview.getNativeEvent();
234 447407c8 Christos Stathis
                if (evt.getType().equals(KeyDownEvent.getType().getName()))
235 a57faaf0 Christos Stathis
                        // Use the popup's key preview hooks to close the dialog when either
236 a57faaf0 Christos Stathis
                        // enter or escape is pressed.
237 a57faaf0 Christos Stathis
                        switch (evt.getKeyCode()) {
238 a57faaf0 Christos Stathis
                                case KeyCodes.KEY_ENTER:
239 a57faaf0 Christos Stathis
                                        createOrUpdateFolder();
240 ecf95c9e Christos Stathis
                    closeDialog();
241 a57faaf0 Christos Stathis
                                        break;
242 a57faaf0 Christos Stathis
                                case KeyCodes.KEY_ESCAPE:
243 a57faaf0 Christos Stathis
                                        closeDialog();
244 a57faaf0 Christos Stathis
                                        break;
245 a57faaf0 Christos Stathis
                        }
246 a57faaf0 Christos Stathis
        }
247 a57faaf0 Christos Stathis
248 a57faaf0 Christos Stathis
249 a57faaf0 Christos Stathis
        /**
250 a57faaf0 Christos Stathis
         * Enables IE selection prevention and hides the dialog
251 a57faaf0 Christos Stathis
         * (we disable the prevention on creation of the dialog)
252 a57faaf0 Christos Stathis
         */
253 a57faaf0 Christos Stathis
        public void closeDialog() {
254 7811b9d1 Christos Stathis
                Pithos.preventIESelection();
255 a57faaf0 Christos Stathis
                hide();
256 a57faaf0 Christos Stathis
        }
257 a57faaf0 Christos Stathis
258 a57faaf0 Christos Stathis
        /**
259 a57faaf0 Christos Stathis
         * Generate an RPC request to create a new folder.
260 a57faaf0 Christos Stathis
         */
261 a57faaf0 Christos Stathis
        private void createFolder() {
262 a57faaf0 Christos Stathis
                String name = folderName.getText();
263 b51c628b Christos Stathis
        String path = folder.getUri() + "/" + name;
264 63ee965c Christos Stathis
        PutRequest createFolder = new PutRequest(app.getApiPath(), folder.getOwner(), path) {
265 b651e67f Christos Stathis
            @Override
266 7811b9d1 Christos Stathis
            public void onSuccess(@SuppressWarnings("unused") Resource result) {
267 64f42c0b Christos Stathis
                app.updateFolder(folder, true, new Command() {
268 64f42c0b Christos Stathis
                                        
269 64f42c0b Christos Stathis
                                        @Override
270 64f42c0b Christos Stathis
                                        public void execute() {
271 64f42c0b Christos Stathis
                                                app.updateStatistics();
272 64f42c0b Christos Stathis
                                        }
273 64f42c0b Christos Stathis
                                });
274 b651e67f Christos Stathis
            }
275 b651e67f Christos Stathis
276 b651e67f Christos Stathis
            @Override
277 b651e67f Christos Stathis
            public void onError(Throwable t) {
278 b651e67f Christos Stathis
                                GWT.log("", t);
279 b651e67f Christos Stathis
                                if (t instanceof RestException) {
280 b651e67f Christos Stathis
                                        app.displayError("Unable to create folder:" + ((RestException) t).getHttpStatusText());
281 b651e67f Christos Stathis
                                }
282 b651e67f Christos Stathis
                                else
283 b651e67f Christos Stathis
                                        app.displayError("System error creating folder:" + t.getMessage());
284 b651e67f Christos Stathis
            }
285 9539e23d Christos Stathis
286 9539e23d Christos Stathis
                        @Override
287 9539e23d Christos Stathis
                        protected void onUnauthorized(Response response) {
288 9539e23d Christos Stathis
                                app.sessionExpired();
289 9539e23d Christos Stathis
                        }
290 9539e23d Christos Stathis
       };
291 f1aabd89 Christos Stathis
        createFolder.setHeader("X-Auth-Token", app.getToken());
292 b651e67f Christos Stathis
        createFolder.setHeader("Accept", "*/*");
293 b651e67f Christos Stathis
        createFolder.setHeader("Content-Length", "0");
294 b651e67f Christos Stathis
        createFolder.setHeader("Content-Type", "application/folder");
295 b651e67f Christos Stathis
        Scheduler.get().scheduleDeferred(createFolder);
296 a57faaf0 Christos Stathis
        }
297 a57faaf0 Christos Stathis
298 a57faaf0 Christos Stathis
        /**
299 a57faaf0 Christos Stathis
         * Upon closing the dialog by clicking OK or pressing ENTER this method does
300 a57faaf0 Christos Stathis
         * the actual work of modifying folder properties or creating a new Folder
301 a57faaf0 Christos Stathis
         * depending on the value of the create field
302 a57faaf0 Christos Stathis
         */
303 7811b9d1 Christos Stathis
        protected void createOrUpdateFolder() {
304 a57faaf0 Christos Stathis
                if (create)
305 a57faaf0 Christos Stathis
                        createFolder();
306 a57faaf0 Christos Stathis
                else
307 a57faaf0 Christos Stathis
                        updateFolder();
308 a57faaf0 Christos Stathis
309 a57faaf0 Christos Stathis
        }
310 a57faaf0 Christos Stathis
311 a57faaf0 Christos Stathis
        private void updateFolder() {
312 5ebc9312 Christos Stathis
        final Map<String, Boolean[]> perms = (permList.hasChanges() ? permList.getPermissions() : null);
313 5ebc9312 Christos Stathis
        final String newName = folderName.getText().trim();
314 d6be39da Christos Stathis
        if (!folder.isContainer() && !folder.getName().equals(newName)) {
315 b51c628b Christos Stathis
            final String path = folder.getParent().getUri() + "/" + newName;
316 63ee965c Christos Stathis
            PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getParent().getOwner(), path) {
317 d6be39da Christos Stathis
                @Override
318 7811b9d1 Christos Stathis
                public void onSuccess(@SuppressWarnings("unused") Resource result) {
319 d6be39da Christos Stathis
                    Iterator<File> iter = folder.getFiles().iterator();
320 63ee965c Christos Stathis
                    app.copyFiles(iter, folder.getParent().getOwner(), folder.getParent().getUri() + "/" + newName, new Command() {
321 d6be39da Christos Stathis
                        @Override
322 d6be39da Christos Stathis
                        public void execute() {
323 d6be39da Christos Stathis
                            Iterator<Folder> iterf = folder.getSubfolders().iterator();
324 63ee965c Christos Stathis
                            app.copySubfolders(iterf, folder.getParent().getOwner(), folder.getParent().getUri() + "/" + newName, new Command() {
325 d6be39da Christos Stathis
                                @Override
326 d6be39da Christos Stathis
                                public void execute() {
327 d6be39da Christos Stathis
                                    app.deleteFolder(folder);
328 5ebc9312 Christos Stathis
                                    updateMetadata(path + "?update=", perms);
329 d6be39da Christos Stathis
                                }
330 d6be39da Christos Stathis
                            });
331 d6be39da Christos Stathis
                        }
332 d6be39da Christos Stathis
                    });
333 d6be39da Christos Stathis
                }
334 d6be39da Christos Stathis
335 d6be39da Christos Stathis
                @Override
336 d6be39da Christos Stathis
                public void onError(Throwable t) {
337 d6be39da Christos Stathis
                    GWT.log("", t);
338 d6be39da Christos Stathis
                    if(t instanceof RestException){
339 d6be39da Christos Stathis
                        app.displayError("Unable to update folder: " + ((RestException) t).getHttpStatusText());
340 d6be39da Christos Stathis
                    }
341 d6be39da Christos Stathis
                    else
342 d6be39da Christos Stathis
                        app.displayError("System error modifying folder: " + t.getMessage());
343 d6be39da Christos Stathis
                }
344 9539e23d Christos Stathis
345 9539e23d Christos Stathis
                                @Override
346 9539e23d Christos Stathis
                                protected void onUnauthorized(Response response) {
347 9539e23d Christos Stathis
                                        app.sessionExpired();
348 9539e23d Christos Stathis
                                }
349 d6be39da Christos Stathis
            };
350 d6be39da Christos Stathis
            newFolder.setHeader("X-Auth-Token", app.getToken());
351 d6be39da Christos Stathis
            newFolder.setHeader("Content-Type", "application/folder");
352 d6be39da Christos Stathis
            newFolder.setHeader("Accept", "*/*");
353 d6be39da Christos Stathis
            newFolder.setHeader("Content-Length", "0");
354 d6be39da Christos Stathis
            Scheduler.get().scheduleDeferred(newFolder);
355 d6be39da Christos Stathis
        }
356 5ebc9312 Christos Stathis
        else
357 5ebc9312 Christos Stathis
            updateMetadata(folder.getUri() + "?update=", perms);
358 a57faaf0 Christos Stathis
        }
359 a57faaf0 Christos Stathis
360 f1b24b82 Christos Stathis
        protected void updateMetadata(final String path, final Map<String, Boolean[]> newPermissions) {
361 5ebc9312 Christos Stathis
        if (newPermissions != null) {
362 5ebc9312 Christos Stathis
            PostRequest updateFolder = new PostRequest(app.getApiPath(), folder.getOwner(), path) {
363 5ebc9312 Christos Stathis
                @Override
364 7811b9d1 Christos Stathis
                public void onSuccess(@SuppressWarnings("unused") Resource result) {
365 16e8478a Christos Stathis
                    app.updateFolder(folder.getParent(), false, null);
366 5ebc9312 Christos Stathis
                }
367 5ebc9312 Christos Stathis
368 5ebc9312 Christos Stathis
                @Override
369 5ebc9312 Christos Stathis
                public void onError(Throwable t) {
370 5ebc9312 Christos Stathis
                    GWT.log("", t);
371 f1b24b82 Christos Stathis
                    if (t instanceof RestException) {
372 f1b24b82 Christos Stathis
                            if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) { //Probably a virtual folder
373 f1b24b82 Christos Stathis
                            final String path1 = folder.getUri();
374 63ee965c Christos Stathis
                            PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getOwner(), path1) {
375 f1b24b82 Christos Stathis
                                @Override
376 f1b24b82 Christos Stathis
                                public void onSuccess(@SuppressWarnings("unused") Resource result) {
377 f1b24b82 Christos Stathis
                                        updateMetadata(path, newPermissions);
378 f1b24b82 Christos Stathis
                                }
379 f1b24b82 Christos Stathis
380 f1b24b82 Christos Stathis
                                @Override
381 abd8738f Christos Stathis
                                public void onError(Throwable _t) {
382 abd8738f Christos Stathis
                                    GWT.log("", _t);
383 abd8738f Christos Stathis
                                    if(_t instanceof RestException){
384 abd8738f Christos Stathis
                                        app.displayError("Unable to update folder: " + ((RestException) _t).getHttpStatusText());
385 f1b24b82 Christos Stathis
                                    }
386 f1b24b82 Christos Stathis
                                    else
387 abd8738f Christos Stathis
                                        app.displayError("System error modifying folder: " + _t.getMessage());
388 f1b24b82 Christos Stathis
                                }
389 9539e23d Christos Stathis
390 9539e23d Christos Stathis
                                                @Override
391 9539e23d Christos Stathis
                                                protected void onUnauthorized(Response response) {
392 9539e23d Christos Stathis
                                                        app.sessionExpired();
393 9539e23d Christos Stathis
                                                }
394 f1b24b82 Christos Stathis
                            };
395 f1b24b82 Christos Stathis
                            newFolder.setHeader("X-Auth-Token", app.getToken());
396 f1b24b82 Christos Stathis
                            newFolder.setHeader("Content-Type", "application/folder");
397 f1b24b82 Christos Stathis
                            newFolder.setHeader("Accept", "*/*");
398 f1b24b82 Christos Stathis
                            newFolder.setHeader("Content-Length", "0");
399 f1b24b82 Christos Stathis
                            Scheduler.get().scheduleDeferred(newFolder);
400 f1b24b82 Christos Stathis
                            }
401 bac098d0 Christos Stathis
                            else if (((RestException) t).getHttpStatusCode() == Response.SC_CONFLICT) {
402 bac098d0 Christos Stathis
                                    app.displayError("Cannot set permissions. Probably subfolders or files already have permissions set");
403 bac098d0 Christos Stathis
                            }
404 bac098d0 Christos Stathis
                            else
405 bac098d0 Christos Stathis
                                    app.displayError("Wrror modifying folder: " + t.getMessage());
406 f1b24b82 Christos Stathis
                    }
407 f1b24b82 Christos Stathis
                    else
408 f1b24b82 Christos Stathis
                            app.displayError("System error modifying folder: " + t.getMessage());
409 5ebc9312 Christos Stathis
                }
410 9539e23d Christos Stathis
411 9539e23d Christos Stathis
                                @Override
412 9539e23d Christos Stathis
                                protected void onUnauthorized(Response response) {
413 9539e23d Christos Stathis
                                        app.sessionExpired();
414 9539e23d Christos Stathis
                                }
415 5ebc9312 Christos Stathis
            };
416 5ebc9312 Christos Stathis
            updateFolder.setHeader("X-Auth-Token", app.getToken());
417 7811b9d1 Christos Stathis
            String readPermHeader = "read=";
418 7811b9d1 Christos Stathis
            String writePermHeader = "write=";
419 7811b9d1 Christos Stathis
            for (String u : newPermissions.keySet()) {
420 7811b9d1 Christos Stathis
                Boolean[] p = newPermissions.get(u);
421 7811b9d1 Christos Stathis
                if (p[0] != null && p[0])
422 7811b9d1 Christos Stathis
                    readPermHeader += u + ",";
423 7811b9d1 Christos Stathis
                if (p[1] != null && p[1])
424 7811b9d1 Christos Stathis
                    writePermHeader += u + ",";
425 5ebc9312 Christos Stathis
            }
426 7811b9d1 Christos Stathis
            if (readPermHeader.endsWith("="))
427 7811b9d1 Christos Stathis
                readPermHeader = "";
428 7811b9d1 Christos Stathis
            else if (readPermHeader.endsWith(","))
429 7811b9d1 Christos Stathis
                readPermHeader = readPermHeader.substring(0, readPermHeader.length() - 1);
430 7811b9d1 Christos Stathis
            if (writePermHeader.endsWith("="))
431 7811b9d1 Christos Stathis
                writePermHeader = "";
432 7811b9d1 Christos Stathis
            else if (writePermHeader.endsWith(","))
433 7811b9d1 Christos Stathis
                writePermHeader = writePermHeader.substring(0, writePermHeader.length() - 1);
434 7811b9d1 Christos Stathis
            String permHeader = readPermHeader +  ((readPermHeader.length()  > 0 && writePermHeader.length() > 0) ?  ";" : "") + writePermHeader;
435 7811b9d1 Christos Stathis
            if (permHeader.length() == 0)
436 7811b9d1 Christos Stathis
                permHeader="~";
437 7811b9d1 Christos Stathis
            updateFolder.setHeader("X-Object-Sharing", permHeader);
438 5ebc9312 Christos Stathis
            Scheduler.get().scheduleDeferred(updateFolder);
439 5ebc9312 Christos Stathis
        }
440 5ebc9312 Christos Stathis
        else
441 16e8478a Christos Stathis
            app.updateFolder(folder.getParent(), false, null);
442 5ebc9312 Christos Stathis
    }
443 5ebc9312 Christos Stathis
444 a57faaf0 Christos Stathis
        public void selectTab(int _tab) {
445 a57faaf0 Christos Stathis
                inner.selectTab(_tab);
446 a57faaf0 Christos Stathis
        }
447 a57faaf0 Christos Stathis
}