/*
- * Copyright 2009 Electronic Business Systems Ltd.
+ * Copyright 2009, 2010 Electronic Business Systems Ltd.
*
* This file is part of GSS.
*
package gr.ebs.gss.client.rest.resource;
+import gr.ebs.gss.client.DisplayHelper;
+import gr.ebs.gss.client.GSS;
import gr.ebs.gss.client.rest.MultipleGetCommand;
import gr.ebs.gss.client.rest.MultipleGetCommand.Cached;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
+import com.google.gwt.user.client.ui.TreeItem;
/**
* @author kman
private boolean filesExpanded=false;
+ boolean readForAll;
+
+ Boolean shared;
+
+
+ /**
+ * Retrieve the shared.
+ *
+ * @return the shared
+ */
+ public Boolean getShared() {
+ return shared;
+ }
+
+
+ /**
+ * Modify the shared.
+ *
+ * @param shared the shared to set
+ */
+ public void setShared(Boolean shared) {
+ this.shared = shared;
+ }
+
/**
* Modify the parentName.
*
*
* @return the name
*/
+ @Override
public String getName() {
return name;
}
JSONObject json = (JSONObject) JSONParser.parse(text);
name = unmarshallString(json, "name");
owner = unmarshallString(json, "owner");
+ createdBy = unmarshallString(json, "createdBy");
+ modifiedBy = unmarshallString(json, "modifiedBy");
deleted = unmarshallBoolean(json, "deleted");
+ shared = unmarshallBoolean(json, "shared");
+ readForAll = unmarshallBoolean(json, "readForAll");
if (deleted)
GWT.log("FOUND A DELETED FOLDER:" + name, null);
JSONObject parent = json.get("parent").isObject();
parentURI = unmarshallString(parent, "uri");
parentName = unmarshallString(parent, "name");
- if(parentName != null)
- parentName = URL.decodeComponent(parentName);
}
if (json.get("permissions") != null) {
subUri = subUri + "/";
FolderResource sub = new FolderResource(subUri);
sub.setName(subName);
+ sub.setParentURI(uri);
+ sub.setParentName(name);
sub.setNeedsExpanding(true);
folders.add(sub);
subfolderPaths.add(subUri);
String fowner = unmarshallString(fo, "owner");
String fcontent = unmarshallString(fo, "content");
String fpath = unmarshallString(fo, "path");
+ Boolean fshared = unmarshallBoolean(fo, "shared");
fpath = URL.decodeComponent(fpath);
Integer fversion = null;
if (fo.get("version") != null)
fs.setVersion(fversion);
fs.setContentLength(fsize);
fs.setDeleted(fdeleted);
+ fs.setShared(fshared);
fs.setCreationDate(fcreationDate);
fs.setModificationDate(fmodificationDate);
fs.setContentType(fcontent);
public void setFilesExpanded(boolean newFilesExpanded) {
filesExpanded = newFilesExpanded;
}
+ /**
+ * this method constructs the partial path of a given TreeItem using it's text
+ *
+ * @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;
+ }
+ @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;
+ }
+
+ }
+
+ /**
+ * Retrieve the readForAll.
+ *
+ * @return the readForAll
+ */
+ public boolean isReadForAll() {
+ return readForAll;
+ }
+ /**
+ * Modify the readForAll.
+ *
+ * @param newReadForAll the readForAll to set
+ */
+ public void setReadForAll(boolean newReadForAll) {
+ readForAll = newReadForAll;
+ }
+
}