Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / GSS.java @ 09031610

History | View | Annotate | Download (22.6 kB)

1
/*
2
 * Copyright 2007, 2008, 2009, 2010 Electronic Business Systems Ltd.
3
 *
4
 * This file is part of GSS.
5
 *
6
 * GSS is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GSS is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
package gr.ebs.gss.client;
20

    
21
import gr.ebs.gss.client.clipboard.Clipboard;
22
import gr.ebs.gss.client.dnd.DnDFocusPanel;
23
import gr.ebs.gss.client.dnd.DnDSimpleFocusPanel;
24
import gr.ebs.gss.client.rest.GetCommand;
25
import gr.ebs.gss.client.rest.RestException;
26
import gr.ebs.gss.client.rest.resource.FileResource;
27
import gr.ebs.gss.client.rest.resource.FolderResource;
28
import gr.ebs.gss.client.rest.resource.TrashResource;
29
import gr.ebs.gss.client.rest.resource.UserResource;
30

    
31
import java.util.Arrays;
32
import java.util.Iterator;
33
import java.util.List;
34

    
35
import com.allen_sauer.gwt.dnd.client.DragContext;
36
import com.allen_sauer.gwt.dnd.client.PickupDragController;
37
import com.allen_sauer.gwt.dnd.client.VetoDragException;
38
import com.google.gwt.core.client.EntryPoint;
39
import com.google.gwt.core.client.GWT;
40
import com.google.gwt.event.logical.shared.ResizeEvent;
41
import com.google.gwt.event.logical.shared.ResizeHandler;
42
import com.google.gwt.event.logical.shared.SelectionEvent;
43
import com.google.gwt.event.logical.shared.SelectionHandler;
44
import com.google.gwt.event.logical.shared.ValueChangeEvent;
45
import com.google.gwt.event.logical.shared.ValueChangeHandler;
46
import com.google.gwt.resources.client.ClientBundle;
47
import com.google.gwt.resources.client.ImageResource;
48
import com.google.gwt.user.client.Command;
49
import com.google.gwt.user.client.Cookies;
50
import com.google.gwt.user.client.DOM;
51
import com.google.gwt.user.client.DeferredCommand;
52
import com.google.gwt.user.client.History;
53
import com.google.gwt.user.client.Window;
54
import com.google.gwt.user.client.ui.AbsolutePanel;
55
import com.google.gwt.user.client.ui.AbstractImagePrototype;
56
import com.google.gwt.user.client.ui.DecoratedTabPanel;
57
import com.google.gwt.user.client.ui.DockPanel;
58
import com.google.gwt.user.client.ui.HTML;
59
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
60
import com.google.gwt.user.client.ui.HasVerticalAlignment;
61
import com.google.gwt.user.client.ui.HorizontalSplitPanel;
62
import com.google.gwt.user.client.ui.Label;
63
import com.google.gwt.user.client.ui.RootPanel;
64
import com.google.gwt.user.client.ui.TabPanel;
65
import com.google.gwt.user.client.ui.TreeItem;
66
import com.google.gwt.user.client.ui.VerticalPanel;
67
import com.google.gwt.user.client.ui.Widget;
68

    
69
/**
70
 * Entry point classes define <code>onModuleLoad()</code>.
71
 */
72
public class GSS implements EntryPoint, ResizeHandler {
73

    
74
        /**
75
         * A constant that denotes the completion of an IncrementalCommand.
76
         */
77
        public static final boolean DONE = false;
78

    
79
        public static final int VISIBLE_FILE_COUNT = 100;
80

    
81
        /**
82
         * Instantiate an application-level image bundle. This object will provide
83
         * programmatic access to all the images needed by widgets.
84
         */
85
        private static Images images = (Images) GWT.create(Images.class);
86

    
87
        private GlassPanel glassPanel = new GlassPanel();
88

    
89
        /**
90
         * An aggregate image bundle that pulls together all the images for this
91
         * application into a single bundle.
92
         */
93
        public interface Images extends ClientBundle, TopPanel.Images, StatusPanel.Images, FileMenu.Images, EditMenu.Images, SettingsMenu.Images, GroupMenu.Images, FilePropertiesDialog.Images, MessagePanel.Images, FileList.Images, SearchResults.Images, Search.Images, Groups.Images, Folders.Images {
94

    
95
                @Source("gr/ebs/gss/resources/document.png")
96
                ImageResource folders();
97

    
98
                @Source("gr/ebs/gss/resources/edit_group_22.png")
99
                ImageResource groups();
100

    
101
                @Source("gr/ebs/gss/resources/search.png")
102
                ImageResource search();
103
        }
104

    
105
        /**
106
         * The single GSS instance.
107
         */
108
        private static GSS singleton;
109

    
110
        /**
111
         * Gets the singleton GSS instance.
112
         *
113
         * @return the GSS object
114
         */
115
        public static GSS get() {
116
                if (GSS.singleton == null)
117
                        GSS.singleton = new GSS();
118
                return GSS.singleton;
119
        }
120

    
121
        /**
122
         * The Application Clipboard implementation;
123
         */
124
        private Clipboard clipboard = new Clipboard();
125

    
126
        private UserResource currentUserResource;
127

    
128
        /**
129
         * The top panel that contains the menu bar.
130
         */
131
        private TopPanel topPanel;
132

    
133
        /**
134
         * The panel that contains the various system messages.
135
         */
136
        private MessagePanel messagePanel = new MessagePanel(GSS.images);
137

    
138
        /**
139
         * The bottom panel that contains the status bar.
140
         */
141
        private StatusPanel statusPanel = new StatusPanel(GSS.images);
142

    
143
        /**
144
         * The top right panel that displays the logged in user details
145
         */
146
        private UserDetailsPanel userDetailsPanel = new UserDetailsPanel();
147

    
148
        /**
149
         * The file list widget.
150
         */
151
        private FileList fileList;
152

    
153
        /**
154
         * The group list widget.
155
         */
156
        private Groups groups = new Groups(images);
157

    
158
        /**
159
         * The search result widget.
160
         */
161
        private SearchResults searchResults;
162

    
163
        /**
164
         * The tab panel that occupies the right side of the screen.
165
         */
166
        private TabPanel inner = new DecoratedTabPanel();
167

    
168
        /**
169
         * The split panel that will contain the left and right panels.
170
         */
171
        private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
172

    
173
        /**
174
         * The horizontal panel that will contain the search and status panels.
175
         */
176
        private DockPanel searchStatus = new DockPanel();
177

    
178
        /**
179
         * The search widget.
180
         */
181
        private Search search;
182

    
183
        /**
184
         * The widget that displays the tree of folders.
185
         */
186
        private Folders folders = new Folders(images);
187

    
188
        /**
189
         * The currently selected item in the application, for use by the Edit menu
190
         * commands. Potential types are Folder, File, User and Group.
191
         */
192
        private Object currentSelection;
193

    
194
        /**
195
         * The authentication token of the current user.
196
         */
197
        private String token;
198

    
199
        /**
200
         * The WebDAV password of the current user
201
         */
202
        private String webDAVPassword;
203

    
204
        private PickupDragController dragController;
205

    
206
        public void onModuleLoad() {
207
                // Initialize the singleton before calling the constructors of the
208
                // various widgets that might call GSS.get().
209
                singleton = this;
210
                RootPanel.get().add(glassPanel, 0, 0);
211
                parseUserCredentials();
212
                dragController = new PickupDragController(RootPanel.get(), false) {
213

    
214
                        @Override
215
                        public void previewDragStart() throws VetoDragException {
216
                                super.previewDragStart();
217
                                if (context.selectedWidgets.isEmpty())
218
                                        throw new VetoDragException();
219

    
220
                                if (context.draggable != null)
221
                                        if (context.draggable instanceof DnDFocusPanel) {
222
                                                DnDFocusPanel toDrop = (DnDFocusPanel) context.draggable;
223
                                                // prevent drag and drop for trashed files and for
224
                                                // unselected tree items
225
                                                if (toDrop.getFiles() != null && folders.isTrashItem(folders.getCurrent()))
226
                                                        throw new VetoDragException();
227
                                                else if (toDrop.getItem() != null && !toDrop.getItem().equals(folders.getCurrent()))
228
                                                        throw new VetoDragException();
229
                                                else if (toDrop.getItem() != null && !toDrop.getItem().isDraggable())
230
                                                        throw new VetoDragException();
231

    
232
                                        } else if (context.draggable instanceof DnDSimpleFocusPanel) {
233
                                                DnDSimpleFocusPanel toDrop = (DnDSimpleFocusPanel) context.draggable;
234
                                                // prevent drag and drop for trashed files and for
235
                                                // unselected tree items
236
                                                if (toDrop.getFiles() != null && folders.isTrashItem(folders.getCurrent()))
237
                                                        throw new VetoDragException();
238
                                        }
239
                        }
240

    
241
                        @Override
242
                        protected Widget newDragProxy(DragContext aContext) {
243
                                AbsolutePanel container = new AbsolutePanel();
244
                                DOM.setStyleAttribute(container.getElement(), "overflow", "visible");
245
                                for (Iterator iterator = aContext.selectedWidgets.iterator(); iterator.hasNext();) {
246
                                        HTML html = null;
247
                                        Widget widget = (Widget) iterator.next();
248
                                        if (widget instanceof DnDFocusPanel) {
249
                                                DnDFocusPanel book = (DnDFocusPanel) widget;
250
                                                html = book.cloneHTML();
251
                                        } else if (widget instanceof DnDSimpleFocusPanel) {
252
                                                DnDSimpleFocusPanel book = (DnDSimpleFocusPanel) widget;
253
                                                html = book.cloneHTML();
254
                                        }
255
                                        if (html == null)
256
                                                container.add(new Label("Drag ME"));
257
                                        else
258
                                                container.add(html);
259
                                }
260
                                return container;
261
                        }
262
                };
263
                dragController.setBehaviorDragProxy(true);
264
                dragController.setBehaviorMultipleSelection(false);
265
                topPanel = new TopPanel(GSS.images);
266
                topPanel.setWidth("100%");
267

    
268
                messagePanel.setWidth("100%");
269
                messagePanel.setVisible(false);
270

    
271
                search = new Search(images);
272
                searchStatus.add(search, DockPanel.WEST);
273
                searchStatus.add(userDetailsPanel, DockPanel.EAST);
274
                searchStatus.setCellHorizontalAlignment(userDetailsPanel, HasHorizontalAlignment.ALIGN_RIGHT);
275
                searchStatus.setCellVerticalAlignment(search, HasVerticalAlignment.ALIGN_MIDDLE);
276
                searchStatus.setCellVerticalAlignment(userDetailsPanel, HasVerticalAlignment.ALIGN_MIDDLE);
277
                searchStatus.setWidth("100%");
278

    
279
                fileList = new FileList(images);
280

    
281
                searchResults = new SearchResults(images);
282

    
283
                // Inner contains the various lists.
284
                inner.setAnimationEnabled(true);
285
                inner.getTabBar().addStyleName("gss-MainTabBar");
286
                inner.getDeckPanel().addStyleName("gss-MainTabPanelBottom");
287
                inner.add(fileList, createHeaderHTML(AbstractImagePrototype.create(images.folders()), "Files"), true);
288

    
289
                inner.add(groups, createHeaderHTML(AbstractImagePrototype.create(images.groups()), "Groups"), true);
290
                inner.add(searchResults, createHeaderHTML(AbstractImagePrototype.create(images.search()), "Search Results"), true);
291
                inner.setWidth("100%");
292
                inner.selectTab(0);
293

    
294
                inner.addSelectionHandler(new SelectionHandler<Integer>() {
295

    
296
                        @Override
297
                        public void onSelection(SelectionEvent<Integer> event) {
298
                                int tabIndex = event.getSelectedItem();
299
//                                TreeItem treeItem = GSS.get().getFolders().getCurrent();
300
                                switch (tabIndex) {
301
                                        case 0:
302
//                                                Files tab selected
303
                                                fileList.clearSelectedRows();
304
                                                fileList.updateCurrentlyShowingStats();
305
                                                break;
306
                                        case 1:
307
//                                                Groups tab selected
308
                                                groups.updateCurrentlyShowingStats();
309
                                        updateHistory("Groups");
310
                                                break;
311
                                        case 2:
312
//                                                Search tab selected
313
                                                searchResults.clearSelectedRows();
314
                                                searchResults.updateCurrentlyShowingStats();
315
                                        updateHistory("Search");
316
                                                break;
317
                                }
318
                        }
319
                });
320
//                If the application starts with no history token, redirect to a new "Files" state
321
                String initToken = History.getToken();
322
                if(initToken.length() == 0)
323
                        History.newItem("Files");
324

    
325

    
326
//                   Add history listener to handle any history events
327
                   History.addValueChangeHandler(new ValueChangeHandler<String>() {
328
                              public void onValueChange(ValueChangeEvent<String> event) {
329
                                String tokenInput = event.getValue();
330
                                String historyToken = handleSpecialFolderNames(tokenInput);
331
                                try {
332
                                        if(historyToken.equals("Search"))
333
                                                inner.selectTab(2);
334
                                        else if(historyToken.equals("Groups"))
335
                                                inner.selectTab(1);
336
                                        else if(historyToken.equals("Files")|| historyToken.length()==0)
337
                                                inner.selectTab(0);
338
                                                else {
339
                                                        PopupTree popupTree = GSS.get().getFolders().getPopupTree();
340
                                                        TreeItem treeObj = GSS.get().getFolders().getPopupTree().getTreeItem(historyToken);
341
                                                        SelectionEvent.fire(popupTree, treeObj);
342
                                                }
343
                                                } catch (IndexOutOfBoundsException e) {
344
                                                inner.selectTab(0);
345
                                                }
346
                                        }
347
                              });
348

    
349
                // Add the left and right panels to the split panel.
350
                splitPanel.setLeftWidget(folders);
351
                splitPanel.setRightWidget(inner);
352
                splitPanel.setSplitPosition("25%");
353
                splitPanel.setSize("100%", "100%");
354
                splitPanel.addStyleName("gss-splitPanel");
355

    
356
                // Create a dock panel that will contain the menu bar at the top,
357
                // the shortcuts to the left, the status bar at the bottom and the
358
                // right panel taking the rest.
359
                VerticalPanel outer = new VerticalPanel();
360
                outer.add(topPanel);
361
                outer.add(searchStatus);
362
                outer.add(messagePanel);
363
                outer.add(splitPanel);
364
                outer.add(statusPanel);
365
                outer.setWidth("100%");
366
                outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);
367

    
368
                outer.setSpacing(4);
369

    
370
                // Hook the window resize event, so that we can adjust the UI.
371
                Window.addResizeHandler(this);
372
                // Clear out the window's built-in margin, because we want to take
373
                // advantage of the entire client area.
374
                Window.setMargin("0px");
375
                // Finally, add the outer panel to the RootPanel, so that it will be
376
                // displayed.
377
                RootPanel.get().add(outer);
378
                // Call the window resized handler to get the initial sizes setup. Doing
379
                // this in a deferred command causes it to occur after all widgets'
380
                // sizes have been computed by the browser.
381
                DeferredCommand.addCommand(new Command() {
382

    
383
                        public void execute() {
384
                                onWindowResized(Window.getClientHeight());
385
                        }
386
                });
387
        }
388

    
389
        /**
390
         * Fetches the User object for the specified username.
391
         *
392
         * @param username the username of the user
393
         */
394
        private void fetchUser(final String username) {
395
                String path = getApiPath() + username + "/";
396
                GetCommand<UserResource> getUserCommand = new GetCommand<UserResource>(UserResource.class, username, path, null) {
397

    
398
                        @Override
399
                        public void onComplete() {
400
                                currentUserResource = getResult();
401
                                final String announcement = currentUserResource.getAnnouncement();
402
                                if (announcement != null)
403
                                        DeferredCommand.addCommand(new Command() {
404

    
405
                                                public void execute() {
406
                                                        displayInformation(announcement);
407
                                                }
408
                                        });
409
                        }
410

    
411
                        @Override
412
                        public void onError(Throwable t) {
413
                                GWT.log("Fetching user error", t);
414
                                if (t instanceof RestException)
415
                                        GSS.get().displayError("No user found:" + ((RestException) t).getHttpStatusText());
416
                                else
417
                                        GSS.get().displayError("System error fetching user data:" + t.getMessage());
418
                                authenticateUser();
419
                        }
420
                };
421
                DeferredCommand.addCommand(getUserCommand);
422
        }
423

    
424
        /**
425
         * Parse and store the user credentials to the appropriate fields.
426
         */
427
        private void parseUserCredentials() {
428
                Configuration conf = (Configuration) GWT.create(Configuration.class);
429
                String cookie = conf.authCookie();
430
                String auth = Cookies.getCookie(cookie);
431
                if (auth == null) {
432
                        authenticateUser();
433
                        // Redundant, but silences warnings about possible auth NPE, below.
434
                        return;
435
                }
436
                int sepIndex = auth.indexOf(conf.cookieSeparator());
437
                if (sepIndex == -1)
438
                        authenticateUser();
439
                token = auth.substring(sepIndex + 1);
440
                final String username = auth.substring(0, sepIndex);
441
                if (username == null)
442
                        authenticateUser();
443

    
444
                refreshWebDAVPassword();
445

    
446
                DeferredCommand.addCommand(new Command() {
447

    
448
                        public void execute() {
449
                                fetchUser(username);
450
                        }
451
                });
452
        }
453

    
454
        /**
455
         * Redirect the user to the login page for authentication.
456
         */
457
        protected void authenticateUser() {
458
                Configuration conf = (Configuration) GWT.create(Configuration.class);
459
                Window.Location.assign(conf.loginUrl() + "?next=" + GWT.getModuleBaseURL());
460
        }
461

    
462
        /**
463
         * Clear the cookie and redirect the user to the logout page.
464
         */
465
        void logout() {
466
                Configuration conf = (Configuration) GWT.create(Configuration.class);
467
                String cookie = conf.authCookie();
468
                String domain = Window.Location.getHostName();
469
                String path = Window.Location.getPath();
470
                Cookies.setCookie(cookie, "", null, domain, path, false);
471
                Window.Location.assign(conf.logoutUrl());
472
        }
473

    
474
        /**
475
         * Creates an HTML fragment that places an image & caption together, for use
476
         * in a group header.
477
         *
478
         * @param imageProto an image prototype for an image
479
         * @param caption the group caption
480
         * @return the header HTML fragment
481
         */
482
        private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) {
483
                String captionHTML = "<table class='caption' cellpadding='0' " + "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML() + "</td><td class='rcaption'><b style='white-space:nowrap'>&nbsp;" + caption + "</b></td></tr></table>";
484
                return captionHTML;
485
        }
486

    
487
        private void onWindowResized(int height) {
488
                // Adjust the split panel to take up the available room in the window.
489
                int newHeight = height - splitPanel.getAbsoluteTop() - 44;
490
                if (newHeight < 1)
491
                        newHeight = 1;
492
                splitPanel.setHeight("" + newHeight);
493
        }
494

    
495
        @Override
496
        public void onResize(ResizeEvent event) {
497
                int height = event.getHeight();
498
                onWindowResized(height);
499
        }
500

    
501
        public boolean isFileListShowing() {
502
                int tab = inner.getTabBar().getSelectedTab();
503
                if (tab == 0)
504
                        return true;
505
                return false;
506
        }
507

    
508
        public boolean isSearchResultsShowing() {
509
                int tab = inner.getTabBar().getSelectedTab();
510
                if (tab == 2)
511
                        return true;
512
                return false;
513
        }
514

    
515
        /**
516
         * Make the user list visible.
517
         */
518
        public void showUserList() {
519
                inner.selectTab(1);
520
        }
521

    
522
        /**
523
         * Make the file list visible.
524
         */
525
        public void showFileList() {
526
                fileList.updateFileCache(false, true /*clear selection*/);
527
                inner.selectTab(0);
528
        }
529

    
530
        /**
531
         * Make the file list visible.
532
         *
533
         * @param update
534
         */
535
        public void showFileList(boolean update) {
536
                TreeItem currentFolder = getFolders().getCurrent();
537
                if (currentFolder != null) {
538
                        List<FileResource> files = null;
539
                        Object cachedObject = currentFolder.getUserObject();
540
                        if (cachedObject instanceof FolderResource) {
541
                                FolderResource folder = (FolderResource) cachedObject;
542
                                files = folder.getFiles();
543
                        } else if (cachedObject instanceof TrashResource) {
544
                                TrashResource folder = (TrashResource) cachedObject;
545
                                files = folder.getFiles();
546
                        }
547
                        if (files != null)
548
                                getFileList().setFiles(files);
549
                }
550
                fileList.updateFileCache(update, true /*clear selection*/);
551
                inner.selectTab(0);
552
        }
553

    
554
        /**
555
         * Make the search results visible.
556
         *
557
         * @param query the search query string
558
         */
559
        public void showSearchResults(String query) {
560
                searchResults.updateFileCache(query);
561
                searchResults.updateCurrentlyShowingStats();
562
                inner.selectTab(2);
563
        }
564

    
565
        /**
566
         * Display the 'loading' indicator.
567
         */
568
        public void showLoadingIndicator() {
569
                topPanel.getLoading().setVisible(true);
570
        }
571

    
572
        /**
573
         * Hide the 'loading' indicator.
574
         */
575
        public void hideLoadingIndicator() {
576
                topPanel.getLoading().setVisible(false);
577
        }
578

    
579
        /**
580
         * A native JavaScript method to reach out to the browser's window and
581
         * invoke its resizeTo() method.
582
         *
583
         * @param x the new width
584
         * @param y the new height
585
         */
586
        public static native void resizeTo(int x, int y) /*-{
587
                $wnd.resizeTo(x,y);
588
        }-*/;
589

    
590
        /**
591
         * A helper method that returns true if the user's list is currently visible
592
         * and false if it is hidden.
593
         *
594
         * @return true if the user list is visible
595
         */
596
        public boolean isUserListVisible() {
597
                return inner.getTabBar().getSelectedTab() == 1;
598
        }
599

    
600
        /**
601
         * Display an error message.
602
         *
603
         * @param msg the message to display
604
         */
605
        public void displayError(String msg) {
606
                messagePanel.displayError(msg);
607
        }
608

    
609
        /**
610
         * Display a warning message.
611
         *
612
         * @param msg the message to display
613
         */
614
        public void displayWarning(String msg) {
615
                messagePanel.displayWarning(msg);
616
        }
617

    
618
        /**
619
         * Display an informational message.
620
         *
621
         * @param msg the message to display
622
         */
623
        public void displayInformation(String msg) {
624
                messagePanel.displayInformation(msg);
625
        }
626

    
627
        /**
628
         * Retrieve the folders.
629
         *
630
         * @return the folders
631
         */
632
        public Folders getFolders() {
633
                return folders;
634
        }
635

    
636
        /**
637
         * Retrieve the search.
638
         *
639
         * @return the search
640
         */
641
        Search getSearch() {
642
                return search;
643
        }
644

    
645
        /**
646
         * Retrieve the currentSelection.
647
         *
648
         * @return the currentSelection
649
         */
650
        public Object getCurrentSelection() {
651
                return currentSelection;
652
        }
653

    
654
        /**
655
         * Modify the currentSelection.
656
         *
657
         * @param newCurrentSelection the currentSelection to set
658
         */
659
        public void setCurrentSelection(Object newCurrentSelection) {
660
                currentSelection = newCurrentSelection;
661
        }
662

    
663
        /**
664
         * Retrieve the groups.
665
         *
666
         * @return the groups
667
         */
668
        public Groups getGroups() {
669
                return groups;
670
        }
671

    
672
        /**
673
         * Retrieve the fileList.
674
         *
675
         * @return the fileList
676
         */
677
        public FileList getFileList() {
678
                return fileList;
679
        }
680

    
681
        public SearchResults getSearchResults() {
682
                return searchResults;
683
        }
684

    
685
        /**
686
         * Retrieve the topPanel.
687
         *
688
         * @return the topPanel
689
         */
690
        TopPanel getTopPanel() {
691
                return topPanel;
692
        }
693

    
694
        /**
695
         * Retrieve the clipboard.
696
         *
697
         * @return the clipboard
698
         */
699
        public Clipboard getClipboard() {
700
                return clipboard;
701
        }
702

    
703
        public StatusPanel getStatusPanel() {
704
                return statusPanel;
705
        }
706

    
707
        /**
708
         * Retrieve the userDetailsPanel.
709
         *
710
         * @return the userDetailsPanel
711
         */
712
        public UserDetailsPanel getUserDetailsPanel() {
713
                return userDetailsPanel;
714
        }
715

    
716
        /**
717
         * Retrieve the dragController.
718
         *
719
         * @return the dragController
720
         */
721
        public PickupDragController getDragController() {
722
                return dragController;
723
        }
724

    
725
        public String getToken() {
726
                return token;
727
        }
728

    
729
        public String getWebDAVPassword() {
730
                return webDAVPassword;
731
        }
732

    
733
        public void removeGlassPanel() {
734
                glassPanel.removeFromParent();
735
        }
736

    
737
        /**
738
         * Retrieve the currentUserResource.
739
         *
740
         * @return the currentUserResource
741
         */
742
        public UserResource getCurrentUserResource() {
743
                return currentUserResource;
744
        }
745

    
746
        /**
747
         * Modify the currentUserResource.
748
         *
749
         * @param newUser the new currentUserResource
750
         */
751
        public void setCurrentUserResource(UserResource newUser) {
752
                currentUserResource = newUser;
753
        }
754

    
755
        public static native void preventIESelection() /*-{
756
                $doc.body.onselectstart = function () { return false; };
757
        }-*/;
758

    
759
        public static native void enableIESelection() /*-{
760
                if ($doc.body.onselectstart != null)
761
                $doc.body.onselectstart = null;
762
        }-*/;
763

    
764
        /**
765
         * @return the absolute path of the API root URL
766
         */
767
        public String getApiPath() {
768
                Configuration conf = (Configuration) GWT.create(Configuration.class);
769
                return GWT.getModuleBaseURL() + conf.apiPath();
770
        }
771

    
772
        public void refreshWebDAVPassword() {
773
                Configuration conf = (Configuration) GWT.create(Configuration.class);
774
                String domain = Window.Location.getHostName();
775
                String path = Window.Location.getPath();
776
                String cookie = conf.webdavCookie();
777
                webDAVPassword = Cookies.getCookie(cookie);
778
                Cookies.setCookie(cookie, "", null, domain, path, false);
779
        }
780

    
781
        /**
782
         * History support for folder navigation
783
         * adds a new browser history entry
784
         *
785
         * @param key
786
         */
787
        public void updateHistory(String key){
788
//                Replace any whitespace of the initial string to "+"
789
//                String result = key.replaceAll("\\s","+");
790
//                Add a new browser history entry.
791
//                History.newItem(result);
792
                History.newItem(key);
793
        }
794

    
795
        /**
796
         * This method examines the token input and add a "/" at the end in case it's omitted.
797
         * This happens only in Files/trash/, Files/shared/, Files/others.
798
         *
799
         * @param tokenInput
800
         * @return the formated token with a "/" at the end or the same tokenInput parameter
801
         */
802

    
803
        public String handleSpecialFolderNames(String tokenInput){
804
                List<String> pathsToCheck = Arrays.asList("Files/trash", "Files/shared", "Files/others");
805
                if(pathsToCheck.contains(tokenInput))
806
                        return tokenInput + "/";
807
                return tokenInput;
808

    
809
        }
810
}