Just before implementing the browser's history-not fully tested yet. Changes: GSS...
[pithos] / src / gr / ebs / gss / client / GSS.java
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.HashMap;
32 import java.util.Iterator;
33 import java.util.List;
34 import java.util.Map;
35
36 import com.allen_sauer.gwt.dnd.client.DragContext;
37 import com.allen_sauer.gwt.dnd.client.PickupDragController;
38 import com.allen_sauer.gwt.dnd.client.VetoDragException;
39 import com.google.gwt.core.client.EntryPoint;
40 import com.google.gwt.core.client.GWT;
41 import com.google.gwt.event.logical.shared.ResizeEvent;
42 import com.google.gwt.event.logical.shared.ResizeHandler;
43 import com.google.gwt.event.logical.shared.SelectionEvent;
44 import com.google.gwt.event.logical.shared.SelectionHandler;
45 import com.google.gwt.event.logical.shared.ValueChangeEvent;
46 import com.google.gwt.event.logical.shared.ValueChangeHandler;
47 import com.google.gwt.http.client.URL;
48 import com.google.gwt.resources.client.ClientBundle;
49 import com.google.gwt.resources.client.ImageResource;
50 import com.google.gwt.user.client.Command;
51 import com.google.gwt.user.client.Cookies;
52 import com.google.gwt.user.client.DOM;
53 import com.google.gwt.user.client.DeferredCommand;
54 import com.google.gwt.user.client.History;
55 import com.google.gwt.user.client.Window;
56 import com.google.gwt.user.client.ui.AbsolutePanel;
57 import com.google.gwt.user.client.ui.AbstractImagePrototype;
58 import com.google.gwt.user.client.ui.DecoratedTabPanel;
59 import com.google.gwt.user.client.ui.DockPanel;
60 import com.google.gwt.user.client.ui.HTML;
61 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
62 import com.google.gwt.user.client.ui.HasVerticalAlignment;
63 import com.google.gwt.user.client.ui.HorizontalSplitPanel;
64 import com.google.gwt.user.client.ui.Label;
65 import com.google.gwt.user.client.ui.RootPanel;
66 import com.google.gwt.user.client.ui.TabPanel;
67 import com.google.gwt.user.client.ui.TreeItem;
68 import com.google.gwt.user.client.ui.VerticalPanel;
69 import com.google.gwt.user.client.ui.Widget;
70
71 /**
72  * Entry point classes define <code>onModuleLoad()</code>.
73  */
74 public class GSS implements EntryPoint, ResizeHandler {
75
76         /**
77          * A constant that denotes the completion of an IncrementalCommand.
78          */
79         public static final boolean DONE = false;
80
81         public static final int VISIBLE_FILE_COUNT = 100;
82
83         /**
84          * Instantiate an application-level image bundle. This object will provide
85          * programmatic access to all the images needed by widgets.
86          */
87         private static Images images = (Images) GWT.create(Images.class);
88
89         private GlassPanel glassPanel = new GlassPanel();
90
91         /**
92          * An aggregate image bundle that pulls together all the images for this
93          * application into a single bundle.
94          */
95         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 {
96
97                 @Source("gr/ebs/gss/resources/document.png")
98                 ImageResource folders();
99
100                 @Source("gr/ebs/gss/resources/edit_group_22.png")
101                 ImageResource groups();
102
103                 @Source("gr/ebs/gss/resources/search.png")
104                 ImageResource search();
105         }
106
107         /**
108          * The single GSS instance.
109          */
110         private static GSS singleton;
111
112         /**
113          * Gets the singleton GSS instance.
114          *
115          * @return the GSS object
116          */
117         public static GSS get() {
118                 if (GSS.singleton == null)
119                         GSS.singleton = new GSS();
120                 return GSS.singleton;
121         }
122
123         /**
124          * The Application Clipboard implementation;
125          */
126         private Clipboard clipboard = new Clipboard();
127
128         private UserResource currentUserResource;
129
130         /**
131          * The top panel that contains the menu bar.
132          */
133         private TopPanel topPanel;
134
135         /**
136          * The panel that contains the various system messages.
137          */
138         private MessagePanel messagePanel = new MessagePanel(GSS.images);
139
140         /**
141          * The bottom panel that contains the status bar.
142          */
143         private StatusPanel statusPanel = new StatusPanel(GSS.images);
144
145         /**
146          * The top right panel that displays the logged in user details
147          */
148         private UserDetailsPanel userDetailsPanel = new UserDetailsPanel();
149
150         /**
151          * The file list widget.
152          */
153         private FileList fileList;
154
155         /**
156          * The group list widget.
157          */
158         private Groups groups = new Groups(images);
159
160         /**
161          * The search result widget.
162          */
163         private SearchResults searchResults;
164
165         /**
166          * The tab panel that occupies the right side of the screen.
167          */
168         private TabPanel inner = new DecoratedTabPanel();
169
170         /**
171          * The split panel that will contain the left and right panels.
172          */
173         private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
174
175         /**
176          * The horizontal panel that will contain the search and status panels.
177          */
178         private DockPanel searchStatus = new DockPanel();
179
180         /**
181          * The search widget.
182          */
183         private Search search;
184
185         /**
186          * The widget that displays the tree of folders.
187          */
188         private Folders folders = new Folders(images);
189
190         /**
191          * The currently selected item in the application, for use by the Edit menu
192          * commands. Potential types are Folder, File, User and Group.
193          */
194         private Object currentSelection;
195
196         /**
197          * The authentication token of the current user.
198          */
199         private String token;
200
201         /**
202          * A map that stores user's selection in order browser's
203          * history functionality to be implemented.
204          */
205         private Map<String, Object> map = new HashMap<String, Object>();
206
207         /**
208          * The WebDAV password of the current user
209          */
210         private String webDAVPassword;
211
212         private PickupDragController dragController;
213
214         public void onModuleLoad() {
215                 // Initialize the singleton before calling the constructors of the
216                 // various widgets that might call GSS.get().
217                 singleton = this;
218                 RootPanel.get().add(glassPanel, 0, 0);
219                 parseUserCredentials();
220                 dragController = new PickupDragController(RootPanel.get(), false) {
221
222                         @Override
223                         public void previewDragStart() throws VetoDragException {
224                                 super.previewDragStart();
225                                 if (context.selectedWidgets.isEmpty())
226                                         throw new VetoDragException();
227
228                                 if (context.draggable != null)
229                                         if (context.draggable instanceof DnDFocusPanel) {
230                                                 DnDFocusPanel toDrop = (DnDFocusPanel) context.draggable;
231                                                 // prevent drag and drop for trashed files and for
232                                                 // unselected tree items
233                                                 if (toDrop.getFiles() != null && folders.isTrashItem(folders.getCurrent()))
234                                                         throw new VetoDragException();
235                                                 else if (toDrop.getItem() != null && !toDrop.getItem().equals(folders.getCurrent()))
236                                                         throw new VetoDragException();
237                                                 else if (toDrop.getItem() != null && !toDrop.getItem().isDraggable())
238                                                         throw new VetoDragException();
239
240                                         } else if (context.draggable instanceof DnDSimpleFocusPanel) {
241                                                 DnDSimpleFocusPanel toDrop = (DnDSimpleFocusPanel) context.draggable;
242                                                 // prevent drag and drop for trashed files and for
243                                                 // unselected tree items
244                                                 if (toDrop.getFiles() != null && folders.isTrashItem(folders.getCurrent()))
245                                                         throw new VetoDragException();
246                                         }
247                         }
248
249                         @Override
250                         protected Widget newDragProxy(DragContext aContext) {
251                                 AbsolutePanel container = new AbsolutePanel();
252                                 DOM.setStyleAttribute(container.getElement(), "overflow", "visible");
253                                 for (Iterator iterator = aContext.selectedWidgets.iterator(); iterator.hasNext();) {
254                                         HTML html = null;
255                                         Widget widget = (Widget) iterator.next();
256                                         if (widget instanceof DnDFocusPanel) {
257                                                 DnDFocusPanel book = (DnDFocusPanel) widget;
258                                                 html = book.cloneHTML();
259                                         } else if (widget instanceof DnDSimpleFocusPanel) {
260                                                 DnDSimpleFocusPanel book = (DnDSimpleFocusPanel) widget;
261                                                 html = book.cloneHTML();
262                                         }
263                                         if (html == null)
264                                                 container.add(new Label("Drag ME"));
265                                         else
266                                                 container.add(html);
267                                 }
268                                 return container;
269                         }
270                 };
271                 dragController.setBehaviorDragProxy(true);
272                 dragController.setBehaviorMultipleSelection(false);
273                 topPanel = new TopPanel(GSS.images);
274                 topPanel.setWidth("100%");
275
276                 messagePanel.setWidth("100%");
277                 messagePanel.setVisible(false);
278
279                 search = new Search(images);
280                 searchStatus.add(search, DockPanel.WEST);
281                 searchStatus.add(userDetailsPanel, DockPanel.EAST);
282                 searchStatus.setCellHorizontalAlignment(userDetailsPanel, HasHorizontalAlignment.ALIGN_RIGHT);
283                 searchStatus.setCellVerticalAlignment(search, HasVerticalAlignment.ALIGN_MIDDLE);
284                 searchStatus.setCellVerticalAlignment(userDetailsPanel, HasVerticalAlignment.ALIGN_MIDDLE);
285                 searchStatus.setWidth("100%");
286
287                 fileList = new FileList(images);
288
289                 searchResults = new SearchResults(images);
290
291                 // Inner contains the various lists.
292                 inner.setAnimationEnabled(true);
293                 inner.getTabBar().addStyleName("gss-MainTabBar");
294                 inner.getDeckPanel().addStyleName("gss-MainTabPanelBottom");
295                 inner.add(fileList, createHeaderHTML(AbstractImagePrototype.create(images.folders()), "Files"), true);
296
297                 inner.add(groups, createHeaderHTML(AbstractImagePrototype.create(images.groups()), "Groups"), true);
298                 inner.add(searchResults, createHeaderHTML(AbstractImagePrototype.create(images.search()), "Search Results"), true);
299                 inner.setWidth("100%");
300                 inner.selectTab(0);
301
302                 inner.addSelectionHandler(new SelectionHandler<Integer>() {
303
304                         @Override
305                         public void onSelection(SelectionEvent<Integer> event) {
306                                 int tabIndex = event.getSelectedItem();
307                                 TreeItem treeItem = GSS.get().getFolders().getCurrent();
308                                 PopupTree tree = GSS.get().getFolders().getPopupTree();
309                                 switch (tabIndex) {
310                                         case 0:
311                                                 fileList.clearSelectedRows();
312                                                 fileList.updateCurrentlyShowingStats();
313                                                 break;
314                                                 /**
315                                                  * When the Groups tab is selected a new
316                                                  */
317                                         case 1:
318                                                 groups.updateCurrentlyShowingStats();
319 //                                              Add a new pair key - object in the History map.
320                                                 setHistory("Groups", treeItem);
321 //                                              Add a new browser history entry.
322                                         History.newItem("Groups");
323                                                 break;
324                                         case 2:
325                                                 searchResults.clearSelectedRows();
326                                                 searchResults.updateCurrentlyShowingStats();
327                                                 setHistory("Search", treeItem);
328                                         History.newItem("Search");
329                                                 break;
330                                 }
331                         }
332                 });
333                 // If the application starts with no history token, redirect to a new "Files" state
334                 String initToken = History.getToken();
335                 if(initToken.length() == 0)
336                         History.newItem("Files");
337
338                 // Add history listener
339                    History.addValueChangeHandler(new ValueChangeHandler<String>() {
340                               public void onValueChange(ValueChangeEvent<String> event) {
341                                 String historyToken = event.getValue();
342                                 TreeItem treeItem = GSS.get().getFolders().getCurrent();
343                                 try {
344                                   if(historyToken.equals("Search"))
345                                                 inner.selectTab(2);
346                                         else if(historyToken.equals("Groups"))
347                                                 inner.selectTab(1);
348                                         else if(historyToken.equals("Files")){
349                                           setHistory("Files", treeItem);
350                                           History.newItem("Files");
351                                           inner.selectTab(0);
352                                   }
353                                   else{
354                                           PopupTree tree = GSS.get().getFolders().getPopupTree();
355                                           String newHistoryToken = URL.decode(historyToken);
356                                           System.out.println(map.keySet());
357                                           SelectionEvent.fire(tree, (TreeItem) getHistoryItem(newHistoryToken));
358                                   }
359                                 } catch (IndexOutOfBoundsException e) {
360                                         inner.selectTab(0);
361                                 }
362                               }
363                             });
364
365
366                 // Add the left and right panels to the split panel.
367                 splitPanel.setLeftWidget(folders);
368                 splitPanel.setRightWidget(inner);
369                 splitPanel.setSplitPosition("25%");
370                 splitPanel.setSize("100%", "100%");
371                 splitPanel.addStyleName("gss-splitPanel");
372
373                 // Create a dock panel that will contain the menu bar at the top,
374                 // the shortcuts to the left, the status bar at the bottom and the
375                 // right panel taking the rest.
376                 VerticalPanel outer = new VerticalPanel();
377                 outer.add(topPanel);
378                 outer.add(searchStatus);
379                 outer.add(messagePanel);
380                 outer.add(splitPanel);
381                 outer.add(statusPanel);
382                 outer.setWidth("100%");
383                 outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);
384
385                 outer.setSpacing(4);
386
387                 // Hook the window resize event, so that we can adjust the UI.
388                 Window.addResizeHandler(this);
389                 // Clear out the window's built-in margin, because we want to take
390                 // advantage of the entire client area.
391                 Window.setMargin("0px");
392                 // Finally, add the outer panel to the RootPanel, so that it will be
393                 // displayed.
394                 RootPanel.get().add(outer);
395                 // Call the window resized handler to get the initial sizes setup. Doing
396                 // this in a deferred command causes it to occur after all widgets'
397                 // sizes have been computed by the browser.
398                 DeferredCommand.addCommand(new Command() {
399
400                         public void execute() {
401                                 onWindowResized(Window.getClientHeight());
402                         }
403                 });
404         }
405
406         /**
407          * Fetches the User object for the specified username.
408          *
409          * @param username the username of the user
410          */
411         private void fetchUser(final String username) {
412                 String path = getApiPath() + username + "/";
413                 GetCommand<UserResource> getUserCommand = new GetCommand<UserResource>(UserResource.class, username, path, null) {
414
415                         @Override
416                         public void onComplete() {
417                                 currentUserResource = getResult();
418                                 final String announcement = currentUserResource.getAnnouncement();
419                                 if (announcement != null)
420                                         DeferredCommand.addCommand(new Command() {
421
422                                                 public void execute() {
423                                                         displayInformation(announcement);
424                                                 }
425                                         });
426                         }
427
428                         @Override
429                         public void onError(Throwable t) {
430                                 GWT.log("Fetching user error", t);
431                                 if (t instanceof RestException)
432                                         GSS.get().displayError("No user found:" + ((RestException) t).getHttpStatusText());
433                                 else
434                                         GSS.get().displayError("System error fetching user data:" + t.getMessage());
435                                 authenticateUser();
436                         }
437                 };
438                 DeferredCommand.addCommand(getUserCommand);
439         }
440
441         /**
442          * Parse and store the user credentials to the appropriate fields.
443          */
444         private void parseUserCredentials() {
445                 Configuration conf = (Configuration) GWT.create(Configuration.class);
446                 String cookie = conf.authCookie();
447                 String auth = Cookies.getCookie(cookie);
448                 String domain = Window.Location.getHostName();
449                 String path = Window.Location.getPath();
450                 Cookies.setCookie(cookie, "", null, domain, path, false);
451                 if (auth == null) {
452                         authenticateUser();
453                         // Redundant, but silences warnings about possible auth NPE, below.
454                         return;
455                 }
456                 int sepIndex = auth.indexOf(conf.cookieSeparator());
457                 if (sepIndex == -1)
458                         authenticateUser();
459                 token = auth.substring(sepIndex + 1, auth.length());
460                 final String username = auth.substring(0, sepIndex);
461                 if (username == null)
462                         authenticateUser();
463
464                 refreshWebDAVPassword();
465
466                 DeferredCommand.addCommand(new Command() {
467
468                         public void execute() {
469                                 fetchUser(username);
470                         }
471                 });
472         }
473
474         /**
475          * Redirect the user to the login page for authentication.
476          */
477         protected void authenticateUser() {
478                 Configuration conf = (Configuration) GWT.create(Configuration.class);
479                 Window.Location.assign(conf.loginUrl() + "?next=" + GWT.getModuleBaseURL());
480         }
481
482         /**
483          * Redirect the user to the logout page.
484          */
485         void logout() {
486                 Configuration conf = (Configuration) GWT.create(Configuration.class);
487                 Window.Location.assign(conf.logoutUrl());
488         }
489
490         /**
491          * Creates an HTML fragment that places an image & caption together, for use
492          * in a group header.
493          *
494          * @param imageProto an image prototype for an image
495          * @param caption the group caption
496          * @return the header HTML fragment
497          */
498         private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) {
499                 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>";
500                 return captionHTML;
501         }
502
503         private void onWindowResized(int height) {
504                 // Adjust the split panel to take up the available room in the window.
505                 int newHeight = height - splitPanel.getAbsoluteTop() - 44;
506                 if (newHeight < 1)
507                         newHeight = 1;
508                 splitPanel.setHeight("" + newHeight);
509         }
510
511         @Override
512         public void onResize(ResizeEvent event) {
513                 int height = event.getHeight();
514                 onWindowResized(height);
515         }
516
517         public boolean isFileListShowing() {
518                 int tab = inner.getTabBar().getSelectedTab();
519                 if (tab == 0)
520                         return true;
521                 return false;
522         }
523
524         public boolean isSearchResultsShowing() {
525                 int tab = inner.getTabBar().getSelectedTab();
526                 if (tab == 2)
527                         return true;
528                 return false;
529         }
530
531         /**
532          * Make the user list visible.
533          */
534         public void showUserList() {
535                 inner.selectTab(1);
536         }
537
538         /**
539          * Make the file list visible.
540          */
541         public void showFileList() {
542                 fileList.updateFileCache(false, true /*clear selection*/);
543                 inner.selectTab(0);
544         }
545
546         /**
547          * Make the file list visible.
548          *
549          * @param update
550          */
551         public void showFileList(boolean update) {
552                 TreeItem currentFolder = getFolders().getCurrent();
553                 if (currentFolder != null) {
554                         List<FileResource> files = null;
555                         Object cachedObject = currentFolder.getUserObject();
556                         if (cachedObject instanceof FolderResource) {
557                                 FolderResource folder = (FolderResource) cachedObject;
558                                 files = folder.getFiles();
559                         } else if (cachedObject instanceof TrashResource) {
560                                 TrashResource folder = (TrashResource) cachedObject;
561                                 files = folder.getFiles();
562                         }
563                         if (files != null)
564                                 getFileList().setFiles(files);
565                 }
566                 fileList.updateFileCache(update, true /*clear selection*/);
567                 inner.selectTab(0);
568         }
569
570         /**
571          * Make the search results visible.
572          *
573          * @param query the search query string
574          */
575         public void showSearchResults(String query) {
576                 searchResults.updateFileCache(query);
577                 searchResults.updateCurrentlyShowingStats();
578                 inner.selectTab(2);
579         }
580
581         /**
582          * Display the 'loading' indicator.
583          */
584         public void showLoadingIndicator() {
585                 topPanel.getLoading().setVisible(true);
586         }
587
588         /**
589          * Hide the 'loading' indicator.
590          */
591         public void hideLoadingIndicator() {
592                 topPanel.getLoading().setVisible(false);
593         }
594
595         /**
596          * A native JavaScript method to reach out to the browser's window and
597          * invoke its resizeTo() method.
598          *
599          * @param x the new width
600          * @param y the new height
601          */
602         public static native void resizeTo(int x, int y) /*-{
603                 $wnd.resizeTo(x,y);
604         }-*/;
605
606         /**
607          * A helper method that returns true if the user's list is currently visible
608          * and false if it is hidden.
609          *
610          * @return true if the user list is visible
611          */
612         public boolean isUserListVisible() {
613                 return inner.getTabBar().getSelectedTab() == 1;
614         }
615
616         /**
617          * Display an error message.
618          *
619          * @param msg the message to display
620          */
621         public void displayError(String msg) {
622                 messagePanel.displayError(msg);
623         }
624
625         /**
626          * Display a warning message.
627          *
628          * @param msg the message to display
629          */
630         public void displayWarning(String msg) {
631                 messagePanel.displayWarning(msg);
632         }
633
634         /**
635          * Display an informational message.
636          *
637          * @param msg the message to display
638          */
639         public void displayInformation(String msg) {
640                 messagePanel.displayInformation(msg);
641         }
642
643         /**
644          * Retrieve the folders.
645          *
646          * @return the folders
647          */
648         public Folders getFolders() {
649                 return folders;
650         }
651
652         /**
653          * Retrieve the search.
654          *
655          * @return the search
656          */
657         Search getSearch() {
658                 return search;
659         }
660
661         /**
662          * Retrieve the currentSelection.
663          *
664          * @return the currentSelection
665          */
666         public Object getCurrentSelection() {
667                 return currentSelection;
668         }
669
670         /**
671          * Modify the currentSelection.
672          *
673          * @param newCurrentSelection the currentSelection to set
674          */
675         public void setCurrentSelection(Object newCurrentSelection) {
676                 currentSelection = newCurrentSelection;
677         }
678
679         /**
680          * Retrieve the groups.
681          *
682          * @return the groups
683          */
684         public Groups getGroups() {
685                 return groups;
686         }
687
688         /**
689          * Retrieve the fileList.
690          *
691          * @return the fileList
692          */
693         public FileList getFileList() {
694                 return fileList;
695         }
696
697         public SearchResults getSearchResults() {
698                 return searchResults;
699         }
700
701         /**
702          * Retrieve the topPanel.
703          *
704          * @return the topPanel
705          */
706         TopPanel getTopPanel() {
707                 return topPanel;
708         }
709
710         /**
711          * Retrieve the clipboard.
712          *
713          * @return the clipboard
714          */
715         public Clipboard getClipboard() {
716                 return clipboard;
717         }
718
719         public StatusPanel getStatusPanel() {
720                 return statusPanel;
721         }
722
723         /**
724          * Retrieve the userDetailsPanel.
725          *
726          * @return the userDetailsPanel
727          */
728         public UserDetailsPanel getUserDetailsPanel() {
729                 return userDetailsPanel;
730         }
731
732         /**
733          * Retrieve the dragController.
734          *
735          * @return the dragController
736          */
737         public PickupDragController getDragController() {
738                 return dragController;
739         }
740
741         public String getToken() {
742                 return token;
743         }
744
745         public String getWebDAVPassword() {
746                 return webDAVPassword;
747         }
748
749         public void removeGlassPanel() {
750                 glassPanel.removeFromParent();
751         }
752
753         /**
754          * Retrieve the currentUserResource.
755          *
756          * @return the currentUserResource
757          */
758         public UserResource getCurrentUserResource() {
759                 return currentUserResource;
760         }
761
762         /**
763          * Modify the currentUserResource.
764          *
765          * @param newUser the new currentUserResource
766          */
767         public void setCurrentUserResource(UserResource newUser) {
768                 currentUserResource = newUser;
769         }
770
771         public static native void preventIESelection() /*-{
772                 $doc.body.onselectstart = function () { return false; };
773         }-*/;
774
775         public static native void enableIESelection() /*-{
776                 if ($doc.body.onselectstart != null)
777                 $doc.body.onselectstart = null;
778         }-*/;
779
780         /**
781          * @return the absolute path of the API root URL
782          */
783         public String getApiPath() {
784                 Configuration conf = (Configuration) GWT.create(Configuration.class);
785                 return GWT.getModuleBaseURL() + conf.apiPath();
786         }
787
788         public void refreshWebDAVPassword() {
789                 Configuration conf = (Configuration) GWT.create(Configuration.class);
790                 String domain = Window.Location.getHostName();
791                 String path = Window.Location.getPath();
792                 String cookie = conf.webdavCookie();
793                 webDAVPassword = Cookies.getCookie(cookie);
794                 Cookies.setCookie(cookie, "", null, domain, path, false);
795         }
796         /**
797          *
798          * @param key
799          * @return Object of the corresponding key in the History map
800          */
801         public Object getHistoryItem(String key){
802                 return map.get(key);
803         }
804         /**
805          * Set a pair of key - object in the History (using a map)
806          * @param key
807          * @param obj
808          */
809
810         public void setHistory(String key, Object obj){
811                 map.put(key, obj);
812         }
813 }