Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (45.4 kB)

1
/*
2
 * Copyright 2011 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.NewFolderCommand;
38
import gr.grnet.pithos.web.client.commands.PropertiesCommand;
39
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
40
import gr.grnet.pithos.web.client.foldertree.AccountResource;
41
import gr.grnet.pithos.web.client.foldertree.File;
42
import gr.grnet.pithos.web.client.foldertree.Folder;
43
import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
44
import gr.grnet.pithos.web.client.foldertree.FolderTreeViewModel;
45
import gr.grnet.pithos.web.client.foldertree.Resource;
46
import gr.grnet.pithos.web.client.grouptree.Group;
47
import gr.grnet.pithos.web.client.grouptree.GroupTreeView;
48
import gr.grnet.pithos.web.client.grouptree.GroupTreeViewModel;
49
import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeView;
50
import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeViewModel;
51
import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeView;
52
import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeViewModel;
53
import gr.grnet.pithos.web.client.rest.DeleteRequest;
54
import gr.grnet.pithos.web.client.rest.GetRequest;
55
import gr.grnet.pithos.web.client.rest.HeadRequest;
56
import gr.grnet.pithos.web.client.rest.PutRequest;
57
import gr.grnet.pithos.web.client.rest.RestException;
58
import gr.grnet.pithos.web.client.tagtree.Tag;
59

    
60
import java.util.ArrayList;
61
import java.util.HashMap;
62
import java.util.Iterator;
63
import java.util.List;
64
import java.util.Set;
65

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

    
110
/**
111
 * Entry point classes define <code>onModuleLoad()</code>.
112
 */
113
public class Pithos implements EntryPoint, ResizeHandler {
114

    
115
        public static final String HOME_CONTAINER = "pithos";
116

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

    
125
    public String getUsername() {
126
        return username;
127
    }
128

    
129
    public void setAccount(AccountResource acct) {
130
        account = acct;
131
    }
132

    
133
    public AccountResource getAccount() {
134
        return account;
135
    }
136

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

    
141
    public void updateGroupNode(Group group) {
142
        groupTreeView.updateGroupNode(group);
143
    }
144

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

    
157
    public List<Tag> getAllTags() {
158
        List<Tag> tagList = new ArrayList<Tag>();
159
        for (Folder f : account.getContainers()) {
160
            for (String t : f.getTags()) {
161
                tagList.add(new Tag(t));
162
            }
163
        }
164
        return tagList;
165
    }
166

    
167
    public MysharedTreeView getMySharedTreeView() {
168
        return mysharedTreeView;
169
    }
170

    
171
    /**
172
         * An aggregate image bundle that pulls together all the images for this
173
         * application into a single bundle.
174
         */
175
        public interface Images extends TopPanel.Images, FileList.Images, ToolsMenu.Images {
176

    
177
                @Source("gr/grnet/pithos/resources/document.png")
178
                ImageResource folders();
179

    
180
                @Source("gr/grnet/pithos/resources/advancedsettings.png")
181
                @ImageOptions(width=32, height=32)
182
                ImageResource tools();
183
        }
184

    
185
        private Throwable error;
186
        
187
        /**
188
         * The Application Clipboard implementation;
189
         */
190
        private Clipboard clipboard = new Clipboard();
191

    
192
        /**
193
         * The top panel that contains the menu bar.
194
         */
195
        private TopPanel topPanel;
196

    
197
        /**
198
         * The panel that contains the various system messages.
199
         */
200
        private MessagePanel messagePanel = new MessagePanel(this, Pithos.images);
201

    
202
        /**
203
         * The bottom panel that contains the status bar.
204
         */
205
        private StatusPanel statusPanel = null;
206

    
207
        /**
208
         * The file list widget.
209
         */
210
        private FileList fileList;
211

    
212
        /**
213
         * The tab panel that occupies the right side of the screen.
214
         */
215
        private VerticalPanel inner = new VerticalPanel();
216

    
217

    
218
        /**
219
         * The split panel that will contain the left and right panels.
220
         */
221
        private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
222

    
223
        /**
224
         * The currently selected item in the application, for use by the Edit menu
225
         * commands. Potential types are Folder, File, User and Group.
226
         */
227
        private Object currentSelection;
228

    
229
        public HashMap<String, String> userFullNameMap = new HashMap<String, String>();
230

    
231
    private String username = null;
232

    
233
    /**
234
     * The authentication token of the current user.
235
     */
236
    private String token;
237

    
238
    VerticalPanel trees;
239
    
240
    SingleSelectionModel<Folder> folderTreeSelectionModel;
241
    FolderTreeViewModel folderTreeViewModel;
242
    FolderTreeView folderTreeView;
243

    
244
    SingleSelectionModel<Folder> mysharedTreeSelectionModel;
245
    MysharedTreeViewModel mysharedTreeViewModel;
246
    MysharedTreeView mysharedTreeView = null;;
247

    
248
    protected SingleSelectionModel<Folder> otherSharedTreeSelectionModel;
249
    OtherSharedTreeViewModel otherSharedTreeViewModel;
250
    OtherSharedTreeView otherSharedTreeView = null;
251

    
252
    GroupTreeViewModel groupTreeViewModel;
253
    private GroupTreeView groupTreeView;
254

    
255
    TreeView selectedTree;
256
    protected AccountResource account;
257
    
258
    Folder trash;
259
    
260
    List<Composite> treeViews = new ArrayList<Composite>();
261

    
262
    @SuppressWarnings("rawtypes") List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>();
263
    
264
    Button upload;
265
    
266
    private HTML usedBytes;
267
    
268
    private HTML totalBytes;
269
    
270
    private HTML usedPercent;
271
    
272
    private HTML numOfFiles;
273
    
274
    private Anchor refreshButton;
275

    
276
    private Anchor toolsButton;
277

    
278
        @Override
279
        public void onModuleLoad() {
280
                if (parseUserCredentials())
281
            initialize();
282
        }
283

    
284
    private void initialize() {
285
            boolean bareContent = Window.Location.getParameter("noframe") != null;
286
            String contentWidth = bareContent ? "100%" : "75%";
287

    
288
            VerticalPanel outer = new VerticalPanel();
289
        outer.setWidth("100%");
290
            if (!bareContent) {
291
                    outer.addStyleName("pithos-outer");
292
            }
293

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

    
317
        messagePanel.setVisible(false);
318
        header.add(messagePanel);
319
        header.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);
320
        header.setCellVerticalAlignment(messagePanel, HasVerticalAlignment.ALIGN_MIDDLE);
321

    
322
        FlowPanel toolbar = new FlowPanel();
323
        toolbar.getElement().setId("toolbar");
324
        toolbar.addStyleName("clearfix");
325
        toolbar.getElement().getStyle().setDisplay(Display.BLOCK);
326

    
327
        Anchor newFolderButton = new Anchor("<span class='ico'></span><span class='title'>New folder</span>", true);
328
        newFolderButton.getElement().setId("newfolder-button");
329
        newFolderButton.addStyleName("pithos-toolbarItem");
330
        newFolderButton.addClickHandler(new ClickHandler() {
331
                        
332
                        @Override
333
                        public void onClick(ClickEvent event) {
334
                                Folder folder = getSelectedTree().getSelection();
335
                                if (folder != null) {
336
                                Boolean[] permissions = folder.getPermissions().get(getUsername());
337
                                    boolean canWrite = folder.getOwner().equals(getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
338
                                    
339
                                    if (!folder.isInTrash() && canWrite)
340
                                            new NewFolderCommand(Pithos.this, null, folder).execute();
341
                                }
342
                        }
343
                });
344
        toolbar.add(newFolderButton);
345

    
346
        Anchor shareFolderButton = new Anchor("<span class='ico'></span><span class='title'>Share folder</span>", true);
347
        shareFolderButton.getElement().setId("sharefolder-button");
348
        shareFolderButton.addStyleName("pithos-toolbarItem");
349
        shareFolderButton.addClickHandler(new ClickHandler() {
350
                        
351
                        @Override
352
                        public void onClick(ClickEvent event) {
353
                                Folder folder = getSelectedTree().getSelection();
354
                                if (folder != null) {
355
                                Boolean[] permissions = folder.getPermissions().get(getUsername());
356
                                    boolean canWrite = folder.getOwner().equals(getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
357
                                    boolean isFolderTreeSelected = selectedTree.equals(getFolderTreeView());
358
                                    
359
                                    if (!folder.isInTrash() && canWrite && isFolderTreeSelected && !folder.isContainer())
360
                                            new PropertiesCommand(Pithos.this, null, folder, PropertiesCommand.PERMISSIONS).execute();
361
                                }
362
                        }
363
                });
364
        toolbar.add(shareFolderButton);
365

    
366
        refreshButton = new Anchor("<span class='ico'></span><span class='title'>Refresh</span>", true);
367
        refreshButton.getElement().setId("refresh-button");
368
        refreshButton.addStyleName("pithos-toolbarItem");
369
        refreshButton.addClickHandler(new ClickHandler() {
370
                        
371
                        @Override
372
                        public void onClick(ClickEvent event) {
373
                            boolean isFolderTreeSelected = selectedTree.equals(getFolderTreeView());
374
                            boolean otherSharedTreeSelected = selectedTree.equals(getOtherSharedTreeView());
375
                            Folder folder = getSelectedTree().getSelection();
376
                            
377
                            if (folder != null && (isFolderTreeSelected || otherSharedTreeSelected))
378
                                    updateFolder(folder, true, new Command() {
379
                                            
380
                                            @Override
381
                                            public void execute() {
382
                                                    updateStatistics();
383
                                            }
384
                                    });
385
                        }
386
                });
387
        toolbar.add(refreshButton);
388

    
389
        toolsButton = new Anchor("<span class='ico'></span><span class='title'>More...</span>", true);
390
        toolsButton.getElement().setId("tools-button");
391
        toolsButton.addStyleName("pithos-toolbarItem");
392
        toolsButton.addClickHandler(new ClickHandler() {
393
                        
394
                        @Override
395
                        public void onClick(ClickEvent event) {
396
                ToolsMenu menu = new ToolsMenu(Pithos.this, images, getSelectedTree(), getSelectedTree().getSelection(), getFileList().getSelectedFiles());
397
                if (!menu.isEmpty()) {
398
                            menu.setPopupPosition(event.getClientX(), event.getClientY());
399
                            menu.show();
400
                }
401
                        }
402
                });
403
        toolbar.add(toolsButton);
404
  
405
        header.add(toolbar);
406
        header.setCellHorizontalAlignment(toolbar, HasHorizontalAlignment.ALIGN_CENTER);
407
        header.setCellVerticalAlignment(toolbar, HasVerticalAlignment.ALIGN_MIDDLE);
408
        
409
        HorizontalPanel folderStatistics = new HorizontalPanel();
410
        folderStatistics.addStyleName("pithos-folderStatistics");
411
        numOfFiles = new HTML();
412
        folderStatistics.add(numOfFiles);
413
        folderStatistics.setCellVerticalAlignment(numOfFiles, HasVerticalAlignment.ALIGN_MIDDLE);
414
        HTML numOfFilesLabel = new HTML("&nbsp;Files");
415
        folderStatistics.add(numOfFilesLabel);
416
        folderStatistics.setCellVerticalAlignment(numOfFilesLabel, HasVerticalAlignment.ALIGN_MIDDLE);
417
        header.add(folderStatistics);
418
        header.setCellHorizontalAlignment(folderStatistics, HasHorizontalAlignment.ALIGN_RIGHT);
419
        header.setCellVerticalAlignment(folderStatistics, HasVerticalAlignment.ALIGN_MIDDLE);
420
        header.setCellWidth(folderStatistics, "40px");
421
        outer.add(header);
422
        outer.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_CENTER);
423
        // Inner contains the various lists.nner
424
        inner.sinkEvents(Event.ONCONTEXTMENU);
425
        inner.setWidth("100%");
426

    
427
        folderTreeSelectionModel = new SingleSelectionModel<Folder>();
428
        folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
429
            @Override
430
            public void onSelectionChange(SelectionChangeEvent event) {
431
                if (folderTreeSelectionModel.getSelectedObject() != null) {
432
                    deselectOthers(folderTreeView, folderTreeSelectionModel);
433
                    applyPermissions(folderTreeSelectionModel.getSelectedObject());
434
                    Folder f = folderTreeSelectionModel.getSelectedObject();
435
                            updateFolder(f, true, new Command() {
436
                                    
437
                                    @Override
438
                                    public void execute() {
439
                                            updateStatistics();
440
                                    }
441
                            });
442
                }
443
            }
444
        });
445
        selectionModels.add(folderTreeSelectionModel);
446

    
447
        folderTreeViewModel = new FolderTreeViewModel(this, folderTreeSelectionModel);
448
        folderTreeView = new FolderTreeView(folderTreeViewModel);
449
        treeViews.add(folderTreeView);
450
        
451
        fileList = new FileList(this, images, folderTreeView);
452
        inner.add(fileList);
453

    
454
        groupTreeViewModel = new GroupTreeViewModel(this);
455
        groupTreeView = new GroupTreeView(groupTreeViewModel);
456
        treeViews.add(groupTreeView);
457
        
458
        trees = new VerticalPanel();
459
        trees.setWidth("100%");
460

    
461
        
462
        HorizontalPanel treeHeader = new HorizontalPanel();
463
        treeHeader.addStyleName("pithos-treeHeader");
464
        treeHeader.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
465
        treeHeader.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
466
        HorizontalPanel statistics = new HorizontalPanel();
467
        statistics.addStyleName("pithos-statistics");
468
        statistics.add(new HTML("Used:&nbsp;"));
469
        usedBytes = new HTML();
470
        statistics.add(usedBytes);
471
        statistics.add(new HTML("&nbsp;of&nbsp;"));
472
        totalBytes = new HTML();
473
        statistics.add(totalBytes);
474
        statistics.add(new HTML("&nbsp;("));
475
        usedPercent = new HTML();
476
        statistics.add(usedPercent);
477
        statistics.add(new HTML(")"));
478
        treeHeader.add(statistics);
479
        treeHeader.setCellHorizontalAlignment(statistics, HasHorizontalAlignment.ALIGN_LEFT);
480
        trees.add(treeHeader);
481

    
482
        trees.add(folderTreeView);
483
        trees.add(groupTreeView);
484
        // Add the left and right panels to the split panel.
485
        splitPanel.setLeftWidget(trees);
486
        splitPanel.setRightWidget(inner);
487
        splitPanel.setSplitPosition("35%");
488
        splitPanel.setSize("100%", "100%");
489
        splitPanel.addStyleName("pithos-splitPanel");
490
        splitPanel.setWidth(contentWidth);
491
        outer.add(splitPanel);
492
        outer.setCellHorizontalAlignment(splitPanel, HasHorizontalAlignment.ALIGN_CENTER);
493

    
494
        if (!bareContent) {
495
                statusPanel = new StatusPanel();
496
                statusPanel.setWidth("100%");
497
                outer.add(statusPanel);
498
                outer.setCellHorizontalAlignment(statusPanel, HasHorizontalAlignment.ALIGN_CENTER);
499
        }
500
        else
501
                splitPanel.addStyleName("pithos-splitPanel-noframe");
502

    
503
        // Hook the window resize event, so that we can adjust the UI.
504
        Window.addResizeHandler(this);
505
        // Clear out the window's built-in margin, because we want to take
506
        // advantage of the entire client area.
507
        Window.setMargin("0px");
508
        // Finally, add the outer panel to the RootPanel, so that it will be
509
        // displayed.
510
        RootPanel.get().add(outer);
511
        // Call the window resized handler to get the initial sizes setup. Doing
512
        // this in a deferred command causes it to occur after all widgets'
513
        // sizes have been computed by the browser.
514
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
515

    
516
            @Override
517
            public void execute() {
518
                onWindowResized(Window.getClientHeight());
519
            }
520
        });
521

    
522
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
523
            @Override
524
            public void execute() {
525
                fetchAccount(new Command() {
526
                                        
527
                                        @Override
528
                                        public void execute() {
529
                                if (!account.hasHomeContainer())
530
                                    createHomeContainer(account, this);
531
                                else if (!account.hasTrashContainer())
532
                                        createTrashContainer(this);
533
                                else {
534
                                        for (Folder f : account.getContainers())
535
                                                if (f.getName().equals(Pithos.TRASH_CONTAINER)) {
536
                                                        trash = f;
537
                                                        break;
538
                                                }
539
                                    folderTreeViewModel.initialize(account, new Command() {
540
                                                                
541
                                                                @Override
542
                                                                public void execute() {
543
                                                    createMySharedTree();
544
                                                                }
545
                                                        });
546
                                    groupTreeViewModel.initialize();
547
                                    showStatistics();
548
                                }
549
                                        }
550
                                });
551
            }
552
        });
553
        
554
//        Scheduler.get().scheduleDeferred(new Command() {
555
//                        
556
//                        @Override
557
//                        public void execute() {
558
//                                displayError("lalala");
559
//                                
560
//                        }
561
//                });
562
    }
563

    
564
    public void applyPermissions(Folder f) {
565
            if (f != null) {
566
                    if (f.isInTrash())
567
                            upload.setEnabled(false);
568
                    else {
569
                            Boolean[] perms = f.getPermissions().get(username);
570
                            if (f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) {
571
                                    upload.setEnabled(true);
572
                            }
573
                            else
574
                                    upload.setEnabled(false);
575
                    }
576
            }
577
            else
578
                    upload.setEnabled(false);
579
        }
580

    
581
        @SuppressWarnings({ "rawtypes", "unchecked" })
582
        public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) {
583
            selectedTree = _selectedTree;
584
            
585
            for (Composite c : treeViews)
586
                    if (c.equals(selectedTree))
587
                            c.addStyleName("cellTreeWidget-selectedTree");
588
                    else
589
                            c.removeStyleName("cellTreeWidget-selectedTree");
590
            
591
        for (SingleSelectionModel s : selectionModels)
592
            if (!s.equals(model))
593
                s.setSelected(s.getSelectedObject(), false);
594
    }
595

    
596
    public void showFiles(final Folder f) {
597
        Set<File> files = f.getFiles();
598
        showFiles(files);
599
    }
600

    
601
    public void showFiles(Set<File> files) {
602
        fileList.setFiles(new ArrayList<File>(files));
603
    }
604

    
605
    protected void fetchFile(final Iterator<File> iter, final Set<File> files) {
606
        if (iter.hasNext()) {
607
            File file = iter.next();
608
            String path = file.getUri() + "?format=json";
609
            GetRequest<File> getFile = new GetRequest<File>(File.class, getApiPath(), username, path, file) {
610
                @Override
611
                public void onSuccess(File _result) {
612
                    fetchFile(iter, files);
613
                }
614

    
615
                @Override
616
                public void onError(Throwable t) {
617
                    GWT.log("Error getting file", t);
618
                                        setError(t);
619
                    if (t instanceof RestException)
620
                        displayError("Error getting file: " + ((RestException) t).getHttpStatusText());
621
                    else
622
                        displayError("System error fetching file: " + t.getMessage());
623
                }
624

    
625
                                @Override
626
                                protected void onUnauthorized(Response response) {
627
                                        sessionExpired();
628
                                }
629
            };
630
            getFile.setHeader("X-Auth-Token", "0000");
631
            Scheduler.get().scheduleDeferred(getFile);
632
        }
633
        else
634
            fileList.setFiles(new ArrayList<File>(files));
635
    }
636

    
637
    /**
638
         * Parse and store the user credentials to the appropriate fields.
639
         */
640
        private boolean parseUserCredentials() {
641
        username = Window.Location.getParameter("user");
642
        token = Window.Location.getParameter("token");
643
        Configuration conf = (Configuration) GWT.create(Configuration.class);
644
        if (username == null || username.length() == 0 || token == null || token.length() == 0) {
645
            String cookie = conf.authCookie();
646
            String auth = Cookies.getCookie(cookie);
647
            if (auth == null) {
648
                authenticateUser();
649
                return false;
650
            }
651
            if (auth.startsWith("\""))
652
                    auth = auth.substring(1);
653
            if (auth.endsWith("\""))
654
                    auth = auth.substring(0, auth.length() - 1);
655
                        String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2);
656
                        if (authSplit.length != 2) {
657
                            authenticateUser();
658
                            return false;
659
                        }
660
                        username = authSplit[0];
661
                        token = authSplit[1];
662
                        return true;
663
        }
664
        
665
                Cookies.setCookie(conf.authCookie(), username + conf.cookieSeparator() + token, null, "", "/", false);
666
                return true;
667
    }
668

    
669
    /**
670
         * Redirect the user to the login page for authentication.
671
         */
672
        protected void authenticateUser() {
673
                Configuration conf = (Configuration) GWT.create(Configuration.class);
674
        Window.Location.assign(conf.loginUrl() + "?next=" + Window.Location.getHref());
675
        }
676

    
677
        protected void fetchAccount(final Command callback) {
678
        String path = "?format=json";
679

    
680
        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), username, path) {
681
            @Override
682
            public void onSuccess(AccountResource _result) {
683
                account = _result;
684
                if (callback != null)
685
                        callback.execute();
686
            }
687

    
688
            @Override
689
            public void onError(Throwable t) {
690
                GWT.log("Error getting account", t);
691
                                setError(t);
692
                if (t instanceof RestException)
693
                    displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
694
                else
695
                    displayError("System error fetching user data: " + t.getMessage());
696
            }
697

    
698
                        @Override
699
                        protected void onUnauthorized(Response response) {
700
                                sessionExpired();
701
                        }
702
        };
703
        getAccount.setHeader("X-Auth-Token", token);
704
        Scheduler.get().scheduleDeferred(getAccount);
705
    }
706

    
707
    public void updateStatistics() {
708
            HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), username, "", account) {
709

    
710
                        @Override
711
                        public void onSuccess(AccountResource _result) {
712
                                showStatistics();
713
                        }
714

    
715
                        @Override
716
                        public void onError(Throwable t) {
717
                GWT.log("Error getting account", t);
718
                                setError(t);
719
                if (t instanceof RestException)
720
                    displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
721
                else
722
                    displayError("System error fetching user data: " + t.getMessage());
723
                        }
724

    
725
                        @Override
726
                        protected void onUnauthorized(Response response) {
727
                                sessionExpired();
728
                        }
729
                };
730
                headAccount.setHeader("X-Auth-Token", token);
731
                Scheduler.get().scheduleDeferred(headAccount);
732
        }
733

    
734
        protected void showStatistics() {
735
            usedBytes.setHTML(String.valueOf(account.getFileSizeAsString()));
736
            totalBytes.setHTML(String.valueOf(account.getQuotaAsString()));
737
            NumberFormat nf = NumberFormat.getPercentFormat();
738
            usedPercent.setHTML(nf.format(account.getUsedPercentage()));
739
        }
740

    
741
        protected void createHomeContainer(final AccountResource _account, final Command callback) {
742
        String path = "/" + Pithos.HOME_CONTAINER;
743
        PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
744
            @Override
745
            public void onSuccess(Resource result) {
746
                    if (!_account.hasTrashContainer())
747
                            createTrashContainer(callback);
748
                    else
749
                            fetchAccount(callback);
750
            }
751

    
752
            @Override
753
            public void onError(Throwable t) {
754
                GWT.log("Error creating pithos", t);
755
                                setError(t);
756
                if (t instanceof RestException)
757
                    displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
758
                else
759
                    displayError("System error Error creating pithos: " + t.getMessage());
760
            }
761

    
762
                        @Override
763
                        protected void onUnauthorized(Response response) {
764
                                sessionExpired();
765
                        }
766
        };
767
        createPithos.setHeader("X-Auth-Token", getToken());
768
        Scheduler.get().scheduleDeferred(createPithos);
769
    }
770

    
771
    protected void createTrashContainer(final Command callback) {
772
        String path = "/" + Pithos.TRASH_CONTAINER;
773
        PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
774
            @Override
775
            public void onSuccess(Resource result) {
776
                           fetchAccount(callback);
777
            }
778

    
779
            @Override
780
            public void onError(Throwable t) {
781
                GWT.log("Error creating pithos", t);
782
                                setError(t);
783
                if (t instanceof RestException)
784
                    displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
785
                else
786
                    displayError("System error Error creating pithos: " + t.getMessage());
787
            }
788

    
789
                        @Override
790
                        protected void onUnauthorized(Response response) {
791
                                sessionExpired();
792
                        }
793
        };
794
        createPithos.setHeader("X-Auth-Token", getToken());
795
        Scheduler.get().scheduleDeferred(createPithos);
796
    }
797

    
798
    /**
799
         * Creates an HTML fragment that places an image & caption together, for use
800
         * in a group header.
801
         *
802
         * @param imageProto an image prototype for an image
803
         * @param caption the group caption
804
         * @return the header HTML fragment
805
         */
806
        private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) {
807
                String captionHTML = "<table class='caption' cellpadding='0' " 
808
                + "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML() 
809
                + "</td><td id =" + caption +" class='rcaption'><b style='white-space:nowrap'>&nbsp;" 
810
                + caption + "</b></td></tr></table>";
811
                return captionHTML;
812
        }
813

    
814
        protected void onWindowResized(int height) {
815
                // Adjust the split panel to take up the available room in the window.
816
                int newHeight = height - splitPanel.getAbsoluteTop();
817
                if (newHeight < 1)
818
                        newHeight = 1;
819
                splitPanel.setHeight("" + newHeight);
820
                inner.setHeight("" + newHeight);
821
        }
822

    
823
        @Override
824
        public void onResize(ResizeEvent event) {
825
                int height = event.getHeight();
826
                onWindowResized(height);
827
        }
828

    
829
        /**
830
         * Display an error message.
831
         *
832
         * @param msg the message to display
833
         */
834
        public void displayError(String msg) {
835
                messagePanel.displayError(msg);
836
        }
837

    
838
        /**
839
         * Display a warning message.
840
         *
841
         * @param msg the message to display
842
         */
843
        public void displayWarning(String msg) {
844
                messagePanel.displayWarning(msg);
845
        }
846

    
847
        /**
848
         * Display an informational message.
849
         *
850
         * @param msg the message to display
851
         */
852
        public void displayInformation(String msg) {
853
                messagePanel.displayInformation(msg);
854
        }
855

    
856
        /**
857
         * Retrieve the fileList.
858
         *
859
         * @return the fileList
860
         */
861
        public FileList getFileList() {
862
                return fileList;
863
        }
864

    
865
        /**
866
         * Retrieve the topPanel.
867
         *
868
         * @return the topPanel
869
         */
870
        TopPanel getTopPanel() {
871
                return topPanel;
872
        }
873

    
874
        /**
875
         * Retrieve the clipboard.
876
         *
877
         * @return the clipboard
878
         */
879
        public Clipboard getClipboard() {
880
                return clipboard;
881
        }
882

    
883
        public StatusPanel getStatusPanel() {
884
                return statusPanel;
885
        }
886

    
887
        public String getToken() {
888
                return token;
889
        }
890

    
891
        public static native void preventIESelection() /*-{
892
                $doc.body.onselectstart = function () { return false; };
893
        }-*/;
894

    
895
        public static native void enableIESelection() /*-{
896
                if ($doc.body.onselectstart != null)
897
                $doc.body.onselectstart = null;
898
        }-*/;
899

    
900
        /**
901
         * @return the absolute path of the API root URL
902
         */
903
        public String getApiPath() {
904
                Configuration conf = (Configuration) GWT.create(Configuration.class);
905
                return conf.apiPath();
906
        }
907

    
908
        /**
909
         * History support for folder navigation
910
         * adds a new browser history entry
911
         *
912
         * @param key
913
         */
914
        public void updateHistory(String key){
915
//                Replace any whitespace of the initial string to "+"
916
//                String result = key.replaceAll("\\s","+");
917
//                Add a new browser history entry.
918
//                History.newItem(result);
919
                History.newItem(key);
920
        }
921

    
922
    public void deleteFolder(final Folder folder) {
923
        String path = getApiPath() + folder.getOwner() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(folder.getPrefix()) + "&t=" + System.currentTimeMillis();
924
        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
925
        builder.setHeader("X-Auth-Token", getToken());
926
        try {
927
            builder.sendRequest("", new RequestCallback() {
928
                @Override
929
                public void onResponseReceived(Request request, Response response) {
930
                    if (response.getStatusCode() == Response.SC_OK) {
931
                        JSONValue json = JSONParser.parseStrict(response.getText());
932
                        JSONArray array = json.isArray();
933
                        int i = 0;
934
                        if (array != null) {
935
                            deleteObject(folder, i, array);
936
                        }
937
                    }
938
                }
939

    
940
                @Override
941
                public void onError(Request request, Throwable exception) {
942
                        setError(exception);
943
                    displayError("System error unable to delete folder: " + exception.getMessage());
944
                }
945
            });
946
        }
947
        catch (RequestException e) {
948
        }
949
    }
950

    
951
    void deleteObject(final Folder folder, final int i, final JSONArray array) {
952
        if (i < array.size()) {
953
            JSONObject o = array.get(i).isObject();
954
            if (o != null && !o.containsKey("subdir")) {
955
                JSONString name = o.get("name").isString();
956
                String path = "/" + folder.getContainer() + "/" + name.stringValue();
957
                DeleteRequest delete = new DeleteRequest(getApiPath(), folder.getOwner(), path) {
958
                    @Override
959
                    public void onSuccess(Resource result) {
960
                        deleteObject(folder, i + 1, array);
961
                    }
962

    
963
                    @Override
964
                    public void onError(Throwable t) {
965
                        GWT.log("", t);
966
                                                setError(t);
967
                        displayError("System error unable to delete folder: " + t.getMessage());
968
                    }
969

    
970
                                    @Override
971
                                    protected void onUnauthorized(Response response) {
972
                                            sessionExpired();
973
                                    }
974
                };
975
                delete.setHeader("X-Auth-Token", getToken());
976
                Scheduler.get().scheduleDeferred(delete);
977
            }
978
            else if (o != null) {
979
                String subdir = o.get("subdir").isString().stringValue();
980
                subdir = subdir.substring(0, subdir.length() - 1);
981
                String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(subdir) + "&t=" + System.currentTimeMillis();
982
                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
983
                builder.setHeader("X-Auth-Token", getToken());
984
                try {
985
                    builder.sendRequest("", new RequestCallback() {
986
                        @Override
987
                        public void onResponseReceived(Request request, Response response) {
988
                            if (response.getStatusCode() == Response.SC_OK) {
989
                                JSONValue json = JSONParser.parseStrict(response.getText());
990
                                JSONArray array2 = json.isArray();
991
                                if (array2 != null) {
992
                                    int l = array.size();
993
                                    for (int j=0; j<array2.size(); j++) {
994
                                        array.set(l++, array2.get(j));
995
                                    }
996
                                }
997
                                deleteObject(folder, i + 1, array);
998
                            }
999
                        }
1000

    
1001
                        @Override
1002
                        public void onError(Request request, Throwable exception) {
1003
                                setError(exception);
1004
                            displayError("System error unable to delete folder: " + exception.getMessage());
1005
                        }
1006
                    });
1007
                }
1008
                catch (RequestException e) {
1009
                }
1010
            }
1011
        }
1012
        else {
1013
            String path = folder.getUri();
1014
            DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), getUsername(), path) {
1015
                @Override
1016
                public void onSuccess(Resource result) {
1017
                    updateFolder(folder.getParent(), true, new Command() {
1018
                                                
1019
                                                @Override
1020
                                                public void execute() {
1021
                                                        updateStatistics();
1022
                                                }
1023
                                        });
1024
                }
1025

    
1026
                @Override
1027
                public void onError(Throwable t) {
1028
                    GWT.log("", t);
1029
                                        setError(t);
1030
                    if (t instanceof RestException) {
1031
                            if (((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND)
1032
                                    displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText());
1033
                            else
1034
                                    onSuccess(null);
1035
                    }
1036
                    else
1037
                        displayError("System error unable to delete folder: " + t.getMessage());
1038
                }
1039

    
1040
                                @Override
1041
                                protected void onUnauthorized(Response response) {
1042
                                        sessionExpired();
1043
                                }
1044
            };
1045
            deleteFolder.setHeader("X-Auth-Token", getToken());
1046
            Scheduler.get().scheduleDeferred(deleteFolder);
1047
        }
1048
    }
1049

    
1050
    public FolderTreeView getFolderTreeView() {
1051
        return folderTreeView;
1052
    }
1053

    
1054
    public void copyFiles(final Iterator<File> iter, final String targetUsername, final String targetUri, final Command callback) {
1055
        if (iter.hasNext()) {
1056
            File file = iter.next();
1057
            String path = targetUri + "/" + file.getName();
1058
            PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) {
1059
                @Override
1060
                public void onSuccess(Resource result) {
1061
                    copyFiles(iter, targetUsername, targetUri, callback);
1062
                }
1063

    
1064
                @Override
1065
                public void onError(Throwable t) {
1066
                    GWT.log("", t);
1067
                                        setError(t);
1068
                    if (t instanceof RestException) {
1069
                        displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText());
1070
                    }
1071
                    else
1072
                        displayError("System error unable to copy file: "+t.getMessage());
1073
                }
1074

    
1075
                                @Override
1076
                                protected void onUnauthorized(Response response) {
1077
                                        sessionExpired();
1078
                                }
1079
            };
1080
            copyFile.setHeader("X-Auth-Token", getToken());
1081
            copyFile.setHeader("X-Copy-From", URL.encodePathSegment(file.getUri()));
1082
            if (!file.getOwner().equals(targetUsername))
1083
                    copyFile.setHeader("X-Source-Account", URL.encodePathSegment(file.getOwner()));
1084
            copyFile.setHeader("Content-Type", file.getContentType());
1085
            Scheduler.get().scheduleDeferred(copyFile);
1086
        }
1087
        else  if (callback != null) {
1088
            callback.execute();
1089
        }
1090
    }
1091

    
1092
    public void copySubfolders(final Iterator<Folder> iter, final String targetUsername, final String targetUri, final Command callback) {
1093
        if (iter.hasNext()) {
1094
            final Folder f = iter.next();
1095
            copyFolder(f, targetUsername, targetUri, new Command() {
1096
                                
1097
                                @Override
1098
                                public void execute() {
1099
                                        copySubfolders(iter, targetUsername, targetUri, callback);
1100
                                }
1101
                        });
1102
        }
1103
        else  if (callback != null) {
1104
            callback.execute();
1105
        }
1106
    }
1107

    
1108
    public void copyFolder(final Folder f, final String targetUsername, final String targetUri, final Command callback) {
1109
        String path = targetUri + "/" + f.getName();
1110
        PutRequest createFolder = new PutRequest(getApiPath(), targetUsername, path) {
1111
            @Override
1112
            public void onSuccess(Resource result) {
1113
                    GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, getApiPath(), f.getOwner(), "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()), f) {
1114

    
1115
                                        @Override
1116
                                        public void onSuccess(final Folder _f) {
1117
                                Iterator<File> iter = _f.getFiles().iterator();
1118
                                copyFiles(iter, targetUsername, targetUri + "/" + _f.getName(), new Command() {
1119
                                    @Override
1120
                                    public void execute() {
1121
                                        Iterator<Folder> iterf = _f.getSubfolders().iterator();
1122
                                        copySubfolders(iterf, targetUsername, targetUri + "/" + _f.getName(), callback);
1123
                                    }
1124
                                });
1125
                                        }
1126

    
1127
                                        @Override
1128
                                        public void onError(Throwable t) {
1129
                                GWT.log("", t);
1130
                                                setError(t);
1131
                                if (t instanceof RestException) {
1132
                                    displayError("Unable to get folder: " + ((RestException) t).getHttpStatusText());
1133
                                }
1134
                                else
1135
                                    displayError("System error getting folder: " + t.getMessage());
1136
                                        }
1137

    
1138
                                        @Override
1139
                                        protected void onUnauthorized(Response response) {
1140
                                                sessionExpired();
1141
                                        }
1142
                                };
1143
                                getFolder.setHeader("X-Auth-Token", getToken());
1144
                                Scheduler.get().scheduleDeferred(getFolder);
1145
            }
1146

    
1147
            @Override
1148
            public void onError(Throwable t) {
1149
                GWT.log("", t);
1150
                                setError(t);
1151
               if (t instanceof RestException) {
1152
                    displayError("Unable to create folder: " + ((RestException) t).getHttpStatusText());
1153
                }
1154
                else
1155
                    displayError("System error creating folder: " + t.getMessage());
1156
            }
1157

    
1158
                        @Override
1159
                        protected void onUnauthorized(Response response) {
1160
                                sessionExpired();
1161
                        }
1162
        };
1163
        createFolder.setHeader("X-Auth-Token", getToken());
1164
        createFolder.setHeader("Accept", "*/*");
1165
        createFolder.setHeader("Content-Length", "0");
1166
        createFolder.setHeader("Content-Type", "application/folder");
1167
        Scheduler.get().scheduleDeferred(createFolder);
1168
    }
1169
    
1170
    public void addSelectionModel(@SuppressWarnings("rawtypes") SingleSelectionModel model) {
1171
            selectionModels.add(model);
1172
    }
1173

    
1174
        public OtherSharedTreeView getOtherSharedTreeView() {
1175
                return otherSharedTreeView;
1176
        }
1177

    
1178
        public void updateTrash(boolean showFiles, Command callback) {
1179
                updateFolder(trash, showFiles, callback);
1180
        }
1181

    
1182
        public void updateGroupsNode() {
1183
                groupTreeView.updateGroupNode(null);
1184
        }
1185

    
1186
        public void addGroup(String groupname) {
1187
                Group newGroup = new Group(groupname);
1188
                account.addGroup(newGroup);
1189
                groupTreeView.updateGroupNode(null);
1190
        }
1191

    
1192
        public void removeGroup(Group group) {
1193
                account.removeGroup(group);
1194
                updateGroupsNode();
1195
        }
1196

    
1197
        public TreeView getSelectedTree() {
1198
                return selectedTree;
1199
        }
1200
        
1201
        public Folder getSelection() {
1202
                return selectedTree.getSelection();
1203
        }
1204

    
1205
        public void showFolderStatistics(int folderFileCount) {
1206
                numOfFiles.setHTML(String.valueOf(folderFileCount));
1207
        }
1208

    
1209
        public GroupTreeView getGroupTreeView() {
1210
                return groupTreeView;
1211
        }
1212

    
1213
        public void sessionExpired() {
1214
                new SessionExpiredDialog(this).center();
1215
        }
1216

    
1217
        public void updateRootFolder(Command callback) {
1218
                updateFolder(account.getPithos(), false, callback);
1219
        }
1220

    
1221
        void createMySharedTree() {
1222
                mysharedTreeSelectionModel = new SingleSelectionModel<Folder>();
1223
                mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
1224
                    @Override
1225
                    public void onSelectionChange(SelectionChangeEvent event) {
1226
                        if (mysharedTreeSelectionModel.getSelectedObject() != null) {
1227
                            deselectOthers(mysharedTreeView, mysharedTreeSelectionModel);
1228
                            upload.setEnabled(false);
1229
                            updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
1230
                        }
1231
                     }
1232
                });
1233
                selectionModels.add(mysharedTreeSelectionModel);
1234
                mysharedTreeViewModel = new MysharedTreeViewModel(Pithos.this, mysharedTreeSelectionModel);
1235
                mysharedTreeViewModel.initialize(new Command() {
1236
                        
1237
                        @Override
1238
                        public void execute() {
1239
                            mysharedTreeView = new MysharedTreeView(mysharedTreeViewModel);
1240
                                trees.insert(mysharedTreeView, 2);
1241
                                treeViews.add(mysharedTreeView);
1242
                                createOtherSharedTree();
1243
                        }
1244
                });
1245
        }
1246

    
1247
        void createOtherSharedTree() {
1248
                otherSharedTreeSelectionModel = new SingleSelectionModel<Folder>();
1249
                otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
1250
                    @Override
1251
                    public void onSelectionChange(SelectionChangeEvent event) {
1252
                        if (otherSharedTreeSelectionModel.getSelectedObject() != null) {
1253
                            deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel);
1254
                            otherSharedTreeView.addStyleName("cellTreeWidget-selectedTree");
1255
                            applyPermissions(otherSharedTreeSelectionModel.getSelectedObject());
1256
                            updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
1257
                        }
1258
                     }
1259
                });
1260
                selectionModels.add(otherSharedTreeSelectionModel);
1261
                otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel);
1262
                otherSharedTreeViewModel.initialize(new Command() {
1263
                        
1264
                        @Override
1265
                        public void execute() {
1266
                            otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel);
1267
                                trees.insert(otherSharedTreeView, 3);
1268
                                treeViews.add(otherSharedTreeView);
1269
                        }
1270
                });
1271
        }
1272

    
1273
        public void logoff() {
1274
        Configuration conf = (Configuration) GWT.create(Configuration.class);
1275
                Cookies.removeCookie(conf.authCookie(), "/");
1276
                Cookies.removeCookie(conf.authTokenCookie(), "/");
1277
                for (String s: Cookies.getCookieNames())
1278
                        if (s.startsWith(conf.shibSessionCookiePrefix()))
1279
                                Cookies.removeCookie(s, "/");
1280
                Window.Location.assign(Window.Location.getPath());
1281
        }
1282

    
1283
        public String getErrorData() {
1284
                if (error != null)
1285
                        return error.toString();
1286
                return "";
1287
        }
1288
        
1289
        public void setError(Throwable t) {
1290
                error = t;
1291
        }
1292
}