X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/8c550474df40f0189391d841e84a0fa12ecd0bc7..9d937b3fca5a7e5e52f0d9a5d1fea2d2b8d345e3:/src/gr/ebs/gss/client/GSS.java diff --git a/src/gr/ebs/gss/client/GSS.java b/src/gr/ebs/gss/client/GSS.java index 0853f28..c786dbc 100644 --- a/src/gr/ebs/gss/client/GSS.java +++ b/src/gr/ebs/gss/client/GSS.java @@ -19,6 +19,7 @@ package gr.ebs.gss.client; import gr.ebs.gss.client.clipboard.Clipboard; +import gr.ebs.gss.client.commands.GetUserCommand; import gr.ebs.gss.client.dnd.DnDFocusPanel; import gr.ebs.gss.client.dnd.DnDSimpleFocusPanel; import gr.ebs.gss.client.rest.GetCommand; @@ -28,10 +29,10 @@ import gr.ebs.gss.client.rest.resource.FolderResource; import gr.ebs.gss.client.rest.resource.TrashResource; import gr.ebs.gss.client.rest.resource.UserResource; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; import com.allen_sauer.gwt.dnd.client.DragContext; import com.allen_sauer.gwt.dnd.client.PickupDragController; @@ -198,18 +199,15 @@ public class GSS implements EntryPoint, ResizeHandler { private String token; /** - * A map that stores a set of String URI and the corresponding object - * in order history functionality to be implemented. - */ - private Map map = new HashMap(); - - /** * The WebDAV password of the current user */ private String webDAVPassword; private PickupDragController dragController; + public HashMap userFullNameMap = new HashMap(); + + @Override public void onModuleLoad() { // Initialize the singleton before calling the constructors of the // various widgets that might call GSS.get(). @@ -303,7 +301,7 @@ public class GSS implements EntryPoint, ResizeHandler { @Override public void onSelection(SelectionEvent event) { int tabIndex = event.getSelectedItem(); - TreeItem treeItem = GSS.get().getFolders().getCurrent(); +// TreeItem treeItem = GSS.get().getFolders().getCurrent(); switch (tabIndex) { case 0: // Files tab selected @@ -313,13 +311,13 @@ public class GSS implements EntryPoint, ResizeHandler { case 1: // Groups tab selected groups.updateCurrentlyShowingStats(); - updateHistory("Groups", treeItem); + updateHistory("Groups"); break; case 2: // Search tab selected searchResults.clearSelectedRows(); searchResults.updateCurrentlyShowingStats(); - updateHistory("Search", treeItem); + updateHistory("Search"); break; } } @@ -328,25 +326,29 @@ public class GSS implements EntryPoint, ResizeHandler { String initToken = History.getToken(); if(initToken.length() == 0) History.newItem("Files"); - // Add history listener to handle any history events - History.addValueChangeHandler(new ValueChangeHandler() { - public void onValueChange(ValueChangeEvent event) { - String historyToken = event.getValue(); - try { - if(historyToken.equals("Search")) - inner.selectTab(2); - else if(historyToken.equals("Groups")) - inner.selectTab(1); - else if(historyToken.equals("Files")|| historyToken.length()==0) - inner.selectTab(0); - else - SelectionEvent.fire(GSS.get().getFolders().getPopupTree(), (TreeItem) getHistoryItem(historyToken)); - } catch (IndexOutOfBoundsException e) { - inner.selectTab(0); - } - } - }); + History.addValueChangeHandler(new ValueChangeHandler() { + @Override + public void onValueChange(ValueChangeEvent event) { + String tokenInput = event.getValue(); + String historyToken = handleSpecialFolderNames(tokenInput); + try { + if(historyToken.equals("Search")) + inner.selectTab(2); + else if(historyToken.equals("Groups")) + inner.selectTab(1); + else if(historyToken.equals("Files")|| historyToken.length()==0) + inner.selectTab(0); + else { + PopupTree popupTree = GSS.get().getFolders().getPopupTree(); + TreeItem treeObj = GSS.get().getFolders().getPopupTree().getTreeItem(historyToken); + SelectionEvent.fire(popupTree, treeObj); + } + } catch (IndexOutOfBoundsException e) { + inner.selectTab(0); + } + } + }); // Add the left and right panels to the split panel. splitPanel.setLeftWidget(folders); @@ -382,6 +384,7 @@ public class GSS implements EntryPoint, ResizeHandler { // sizes have been computed by the browser. DeferredCommand.addCommand(new Command() { + @Override public void execute() { onWindowResized(Window.getClientHeight()); } @@ -404,6 +407,7 @@ public class GSS implements EntryPoint, ResizeHandler { if (announcement != null) DeferredCommand.addCommand(new Command() { + @Override public void execute() { displayInformation(announcement); } @@ -447,6 +451,7 @@ public class GSS implements EntryPoint, ResizeHandler { DeferredCommand.addCommand(new Command() { + @Override public void execute() { fetchUser(username); } @@ -779,27 +784,64 @@ public class GSS implements EntryPoint, ResizeHandler { webDAVPassword = Cookies.getCookie(cookie); Cookies.setCookie(cookie, "", null, domain, path, false); } + /** + * History support for folder navigation + * adds a new browser history entry + * * @param key - * @return Object of the corresponding String URI which is stored in the history map */ - public Object getHistoryItem(String key){ - return map.get(key); + public void updateHistory(String key){ +// Replace any whitespace of the initial string to "+" +// String result = key.replaceAll("\\s","+"); +// Add a new browser history entry. +// History.newItem(result); + History.newItem(key); + } + + /** + * This method examines the token input and add a "/" at the end in case it's omitted. + * This happens only in Files/trash/, Files/shared/, Files/others. + * + * @param tokenInput + * @return the formated token with a "/" at the end or the same tokenInput parameter + */ + + private String handleSpecialFolderNames(String tokenInput){ + List pathsToCheck = Arrays.asList("Files/trash", "Files/shared", "Files/others"); + if(pathsToCheck.contains(tokenInput)) + return tokenInput + "/"; + return tokenInput; + } /** - * Replaces any whitespace in the given string to "+" - * Sets a pair of key - object in the History (using a map) - * and adds a new browser history entry - * @param key - * @param obj + * Reject illegal resource names, like '.' or '..' or slashes '/'. */ - public void updateHistory(String key, Object obj){ -// Replace any whitespace of the initial string to "+" - String result = key.replaceAll("\\s","+"); -// Add a new pair key - object in the History map. - map.put(result, obj); -// Add a new browser history entry. - History.newItem(result); + static boolean isValidResourceName(String name) { + if (".".equals(name) || "..".equals(name) || name.contains("/")) + return false; + return true; + } + + public void putUserToMap(String _userName, String _userFullName){ + userFullNameMap.put(_userName, _userFullName); + } + + public String findUserFullName(String _userName){ + return userFullNameMap.get(_userName); + } + + public String getUserFullName(String _userName) { + if (GSS.get().findUserFullName(_userName) == null) + //if there is no userFullName found then the map fills with the given _userName, + //so userFullName = _userName + GSS.get().putUserToMap(_userName, _userName); + else if(GSS.get().findUserFullName(_userName).indexOf('@') != -1){ + //if the userFullName = _userName the GetUserCommand updates the userFullName in the map + GetUserCommand guc = new GetUserCommand(_userName); + guc.execute(); + } + return GSS.get().findUserFullName(_userName); } }