Fix the response uri when making a GET request by username to /pithos/rest/users/
[pithos] / src / gr / ebs / gss / client / PopupTree.java
index df15661..a2c92fd 100644 (file)
@@ -22,7 +22,10 @@ import gr.ebs.gss.client.Folders.Images;
 import gr.ebs.gss.client.dnd.DnDTreeItem;
 import gr.ebs.gss.client.rest.resource.FolderResource;
 import gr.ebs.gss.client.rest.resource.OtherUserResource;
+import gr.ebs.gss.client.rest.resource.OthersResource;
 import gr.ebs.gss.client.rest.resource.RestResource;
+import gr.ebs.gss.client.rest.resource.SharedResource;
+import gr.ebs.gss.client.rest.resource.TrashResource;
 
 import java.util.Iterator;
 
@@ -67,11 +70,12 @@ public class PopupTree extends Tree {
 
                        @Override
                        public void onSelection(SelectionEvent<TreeItem> event) {
-                               TreeItem item = event.getSelectedItem();
-                               processItemSelected(item);
+                               TreeItem treeItem = event.getSelectedItem();
+                               processItemSelected(treeItem);
                                String path = GSS.get().getApiPath() + GSS.get().getCurrentUserResource().getUsername()+ "/";
-                               ((RestResource) GSS.get().getFolders().getCurrent().getUserObject()).updateHistory(item,path);
-                               }
+                               String constructedUri = ((RestResource) GSS.get().getFolders().getCurrent().getUserObject()).constructUri(treeItem, path);
+                               GSS.get().updateHistory(constructedUri);
+                       }
                });
 
                addOpenHandler(new OpenHandler<TreeItem>() {
@@ -228,44 +232,62 @@ public class PopupTree extends Tree {
                treeSelectedItem = newSelectedItem;
        }
        /**
-        * Method that takes the current string uri, finds the corresponding treeItem object
-        * using the getTreeItem method and fires this treeItem object
-        * @param uri
-        * @return treeItem
-        */
-//     #Files/files/home
-       public TreeItem getTreeItemFromUri (String uri){
-               String newUri = uri.substring(uri.indexOf("/")+1);
-//             newUri = files/home
-               String uri2 = newUri.substring(0,newUri.indexOf("/"));
-               if(uri2.equalsIgnoreCase("files")){
-//                     folderResource
-                       String[] tokens = uri2.split("/");
-                       for (String t : tokens){
-                               TreeItem parentItem = getTreeItem(t);
-                               getTreeItemFromUri(parentItem.getText());
-                       }
-               }else if(uri2.equalsIgnoreCase("trash") || uri2.equalsIgnoreCase("shared") || uri2.equalsIgnoreCase("others"))
-                       //                      trashResource, sharedResource, othersResource
-                       return getTreeItem(uri2);
-               return getTreeItem(newUri);
-       }
-
-       /**
         * Method that takes a folderName and finds the corresponding treeItem object and returns it
-        * @param folderName
+        * @param historyToken
         * @return treeItem
         */
 
-       public TreeItem getTreeItem (String folderName){
+       public TreeItem getTreeItem (String historyToken){
+//             String historyTokenOriginal = historyToken.replace("+", " ");
+               String path = GSS.get().getApiPath() + GSS.get().getCurrentUserResource().getUsername()+ "/";
+               String rootText = DisplayHelper.trim(GSS.get().getFolders().getRootItem().getText());
+               String uriToGet = "Files/files/" + rootText;
                Iterator<TreeItem> it = GSS.get().getFolders().getPopupTree().treeItemIterator() ;
                while(it.hasNext()){
-                       TreeItem treeitem = it.next();
-                       if(treeitem.getText().equals(folderName))
-                               return treeitem;
+                       String constructedUri = "";
+                       TreeItem treeItem = it.next();
+                       if(treeItem.getUserObject() instanceof TrashResource){
+                               TrashResource currentObject = (TrashResource) treeItem.getUserObject();
+                               constructedUri = constructedUri + currentObject.constructUri(treeItem,path);
+                       }
+                       if(treeItem.getUserObject() instanceof SharedResource){
+                               SharedResource currentObject = (SharedResource) treeItem.getUserObject();
+                               constructedUri = constructedUri + currentObject.constructUri(treeItem, path);
+                       }
+                       if(treeItem.getUserObject() instanceof OthersResource){
+                               OthersResource currentObject = (OthersResource) treeItem.getUserObject();
+                               constructedUri = constructedUri + currentObject.constructUri(treeItem, path);
                        }
-               return null;
+                       if(treeItem.getUserObject() instanceof OtherUserResource){
+                               OtherUserResource currentObject = (OtherUserResource) treeItem.getUserObject();
+                               constructedUri = constructedUri + currentObject.constructUri(treeItem, path);
+                       }
+                       if(treeItem.getUserObject() instanceof FolderResource){
+                               FolderResource currentObject = (FolderResource) treeItem.getUserObject();
+                               constructedUri = constructedUri + currentObject.constructUri(treeItem, path);
+                       }
+                       if(constructedUri.equals(historyToken))
+                               return treeItem;
+               }
+               return expandHiddenItems(uriToGet);
+
        }
-//     TODO when Groups or Search tab is selected then is there a TreeItem selected? guess not....
+
+
+       public TreeItem expandHiddenItems(String tokenInput){
+               //TODO
+               // this method handles objects that are not constructed during loading the application
+               // and when there's a need to seek them inside some non-expanded folder
+               // This method is not implemented yet and in case of a non-constructed object
+               // returns the home/root folder
+               // treeItem.getState() method returns always false so the OpenEvent.fire() method
+               // fails to expand the parent folder in the UI
+
+               GSS.get().getFolders().getRootItem().getText();
+               TreeItem treeItem = getTreeItem(tokenInput);
+               OpenEvent.fire(GSS.get().getFolders().getPopupTree(), treeItem);
+               return treeItem;
+       }
+
 
 }