273 lines
7.1 KiB
Java
273 lines
7.1 KiB
Java
|
package org.gcube.portlets.user.workspace.client.model;
|
||
|
|
||
|
import java.io.Serializable;
|
||
|
import java.util.List;
|
||
|
|
||
|
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
||
|
import org.gcube.portlets.user.workspace.client.interfaces.GXTFolderItemTypeEnum;
|
||
|
import org.gcube.portlets.user.workspace.client.resources.Resources;
|
||
|
|
||
|
import com.extjs.gxt.ui.client.data.BaseModelData;
|
||
|
import com.google.gwt.user.client.ui.AbstractImagePrototype;
|
||
|
import com.google.gwt.user.client.ui.Image;
|
||
|
|
||
|
/**
|
||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||
|
*
|
||
|
*/
|
||
|
public class FileModel extends BaseModelData implements Serializable {
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
private static final long serialVersionUID = 1L;
|
||
|
|
||
|
protected GXTFolderItemTypeEnum test; //TODO remove?
|
||
|
protected InfoContactModel infoContacts;
|
||
|
protected boolean isRoot = false;
|
||
|
protected FileModel(){
|
||
|
}
|
||
|
|
||
|
public FileModel(String identifier, String name, FileModel parent, boolean isDirectory, boolean isShared) {
|
||
|
setIdentifier(identifier);
|
||
|
setName(name);
|
||
|
setParentFileModel(parent);
|
||
|
setIsDirectory(isDirectory);
|
||
|
setShared(isShared);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* USED FOR ATTACHMENTS AND FolderBulkCreator
|
||
|
* @param identifier
|
||
|
* @param name
|
||
|
* @param isDirectory
|
||
|
*/
|
||
|
public FileModel(String identifier, String name, boolean isDirectory) {
|
||
|
setIdentifier(identifier);
|
||
|
setName(name);
|
||
|
setIsDirectory(isDirectory);
|
||
|
}
|
||
|
|
||
|
public FileModel(String identifier, String name, String type, GXTFolderItemTypeEnum folderItemTypeEnum, boolean isDirectory, boolean isShared) {
|
||
|
setIdentifier(identifier);
|
||
|
setName(name);
|
||
|
setType(type);
|
||
|
setFolderItemType(folderItemTypeEnum);
|
||
|
setIsDirectory(isDirectory);
|
||
|
setShared(isShared);
|
||
|
}
|
||
|
|
||
|
public void setParentFileModel(FileModel parent) {
|
||
|
set(ConstantsExplorer.PARENT,parent);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Status values
|
||
|
* ConstantsExplorer.FOLDERNOTLOAD = "notload";
|
||
|
* ConstantsExplorer.FOLDERLOADED = "loaded";
|
||
|
* @param status
|
||
|
*/
|
||
|
public void setStatus(String status) {
|
||
|
set("status", status);
|
||
|
}
|
||
|
|
||
|
public void setIcon() {
|
||
|
|
||
|
AbstractImagePrototype absImgPr = null;
|
||
|
|
||
|
if (!this.isDirectory()) {
|
||
|
if(this.getType()!=null)
|
||
|
absImgPr = Resources.getIconByType(this.getType());
|
||
|
// absImgPr = Resources.getImageCancel();
|
||
|
else
|
||
|
absImgPr = Resources.getIconByFolderItemType(this.getGXTFolderItemType());
|
||
|
}
|
||
|
//SHARED FOLDER
|
||
|
else if(this.isShared()){
|
||
|
|
||
|
absImgPr = Resources.getIconSharedFolder();
|
||
|
|
||
|
//SIMPLE FOLDER
|
||
|
}else{
|
||
|
absImgPr = Resources.getIconFolder();
|
||
|
}
|
||
|
|
||
|
set(ConstantsExplorer.ICON, absImgPr.createImage());
|
||
|
set(ConstantsExplorer.ABSTRACTICON, absImgPr);
|
||
|
}
|
||
|
|
||
|
public void setOwner(InfoContactModel owner){
|
||
|
set(ConstantsExplorer.OWNER, owner);
|
||
|
}
|
||
|
|
||
|
public void setMarkAsRead(boolean mark){
|
||
|
set(ConstantsExplorer.MARKASREAD, mark);
|
||
|
}
|
||
|
public boolean isMarkAsRead(){
|
||
|
return (Boolean) get(ConstantsExplorer.MARKASREAD);
|
||
|
}
|
||
|
|
||
|
//TODO Accounting
|
||
|
|
||
|
public InfoContactModel getOwner(){
|
||
|
return (InfoContactModel) get(ConstantsExplorer.OWNER);
|
||
|
}
|
||
|
|
||
|
public void setSharingValue(boolean isShared, List<InfoContactModel> listShareUsers){
|
||
|
set(ConstantsExplorer.ISSHARED, isShared);
|
||
|
set(ConstantsExplorer.SHAREUSERS, listShareUsers);
|
||
|
}
|
||
|
|
||
|
@SuppressWarnings("unchecked")
|
||
|
public List<InfoContactModel> getListUserSharing(){
|
||
|
return (List<InfoContactModel>) get(ConstantsExplorer.SHAREUSERS);
|
||
|
}
|
||
|
|
||
|
public void setListShareUser(List<InfoContactModel> listShareUsers){
|
||
|
set(ConstantsExplorer.SHAREUSERS, listShareUsers);
|
||
|
}
|
||
|
|
||
|
public boolean isShared(){
|
||
|
return (Boolean) get(ConstantsExplorer.ISSHARED);
|
||
|
}
|
||
|
|
||
|
public boolean isRoot(){
|
||
|
return isRoot;
|
||
|
}
|
||
|
|
||
|
public void setIsRoot(boolean isRoot){
|
||
|
this.isRoot = isRoot;
|
||
|
}
|
||
|
|
||
|
|
||
|
public Image getIcon() {
|
||
|
return (Image) get(ConstantsExplorer.ICON);
|
||
|
}
|
||
|
|
||
|
public AbstractImagePrototype getAbstractPrototypeIcon() {
|
||
|
return (AbstractImagePrototype) get(ConstantsExplorer.ABSTRACTICON);
|
||
|
}
|
||
|
|
||
|
|
||
|
public String getStatus() {
|
||
|
return get("status");
|
||
|
}
|
||
|
|
||
|
|
||
|
private void setIsDirectory(boolean flag){
|
||
|
set(ConstantsExplorer.ISDIRECTORY, flag);
|
||
|
}
|
||
|
|
||
|
public void setIdentifier(String identifier) {
|
||
|
set(ConstantsExplorer.IDENTIFIER, identifier);
|
||
|
}
|
||
|
|
||
|
public String getIdentifier(){
|
||
|
return get(ConstantsExplorer.IDENTIFIER);
|
||
|
}
|
||
|
|
||
|
public void setShortcutCategory(String category) {
|
||
|
set(ConstantsExplorer.SHORTCUTCATEGORY, category);
|
||
|
}
|
||
|
|
||
|
public String getShortcutCategory(){
|
||
|
return get(ConstantsExplorer.SHORTCUTCATEGORY).toString();
|
||
|
}
|
||
|
|
||
|
|
||
|
private void setName(String name) {
|
||
|
set(ConstantsExplorer.NAME, name);
|
||
|
}
|
||
|
|
||
|
public String getName() {
|
||
|
return get(ConstantsExplorer.NAME);
|
||
|
}
|
||
|
|
||
|
public FileModel getParentFileModel(){
|
||
|
return get(ConstantsExplorer.PARENT);
|
||
|
}
|
||
|
|
||
|
public boolean isDirectory(){
|
||
|
return (Boolean) get(ConstantsExplorer.ISDIRECTORY);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean equals(Object obj) {
|
||
|
if (obj != null && obj instanceof FileModel) {
|
||
|
FileModel mobj = (FileModel) obj;
|
||
|
return getIdentifier().equals(mobj.getIdentifier());
|
||
|
}
|
||
|
return super.equals(obj);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param isShared the isShared to set
|
||
|
*/
|
||
|
public void setShared(boolean isShared) {
|
||
|
set(ConstantsExplorer.ISSHARED, isShared);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* It's: folder, mime type or unknown
|
||
|
* @param type
|
||
|
*/
|
||
|
public void setType(String type){
|
||
|
set(ConstantsExplorer.TYPE, type);
|
||
|
}
|
||
|
|
||
|
public String getType(){
|
||
|
return get(ConstantsExplorer.TYPE);
|
||
|
}
|
||
|
|
||
|
public void setFolderItemType(GXTFolderItemTypeEnum folderItemTypeEnum){
|
||
|
set(ConstantsExplorer.FOLDERITEMTYPE, folderItemTypeEnum);
|
||
|
}
|
||
|
|
||
|
public GXTFolderItemTypeEnum getGXTFolderItemType(){
|
||
|
return (GXTFolderItemTypeEnum) get(ConstantsExplorer.FOLDERITEMTYPE);
|
||
|
}
|
||
|
|
||
|
public String getGXTFolderItemTypeToString(){
|
||
|
return get(ConstantsExplorer.FOLDERITEMTYPE).toString();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String toString() {
|
||
|
StringBuilder builder = new StringBuilder();
|
||
|
builder.append("FileModel [isMarkAsRead()=");
|
||
|
builder.append(isMarkAsRead());
|
||
|
builder.append(", getOwner()=");
|
||
|
builder.append(getOwner());
|
||
|
builder.append(", getListUserSharing()=");
|
||
|
builder.append(getListUserSharing());
|
||
|
builder.append(", isShared()=");
|
||
|
builder.append(isShared());
|
||
|
builder.append(", getIcon()=");
|
||
|
builder.append(getIcon());
|
||
|
builder.append(", getAbstractPrototypeIcon()=");
|
||
|
builder.append(getAbstractPrototypeIcon());
|
||
|
builder.append(", getStatus()=");
|
||
|
builder.append(getStatus());
|
||
|
builder.append(", getIdentifier()=");
|
||
|
builder.append(getIdentifier());
|
||
|
builder.append(", getShortcutCategory()=");
|
||
|
builder.append(getShortcutCategory());
|
||
|
builder.append(", getName()=");
|
||
|
builder.append(getName());
|
||
|
builder.append(", getParentFileModel()=");
|
||
|
builder.append(getParentFileModel());
|
||
|
builder.append(", isDirectory()=");
|
||
|
builder.append(isDirectory());
|
||
|
builder.append(", getType()=");
|
||
|
builder.append(getType());
|
||
|
builder.append(", getGXTFolderItemType()=");
|
||
|
builder.append(getGXTFolderItemType());
|
||
|
builder.append(", getGXTFolderItemTypeToString()=");
|
||
|
builder.append(getGXTFolderItemTypeToString());
|
||
|
builder.append("]");
|
||
|
return builder.toString();
|
||
|
}
|
||
|
|
||
|
}
|