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