X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/312631e1134ba07a806a6e985e25798ed62b5582..c5070ebed39e7c90d2abaa6deb9aa0f0a3668156:/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 bda3d2b..0853f28 100644 --- a/src/gr/ebs/gss/client/GSS.java +++ b/src/gr/ebs/gss/client/GSS.java @@ -28,8 +28,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.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; @@ -40,6 +42,8 @@ import com.google.gwt.event.logical.shared.ResizeEvent; import com.google.gwt.event.logical.shared.ResizeHandler; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; +import com.google.gwt.event.logical.shared.ValueChangeEvent; +import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.resources.client.ImageResource; import com.google.gwt.user.client.Command; @@ -194,6 +198,12 @@ 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; @@ -293,24 +303,50 @@ public class GSS implements EntryPoint, ResizeHandler { @Override public void onSelection(SelectionEvent event) { int tabIndex = event.getSelectedItem(); + TreeItem treeItem = GSS.get().getFolders().getCurrent(); switch (tabIndex) { case 0: +// Files tab selected fileList.clearSelectedRows(); fileList.updateCurrentlyShowingStats(); - History.newItem("Files"); break; case 1: +// Groups tab selected groups.updateCurrentlyShowingStats(); - History.newItem("Groups"); + updateHistory("Groups", treeItem); break; case 2: +// Search tab selected searchResults.clearSelectedRows(); searchResults.updateCurrentlyShowingStats(); - History.newItem("Search"); + updateHistory("Search", treeItem); break; } } }); +// If the application starts with no history token, redirect to a new "Files" state + 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); + } + } + }); // Add the left and right panels to the split panel. splitPanel.setLeftWidget(folders); @@ -402,7 +438,7 @@ public class GSS implements EntryPoint, ResizeHandler { int sepIndex = auth.indexOf(conf.cookieSeparator()); if (sepIndex == -1) authenticateUser(); - token = auth.substring(sepIndex + 1, auth.length()); + token = auth.substring(sepIndex + 1); final String username = auth.substring(0, sepIndex); if (username == null) authenticateUser(); @@ -743,5 +779,27 @@ public class GSS implements EntryPoint, ResizeHandler { webDAVPassword = Cookies.getCookie(cookie); Cookies.setCookie(cookie, "", null, domain, path, false); } + /** + * @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); + } + /** + * 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 + */ + 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); + } }