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;
@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);
+ }
});
addOpenHandler(new OpenHandler<TreeItem>() {
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 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()){
- 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+"'");
+ 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();
- GWT.log("currentObject.toString() ='"+currentObject.toString() +"'");
- name = name +"Files/"+ currentObject.getUri().substring(path.lastIndexOf("/")+1);
- GWT.log("name = '"+name+"'");
+ 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();
- GWT.log("currentObject.toString() ='"+currentObject.toString() +"'");
- name = name + "Files/"+ path.substring(path.lastIndexOf("/")+1) + "others/";
- GWT.log("name = '"+name+"'");
+ if(treeItem.getUserObject() instanceof OthersResource){
+ OthersResource currentObject = (OthersResource) 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 OtherUserResource){
+ OtherUserResource currentObject = (OtherUserResource) 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 FolderResource){
+ FolderResource currentObject = (FolderResource) treeItem.getUserObject();
+ constructedUri = constructedUri + currentObject.constructUri(treeItem, path);
}
+ if(constructedUri.equals(historyToken))
+ return treeItem;
+ }
+ return expandHiddenItems(uriToGet);
- if(name.equals(historyTokenOriginal)){
- GWT.log("@@@treeitem.toString() = '" +treeitem.toString() +"'");
- return treeitem;
- }
- }
- return null;
}
- public String getFolderName(String historyToken){
- 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;
+ 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;
}
-// TODO when Groups or Search tab is selected then is there a TreeItem selected? guess not....
+
}