workspace/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/WindowTrash.java

138 lines
3.2 KiB
Java
Raw Normal View History

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<FileTrashedModel> trashedFiles;
private TrashInfoContainer trashContainers;
private static WindowTrash INSTANCE = null;
private WindowTrash() {
initAccounting();
setIcon(Resources.getTrash()); //TODO
setHeading("Trash");
// addResizeListner();
}
/**
*
* @return
*/
public static synchronized WindowTrash getInstance(){
if(INSTANCE==null)
INSTANCE = new WindowTrash();
return INSTANCE;
}
// public void addResizeListner(){
//
// this.addListener(Events.Resize, new Listener<WindowEvent>() {
//
// @Override
// public void handleEvent(WindowEvent we )
// {
//
// if(trashContainers!=null){
//// System.out.println("Size in event: " + we.getWidth() + "x" + we.getHeight() );
//// accountingsContainers.setPanelSize(we.getWidth()-14, we.getHeight()-30);
// }
// }
//
// });
// }
// public WindowTrash(List<FileModel> trashFiles) {
// updateTrashContainer(trashFiles);
// }
private void initAccounting() {
// setModal(true);
setLayout(new FitLayout());
setSize(700, 350);
setResizable(true);
setMaximizable(true);
// setCollapsible(true);
this.trashContainers = new TrashInfoContainer();
add(trashContainers);
}
public void setWindowTitle(String title) {
this.setHeading(title);
}
/**
*
* @param fileModelId
* @return
*/
public boolean deleteFileFromTrash(String fileModelId){
return this.trashContainers.deleteItem(fileModelId);
}
public void updateTrashContainer(List<FileTrashedModel> trashFiles) {
this.trashContainers.resetStore();
this.trashedFiles = trashFiles;
this.trashContainers.updateTrash(trashFiles);
}
public void executeOperationOnTrashContainer(List<String> trashIds, WorkspaceTrashOperation operation) {
if(operation.equals(WorkspaceTrashOperation.DELETE_PERMANENTLY)){
deleteListItems(trashIds);
}else if(operation.equals(WorkspaceTrashOperation.RESTORE)){
deleteListItems(trashIds);
}
}
public List<FileTrashedModel> getTrashedFiles() {
return trashedFiles;
}
private void deleteListItems(List<String> trashIds){
for (String identifier : trashIds) {
this.trashContainers.deleteItem(identifier);
}
}
public void maskAccountingInfo(boolean bool){
// if(accountingsContainers!=null){
//
// if(bool)
// accountingsContainers.mask(ConstantsExplorer.LOADING, ConstantsExplorer.LOADINGSTYLE);
// else
// accountingsContainers.unmask();
// }
if(bool)
this.mask(ConstantsExplorer.LOADING, ConstantsExplorer.LOADINGSTYLE);
else
this.unmask();
}
}