fixing 'All tags' display version 2 - add a new css class named 'gss-tag'
[pithos] / src / gr / ebs / gss / client / GSS.java
index 0853f28..af95cac 100644 (file)
@@ -28,10 +28,9 @@ 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.Arrays;
 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 +197,13 @@ 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<String, Object> map = new HashMap<String, Object>();
-
-       /**
         * The WebDAV password of the current user
         */
        private String webDAVPassword;
 
        private PickupDragController dragController;
 
+       @Override
        public void onModuleLoad() {
                // Initialize the singleton before calling the constructors of the
                // various widgets that might call GSS.get().
@@ -303,7 +297,7 @@ public class GSS implements EntryPoint, ResizeHandler {
                        @Override
                        public void onSelection(SelectionEvent<Integer> 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 +307,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 +322,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<String>() {
-                             public void onValueChange(ValueChangeEvent<String> 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<String>() {
+                       @Override
+                       public void onValueChange(ValueChangeEvent<String> 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 +380,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 +403,7 @@ public class GSS implements EntryPoint, ResizeHandler {
                                if (announcement != null)
                                        DeferredCommand.addCommand(new Command() {
 
+                                               @Override
                                                public void execute() {
                                                        displayInformation(announcement);
                                                }
@@ -447,6 +447,7 @@ public class GSS implements EntryPoint, ResizeHandler {
 
                DeferredCommand.addCommand(new Command() {
 
+                       @Override
                        public void execute() {
                                fetchUser(username);
                        }
@@ -779,27 +780,45 @@ 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);
        }
 
        /**
-        * 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
+        * 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
         */
-       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);
+
+       private String handleSpecialFolderNames(String tokenInput){
+               List<String> pathsToCheck = Arrays.asList("Files/trash", "Files/shared", "Files/others");
+               if(pathsToCheck.contains(tokenInput))
+                       return tokenInput + "/";
+               return tokenInput;
+
        }
+
+       /**
+        * Reject illegal resource names, like '.' or '..'.
+        */
+       static boolean isValidResourceName(String name) {
+               if (".".equals(name) || "..".equals(name))
+                       return false;
+               return true;
+       }
+
+
 }