2014-02-17 19:20:45 +01:00
|
|
|
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;
|
2014-05-13 11:27:30 +02:00
|
|
|
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
|
2014-02-17 19:20:45 +01:00
|
|
|
|
|
|
|
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<FileTrashedModel> trashedFiles;
|
|
|
|
private TrashInfoContainer trashContainers;
|
|
|
|
private static WindowTrash INSTANCE = null;
|
|
|
|
|
|
|
|
|
|
|
|
private WindowTrash() {
|
|
|
|
initAccounting();
|
2014-05-13 17:46:02 +02:00
|
|
|
setIcon(Resources.getTrashFull()); //TODO
|
2014-02-17 19:20:45 +01:00
|
|
|
setHeading("Trash");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static synchronized WindowTrash getInstance(){
|
|
|
|
if(INSTANCE==null)
|
|
|
|
INSTANCE = new WindowTrash();
|
|
|
|
|
|
|
|
return INSTANCE;
|
|
|
|
}
|
2014-05-13 17:46:02 +02:00
|
|
|
|
2014-02-17 19:20:45 +01:00
|
|
|
private void initAccounting() {
|
|
|
|
setLayout(new FitLayout());
|
2014-05-13 18:43:35 +02:00
|
|
|
setSize(750, 400);
|
2014-02-17 19:20:45 +01:00
|
|
|
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){
|
2014-05-13 17:46:02 +02:00
|
|
|
boolean deleted = this.trashContainers.deleteItem(fileModelId);
|
|
|
|
|
|
|
|
updateTrashIcon(this.trashContainers.trashSize()>0);
|
|
|
|
|
|
|
|
return deleted;
|
2014-02-17 19:20:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void updateTrashContainer(List<FileTrashedModel> trashFiles) {
|
|
|
|
|
|
|
|
this.trashContainers.resetStore();
|
|
|
|
this.trashedFiles = trashFiles;
|
|
|
|
this.trashContainers.updateTrash(trashFiles);
|
2014-05-13 17:46:02 +02:00
|
|
|
|
|
|
|
updateTrashIcon(this.trashContainers.trashSize()>0);
|
2014-02-17 19:20:45 +01:00
|
|
|
}
|
2014-05-13 11:27:30 +02:00
|
|
|
|
|
|
|
public void executeOperationOnTrashContainer(List<String> trashIds, WorkspaceTrashOperation operation) {
|
|
|
|
|
|
|
|
if(operation.equals(WorkspaceTrashOperation.DELETE_PERMANENTLY)){
|
|
|
|
deleteListItems(trashIds);
|
|
|
|
|
|
|
|
}else if(operation.equals(WorkspaceTrashOperation.RESTORE)){
|
|
|
|
deleteListItems(trashIds);
|
|
|
|
}
|
2014-05-13 17:46:02 +02:00
|
|
|
|
|
|
|
updateTrashIcon(this.trashContainers.trashSize()>0);
|
2014-05-13 11:27:30 +02:00
|
|
|
}
|
2014-02-17 19:20:45 +01:00
|
|
|
|
|
|
|
public List<FileTrashedModel> getTrashedFiles() {
|
|
|
|
return trashedFiles;
|
|
|
|
}
|
|
|
|
|
2014-05-13 11:27:30 +02:00
|
|
|
private void deleteListItems(List<String> trashIds){
|
|
|
|
|
|
|
|
for (String identifier : trashIds) {
|
|
|
|
this.trashContainers.deleteItem(identifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
public void maskContainer(String title){
|
|
|
|
this.trashContainers.mask(title, ConstantsExplorer.LOADINGSTYLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unmaskContainer(){
|
|
|
|
this.trashContainers.unmask();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateTrashIcon(boolean trashIsFull){
|
2014-02-17 19:20:45 +01:00
|
|
|
|
2014-05-13 17:46:02 +02:00
|
|
|
if(trashIsFull)
|
|
|
|
setIcon(Resources.getTrashFull());
|
2014-02-17 19:20:45 +01:00
|
|
|
else
|
2014-05-13 17:46:02 +02:00
|
|
|
setIcon(Resources.getTrashEmpty());
|
2014-02-17 19:20:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|