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