Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / GSS.java @ 623:66f69a7348ed

History | View | Annotate | Download (22.1 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.Iterator;
32
import java.util.List;
33

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

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

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

    
78
        public static final int VISIBLE_FILE_COUNT = 100;
79

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

    
86
        private GlassPanel glassPanel = new GlassPanel();
87

    
88
        /**
89
         * An aggregate image bundle that pulls together all the images for this
90
         * application into a single bundle.
91
         */
92
        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 {
93

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

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

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

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

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

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

    
125
        private UserResource currentUserResource;
126

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
203
        private PickupDragController dragController;
204

    
205
        @Override
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
                              @Override
329
                                public void onValueChange(ValueChangeEvent<String> event) {
330
                                String historyToken = event.getValue();
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
                        @Override
384
                        public void execute() {
385
                                onWindowResized(Window.getClientHeight());
386
                        }
387
                });
388
        }
389

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

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

    
406
                                                @Override
407
                                                public void execute() {
408
                                                        displayInformation(announcement);
409
                                                }
410
                                        });
411
                        }
412

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

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

    
446
                refreshWebDAVPassword();
447

    
448
                DeferredCommand.addCommand(new Command() {
449

    
450
                        @Override
451
                        public void execute() {
452
                                fetchUser(username);
453
                        }
454
                });
455
        }
456

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

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

    
477
        /**
478
         * Creates an HTML fragment that places an image & caption together, for use
479
         * in a group header.
480
         *
481
         * @param imageProto an image prototype for an image
482
         * @param caption the group caption
483
         * @return the header HTML fragment
484
         */
485
        private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) {
486
                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>";
487
                return captionHTML;
488
        }
489

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

    
498
        @Override
499
        public void onResize(ResizeEvent event) {
500
                int height = event.getHeight();
501
                onWindowResized(height);
502
        }
503

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

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

    
518
        /**
519
         * Make the user list visible.
520
         */
521
        public void showUserList() {
522
                inner.selectTab(1);
523
        }
524

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

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

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

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

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

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

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

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

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

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

    
630
        /**
631
         * Retrieve the folders.
632
         *
633
         * @return the folders
634
         */
635
        public Folders getFolders() {
636
                return folders;
637
        }
638

    
639
        /**
640
         * Retrieve the search.
641
         *
642
         * @return the search
643
         */
644
        Search getSearch() {
645
                return search;
646
        }
647

    
648
        /**
649
         * Retrieve the currentSelection.
650
         *
651
         * @return the currentSelection
652
         */
653
        public Object getCurrentSelection() {
654
                return currentSelection;
655
        }
656

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

    
666
        /**
667
         * Retrieve the groups.
668
         *
669
         * @return the groups
670
         */
671
        public Groups getGroups() {
672
                return groups;
673
        }
674

    
675
        /**
676
         * Retrieve the fileList.
677
         *
678
         * @return the fileList
679
         */
680
        public FileList getFileList() {
681
                return fileList;
682
        }
683

    
684
        public SearchResults getSearchResults() {
685
                return searchResults;
686
        }
687

    
688
        /**
689
         * Retrieve the topPanel.
690
         *
691
         * @return the topPanel
692
         */
693
        TopPanel getTopPanel() {
694
                return topPanel;
695
        }
696

    
697
        /**
698
         * Retrieve the clipboard.
699
         *
700
         * @return the clipboard
701
         */
702
        public Clipboard getClipboard() {
703
                return clipboard;
704
        }
705

    
706
        public StatusPanel getStatusPanel() {
707
                return statusPanel;
708
        }
709

    
710
        /**
711
         * Retrieve the userDetailsPanel.
712
         *
713
         * @return the userDetailsPanel
714
         */
715
        public UserDetailsPanel getUserDetailsPanel() {
716
                return userDetailsPanel;
717
        }
718

    
719
        /**
720
         * Retrieve the dragController.
721
         *
722
         * @return the dragController
723
         */
724
        public PickupDragController getDragController() {
725
                return dragController;
726
        }
727

    
728
        public String getToken() {
729
                return token;
730
        }
731

    
732
        public String getWebDAVPassword() {
733
                return webDAVPassword;
734
        }
735

    
736
        public void removeGlassPanel() {
737
                glassPanel.removeFromParent();
738
        }
739

    
740
        /**
741
         * Retrieve the currentUserResource.
742
         *
743
         * @return the currentUserResource
744
         */
745
        public UserResource getCurrentUserResource() {
746
                return currentUserResource;
747
        }
748

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

    
758
        public static native void preventIESelection() /*-{
759
                $doc.body.onselectstart = function () { return false; };
760
        }-*/;
761

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

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

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

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