package org.gcube.portlets.user.workspace.client.view.trash; import java.util.List; import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.client.model.FileTrashedModel; import org.gcube.portlets.user.workspace.client.resources.Resources; import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation; import com.extjs.gxt.ui.client.widget.Window; import com.extjs.gxt.ui.client.widget.layout.FitLayout; /** * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @May 23, 2013 * * Singleton */ public class WindowTrash extends Window { private List trashedFiles; private TrashInfoContainer trashContainers; private static WindowTrash INSTANCE = null; private WindowTrash() { initAccounting(); setIcon(Resources.getTrashFull()); //TODO setHeading("Trash"); } /** * * @return */ public static synchronized WindowTrash getInstance(){ if(INSTANCE==null) INSTANCE = new WindowTrash(); return INSTANCE; } private void initAccounting() { setLayout(new FitLayout()); setSize(750, 400); setResizable(true); setMaximizable(true); this.trashContainers = new TrashInfoContainer(); add(trashContainers); } public void setWindowTitle(String title) { this.setHeading(title); } /** * * @param fileModelId * @return */ public boolean deleteFileFromTrash(String fileModelId){ boolean deleted = this.trashContainers.deleteItem(fileModelId); updateTrashIcon(this.trashContainers.trashSize()>0); return deleted; } public void updateTrashContainer(List trashFiles) { this.trashContainers.resetStore(); this.trashedFiles = trashFiles; this.trashContainers.updateTrash(trashFiles); updateTrashIcon(this.trashContainers.trashSize()>0); } public void executeOperationOnTrashContainer(List trashIds, WorkspaceTrashOperation operation) { if(operation.equals(WorkspaceTrashOperation.DELETE_PERMANENTLY)){ deleteListItems(trashIds); }else if(operation.equals(WorkspaceTrashOperation.RESTORE)){ deleteListItems(trashIds); } updateTrashIcon(this.trashContainers.trashSize()>0); } public List getTrashedFiles() { return trashedFiles; } private void deleteListItems(List trashIds){ for (String identifier : trashIds) { this.trashContainers.deleteItem(identifier); } } public void maskContainer(String title){ this.trashContainers.mask(title, ConstantsExplorer.LOADINGSTYLE); } public void unmaskContainer(){ this.trashContainers.unmask(); } public void updateTrashIcon(boolean trashIsFull){ if(trashIsFull) setIcon(Resources.getTrashFull()); else setIcon(Resources.getTrashEmpty()); } }