Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / FilePropertiesDialog.java @ ea30dad9

History | View | Annotate | Download (13.9 kB)

1 a57faaf0 Christos Stathis
/*
2 cae2a8db Christos Stathis
 * Copyright 2011-2012 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 31997f49 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.File;
38 31997f49 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Resource;
39 ef5b664d Christos Stathis
import gr.grnet.pithos.web.client.rest.PostRequest;
40 31997f49 Christos Stathis
import gr.grnet.pithos.web.client.rest.PutRequest;
41 7811b9d1 Christos Stathis
42 d26e2ef7 Christos Stathis
import java.util.Arrays;
43 947da718 Christos Stathis
import java.util.HashMap;
44 7811b9d1 Christos Stathis
import java.util.Map;
45 a57faaf0 Christos Stathis
46 a57faaf0 Christos Stathis
import com.google.gwt.core.client.GWT;
47 7811b9d1 Christos Stathis
import com.google.gwt.core.client.Scheduler;
48 a57faaf0 Christos Stathis
import com.google.gwt.event.dom.client.ClickEvent;
49 a57faaf0 Christos Stathis
import com.google.gwt.event.dom.client.ClickHandler;
50 9539e23d Christos Stathis
import com.google.gwt.http.client.Response;
51 ea94470a Christos Stathis
import com.google.gwt.http.client.URL;
52 a57faaf0 Christos Stathis
import com.google.gwt.i18n.client.DateTimeFormat;
53 3601b114 Christos Stathis
import com.google.gwt.user.client.Command;
54 7811b9d1 Christos Stathis
import com.google.gwt.user.client.ui.Anchor;
55 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.Button;
56 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.FlexTable;
57 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
58 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.HorizontalPanel;
59 947da718 Christos Stathis
import com.google.gwt.user.client.ui.Image;
60 7811b9d1 Christos Stathis
import com.google.gwt.user.client.ui.Label;
61 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.TextBox;
62 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.VerticalPanel;
63 a57faaf0 Christos Stathis
64 a57faaf0 Christos Stathis
/**
65 a57faaf0 Christos Stathis
 * The 'File properties' dialog box implementation.
66 a57faaf0 Christos Stathis
 *
67 a57faaf0 Christos Stathis
 */
68 a57faaf0 Christos Stathis
public class FilePropertiesDialog extends AbstractPropertiesDialog {
69 a57faaf0 Christos Stathis
70 a57faaf0 Christos Stathis
        /**
71 a57faaf0 Christos Stathis
         * The widget that holds the name of the file.
72 a57faaf0 Christos Stathis
         */
73 a57faaf0 Christos Stathis
        private TextBox name = new TextBox();
74 a57faaf0 Christos Stathis
75 31997f49 Christos Stathis
        final File file;
76 a57faaf0 Christos Stathis
77 904447e4 Christos Stathis
    FlexTable metaTable;
78 a57faaf0 Christos Stathis
        /**
79 a57faaf0 Christos Stathis
         * The widget's constructor.
80 a57faaf0 Christos Stathis
         */
81 749068ba Christos Stathis
        public FilePropertiesDialog(Pithos _app, File _file) {
82 a7c43f26 Christos Stathis
        super(_app);
83 31997f49 Christos Stathis
        file = _file;
84 a57faaf0 Christos Stathis
85 96705b13 Christos Stathis
                Anchor close = new Anchor("close");
86 4420a247 Christos Stathis
                close.addStyleName("close");
87 4420a247 Christos Stathis
                close.addClickHandler(new ClickHandler() {
88 4420a247 Christos Stathis
                        
89 4420a247 Christos Stathis
                        @Override
90 ebead1b5 Christos Stathis
                        public void onClick(ClickEvent event) {
91 4420a247 Christos Stathis
                                hide();
92 4420a247 Christos Stathis
                        }
93 4420a247 Christos Stathis
                });
94 a57faaf0 Christos Stathis
                // Set the dialog's caption.
95 a57faaf0 Christos Stathis
                setText("File properties");
96 4420a247 Christos Stathis
                setAnimationEnabled(true);
97 4420a247 Christos Stathis
                setGlassEnabled(true);
98 4420a247 Christos Stathis
                setStyleName("pithos-DialogBox");
99 a57faaf0 Christos Stathis
100 a57faaf0 Christos Stathis
                // Outer contains inner and buttons.
101 a57faaf0 Christos Stathis
                final VerticalPanel outer = new VerticalPanel();
102 4420a247 Christos Stathis
                outer.add(close);
103 a57faaf0 Christos Stathis
                // Inner contains generalPanel and permPanel.
104 9326b841 Christos Stathis
                inner = new VerticalPanel();
105 4420a247 Christos Stathis
                inner.addStyleName("inner");
106 a57faaf0 Christos Stathis
107 9326b841 Christos Stathis
        inner.add(createGeneralPanel());
108 a57faaf0 Christos Stathis
109 31997f49 Christos Stathis
        outer.add(inner);
110 31997f49 Christos Stathis
111 a57faaf0 Christos Stathis
                // Create the 'OK' button, along with a listener that hides the dialog
112 a57faaf0 Christos Stathis
                // when the button is clicked.
113 a57faaf0 Christos Stathis
                final Button ok = new Button("OK", new ClickHandler() {
114 a57faaf0 Christos Stathis
                        @Override
115 ebead1b5 Christos Stathis
                        public void onClick(ClickEvent event) {
116 0099339a Christos Stathis
                                if (accept())
117 0099339a Christos Stathis
                                        closeDialog();
118 a57faaf0 Christos Stathis
                        }
119 a57faaf0 Christos Stathis
                });
120 4420a247 Christos Stathis
                ok.addStyleName("button");
121 31997f49 Christos Stathis
122 4420a247 Christos Stathis
        outer.add(ok);
123 4420a247 Christos Stathis
        outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
124 31997f49 Christos Stathis
125 31997f49 Christos Stathis
        setWidget(outer);
126 a57faaf0 Christos Stathis
        }
127 a57faaf0 Christos Stathis
128 611de529 Christos Stathis
        private VerticalPanel createGeneralPanel() {
129 31997f49 Christos Stathis
        final VerticalPanel generalPanel = new VerticalPanel();
130 31997f49 Christos Stathis
        final FlexTable generalTable = new FlexTable();
131 31997f49 Christos Stathis
        generalTable.setText(0, 0, "Name");
132 31997f49 Christos Stathis
        generalTable.setText(1, 0, "Folder");
133 31997f49 Christos Stathis
        generalTable.setText(2, 0, "Owner");
134 31997f49 Christos Stathis
        generalTable.setText(3, 0, "Last modified");
135 31997f49 Christos Stathis
136 31997f49 Christos Stathis
        name.setWidth("100%");
137 31997f49 Christos Stathis
        name.setText(file.getName());
138 31997f49 Christos Stathis
        generalTable.setWidget(0, 1, name);
139 31997f49 Christos Stathis
        if(file.getParent() != null)
140 31997f49 Christos Stathis
            generalTable.setText(1, 1, file.getParent().getName());
141 31997f49 Christos Stathis
        else
142 31997f49 Christos Stathis
            generalTable.setText(1, 1, "-");
143 31997f49 Christos Stathis
        generalTable.setText(2, 1, file.getOwner());
144 31997f49 Christos Stathis
145 31997f49 Christos Stathis
        final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
146 f3c8bd5b Christos Stathis
        generalTable.setText(3, 1, file.getLastModified() != null ? formatter.format(file.getLastModified()) : "");
147 31997f49 Christos Stathis
148 31997f49 Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
149 31997f49 Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
150 31997f49 Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
151 31997f49 Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");
152 ef5b664d Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels");
153 31997f49 Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
154 31997f49 Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
155 31997f49 Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
156 31997f49 Christos Stathis
        generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");
157 31997f49 Christos Stathis
        generalTable.setCellSpacing(4);
158 31997f49 Christos Stathis
159 31997f49 Christos Stathis
        generalPanel.add(generalTable);
160 31997f49 Christos Stathis
161 904447e4 Christos Stathis
        HorizontalPanel metaTitlePanel = new HorizontalPanel();
162 904447e4 Christos Stathis
        metaTitlePanel.setSpacing(5);
163 947da718 Christos Stathis
        Label meta = new Label("Meta data");
164 904447e4 Christos Stathis
        meta.addStyleName("pithos-metaTitle");
165 904447e4 Christos Stathis
        metaTitlePanel.add(meta);
166 904447e4 Christos Stathis
        
167 5d2050bf Christos Stathis
                Anchor plus = new Anchor("add");
168 5d2050bf Christos Stathis
                plus.addStyleName(Pithos.resources.pithosCss().commandAnchor());
169 904447e4 Christos Stathis
                metaTitlePanel.add(plus);
170 904447e4 Christos Stathis
                
171 904447e4 Christos Stathis
                generalPanel.add(metaTitlePanel);
172 947da718 Christos Stathis
                
173 947da718 Christos Stathis
                metaTable = new FlexTable();
174 947da718 Christos Stathis
                metaTable.setCellSpacing(0);
175 947da718 Christos Stathis
                metaTable.setHTML(0, 0, "Name");
176 947da718 Christos Stathis
                metaTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
177 947da718 Christos Stathis
                metaTable.setText(0, 1, "Value");
178 947da718 Christos Stathis
                metaTable.getFlexCellFormatter().setStyleName(0, 1, "props-labels");
179 947da718 Christos Stathis
                int rows = 1;
180 947da718 Christos Stathis
                for (String metaKey : file.getMeta().keySet()) {
181 947da718 Christos Stathis
                        addFormLine(metaTable, rows++, metaKey, file.getMeta().get(metaKey));
182 947da718 Christos Stathis
                }
183 904447e4 Christos Stathis
                if (rows == 1) //If no meta add an empty line
184 904447e4 Christos Stathis
                        addFormLine(metaTable, rows++, "", "");
185 947da718 Christos Stathis
                
186 947da718 Christos Stathis
                plus.addClickHandler(new ClickHandler() {
187 947da718 Christos Stathis
                        
188 947da718 Christos Stathis
                        @Override
189 ebead1b5 Christos Stathis
                        public void onClick(ClickEvent event) {
190 947da718 Christos Stathis
                                addFormLine(metaTable, metaTable.getRowCount(), "", "");
191 947da718 Christos Stathis
                        }
192 947da718 Christos Stathis
                });
193 ef5b664d Christos Stathis
194 947da718 Christos Stathis
                generalPanel.add(metaTable);
195 31997f49 Christos Stathis
        generalPanel.setSpacing(4);
196 31997f49 Christos Stathis
        return generalPanel;
197 31997f49 Christos Stathis
    }
198 31997f49 Christos Stathis
199 904447e4 Christos Stathis
        void addFormLine(final FlexTable table, int row, String _name, String _value) {
200 947da718 Christos Stathis
                TextBox nameBox = new TextBox();
201 904447e4 Christos Stathis
                nameBox.setText(_name);
202 904447e4 Christos Stathis
                nameBox.addStyleName("pithos-metaName");
203 947da718 Christos Stathis
                table.setWidget(row, 0, nameBox);
204 947da718 Christos Stathis
                table.getFlexCellFormatter().setStyleName(1, 0, "props-values");
205 947da718 Christos Stathis
206 947da718 Christos Stathis
                TextBox valueBox = new TextBox();
207 904447e4 Christos Stathis
                valueBox.setText(_value);
208 904447e4 Christos Stathis
                valueBox.addStyleName("pithos-metaValue");
209 947da718 Christos Stathis
                table.setWidget(row, 1, valueBox);
210 947da718 Christos Stathis
                table.getFlexCellFormatter().setStyleName(1, 1, "props-values");
211 947da718 Christos Stathis
                
212 5d2050bf Christos Stathis
                Anchor delete = new Anchor("remove");
213 5d2050bf Christos Stathis
                delete.addStyleName(Pithos.resources.pithosCss().commandAnchor());
214 947da718 Christos Stathis
                delete.addClickHandler(new ClickHandler() {
215 947da718 Christos Stathis
                        
216 947da718 Christos Stathis
                        @Override
217 947da718 Christos Stathis
                        public void onClick(ClickEvent event) {
218 947da718 Christos Stathis
                                int rowIndex = table.getCellForEvent(event).getRowIndex();
219 947da718 Christos Stathis
                                table.removeRow(rowIndex);
220 947da718 Christos Stathis
                        }
221 947da718 Christos Stathis
                });
222 947da718 Christos Stathis
                table.setWidget(row, 2, delete);
223 947da718 Christos Stathis
        }
224 947da718 Christos Stathis
225 a57faaf0 Christos Stathis
        /**
226 a57faaf0 Christos Stathis
         * Accepts any change and updates the file
227 a57faaf0 Christos Stathis
         *
228 a57faaf0 Christos Stathis
         */
229 a57faaf0 Christos Stathis
        @Override
230 0099339a Christos Stathis
        protected boolean accept() {
231 a57faaf0 Christos Stathis
                String newFilename = null;
232 ecf95c9e Christos Stathis
233 ef5b664d Christos Stathis
                if (!name.getText().trim().equals(file.getName())) {
234 ef5b664d Christos Stathis
                        newFilename = name.getText().trim();
235 0099339a Christos Stathis
                        if (newFilename.length() == 0)
236 0099339a Christos Stathis
                                newFilename = null;
237 a57faaf0 Christos Stathis
                }
238 0099339a Christos Stathis
                
239 ecf95c9e Christos Stathis
240 947da718 Christos Stathis
        final Map<String, String> newMeta = new HashMap<String, String>();
241 947da718 Christos Stathis
        for (int row = 1; row < metaTable.getRowCount(); row++) {
242 947da718 Christos Stathis
                String key = ((TextBox) metaTable.getWidget(row, 0)).getText().trim();
243 947da718 Christos Stathis
                String value = ((TextBox) metaTable.getWidget(row, 1)).getText().trim();
244 904447e4 Christos Stathis
                if (key.length() > 0 && value.length() > 0)
245 904447e4 Christos Stathis
                        newMeta.put(key, value);
246 0099339a Christos Stathis
                else if ((key.length() > 0 && value.length() == 0) || (key.length() == 0 && value.length() > 0)) {
247 0099339a Christos Stathis
                        app.displayError("You have empty keys or values");
248 0099339a Christos Stathis
                        return false;
249 0099339a Christos Stathis
                }
250 947da718 Christos Stathis
        }
251 ef5b664d Christos Stathis
252 ef5b664d Christos Stathis
        if (newFilename != null) {
253 b51c628b Christos Stathis
            final String path = file.getParent().getUri() + "/" + newFilename;
254 b51c628b Christos Stathis
            PutRequest updateFile = new PutRequest(app.getApiPath(), app.getUsername(), path) {
255 ef5b664d Christos Stathis
                @Override
256 ebead1b5 Christos Stathis
                public void onSuccess(Resource result) {
257 d26e2ef7 Christos Stathis
                    updateMetaData(app.getApiPath(), file.getOwner(), path, newMeta);
258 ef5b664d Christos Stathis
                }
259 ef5b664d Christos Stathis
260 ef5b664d Christos Stathis
                @Override
261 ef5b664d Christos Stathis
                public void onError(Throwable t) {
262 ef5b664d Christos Stathis
                    GWT.log("", t);
263 3f8622d4 Christos Stathis
                                        app.setError(t);
264 ef5b664d Christos Stathis
                    app.displayError("System error modifying file:" + t.getMessage());
265 ef5b664d Christos Stathis
                }
266 9539e23d Christos Stathis
267 9539e23d Christos Stathis
                                @Override
268 ebead1b5 Christos Stathis
                                protected void onUnauthorized(Response response) {
269 9539e23d Christos Stathis
                                        app.sessionExpired();
270 9539e23d Christos Stathis
                                }
271 ef5b664d Christos Stathis
            };
272 ef5b664d Christos Stathis
            updateFile.setHeader("X-Auth-Token", app.getToken());
273 a2411896 Christos Stathis
            updateFile.setHeader("X-Move-From", URL.encodePathSegment(file.getUri()));
274 ef5b664d Christos Stathis
            updateFile.setHeader("Content-Type", file.getContentType());
275 3601b114 Christos Stathis
            for (String key : file.getMeta().keySet())
276 3601b114 Christos Stathis
                updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(key.trim()), URL.encodePathSegment(newMeta.get(key)));
277 3601b114 Christos Stathis
            if (file.isPublished())
278 3601b114 Christos Stathis
                updateFile.setHeader("X-Object-Public", "true");
279 3601b114 Christos Stathis
            String readPermHeader = "read=";
280 3601b114 Christos Stathis
            String writePermHeader = "write=";
281 3601b114 Christos Stathis
            for (String u : file.getPermissions().keySet()) {
282 3601b114 Christos Stathis
                Boolean[] p = file.getPermissions().get(u);
283 3601b114 Christos Stathis
                if (p[0] != null && p[0])
284 3601b114 Christos Stathis
                    readPermHeader += u + ",";
285 3601b114 Christos Stathis
                if (p[1] != null && p[1])
286 3601b114 Christos Stathis
                    writePermHeader += u + ",";
287 3601b114 Christos Stathis
            }
288 3601b114 Christos Stathis
            if (readPermHeader.endsWith("="))
289 3601b114 Christos Stathis
                readPermHeader = "";
290 3601b114 Christos Stathis
            else if (readPermHeader.endsWith(","))
291 3601b114 Christos Stathis
                readPermHeader = readPermHeader.substring(0, readPermHeader.length() - 1);
292 3601b114 Christos Stathis
            if (writePermHeader.endsWith("="))
293 3601b114 Christos Stathis
                writePermHeader = "";
294 3601b114 Christos Stathis
            else if (writePermHeader.endsWith(","))
295 3601b114 Christos Stathis
                writePermHeader = writePermHeader.substring(0, writePermHeader.length() - 1);
296 3601b114 Christos Stathis
            String permHeader = readPermHeader +  ((readPermHeader.length()  > 0 && writePermHeader.length() > 0) ?  ";" : "") + writePermHeader;
297 3601b114 Christos Stathis
            if (permHeader.length() == 0)
298 3601b114 Christos Stathis
                permHeader="~";
299 3601b114 Christos Stathis
            else
300 3601b114 Christos Stathis
                    permHeader = URL.encodePathSegment(permHeader);
301 3601b114 Christos Stathis
            updateFile.setHeader("X-Object-Sharing", permHeader);
302 3601b114 Christos Stathis
303 ef5b664d Christos Stathis
            Scheduler.get().scheduleDeferred(updateFile);
304 ef5b664d Christos Stathis
        }
305 ecf95c9e Christos Stathis
        else
306 d26e2ef7 Christos Stathis
            updateMetaData(app.getApiPath(), app.getUsername(), file.getUri(), newMeta);
307 0099339a Christos Stathis
        return true;
308 ef5b664d Christos Stathis
        }
309 a57faaf0 Christos Stathis
310 d26e2ef7 Christos Stathis
        protected void updateMetaData(final String api, final String owner, final String path, Map<String, String> newMeta) {
311 9326b841 Christos Stathis
        if (newMeta != null) {
312 d26e2ef7 Christos Stathis
            PostRequest updateFile = new PostRequest(api, owner, path + "?update=") {
313 ecf95c9e Christos Stathis
                @Override
314 ebead1b5 Christos Stathis
                public void onSuccess(Resource result) {
315 5d18aa82 Christos Stathis
                        if (!app.isMySharedSelected())
316 5d18aa82 Christos Stathis
                            app.updateFolder(file.getParent(), true, new Command() {
317 5d18aa82 Christos Stathis
                                                        
318 5d18aa82 Christos Stathis
                                                        @Override
319 5d18aa82 Christos Stathis
                                                        public void execute() {
320 d26e2ef7 Christos Stathis
                                                                app.getFileList().selectByUrl(Arrays.asList(api + owner + path));
321 5d18aa82 Christos Stathis
                                                                app.updateMySharedRoot();
322 5d18aa82 Christos Stathis
                                                        }
323 5d18aa82 Christos Stathis
                                                }, true);
324 d26e2ef7 Christos Stathis
                        else {
325 d26e2ef7 Christos Stathis
                                app.updateSharedFolder(file.getParent(), true, new Command() {
326 d26e2ef7 Christos Stathis
                                        
327 d26e2ef7 Christos Stathis
                                                        @Override
328 d26e2ef7 Christos Stathis
                                                        public void execute() {
329 d26e2ef7 Christos Stathis
                                                                app.getFileList().selectByUrl(Arrays.asList(api + owner + path));
330 d26e2ef7 Christos Stathis
                                                        }
331 d26e2ef7 Christos Stathis
                                });
332 d26e2ef7 Christos Stathis
                        }
333 ecf95c9e Christos Stathis
                }
334 31997f49 Christos Stathis
335 ecf95c9e Christos Stathis
                @Override
336 ecf95c9e Christos Stathis
                public void onError(Throwable t) {
337 ecf95c9e Christos Stathis
                    GWT.log("", t);
338 3f8622d4 Christos Stathis
                                        app.setError(t);
339 ecf95c9e Christos Stathis
                    app.displayError("System error modifying file:" + t.getMessage());
340 ecf95c9e Christos Stathis
                }
341 9539e23d Christos Stathis
342 9539e23d Christos Stathis
                                @Override
343 ebead1b5 Christos Stathis
                                protected void onUnauthorized(Response response) {
344 9539e23d Christos Stathis
                                        app.sessionExpired();
345 9539e23d Christos Stathis
                                }
346 ecf95c9e Christos Stathis
            };
347 ecf95c9e Christos Stathis
            updateFile.setHeader("X-Auth-Token", app.getToken());
348 904447e4 Christos Stathis
            
349 9326b841 Christos Stathis
            for (String t : file.getMeta().keySet()) {
350 9326b841 Christos Stathis
                        updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(t.trim()), "~");
351 ea94470a Christos Stathis
            }
352 947da718 Christos Stathis
            
353 9326b841 Christos Stathis
            for (String key : newMeta.keySet())
354 9326b841 Christos Stathis
                updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(key.trim()), URL.encodePathSegment(newMeta.get(key)));
355 9326b841 Christos Stathis
            
356 ecf95c9e Christos Stathis
            Scheduler.get().scheduleDeferred(updateFile);
357 ecf95c9e Christos Stathis
        }
358 5d18aa82 Christos Stathis
        else if (!app.isMySharedSelected())
359 3601b114 Christos Stathis
            app.updateFolder(file.getParent(), true, new Command() {
360 3601b114 Christos Stathis
                                
361 3601b114 Christos Stathis
                                @Override
362 3601b114 Christos Stathis
                                public void execute() {
363 d26e2ef7 Christos Stathis
                                        app.getFileList().selectByUrl(Arrays.asList(api + owner + path));
364 71875b42 Christos Stathis
                                        if (file.isSharedOrPublished())
365 3601b114 Christos Stathis
                                                app.updateMySharedRoot();
366 3601b114 Christos Stathis
                                }
367 6acd4df3 Christos Stathis
                        }, true);
368 d26e2ef7 Christos Stathis
        else {
369 d26e2ef7 Christos Stathis
                        app.getFileList().selectByUrl(Arrays.asList(api + owner + path));
370 5d18aa82 Christos Stathis
                app.updateSharedFolder(file.getParent(), true);
371 d26e2ef7 Christos Stathis
        }
372 ef5b664d Christos Stathis
    }
373 a57faaf0 Christos Stathis
}