/*
- * Copyright 2008, 2009 Electronic Business Systems Ltd. This file is part of
- * GSS. GSS is free software: you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version. GSS is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details. You should have received a copy of the GNU General Public License
- * along with GSS. If not, see <http://www.gnu.org/licenses/>.
+ * Copyright 2008, 2009, 2010 Electronic Business Systems Ltd.
+ *
+ * This file is part of GSS.
+ *
+ * GSS is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GSS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GSS. If not, see <http://www.gnu.org/licenses/>.
*/
package gr.ebs.gss.client;
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.SharedResource;
+import gr.ebs.gss.client.rest.resource.TrashResource;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.dom.client.ContextMenuEvent;
import com.google.gwt.event.logical.shared.OpenHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
+import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.History;
images = theImages;
sinkEvents(Event.ONCONTEXTMENU);
sinkEvents(Event.ONMOUSEUP);
- // sinkEvents(Event.ONMOUSEDOWN);
+// sinkEvents(Event.ONMOUSEDOWN);
addSelectionHandler(new SelectionHandler<TreeItem>() {
public void onSelection(SelectionEvent<TreeItem> event) {
TreeItem item = event.getSelectedItem();
processItemSelected(item, true);
- String path = GSS.get().getApiPath() + GSS.get().getCurrentUserResource().getUsername()+ "/";
- FolderResource currentObject = (FolderResource) GSS.get().getFolders().getCurrent().getUserObject();
-// String currentURI = currentObject.getParentURI();
- History.newItem("Files" + currentObject.getParentURI().substring(path.lastIndexOf("/")) + GSS.get().getFolders().getCurrent().getText());
-// History.newItem(currentObject.getParentURI() + GSS.get().getFolders().getCurrent().getText());
+
+ String path = GSS.get().getApiPath() + GSS.get().getCurrentUserResource().getUsername()+ "/";
+
+// case: Trash is selected
+ if(GSS.get().getFolders().isTrash(item)){
+ TrashResource currentObject = (TrashResource) GSS.get().getFolders().getCurrent().getUserObject();
+ String finalUri = currentObject.getUri().substring(path.lastIndexOf("/")+1);
+ History.newItem("Files/"+finalUri);
+ }
+// case: Other's shared option is selected
+ else if (GSS.get().getFolders().getCurrent().getUserObject() instanceof OthersResource){
+ String currentPartTrimmed = DisplayHelper.trim(item.getText());
+ String finalUri = URL.encodeComponent("Files/"+path.substring(path.lastIndexOf("/")+1) + currentPartTrimmed);
+
+ History.newItem(finalUri);
+ }
+// case: expand Other's shared to folder below
+ else if(GSS.get().getFolders().getCurrent().getUserObject() instanceof OtherUserResource){
+ OtherUserResource currentObject = (OtherUserResource) GSS.get().getFolders().getCurrent().getUserObject();
+ String finalUri = URL.encodeComponent("others/"+ currentObject.getName());
+ History.newItem(finalUri);
+ }
+// case: my shared is selected
+ else if(GSS.get().getFolders().getCurrent().getUserObject() instanceof SharedResource){
+ SharedResource currentObject = (SharedResource) GSS.get().getFolders().getCurrent().getUserObject();
+ String finalUri = currentObject.getUri().substring(path.lastIndexOf("/")+1);
+ History.newItem("Files/"+finalUri);
+ }
+
+// case: home folders are selected
+ else{
+ FolderResource currentObject = (FolderResource) GSS.get().getFolders().getCurrent().getUserObject();
+ String parentUri = currentObject.getParentURI();
+ if(parentUri == null){
+ if(containsTrash(GSS.get().getFolders().getCurrent())){
+ String finalUri = constructPartialPath(GSS.get().getFolders().getCurrent());
+ History.newItem("trash/"+finalUri);
+ }else{
+ String nonEncodedUri = "Files/" + currentObject.getName();
+
+ History.newItem(URL.encode(nonEncodedUri));
+ }
+ } else if(containsSharedFolder(GSS.get().getFolders().getCurrent())){
+ String finalUri = constructPartialPath(GSS.get().getFolders().getCurrent());
+ History.newItem("shared/"+finalUri);
+ }else if(containsSharedFolder(GSS.get().getFolders().getCurrent())){
+ String finalUri = constructPartialPath(GSS.get().getFolders().getCurrent());
+ History.newItem("other's/"+finalUri);
+ }
+ else{
+ String uri = "Files"+ parentUri.substring(path.lastIndexOf("/")) + URL.encode(currentObject.getName());
+ History.newItem(uri);
+ }
+ }
}
+
+
});
addOpenHandler(new OpenHandler<TreeItem>() {
GSS.get().showFileList();
}
// refresh Others Shared User Node
- // else if(GSS.get().getFolders().isOthersSharedItem(item) &&
- // item.getUserObject() instanceof UserDTO)
- // GSS.get().getFolders().update(item);
+// else if(GSS.get().getFolders().isOthersSharedItem(item) &&
+// item.getUserObject() instanceof UserDTO)
+// GSS.get().getFolders().update(item);
if (!item.equals(treeSelectedItem))
processSelection(item);
treeSelectedItem = newSelectedItem;
}
+ /**
+ * examine whether there is "My Shared" inside path
+ *
+ * @param selectedItem the selectedItem to check
+ */
+
+ public boolean containsSharedFolder(TreeItem selectedItem){
+ TreeItem parent = selectedItem.getParentItem();
+ while (parent != null){
+ String parentItemText = parent.getText();
+ String parentItemTextTr = DisplayHelper.trim(parentItemText);
+ if(parentItemTextTr.equals("My Shared")||parentItemTextTr.equals("Other's Shared")) return true;
+ parent = parent.getParentItem();
+ }
+ return false;
+ }
+ public boolean containsTrash(TreeItem selectedItem){
+ TreeItem parent = selectedItem.getParentItem();
+ while (parent != null){
+ String parentItemText = parent.getText();
+ String parentItemTextTr = DisplayHelper.trim(parentItemText);
+ if(parentItemTextTr.equals("Trash")) return true;
+ parent = parent.getParentItem();
+ }
+ return false;
+ }
+
+ /**
+ * construct the partial path of the selected TreeItem
+ *
+ * @param selectedItem the selectedItem to check
+ */
+ public 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;
+ }
+
+
}