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