Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / Pithos.java @ e6b93be1

History | View | Annotate | Download (44.6 kB)

1
/*
2
 * Copyright 2011-2012 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35
package gr.grnet.pithos.web.client;
36

    
37
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
38
import gr.grnet.pithos.web.client.foldertree.AccountResource;
39
import gr.grnet.pithos.web.client.foldertree.File;
40
import gr.grnet.pithos.web.client.foldertree.Folder;
41
import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
42
import gr.grnet.pithos.web.client.foldertree.FolderTreeViewModel;
43
import gr.grnet.pithos.web.client.foldertree.Resource;
44
import gr.grnet.pithos.web.client.grouptree.Group;
45
import gr.grnet.pithos.web.client.grouptree.GroupTreeView;
46
import gr.grnet.pithos.web.client.grouptree.GroupTreeViewModel;
47
import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeView;
48
import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeViewModel;
49
import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeView;
50
import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeViewModel;
51
import gr.grnet.pithos.web.client.rest.DeleteRequest;
52
import gr.grnet.pithos.web.client.rest.GetRequest;
53
import gr.grnet.pithos.web.client.rest.HeadRequest;
54
import gr.grnet.pithos.web.client.rest.PutRequest;
55
import gr.grnet.pithos.web.client.rest.RestException;
56

    
57
import java.util.ArrayList;
58
import java.util.HashMap;
59
import java.util.Iterator;
60
import java.util.List;
61
import java.util.Set;
62

    
63
import com.google.gwt.core.client.EntryPoint;
64
import com.google.gwt.core.client.GWT;
65
import com.google.gwt.core.client.Scheduler;
66
import com.google.gwt.core.client.Scheduler.RepeatingCommand;
67
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
68
import com.google.gwt.event.dom.client.ClickEvent;
69
import com.google.gwt.event.dom.client.ClickHandler;
70
import com.google.gwt.event.logical.shared.ResizeEvent;
71
import com.google.gwt.event.logical.shared.ResizeHandler;
72
import com.google.gwt.http.client.Request;
73
import com.google.gwt.http.client.RequestBuilder;
74
import com.google.gwt.http.client.RequestCallback;
75
import com.google.gwt.http.client.RequestException;
76
import com.google.gwt.http.client.Response;
77
import com.google.gwt.http.client.URL;
78
import com.google.gwt.i18n.client.Dictionary;
79
import com.google.gwt.i18n.client.NumberFormat;
80
import com.google.gwt.json.client.JSONArray;
81
import com.google.gwt.json.client.JSONObject;
82
import com.google.gwt.json.client.JSONParser;
83
import com.google.gwt.json.client.JSONString;
84
import com.google.gwt.json.client.JSONValue;
85
import com.google.gwt.resources.client.ImageResource;
86
import com.google.gwt.resources.client.ImageResource.ImageOptions;
87
import com.google.gwt.user.client.Command;
88
import com.google.gwt.user.client.Cookies;
89
import com.google.gwt.user.client.Event;
90
import com.google.gwt.user.client.History;
91
import com.google.gwt.user.client.Window;
92
import com.google.gwt.user.client.ui.AbstractImagePrototype;
93
import com.google.gwt.user.client.ui.Button;
94
import com.google.gwt.user.client.ui.Composite;
95
import com.google.gwt.user.client.ui.HTML;
96
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
97
import com.google.gwt.user.client.ui.HasVerticalAlignment;
98
import com.google.gwt.user.client.ui.HorizontalPanel;
99
import com.google.gwt.user.client.ui.HorizontalSplitPanel;
100
import com.google.gwt.user.client.ui.RootPanel;
101
import com.google.gwt.user.client.ui.VerticalPanel;
102
import com.google.gwt.view.client.SelectionChangeEvent;
103
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
104
import com.google.gwt.view.client.SingleSelectionModel;
105

    
106
/**
107
 * Entry point classes define <code>onModuleLoad()</code>.
108
 */
109
public class Pithos implements EntryPoint, ResizeHandler {
110

    
111
        public static final String HOME_CONTAINER = "pithos";
112

    
113
        public static final String TRASH_CONTAINER = "trash";
114

    
115
        public static final Configuration config = GWT.create(Configuration.class);
116
        
117
        /**
118
         * Instantiate an application-level image bundle. This object will provide
119
         * programmatic access to all the images needed by widgets.
120
         */
121
        static Images images = (Images) GWT.create(Images.class);
122

    
123
    public String getUsername() {
124
        return username;
125
    }
126

    
127
    public void setAccount(AccountResource acct) {
128
        account = acct;
129
    }
130

    
131
    public AccountResource getAccount() {
132
        return account;
133
    }
134

    
135
    public void updateFolder(Folder f, boolean showfiles, Command callback) {
136
        folderTreeView.updateFolder(f, showfiles, callback);
137
    }
138

    
139
    public void updateGroupNode(Group group) {
140
        groupTreeView.updateGroupNode(group);
141
    }
142

    
143
    public void updateMySharedRoot() {
144
            mysharedTreeView.updateRoot();
145
    }
146
    
147
    public void updateSharedFolder(Folder f, boolean showfiles) {
148
            mysharedTreeView.updateFolder(f, showfiles);
149
    }
150
    
151
    public void updateOtherSharedFolder(Folder f, boolean showfiles) {
152
            otherSharedTreeView.updateFolder(f, showfiles);
153
    }
154

    
155
    public MysharedTreeView getMySharedTreeView() {
156
        return mysharedTreeView;
157
    }
158

    
159
    /**
160
         * An aggregate image bundle that pulls together all the images for this
161
         * application into a single bundle.
162
         */
163
        public interface Images extends TopPanel.Images, FileList.Images, ToolsMenu.Images {
164

    
165
                @Source("gr/grnet/pithos/resources/document.png")
166
                ImageResource folders();
167

    
168
                @Source("gr/grnet/pithos/resources/advancedsettings.png")
169
                @ImageOptions(width=32, height=32)
170
                ImageResource tools();
171
        }
172

    
173
        private Throwable error;
174
        
175
        /**
176
         * The Application Clipboard implementation;
177
         */
178
        private Clipboard clipboard = new Clipboard();
179

    
180
        /**
181
         * The top panel that contains the menu bar.
182
         */
183
        private TopPanel topPanel;
184

    
185
        /**
186
         * The panel that contains the various system messages.
187
         */
188
        private MessagePanel messagePanel = new MessagePanel(this, Pithos.images);
189

    
190
        /**
191
         * The bottom panel that contains the status bar.
192
         */
193
        private StatusPanel statusPanel = null;
194

    
195
        /**
196
         * The file list widget.
197
         */
198
        private FileList fileList;
199

    
200
        /**
201
         * The tab panel that occupies the right side of the screen.
202
         */
203
        private VerticalPanel inner = new VerticalPanel();
204

    
205

    
206
        /**
207
         * The split panel that will contain the left and right panels.
208
         */
209
        private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
210

    
211
        /**
212
         * The currently selected item in the application, for use by the Edit menu
213
         * commands. Potential types are Folder, File, User and Group.
214
         */
215
        private Object currentSelection;
216

    
217
        public HashMap<String, String> userFullNameMap = new HashMap<String, String>();
218

    
219
    private String username = null;
220

    
221
    /**
222
     * The authentication token of the current user.
223
     */
224
    private String token;
225

    
226
    VerticalPanel trees;
227
    
228
    SingleSelectionModel<Folder> folderTreeSelectionModel;
229
    FolderTreeViewModel folderTreeViewModel;
230
    FolderTreeView folderTreeView;
231

    
232
    SingleSelectionModel<Folder> mysharedTreeSelectionModel;
233
    MysharedTreeViewModel mysharedTreeViewModel;
234
    MysharedTreeView mysharedTreeView = null;;
235

    
236
    protected SingleSelectionModel<Folder> otherSharedTreeSelectionModel;
237
    OtherSharedTreeViewModel otherSharedTreeViewModel;
238
    OtherSharedTreeView otherSharedTreeView = null;
239

    
240
    GroupTreeViewModel groupTreeViewModel;
241
    private GroupTreeView groupTreeView;
242

    
243
    TreeView selectedTree;
244
    protected AccountResource account;
245
    
246
    Folder trash;
247
    
248
    List<Composite> treeViews = new ArrayList<Composite>();
249

    
250
    @SuppressWarnings("rawtypes") List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>();
251
    
252
    Button upload;
253
    
254
    private HTML usedBytes;
255
    
256
    private HTML totalBytes;
257
    
258
    private HTML usedPercent;
259
    
260
    private HTML numOfFiles;
261
    
262
    private Toolbar toolbar;
263
    
264
    private FileUploadDialog fileUploadDialog;
265
    
266
        @Override
267
        public void onModuleLoad() {
268
                if (parseUserCredentials())
269
            initialize();
270
        }
271

    
272
    private void initialize() {
273
            boolean bareContent = Window.Location.getParameter("noframe") != null;
274
            String contentWidth = bareContent ? "100%" : "75%";
275

    
276
            VerticalPanel outer = new VerticalPanel();
277
        outer.setWidth("100%");
278
            if (!bareContent) {
279
                    outer.addStyleName("pithos-outer");
280
            }
281

    
282
        if (!bareContent) {
283
                topPanel = new TopPanel(this, Pithos.images);
284
                topPanel.setWidth("100%");
285
                outer.add(topPanel);
286
                outer.setCellHorizontalAlignment(topPanel, HasHorizontalAlignment.ALIGN_CENTER);
287
        }
288
        
289
        messagePanel.setVisible(false);
290
        outer.add(messagePanel);
291
        outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);
292
        outer.setCellVerticalAlignment(messagePanel, HasVerticalAlignment.ALIGN_MIDDLE);
293

    
294
        HorizontalPanel header = new HorizontalPanel();
295
        header.addStyleName("pithos-header");
296
        header.setWidth(contentWidth);
297
        if (bareContent)
298
                header.addStyleName("pithos-header-noframe");
299
        upload = new Button("Upload", new ClickHandler() {
300
            @Override
301
            public void onClick(ClickEvent event) {
302
                    if (getSelection() != null)
303
                            new UploadFileCommand(Pithos.this, null, getSelection()).execute();
304
            }
305
        });
306
        upload.addStyleName("pithos-uploadButton");
307
        header.add(upload);
308
        header.setCellHorizontalAlignment(upload, HasHorizontalAlignment.ALIGN_LEFT);
309
        header.setCellVerticalAlignment(upload, HasVerticalAlignment.ALIGN_MIDDLE);
310

    
311
        toolbar = new Toolbar(this);
312
        header.add(toolbar);
313
        header.setCellHorizontalAlignment(toolbar, HasHorizontalAlignment.ALIGN_CENTER);
314
        header.setCellVerticalAlignment(toolbar, HasVerticalAlignment.ALIGN_MIDDLE);
315
        
316
        HorizontalPanel folderStatistics = new HorizontalPanel();
317
        folderStatistics.addStyleName("pithos-folderStatistics");
318
        numOfFiles = new HTML();
319
        folderStatistics.add(numOfFiles);
320
        folderStatistics.setCellVerticalAlignment(numOfFiles, HasVerticalAlignment.ALIGN_MIDDLE);
321
        HTML numOfFilesLabel = new HTML("&nbsp;Files");
322
        folderStatistics.add(numOfFilesLabel);
323
        folderStatistics.setCellVerticalAlignment(numOfFilesLabel, HasVerticalAlignment.ALIGN_MIDDLE);
324
        header.add(folderStatistics);
325
        header.setCellHorizontalAlignment(folderStatistics, HasHorizontalAlignment.ALIGN_RIGHT);
326
        header.setCellVerticalAlignment(folderStatistics, HasVerticalAlignment.ALIGN_MIDDLE);
327
        header.setCellWidth(folderStatistics, "40px");
328
        outer.add(header);
329
        outer.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_CENTER);
330
        // Inner contains the various lists.nner
331
        inner.sinkEvents(Event.ONCONTEXTMENU);
332
        inner.setWidth("100%");
333

    
334
        folderTreeSelectionModel = new SingleSelectionModel<Folder>();
335
        folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
336
            @Override
337
            public void onSelectionChange(SelectionChangeEvent event) {
338
                if (folderTreeSelectionModel.getSelectedObject() != null) {
339
                    deselectOthers(folderTreeView, folderTreeSelectionModel);
340
                    applyPermissions(folderTreeSelectionModel.getSelectedObject());
341
                    Folder f = folderTreeSelectionModel.getSelectedObject();
342
                            updateFolder(f, true, new Command() {
343
                                    
344
                                    @Override
345
                                    public void execute() {
346
                                            updateStatistics();
347
                                    }
348
                            });
349
                }
350
                showRelevantToolbarButtons();
351
            }
352
        });
353
        selectionModels.add(folderTreeSelectionModel);
354

    
355
        folderTreeViewModel = new FolderTreeViewModel(this, folderTreeSelectionModel);
356
        folderTreeView = new FolderTreeView(folderTreeViewModel);
357
        treeViews.add(folderTreeView);
358
        
359
        fileList = new FileList(this, images, folderTreeView);
360
        inner.add(fileList);
361

    
362
        groupTreeViewModel = new GroupTreeViewModel(this);
363
        groupTreeView = new GroupTreeView(groupTreeViewModel);
364
        treeViews.add(groupTreeView);
365
        
366
        trees = new VerticalPanel();
367
        trees.setWidth("100%");
368

    
369
        
370
        HorizontalPanel treeHeader = new HorizontalPanel();
371
        treeHeader.addStyleName("pithos-treeHeader");
372
        treeHeader.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
373
        treeHeader.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
374
        HorizontalPanel statistics = new HorizontalPanel();
375
        statistics.addStyleName("pithos-statistics");
376
        statistics.add(new HTML("Used:&nbsp;"));
377
        usedBytes = new HTML();
378
        statistics.add(usedBytes);
379
        statistics.add(new HTML("&nbsp;of&nbsp;"));
380
        totalBytes = new HTML();
381
        statistics.add(totalBytes);
382
        statistics.add(new HTML("&nbsp;("));
383
        usedPercent = new HTML();
384
        statistics.add(usedPercent);
385
        statistics.add(new HTML(")"));
386
        treeHeader.add(statistics);
387
        treeHeader.setCellHorizontalAlignment(statistics, HasHorizontalAlignment.ALIGN_LEFT);
388
        trees.add(treeHeader);
389

    
390
        trees.add(folderTreeView);
391
        trees.add(groupTreeView);
392
        // Add the left and right panels to the split panel.
393
        splitPanel.setLeftWidget(trees);
394
        splitPanel.setRightWidget(inner);
395
        splitPanel.setSplitPosition("35%");
396
        splitPanel.setSize("100%", "100%");
397
        splitPanel.addStyleName("pithos-splitPanel");
398
        splitPanel.setWidth(contentWidth);
399
        outer.add(splitPanel);
400
        outer.setCellHorizontalAlignment(splitPanel, HasHorizontalAlignment.ALIGN_CENTER);
401

    
402
        if (!bareContent) {
403
                statusPanel = new StatusPanel();
404
                statusPanel.setWidth("100%");
405
                outer.add(statusPanel);
406
                outer.setCellHorizontalAlignment(statusPanel, HasHorizontalAlignment.ALIGN_CENTER);
407
        }
408
        else
409
                splitPanel.addStyleName("pithos-splitPanel-noframe");
410

    
411
        // Hook the window resize event, so that we can adjust the UI.
412
        Window.addResizeHandler(this);
413
        // Clear out the window's built-in margin, because we want to take
414
        // advantage of the entire client area.
415
        Window.setMargin("0px");
416
        // Finally, add the outer panel to the RootPanel, so that it will be
417
        // displayed.
418
        RootPanel.get().add(outer);
419
        // Call the window resized handler to get the initial sizes setup. Doing
420
        // this in a deferred command causes it to occur after all widgets'
421
        // sizes have been computed by the browser.
422
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
423

    
424
            @Override
425
            public void execute() {
426
                onWindowResized(Window.getClientHeight());
427
            }
428
        });
429

    
430
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
431
            @Override
432
            public void execute() {
433
                fetchAccount(new Command() {
434
                                        
435
                                        @Override
436
                                        public void execute() {
437
                                if (!account.hasHomeContainer())
438
                                    createHomeContainer(account, this);
439
                                else if (!account.hasTrashContainer())
440
                                        createTrashContainer(this);
441
                                else {
442
                                        for (Folder f : account.getContainers())
443
                                                if (f.getName().equals(Pithos.TRASH_CONTAINER)) {
444
                                                        trash = f;
445
                                                        break;
446
                                                }
447
                                    folderTreeViewModel.initialize(account, new Command() {
448
                                                                
449
                                                                @Override
450
                                                                public void execute() {
451
                                                    createMySharedTree();
452
                                                                }
453
                                                        });
454
                                    groupTreeViewModel.initialize();
455
                                    showStatistics();
456
                                }
457
                                        }
458
                                });
459
            }
460
        });
461
        
462
        Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
463
                        
464
                        @Override
465
                        public boolean execute() {
466
                                Folder f = getSelection();
467
                                if (f != null) {
468
                                        if (getSelectedTree().equals(folderTreeView))
469
                                                updateFolder(f, true, null);
470
                                        else if (getSelectedTree().equals(mysharedTreeView))
471
                                                updateSharedFolder(f, true);
472
                                        else if (getSelectedTree().equals(otherSharedTreeView))
473
                                                updateOtherSharedFolder(f, true);
474
                                }
475
                                return true;
476
                        }
477
                }, 3000);
478
    }
479

    
480
    public void applyPermissions(Folder f) {
481
            if (f != null) {
482
                    if (f.isInTrash())
483
                            upload.setEnabled(false);
484
                    else {
485
                            Boolean[] perms = f.getPermissions().get(username);
486
                            if (f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) {
487
                                    upload.setEnabled(true);
488
                            }
489
                            else
490
                                    upload.setEnabled(false);
491
                    }
492
            }
493
            else
494
                    upload.setEnabled(false);
495
        }
496

    
497
        @SuppressWarnings({ "rawtypes", "unchecked" })
498
        public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) {
499
            selectedTree = _selectedTree;
500
            
501
            for (Composite c : treeViews)
502
                    if (c.equals(selectedTree))
503
                            c.addStyleName("cellTreeWidget-selectedTree");
504
                    else
505
                            c.removeStyleName("cellTreeWidget-selectedTree");
506
            
507
        for (SingleSelectionModel s : selectionModels)
508
            if (!s.equals(model))
509
                s.setSelected(s.getSelectedObject(), false);
510
    }
511

    
512
    public void showFiles(final Folder f) {
513
        Set<File> files = f.getFiles();
514
        showFiles(files);
515
    }
516

    
517
    public void showFiles(Set<File> files) {
518
        fileList.setFiles(new ArrayList<File>(files));
519
    }
520

    
521
    /**
522
         * Parse and store the user credentials to the appropriate fields.
523
         */
524
        private boolean parseUserCredentials() {
525
        username = Window.Location.getParameter("user");
526
        token = Window.Location.getParameter("token");
527
        Configuration conf = (Configuration) GWT.create(Configuration.class);
528
                Dictionary otherProperties = Dictionary.getDictionary("otherProperties");
529
        if (username == null || username.length() == 0 || token == null || token.length() == 0) {
530
            String cookie = otherProperties.get("authCookie");
531
            String auth = Cookies.getCookie(cookie);
532
            if (auth == null) {
533
                authenticateUser();
534
                return false;
535
            }
536
            if (auth.startsWith("\""))
537
                    auth = auth.substring(1);
538
            if (auth.endsWith("\""))
539
                    auth = auth.substring(0, auth.length() - 1);
540
                        String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2);
541
                        if (authSplit.length != 2) {
542
                            authenticateUser();
543
                            return false;
544
                        }
545
                        username = authSplit[0];
546
                        token = authSplit[1];
547
        }
548
        else
549
                Cookies.setCookie(otherProperties.get("authCookie"), username + conf.cookieSeparator() + token, null, "", "/", false);
550

    
551
        String gotoUrl = Window.Location.getParameter("goto");
552
                if (gotoUrl != null && gotoUrl.length() > 0) {
553
                        Window.Location.assign(gotoUrl + "?X-Auth-Token=" + token);
554
                        return false;
555
                }
556
                return true;
557
    }
558

    
559
    /**
560
         * Redirect the user to the login page for authentication.
561
         */
562
        protected void authenticateUser() {
563
                Dictionary otherProperties = Dictionary.getDictionary("otherProperties");
564
        Window.Location.assign(otherProperties.get("loginUrl") + Window.Location.getHref());
565
        }
566

    
567
        protected void fetchAccount(final Command callback) {
568
        String path = "?format=json";
569

    
570
        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), username, path) {
571
            @Override
572
            public void onSuccess(AccountResource _result) {
573
                account = _result;
574
                if (callback != null)
575
                        callback.execute();
576
            }
577

    
578
            @Override
579
            public void onError(Throwable t) {
580
                GWT.log("Error getting account", t);
581
                                setError(t);
582
                if (t instanceof RestException)
583
                    displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
584
                else
585
                    displayError("System error fetching user data: " + t.getMessage());
586
            }
587

    
588
                        @Override
589
                        protected void onUnauthorized(Response response) {
590
                                sessionExpired();
591
                        }
592
        };
593
        getAccount.setHeader("X-Auth-Token", token);
594
        Scheduler.get().scheduleDeferred(getAccount);
595
    }
596

    
597
    public void updateStatistics() {
598
            HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), username, "", account) {
599

    
600
                        @Override
601
                        public void onSuccess(AccountResource _result) {
602
                                showStatistics();
603
                        }
604

    
605
                        @Override
606
                        public void onError(Throwable t) {
607
                GWT.log("Error getting account", t);
608
                                setError(t);
609
                if (t instanceof RestException)
610
                    displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
611
                else
612
                    displayError("System error fetching user data: " + t.getMessage());
613
                        }
614

    
615
                        @Override
616
                        protected void onUnauthorized(Response response) {
617
                                sessionExpired();
618
                        }
619
                };
620
                headAccount.setHeader("X-Auth-Token", token);
621
                Scheduler.get().scheduleDeferred(headAccount);
622
        }
623

    
624
        protected void showStatistics() {
625
            usedBytes.setHTML(String.valueOf(account.getFileSizeAsString()));
626
            totalBytes.setHTML(String.valueOf(account.getQuotaAsString()));
627
            NumberFormat nf = NumberFormat.getPercentFormat();
628
            usedPercent.setHTML(nf.format(account.getUsedPercentage()));
629
        }
630

    
631
        protected void createHomeContainer(final AccountResource _account, final Command callback) {
632
        String path = "/" + Pithos.HOME_CONTAINER;
633
        PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
634
            @Override
635
            public void onSuccess(Resource result) {
636
                    if (!_account.hasTrashContainer())
637
                            createTrashContainer(callback);
638
                    else
639
                            fetchAccount(callback);
640
            }
641

    
642
            @Override
643
            public void onError(Throwable t) {
644
                GWT.log("Error creating pithos", t);
645
                                setError(t);
646
                if (t instanceof RestException)
647
                    displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
648
                else
649
                    displayError("System error Error creating pithos: " + t.getMessage());
650
            }
651

    
652
                        @Override
653
                        protected void onUnauthorized(Response response) {
654
                                sessionExpired();
655
                        }
656
        };
657
        createPithos.setHeader("X-Auth-Token", getToken());
658
        Scheduler.get().scheduleDeferred(createPithos);
659
    }
660

    
661
    protected void createTrashContainer(final Command callback) {
662
        String path = "/" + Pithos.TRASH_CONTAINER;
663
        PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
664
            @Override
665
            public void onSuccess(Resource result) {
666
                           fetchAccount(callback);
667
            }
668

    
669
            @Override
670
            public void onError(Throwable t) {
671
                GWT.log("Error creating pithos", t);
672
                                setError(t);
673
                if (t instanceof RestException)
674
                    displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
675
                else
676
                    displayError("System error Error creating pithos: " + t.getMessage());
677
            }
678

    
679
                        @Override
680
                        protected void onUnauthorized(Response response) {
681
                                sessionExpired();
682
                        }
683
        };
684
        createPithos.setHeader("X-Auth-Token", getToken());
685
        Scheduler.get().scheduleDeferred(createPithos);
686
    }
687

    
688
    /**
689
         * Creates an HTML fragment that places an image & caption together, for use
690
         * in a group header.
691
         *
692
         * @param imageProto an image prototype for an image
693
         * @param caption the group caption
694
         * @return the header HTML fragment
695
         */
696
        private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) {
697
                String captionHTML = "<table class='caption' cellpadding='0' " 
698
                + "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML() 
699
                + "</td><td id =" + caption +" class='rcaption'><b style='white-space:nowrap'>&nbsp;" 
700
                + caption + "</b></td></tr></table>";
701
                return captionHTML;
702
        }
703

    
704
        protected void onWindowResized(int height) {
705
                // Adjust the split panel to take up the available room in the window.
706
                int newHeight = height - splitPanel.getAbsoluteTop();
707
                if (newHeight < 1)
708
                        newHeight = 1;
709
                splitPanel.setHeight("" + newHeight);
710
                inner.setHeight("" + newHeight);
711
        }
712

    
713
        @Override
714
        public void onResize(ResizeEvent event) {
715
                int height = event.getHeight();
716
                onWindowResized(height);
717
        }
718

    
719
        /**
720
         * Display an error message.
721
         *
722
         * @param msg the message to display
723
         */
724
        public void displayError(String msg) {
725
                messagePanel.displayError(msg);
726
        }
727

    
728
        /**
729
         * Display a warning message.
730
         *
731
         * @param msg the message to display
732
         */
733
        public void displayWarning(String msg) {
734
                messagePanel.displayWarning(msg);
735
        }
736

    
737
        /**
738
         * Display an informational message.
739
         *
740
         * @param msg the message to display
741
         */
742
        public void displayInformation(String msg) {
743
                messagePanel.displayInformation(msg);
744
        }
745

    
746
        /**
747
         * Retrieve the fileList.
748
         *
749
         * @return the fileList
750
         */
751
        public FileList getFileList() {
752
                return fileList;
753
        }
754

    
755
        /**
756
         * Retrieve the topPanel.
757
         *
758
         * @return the topPanel
759
         */
760
        TopPanel getTopPanel() {
761
                return topPanel;
762
        }
763

    
764
        /**
765
         * Retrieve the clipboard.
766
         *
767
         * @return the clipboard
768
         */
769
        public Clipboard getClipboard() {
770
                return clipboard;
771
        }
772

    
773
        public StatusPanel getStatusPanel() {
774
                return statusPanel;
775
        }
776

    
777
        public String getToken() {
778
                return token;
779
        }
780

    
781
        public static native void preventIESelection() /*-{
782
                $doc.body.onselectstart = function () { return false; };
783
        }-*/;
784

    
785
        public static native void enableIESelection() /*-{
786
                if ($doc.body.onselectstart != null)
787
                $doc.body.onselectstart = null;
788
        }-*/;
789

    
790
        /**
791
         * @return the absolute path of the API root URL
792
         */
793
        public String getApiPath() {
794
                Configuration conf = (Configuration) GWT.create(Configuration.class);
795
                return conf.apiPath();
796
        }
797

    
798
        /**
799
         * History support for folder navigation
800
         * adds a new browser history entry
801
         *
802
         * @param key
803
         */
804
        public void updateHistory(String key){
805
//                Replace any whitespace of the initial string to "+"
806
//                String result = key.replaceAll("\\s","+");
807
//                Add a new browser history entry.
808
//                History.newItem(result);
809
                History.newItem(key);
810
        }
811

    
812
    public void deleteFolder(final Folder folder) {
813
        String path = getApiPath() + folder.getOwner() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(folder.getPrefix()) + "&t=" + System.currentTimeMillis();
814
        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
815
        builder.setHeader("X-Auth-Token", getToken());
816
        try {
817
            builder.sendRequest("", new RequestCallback() {
818
                @Override
819
                public void onResponseReceived(Request request, Response response) {
820
                    if (response.getStatusCode() == Response.SC_OK) {
821
                        JSONValue json = JSONParser.parseStrict(response.getText());
822
                        JSONArray array = json.isArray();
823
                        int i = 0;
824
                        if (array != null) {
825
                            deleteObject(folder, i, array);
826
                        }
827
                    }
828
                }
829

    
830
                @Override
831
                public void onError(Request request, Throwable exception) {
832
                        setError(exception);
833
                    displayError("System error unable to delete folder: " + exception.getMessage());
834
                }
835
            });
836
        }
837
        catch (RequestException e) {
838
        }
839
    }
840

    
841
    void deleteObject(final Folder folder, final int i, final JSONArray array) {
842
        if (i < array.size()) {
843
            JSONObject o = array.get(i).isObject();
844
            if (o != null && !o.containsKey("subdir")) {
845
                JSONString name = o.get("name").isString();
846
                String path = "/" + folder.getContainer() + "/" + name.stringValue();
847
                DeleteRequest delete = new DeleteRequest(getApiPath(), folder.getOwner(), URL.encode(path)) {
848
                    @Override
849
                    public void onSuccess(Resource result) {
850
                        deleteObject(folder, i + 1, array);
851
                    }
852

    
853
                    @Override
854
                    public void onError(Throwable t) {
855
                        GWT.log("", t);
856
                                                setError(t);
857
                        displayError("System error unable to delete folder: " + t.getMessage());
858
                    }
859

    
860
                                    @Override
861
                                    protected void onUnauthorized(Response response) {
862
                                            sessionExpired();
863
                                    }
864
                };
865
                delete.setHeader("X-Auth-Token", getToken());
866
                Scheduler.get().scheduleDeferred(delete);
867
            }
868
            else if (o != null) {
869
                String subdir = o.get("subdir").isString().stringValue();
870
                subdir = subdir.substring(0, subdir.length() - 1);
871
                String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(subdir) + "&t=" + System.currentTimeMillis();
872
                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
873
                builder.setHeader("X-Auth-Token", getToken());
874
                try {
875
                    builder.sendRequest("", new RequestCallback() {
876
                        @Override
877
                        public void onResponseReceived(Request request, Response response) {
878
                            if (response.getStatusCode() == Response.SC_OK) {
879
                                JSONValue json = JSONParser.parseStrict(response.getText());
880
                                JSONArray array2 = json.isArray();
881
                                if (array2 != null) {
882
                                    int l = array.size();
883
                                    for (int j=0; j<array2.size(); j++) {
884
                                        array.set(l++, array2.get(j));
885
                                    }
886
                                }
887
                                deleteObject(folder, i + 1, array);
888
                            }
889
                        }
890

    
891
                        @Override
892
                        public void onError(Request request, Throwable exception) {
893
                                setError(exception);
894
                            displayError("System error unable to delete folder: " + exception.getMessage());
895
                        }
896
                    });
897
                }
898
                catch (RequestException e) {
899
                }
900
            }
901
        }
902
        else {
903
            String path = folder.getUri();
904
            DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), getUsername(), URL.encode(path)) {
905
                @Override
906
                public void onSuccess(Resource result) {
907
                    updateFolder(folder.getParent(), true, new Command() {
908
                                                
909
                                                @Override
910
                                                public void execute() {
911
                                                        updateStatistics();
912
                                                }
913
                                        });
914
                }
915

    
916
                @Override
917
                public void onError(Throwable t) {
918
                    GWT.log("", t);
919
                                        setError(t);
920
                    if (t instanceof RestException) {
921
                            if (((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND)
922
                                    displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText());
923
                            else
924
                                    onSuccess(null);
925
                    }
926
                    else
927
                        displayError("System error unable to delete folder: " + t.getMessage());
928
                }
929

    
930
                                @Override
931
                                protected void onUnauthorized(Response response) {
932
                                        sessionExpired();
933
                                }
934
            };
935
            deleteFolder.setHeader("X-Auth-Token", getToken());
936
            Scheduler.get().scheduleDeferred(deleteFolder);
937
        }
938
    }
939

    
940
    public FolderTreeView getFolderTreeView() {
941
        return folderTreeView;
942
    }
943

    
944
    public void copyFiles(final Iterator<File> iter, final String targetUsername, final String targetUri, final Command callback) {
945
        if (iter.hasNext()) {
946
            File file = iter.next();
947
            String path = targetUri + "/" + file.getName();
948
            PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) {
949
                @Override
950
                public void onSuccess(Resource result) {
951
                    copyFiles(iter, targetUsername, targetUri, callback);
952
                }
953

    
954
                @Override
955
                public void onError(Throwable t) {
956
                    GWT.log("", t);
957
                                        setError(t);
958
                    if (t instanceof RestException) {
959
                        displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText());
960
                    }
961
                    else
962
                        displayError("System error unable to copy file: "+t.getMessage());
963
                }
964

    
965
                                @Override
966
                                protected void onUnauthorized(Response response) {
967
                                        sessionExpired();
968
                                }
969
            };
970
            copyFile.setHeader("X-Auth-Token", getToken());
971
            copyFile.setHeader("X-Copy-From", URL.encodePathSegment(file.getUri()));
972
            if (!file.getOwner().equals(targetUsername))
973
                    copyFile.setHeader("X-Source-Account", URL.encodePathSegment(file.getOwner()));
974
            copyFile.setHeader("Content-Type", file.getContentType());
975
            Scheduler.get().scheduleDeferred(copyFile);
976
        }
977
        else  if (callback != null) {
978
            callback.execute();
979
        }
980
    }
981

    
982
    public void copySubfolders(final Iterator<Folder> iter, final String targetUsername, final String targetUri, final Command callback) {
983
        if (iter.hasNext()) {
984
            final Folder f = iter.next();
985
            copyFolder(f, targetUsername, targetUri, new Command() {
986
                                
987
                                @Override
988
                                public void execute() {
989
                                        copySubfolders(iter, targetUsername, targetUri, callback);
990
                                }
991
                        });
992
        }
993
        else  if (callback != null) {
994
            callback.execute();
995
        }
996
    }
997

    
998
    public void copyFolder(final Folder f, final String targetUsername, final String targetUri, final Command callback) {
999
        String path = targetUri + "/" + f.getName();
1000
        PutRequest createFolder = new PutRequest(getApiPath(), targetUsername, path) {
1001
            @Override
1002
            public void onSuccess(Resource result) {
1003
                    GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, getApiPath(), f.getOwner(), "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()), f) {
1004

    
1005
                                        @Override
1006
                                        public void onSuccess(final Folder _f) {
1007
                                Iterator<File> iter = _f.getFiles().iterator();
1008
                                copyFiles(iter, targetUsername, targetUri + "/" + _f.getName(), new Command() {
1009
                                    @Override
1010
                                    public void execute() {
1011
                                        Iterator<Folder> iterf = _f.getSubfolders().iterator();
1012
                                        copySubfolders(iterf, targetUsername, targetUri + "/" + _f.getName(), callback);
1013
                                    }
1014
                                });
1015
                                        }
1016

    
1017
                                        @Override
1018
                                        public void onError(Throwable t) {
1019
                                GWT.log("", t);
1020
                                                setError(t);
1021
                                if (t instanceof RestException) {
1022
                                    displayError("Unable to get folder: " + ((RestException) t).getHttpStatusText());
1023
                                }
1024
                                else
1025
                                    displayError("System error getting folder: " + t.getMessage());
1026
                                        }
1027

    
1028
                                        @Override
1029
                                        protected void onUnauthorized(Response response) {
1030
                                                sessionExpired();
1031
                                        }
1032
                                };
1033
                                getFolder.setHeader("X-Auth-Token", getToken());
1034
                                Scheduler.get().scheduleDeferred(getFolder);
1035
            }
1036

    
1037
            @Override
1038
            public void onError(Throwable t) {
1039
                GWT.log("", t);
1040
                                setError(t);
1041
               if (t instanceof RestException) {
1042
                    displayError("Unable to create folder: " + ((RestException) t).getHttpStatusText());
1043
                }
1044
                else
1045
                    displayError("System error creating folder: " + t.getMessage());
1046
            }
1047

    
1048
                        @Override
1049
                        protected void onUnauthorized(Response response) {
1050
                                sessionExpired();
1051
                        }
1052
        };
1053
        createFolder.setHeader("X-Auth-Token", getToken());
1054
        createFolder.setHeader("Accept", "*/*");
1055
        createFolder.setHeader("Content-Length", "0");
1056
        createFolder.setHeader("Content-Type", "application/folder");
1057
        Scheduler.get().scheduleDeferred(createFolder);
1058
    }
1059
    
1060
    public void addSelectionModel(@SuppressWarnings("rawtypes") SingleSelectionModel model) {
1061
            selectionModels.add(model);
1062
    }
1063

    
1064
        public OtherSharedTreeView getOtherSharedTreeView() {
1065
                return otherSharedTreeView;
1066
        }
1067

    
1068
        public void updateTrash(boolean showFiles, Command callback) {
1069
                updateFolder(trash, showFiles, callback);
1070
        }
1071

    
1072
        public void updateGroupsNode() {
1073
                groupTreeView.updateGroupNode(null);
1074
        }
1075

    
1076
        public void addGroup(String groupname) {
1077
                Group newGroup = new Group(groupname);
1078
                account.addGroup(newGroup);
1079
                groupTreeView.updateGroupNode(null);
1080
        }
1081

    
1082
        public void removeGroup(Group group) {
1083
                account.removeGroup(group);
1084
                updateGroupsNode();
1085
        }
1086

    
1087
        public TreeView getSelectedTree() {
1088
                return selectedTree;
1089
        }
1090
        
1091
        public Folder getSelection() {
1092
                return selectedTree.getSelection();
1093
        }
1094

    
1095
        public void showFolderStatistics(int folderFileCount) {
1096
                numOfFiles.setHTML(String.valueOf(folderFileCount));
1097
        }
1098

    
1099
        public GroupTreeView getGroupTreeView() {
1100
                return groupTreeView;
1101
        }
1102

    
1103
        public void sessionExpired() {
1104
                new SessionExpiredDialog(this).center();
1105
        }
1106

    
1107
        public void updateRootFolder(Command callback) {
1108
                updateFolder(account.getPithos(), false, callback);
1109
        }
1110

    
1111
        void createMySharedTree() {
1112
                mysharedTreeSelectionModel = new SingleSelectionModel<Folder>();
1113
                mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
1114
                    @Override
1115
                    public void onSelectionChange(SelectionChangeEvent event) {
1116
                        if (mysharedTreeSelectionModel.getSelectedObject() != null) {
1117
                            deselectOthers(mysharedTreeView, mysharedTreeSelectionModel);
1118
                            upload.setEnabled(false);
1119
                            updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
1120
                        }
1121
                        showRelevantToolbarButtons();
1122
                     }
1123
                });
1124
                selectionModels.add(mysharedTreeSelectionModel);
1125
                mysharedTreeViewModel = new MysharedTreeViewModel(Pithos.this, mysharedTreeSelectionModel);
1126
                mysharedTreeViewModel.initialize(new Command() {
1127
                        
1128
                        @Override
1129
                        public void execute() {
1130
                            mysharedTreeView = new MysharedTreeView(mysharedTreeViewModel);
1131
                                trees.insert(mysharedTreeView, 2);
1132
                                treeViews.add(mysharedTreeView);
1133
                                createOtherSharedTree();
1134
                        }
1135
                });
1136
        }
1137

    
1138
        void createOtherSharedTree() {
1139
                otherSharedTreeSelectionModel = new SingleSelectionModel<Folder>();
1140
                otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
1141
                    @Override
1142
                    public void onSelectionChange(SelectionChangeEvent event) {
1143
                        if (otherSharedTreeSelectionModel.getSelectedObject() != null) {
1144
                            deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel);
1145
                            otherSharedTreeView.addStyleName("cellTreeWidget-selectedTree");
1146
                            applyPermissions(otherSharedTreeSelectionModel.getSelectedObject());
1147
                            updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
1148
                        }
1149
                        showRelevantToolbarButtons();
1150
                     }
1151
                });
1152
                selectionModels.add(otherSharedTreeSelectionModel);
1153
                otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel);
1154
                otherSharedTreeViewModel.initialize(new Command() {
1155
                        
1156
                        @Override
1157
                        public void execute() {
1158
                            otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel);
1159
                                trees.insert(otherSharedTreeView, 3);
1160
                                treeViews.add(otherSharedTreeView);
1161
                        }
1162
                });
1163
        }
1164

    
1165
        public native void log1(String message)/*-{
1166
                $wnd.console.log(message);
1167
        }-*/;
1168

    
1169
        public String getErrorData() {
1170
                if (error != null)
1171
                        return error.toString();
1172
                return "";
1173
        }
1174
        
1175
        public void setError(Throwable t) {
1176
                error = t;
1177
        }
1178
        
1179
        public void showRelevantToolbarButtons() {
1180
                toolbar.showRelevantButtons();
1181
        }
1182

    
1183
        public FileUploadDialog getFileUploadDialog() {
1184
                if (fileUploadDialog == null)
1185
                        fileUploadDialog = new FileUploadDialog(this);
1186
                return fileUploadDialog;
1187
        }
1188

    
1189
        public void hideUploadIndicator() {
1190
                upload.removeStyleName("pithos-uploadButton-loading");
1191
                upload.setTitle("");
1192
        }
1193
        
1194
        public void showUploadIndicator() {
1195
                upload.addStyleName("pithos-uploadButton-loading");
1196
                upload.setTitle("Upload in progress. Click for details.");
1197
        }
1198

    
1199
        public void scheduleFolderHeadCommand(final Folder folder, final Command callback) {
1200
                HeadRequest<Folder> headFolder = new HeadRequest<Folder>(Folder.class, getApiPath(), folder.getOwner(), folder.getUri(), folder) {
1201

    
1202
                        @Override
1203
                        public void onSuccess(Folder _result) {
1204
                                if (callback != null)
1205
                                        callback.execute();
1206
                        }
1207

    
1208
                        @Override
1209
                        public void onError(Throwable t) {
1210
                        if (t instanceof RestException) {
1211
                                if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) {
1212
                        final String path = folder.getUri();
1213
                        PutRequest newFolder = new PutRequest(getApiPath(), folder.getOwner(), path) {
1214
                            @Override
1215
                            public void onSuccess(Resource _result) {
1216
                                    scheduleFolderHeadCommand(folder, callback);
1217
                            }
1218

    
1219
                            @Override
1220
                            public void onError(Throwable _t) {
1221
                                GWT.log("", _t);
1222
                                                        setError(_t);
1223
                                if(_t instanceof RestException){
1224
                                    displayError("Unable to create folder: " + ((RestException) _t).getHttpStatusText());
1225
                                }
1226
                                else
1227
                                    displayError("System error creating folder: " + _t.getMessage());
1228
                            }
1229

    
1230
                                            @Override
1231
                                            protected void onUnauthorized(Response response) {
1232
                                                    sessionExpired();
1233
                                            }
1234
                        };
1235
                        newFolder.setHeader("X-Auth-Token", getToken());
1236
                        newFolder.setHeader("Content-Type", "application/folder");
1237
                        newFolder.setHeader("Accept", "*/*");
1238
                        newFolder.setHeader("Content-Length", "0");
1239
                        Scheduler.get().scheduleDeferred(newFolder);
1240
                                }
1241
                                else
1242
                                        displayError("Error heading folder: " + ((RestException) t).getHttpStatusText());
1243
                        }
1244
                        else
1245
                            displayError("System error heading folder: " + t.getMessage());
1246

    
1247
                        GWT.log("Error heading folder", t);
1248
                                setError(t);
1249
                        }
1250

    
1251
                        @Override
1252
                        protected void onUnauthorized(Response response) {
1253
                                sessionExpired();
1254
                        }
1255
                };
1256
                headFolder.setHeader("X-Auth-Token", getToken());
1257
                Scheduler.get().scheduleDeferred(headFolder);
1258
        }
1259

    
1260
        public void scheduleFileHeadCommand(File f, final Command callback) {
1261
                HeadRequest<File> headFile = new HeadRequest<File>(File.class, getApiPath(), f.getOwner(), f.getUri(), f) {
1262

    
1263
                        @Override
1264
                        public void onSuccess(File _result) {
1265
                                if (callback != null)
1266
                                        callback.execute();
1267
                        }
1268

    
1269
                        @Override
1270
                        public void onError(Throwable t) {
1271
                        GWT.log("Error heading file", t);
1272
                                setError(t);
1273
                        if (t instanceof RestException)
1274
                            displayError("Error heading file: " + ((RestException) t).getHttpStatusText());
1275
                        else
1276
                            displayError("System error heading file: " + t.getMessage());
1277
                        }
1278

    
1279
                        @Override
1280
                        protected void onUnauthorized(Response response) {
1281
                                sessionExpired();
1282
                        }
1283
                };
1284
                headFile.setHeader("X-Auth-Token", getToken());
1285
                Scheduler.get().scheduleDeferred(headFile);
1286
        }
1287
}