updateHistory removed from RestResource and other resources and implemented only...
authorNatasa Kapravelou <akapravelou@gmail.com>
Wed, 9 Jun 2010 14:23:18 +0000 (17:23 +0300)
committerNatasa Kapravelou <akapravelou@gmail.com>
Wed, 9 Jun 2010 14:23:18 +0000 (17:23 +0300)
src/gr/ebs/gss/client/GSS.java
src/gr/ebs/gss/client/PopupTree.java
src/gr/ebs/gss/client/rest/resource/FolderResource.java
src/gr/ebs/gss/client/rest/resource/OtherUserResource.java
src/gr/ebs/gss/client/rest/resource/OthersResource.java
src/gr/ebs/gss/client/rest/resource/RestResource.java
src/gr/ebs/gss/client/rest/resource/SharedResource.java
src/gr/ebs/gss/client/rest/resource/TrashResource.java

index ea49b32..4fef185 100644 (file)
@@ -28,10 +28,8 @@ 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;
@@ -198,12 +196,6 @@ 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;
@@ -303,7 +295,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 +305,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;
                                }
                        }
@@ -342,11 +334,8 @@ public class GSS implements EntryPoint, ResizeHandler {
                                        else if(historyToken.equals("Files")|| historyToken.length()==0)
                                                inner.selectTab(0);
                                                else {
-                                                       GWT.log("****Inside addValueChangeHandler****");
-                                                       GWT.log("historyToken = '" +historyToken+ "'");
                                                        PopupTree popupTree = GSS.get().getFolders().getPopupTree();
                                                        TreeItem treeObj = GSS.get().getFolders().getPopupTree().getTreeItem(historyToken);
-                                                       GWT.log("treeObj.getUserObject().toString() = '" +treeObj.getUserObject().toString()+ "'");
                                                        SelectionEvent.fire(popupTree, treeObj);
 
 //                                                     SelectionEvent.fire(GSS.get().getFolders().getPopupTree(), (TreeItem) getHistoryItem(historyToken));
@@ -788,28 +777,16 @@ 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);
-       }
 
        /**
+        * History support for folder navigation
         * 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){
+       public void updateHistory(String key){
 //             Replace any whitespace of the initial string to "+"
                String result = key.replaceAll("\\s","+");
-               GWT.log("~~~~Inside GSS.get().updateHistory()~~~~");
-               GWT.log("result = "+result+"'");
-//             Add a new pair key - object in the History map.
-               map.put(result, obj);
 //             Add a new browser history entry.
                History.newItem(result);
        }
index bac67a0..308f463 100644 (file)
@@ -29,7 +29,6 @@ import gr.ebs.gss.client.rest.resource.TrashResource;
 
 import java.util.Iterator;
 
-import com.google.gwt.core.client.GWT;
 import com.google.gwt.dom.client.NativeEvent;
 import com.google.gwt.event.dom.client.ContextMenuEvent;
 import com.google.gwt.event.dom.client.ContextMenuHandler;
@@ -71,12 +70,12 @@ public class PopupTree extends Tree {
 
                        @Override
                        public void onSelection(SelectionEvent<TreeItem> event) {
-                               TreeItem item = event.getSelectedItem();
-                               GWT.log("====Inside PopupTree ====");
-                               GWT.log("item.getUserObject().toString() = '" +item.getUserObject().toString()+ "'");
-                               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);
+//                             ((RestResource) GSS.get().getFolders().getCurrent().getUserObject()).updateHistory(treeItem,path);
                                }
                });
 
@@ -234,130 +233,40 @@ 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")){
-//                     TrashResource currentObject = (TrashResource) GSS.get().getFolders().getCurrent().getUserObject();
-//                     return getTreeItem(uri2);
-               }
-               else if(uri2.equalsIgnoreCase("shared")){
-                       FolderResource currentObject = (FolderResource) GSS.get().getFolders().getCurrent().getUserObject();
-                       currentObject.getName();
-               }
-               else if(uri2.equalsIgnoreCase("others")){
-                       OtherUserResource currentObject = (OtherUserResource) GSS.get().getFolders().getCurrent().getUserObject();
-                       String objName = currentObject.getName();
-                       GWT.log("currentObject.getName() ='"+currentObject.getName()+"'");
-                       return getTreeItem(objName);
-
-               }
-               return getTreeItem(newUri);
-       }
-
-       /**
         * Method that takes a folderName and finds the corresponding treeItem object and returns it
         * @param historyToken
         * @return treeItem
         */
 
        public TreeItem getTreeItem (String historyToken){
-               GWT.log("----Inside getTreeItem ----");
                String historyTokenOriginal = historyToken.replace("+", " ");
-               GWT.log("historyTokenOriginal = '"+historyTokenOriginal+"'");
-
                String path = GSS.get().getApiPath() + GSS.get().getCurrentUserResource().getUsername()+ "/";
                Iterator<TreeItem> it = GSS.get().getFolders().getPopupTree().treeItemIterator() ;
                while(it.hasNext()){
-                       String name = "";
-                       TreeItem treeitem = it.next();
-                       if(treeitem.getUserObject() instanceof TrashResource){
-                               TrashResource currentObject = (TrashResource) treeitem.getUserObject();
-                               GWT.log("currentObject.toString() ='"+currentObject.toString() +"'");
-                               name = name +"Files/"+ currentObject.getUri().substring(path.lastIndexOf("/")+1);
-//                             "Files/"+ currentObject.getName();
-                               GWT.log("name = '"+name+"'");
-                       }
-                       if(treeitem.getUserObject() instanceof SharedResource){
-                               SharedResource currentObject = (SharedResource) treeitem.getUserObject();
-                               GWT.log("currentObject.toString() ='"+currentObject.toString() +"'");
-                               name = name +"Files/"+ currentObject.getUri().substring(path.lastIndexOf("/")+1);
-                               GWT.log("name = '"+name+"'");
+                       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 OthersResource){
-                               OthersResource currentObject = (OthersResource) treeitem.getUserObject();
-                               GWT.log("currentObject.toString() ='"+currentObject.toString() +"'");
-                               name = name + "Files/"+ path.substring(path.lastIndexOf("/")+1) + "others/";
-                               GWT.log("name = '"+name+"'");
+                       if(treeItem.getUserObject() instanceof SharedResource){
+                               SharedResource currentObject = (SharedResource) treeItem.getUserObject();
+                               constructedUri = constructedUri +currentObject.constructUri(treeItem, path);
                        }
-                       if(treeitem.getUserObject() instanceof OtherUserResource){
-                               OtherUserResource currentObject = (OtherUserResource) treeitem.getUserObject();
-                               GWT.log("currentObject.toString() ='"+currentObject.toString() +"'");
-                               name = name + "Files/others/"+ currentObject.getName();
-                               GWT.log("name = '"+name+"'");
+                       if(treeItem.getUserObject() instanceof OthersResource){
+                               OthersResource currentObject = (OthersResource) treeItem.getUserObject();
+                               constructedUri = constructedUri +currentObject.constructUri(treeItem, path);
                        }
-                       if(treeitem.getUserObject() instanceof FolderResource){
-                               FolderResource currentObject = (FolderResource) treeitem.getUserObject();
-                               GWT.log("currentObject.toString() ='"+currentObject.toString() +"'");
-                               GWT.log("currentObject.getParentURI() ='"+currentObject.getParentURI()+"'");
-                               if(currentObject.getParentURI() == null){
-                                       if(containsFolder(treeitem, "Trash")){
-//                                             case: selected folders below Trash folder
-                                               String partialUri = constructPartialPath(treeitem);
-                                               name = name +"Files/trash/" + partialUri;
-                                               GWT.log("name = '"+name+"'");
-                                       } else{
-//                                             case: home folders are selected
-                                               name = name + "Files/files/" + currentObject.getName();
-                                               GWT.log("name = '"+name+"'");
-                                       }
-                               }
-                               else if(treeitem.getParentItem() == null){
-//                                     this is the case when the user uses the browser's forward arrow to navigate through other's
-//                                     shared folders and      item.getParentItem is null only inside other's shared folder
-                                       String apiPath = GSS.get().getApiPath();
-                                       String newPath = currentObject.getParentURI().substring(apiPath.lastIndexOf("/"));
-                                       name = name + "Files"+ newPath + currentObject.getName();
-                                       GWT.log("name = '"+name+"'");
-                               }
-                               else if(containsFolder(treeitem, "My Shared")){
-//                                     case: selected folders below My Shared folder
-                                       String partialUri = constructPartialPath(treeitem);
-                                       name = name + "Files/shared/" + partialUri;
-                                       GWT.log("name = '"+name+"'");
-                               }else if(containsFolder(treeitem, "Other's Shared")){
-//                                     case: selected folders below Other's Shared folder
-                                       String partialPath = constructPartialPath(treeitem);
-                                       name = name + "Files/others/"+ partialPath;
-                                       GWT.log("name = '"+name+"'");
-                               }
-                               else{
-//                                     case:all folders in user's folders tree
-                                       String finalUri = currentObject.getParentURI().substring(path.lastIndexOf("/")) + currentObject.getName();
-                                       name = name + "Files"+ finalUri;
-                                       GWT.log("name = '"+name+"'");
-                               }
+                       if(treeItem.getUserObject() instanceof OtherUserResource){
+                               OtherUserResource currentObject = (OtherUserResource) treeItem.getUserObject();
+                               constructedUri = constructedUri +currentObject.constructUri(treeItem, path);
                        }
-
-                       if(name.equals(historyTokenOriginal)){
-                               GWT.log("@@@treeitem.toString() = '" +treeitem.toString() +"'");
-                               return treeitem;
+                       if(treeItem.getUserObject() instanceof FolderResource){
+                               FolderResource currentObject = (FolderResource) treeItem.getUserObject();
+                               constructedUri = constructedUri + currentObject.constructUri(treeItem, path);
                        }
+                       if(constructedUri.equals(historyTokenOriginal))
+                               return treeItem;
                        }
                return null;
        }
@@ -366,38 +275,5 @@ public class PopupTree extends Tree {
                String[] names = historyToken.split("/");
                return names[names.length -1];
        }
-       /**
-        * construct the partial path of the selected TreeItem
-        *
-        * @param selectedItem the selectedItem to check
-        */
-       private String constructPartialPath(TreeItem selectedItem){
-          String result = DisplayHelper.trim(selectedItem.getText());
-          TreeItem parent = selectedItem.getParentItem();
-          while (!(DisplayHelper.trim(parent.getText()).equals("My Shared") || DisplayHelper.trim(parent.getText()).equals("Other's Shared")||DisplayHelper.trim(parent.getText()).equals("Trash"))){
-             result = DisplayHelper.trim(parent.getText()) + "/" + result;
-             if(result.equals("My Shared")||result.equals("Other's Shared")) return result;
-             parent = parent.getParentItem();
-          }
-
-          return result;
-       }
-       /**
-        * examine whether a folder name like "Trash", "My Shared", "Other's Shared" is inside path
-        *
-        * @param selectedItem the selectedTreeItem to check
-        */
-
-       private boolean containsFolder(TreeItem selectedItem, String folderName){
-               TreeItem parent = selectedItem.getParentItem();
-               while (parent != null){
-                       String parentItemText = parent.getText();
-                       String parentItemTextTr = DisplayHelper.trim(parentItemText);
-                       if(parentItemTextTr.equals(folderName)) return true;
-                       parent = parent.getParentItem();
-                       }
-               return false;
-       }
-//     TODO when Groups or Search tab is selected then is there a TreeItem selected? guess not....
 
 }
index 395e23d..84e4861 100644 (file)
@@ -508,53 +508,6 @@ public class FolderResource extends RestResource {
        public void setFilesExpanded(boolean newFilesExpanded) {
                filesExpanded = newFilesExpanded;
        }
-
-       /**
-        * History support for folder navigation
-        * This method constructs the uri when a folder is selected. This folder is either below user's
-        * home directory or below "My Shared" or "Trash" or "Other's Shared" directory/
-        * (each if/else describes the case)
-        */
-       @Override
-       public void updateHistory(TreeItem item, String path){
-               try{
-                       GWT.log("getParentURI() ='"+getParentURI()+"'");
-                       if(getParentURI() == null){
-                               if(containsFolder(item, "Trash")){
-//                                     case: selected folders below Trash folder
-                                       String partialUri = constructPartialPath(item);
-                                       GSS.get().updateHistory("Files/trash/" + partialUri, item);
-                               } else
-//                                     case: home folders are selected
-                                       GSS.get().updateHistory("Files/files/" + getName(), item);
-                       }
-                       else if(item.getParentItem() == null){
-//                             this is the case when the user uses the browser's forward arrow to navigate through other's
-//                             shared folders and      item.getParentItem is null only inside other's shared folder
-                               String apiPath = GSS.get().getApiPath();
-                               String newPath = getParentURI().substring(apiPath.lastIndexOf("/"));
-                               GSS.get().updateHistory("Files"+ newPath + getName(), item);
-                       }
-                       else if(containsFolder(item, "My Shared")){
-//                             case: selected folders below My Shared folder
-                               String partialUri = constructPartialPath(item);
-                               GSS.get().updateHistory("Files/shared/" + partialUri, item);
-                       }else if(containsFolder(item, "Other's Shared")){
-//                             case: selected folders below Other's Shared folder
-                               String partialPath = constructPartialPath(item);
-                               GSS.get().updateHistory("Files/others/"+ partialPath, item);
-                       }
-                       else{
-//                             case:all folders in user's folders tree
-                               String finalUri = getParentURI().substring(path.lastIndexOf("/")) + getName();
-                               GSS.get().updateHistory("Files"+ finalUri, item);
-                       }
-
-               }catch (Exception e){
-                       throw new UnsupportedOperationException(e);
-               }
-
-       }
        /**
         * construct the partial path of the selected TreeItem
         *
@@ -587,5 +540,45 @@ public class FolderResource extends RestResource {
                        }
                return false;
        }
+       @Override
+       public String constructUri(TreeItem treeItem, String path){
+               String constructedUri = "";
+               if(containsFolder(treeItem, "My Shared")){
+                       //case: selected folders below My Shared folder
+                       String partialUri = constructPartialPath(treeItem);
+                       constructedUri = constructedUri + "Files/shared/" + partialUri;
+                       return constructedUri;
+               }else if(containsFolder(treeItem, "Other's Shared")){
+                       //case: selected folders below Other's Shared folder
+                       String partialPath = constructPartialPath(treeItem);
+                       constructedUri = constructedUri + "Files/others/"+ partialPath;
+                       return constructedUri;
+               }
+               else if(getParentURI()==null){
+                       if(containsFolder(treeItem, "Trash")){
+                               //case: selected folders below Trash folder
+                               String partialUri = constructPartialPath(treeItem);
+                               constructedUri = constructedUri + "Files/trash/" + partialUri;
+                               return constructedUri;
+                       }
+                       //case: home folder is selected
+                       constructedUri = constructedUri + "Files/files/" + getName();
+                       return constructedUri;
+               }
+               else if(treeItem.getParentItem() == null){
+                       //this is the case when the user uses the browser's forward arrow to navigate through other's
+                       //shared folders and item.getParentItem is null only inside other's shared folder
+                       String apiPath = GSS.get().getApiPath();
+                       String newPath = getParentURI().substring(apiPath.lastIndexOf("/"));
+                       constructedUri = constructedUri + "Files"+ newPath + getName();
+                       return constructedUri;
+               }
+               else{
+                       String finalUri = getParentURI().substring(path.lastIndexOf("/")) + getName();
+                       constructedUri = constructedUri + "Files"+ finalUri;
+                       return constructedUri;
+               }
+
+       }
 
 }
index 4392a4c..1ec64c1 100644 (file)
@@ -18,7 +18,6 @@
  */
 package gr.ebs.gss.client.rest.resource;
 
-import gr.ebs.gss.client.GSS;
 import gr.ebs.gss.client.rest.MultipleGetCommand;
 import gr.ebs.gss.client.rest.MultipleGetCommand.Cached;
 
@@ -238,12 +237,10 @@ public class OtherUserResource extends RestResource{
        public void setFilesExpanded(boolean newFilesExpanded) {
                filesExpanded = newFilesExpanded;
        }
-       /**
-        * History support for folder navigation.
-        * This is the case when a folder below "Other's Shared" is selected
-        */
+
        @Override
-       public void updateHistory(TreeItem item, String path){
-               GSS.get().updateHistory("Files/others/"+ getName(), item);
+       public String constructUri(TreeItem treeItem, String path){
+               String constructedUri = "Files/others/"+ getName();
+               return constructedUri;
        }
 }
index 9e77f46..9ca16ee 100644 (file)
@@ -18,8 +18,6 @@
  */
 package gr.ebs.gss.client.rest.resource;
 
-import gr.ebs.gss.client.GSS;
-
 import java.util.ArrayList;
 import java.util.List;
 
@@ -105,12 +103,9 @@ public class OthersResource extends RestResource {
                return null;
        }
 
-       /**
-        * History support for folder navigation
-        * This method constructs the uri when "Other's Shared" option is selected
-        */
        @Override
-       public void updateHistory(TreeItem item, String path){
-               GSS.get().updateHistory("Files/"+ path.substring(path.lastIndexOf("/")+1) + "others/", item);
+       public String constructUri(TreeItem treeItem,String path){
+               String constructedUri = "Files/"+ path.substring(path.lastIndexOf("/")+1) + "others/";
+               return constructedUri;
        }
 }
index a47597e..65e7fda 100644 (file)
@@ -81,8 +81,8 @@ public abstract class RestResource implements Serializable{
 
        public abstract String getLastModifiedSince();
 
-       public void updateHistory(@SuppressWarnings("unused") TreeItem item, @SuppressWarnings("unused") String path) {
-               // Most resources won't have to do anything here.
+       public String constructUri(@SuppressWarnings("unused") TreeItem treeItem, @SuppressWarnings("unused") String path){
+               return "";
        }
 
        public String getName(){
index c8f6081..65b0929 100644 (file)
@@ -18,7 +18,6 @@
  */
 package gr.ebs.gss.client.rest.resource;
 
-import gr.ebs.gss.client.GSS;
 import gr.ebs.gss.client.rest.MultipleGetCommand;
 import gr.ebs.gss.client.rest.MultipleGetCommand.Cached;
 
@@ -229,12 +228,11 @@ public class SharedResource extends RestResource{
        public void setFilesExpanded(boolean newFilesExpanded) {
                filesExpanded = newFilesExpanded;
        }
-       /**
-        * History support for folder navigation
-        * This method constructs the uri when "My Shared" folder option from the UI is selected
-        */
+
        @Override
-       public void updateHistory(TreeItem item, String path){
-               GSS.get().updateHistory("Files/"+ getUri().substring(path.lastIndexOf("/")+1), item);
+       public String constructUri(TreeItem treeItem, String path){
+               String constructedUri = "Files/"+ getUri().substring(path.lastIndexOf("/")+1);
+               return constructedUri;
        }
+
 }
index 8ad9c64..401e068 100644 (file)
@@ -18,8 +18,6 @@
  */
 package gr.ebs.gss.client.rest.resource;
 
-import gr.ebs.gss.client.GSS;
-
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.LinkedList;
@@ -200,12 +198,9 @@ public class TrashResource extends RestResource{
        public String getLastModifiedSince() {
                return null;
        }
-       /**
-        * History support for folder navigation.
-        * This method constructs the uri when "Trash" option is selected
-        */
        @Override
-       public void updateHistory(TreeItem item, String path){
-               GSS.get().updateHistory("Files/"+ getUri().substring(path.lastIndexOf("/")+1), item);
+       public String constructUri(TreeItem treeItem, String path){
+               String constructedUri = "Files/"+ getUri().substring(path.lastIndexOf("/")+1);
+               return constructedUri;
        }
 }