From 0b53c23b4aec7a435f79b49d9efaa2cfdbad886b Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Tue, 13 May 2014 09:27:30 +0000 Subject: [PATCH] enhancements on trash git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace@95585 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../user/workspace/client/AppController.java | 134 +++++++++++++----- .../view/toolbars/GxtBottomToolBarItem.java | 6 +- .../client/view/trash/TrashInfoContainer.java | 17 +-- .../client/view/trash/WindowTrash.java | 18 +++ 4 files changed, 122 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/AppController.java b/src/main/java/org/gcube/portlets/user/workspace/client/AppController.java index 1efa813..fcac748 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/AppController.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/AppController.java @@ -94,7 +94,8 @@ import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplay; import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert; import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxConfirm; import org.gcube.portlets.user.workspace.shared.SessionExpiredException; -import org.gcube.portlets.user.workspace.shared.TrashOperationResult; +import org.gcube.portlets.user.workspace.shared.TrashContent; +import org.gcube.portlets.user.workspace.shared.TrashOperationContent; import org.gcube.portlets.user.workspace.shared.WorkspaceACL; import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation; import org.gcube.portlets.widgets.wsmail.client.forms.MailForm; @@ -176,35 +177,8 @@ public class AppController implements SubscriberInterface { @Override public void onTrashEvent(TrashEvent trashEvent) { - - - switch (trashEvent.getTrashOperation()) { - case SHOW: - WindowTrash.getInstance().show(); - break; - default: - - if(trashEvent.getTrashOperation()!=null){ - WindowTrash.getInstance().mask("Submitting Operation"); - AppControllerExplorer.rpcWorkspaceService.executeOperationOnTrash(trashEvent.getTargetFileModel().getIdentifier(), trashEvent.getTrashOperation(), new AsyncCallback() { - - @Override - public void onFailure(Throwable arg0) { - WindowTrash.getInstance().unmask(); - - } - - @Override - public void onSuccess(TrashOperationResult operationResult) { - WindowTrash.getInstance().unmask(); - WindowTrash.getInstance().updateTrashContainer(operationResult.getTrashContent()); - } - }); - - } - break; - } + executeTrashOperation(trashEvent.getTrashOperation(), trashEvent.getTargetFileModels()); } }); @@ -1223,6 +1197,14 @@ public class AppController implements SubscriberInterface { } + //LOADING TRASH CONTENT + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + executeTrashOperation(WorkspaceTrashOperation.REFRESH, null); + } + }); + } @@ -1418,6 +1400,9 @@ public class AppController implements SubscriberInterface { @Override public boolean deleteItem(String itemIdentifier) { + + executeTrashOperation(WorkspaceTrashOperation.REFRESH, null); + return wsPortlet.getGridGroupContainer().deleteItem(itemIdentifier); } @@ -1665,16 +1650,6 @@ public class AppController implements SubscriberInterface { } - - /* (non-Javadoc) - * @see org.gcube.portlets.user.workspace.client.interfaces.SubscriberInterface#trashEvent(org.gcube.portlets.user.workspace.client.event.TrashEvent.TRASHOPERATION, org.gcube.portlets.user.workspace.client.model.FileModel) - */ - @Override - public void trashEvent(WorkspaceTrashOperation trashOperation, FileModel targetFileModel) { - - } - - /* (non-Javadoc) * @see org.gcube.portlets.user.workspace.client.interfaces.SubscriberInterface#updatedVREPermissions(java.lang.String) */ @@ -1691,4 +1666,85 @@ public class AppController implements SubscriberInterface { setACLInfo(vreFolderId); } } + + /** + * + * @param operation + * @param trashItemId + */ + private void executeTrashOperation(WorkspaceTrashOperation operation, List trashItemIds){ + + GWT.log("Executing trash operation: "+operation); + + if(operation==null) + return; + + switch (operation) { + + case SHOW: + WindowTrash.getInstance().show(); + break; + + case DELETE_PERMANENTLY: + case RESTORE:{ + + if(trashItemIds==null || trashItemIds.isEmpty()) + return; + + + WindowTrash.getInstance().mask("Updating Trash"); + List trashIds = new ArrayList(trashItemIds.size()); + for (FileModel fileModel : trashItemIds) { + trashIds.add(fileModel.getIdentifier()); + } + + AppControllerExplorer.rpcWorkspaceService.executeOperationOnTrash(trashIds, operation, new AsyncCallback() { + + @Override + public void onFailure(Throwable arg0) { + WindowTrash.getInstance().unmask(); + + } + + @Override + public void onSuccess(TrashOperationContent operationResult) { + WindowTrash.getInstance().unmask(); + + WindowTrash.getInstance().executeOperationOnTrashContainer(operationResult.getListTrashIds(), operationResult.getOperation()); + } + }); + } + + default:{ + + WindowTrash.getInstance().mask("Updating Trash"); + AppControllerExplorer.rpcWorkspaceService.updateTrashContent(operation, new AsyncCallback() { + + @Override + public void onFailure(Throwable arg0) { + WindowTrash.getInstance().unmask(); + + } + + @Override + public void onSuccess(TrashContent operationResult) { + WindowTrash.getInstance().unmask(); + WindowTrash.getInstance().updateTrashContainer(operationResult.getTrashContent()); + } + }); + + break; + } + } + } + + + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.interfaces.SubscriberInterface#trashEvent(org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation, java.util.List) + */ + @Override + public void trashEvent(WorkspaceTrashOperation trashOperation, List targetFileModels) { + executeTrashOperation(trashOperation, targetFileModels); + + } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtBottomToolBarItem.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtBottomToolBarItem.java index 5b38a60..b653aab 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtBottomToolBarItem.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtBottomToolBarItem.java @@ -120,10 +120,8 @@ public class GxtBottomToolBarItem extends ToolBar{ } }); -// add(new FillToolItem()); -// add(btnGetTrash); - - + add(new FillToolItem()); + add(btnGetTrash); enableInfoHistoryButtons(false); diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/TrashInfoContainer.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/TrashInfoContainer.java index f37e966..9c5569a 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/TrashInfoContainer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/TrashInfoContainer.java @@ -35,7 +35,6 @@ import com.extjs.gxt.ui.client.widget.grid.filters.GridFilters; import com.extjs.gxt.ui.client.widget.grid.filters.StringFilter; import com.extjs.gxt.ui.client.widget.layout.FitLayout; import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; -import com.google.gwt.i18n.client.NumberFormat; public class TrashInfoContainer extends LayoutContainer { @@ -49,7 +48,6 @@ public class TrashInfoContainer extends LayoutContainer { private GroupingStore store = new GroupingStore(); private boolean groupingEnabled; private ListStore typeStoreOperation = new ListStore(); - private NumberFormat number = ConstantsExplorer.numberFormatterKB; private GridDropTarget gridDropTarget; public TrashInfoContainer() { @@ -178,18 +176,12 @@ public class TrashInfoContainer extends LayoutContainer { public void initGrid() { -// store.groupBy(ConstantsExplorer.SHORTCUTCATEGORY); -// groupingEnabled = true; - ColumnConfig icon = new ColumnConfig(ConstantsExplorer.ICON, "", 25); ColumnConfig name = createSortableColumnConfig(ConstantsExplorer.NAME, ConstantsExplorer.NAME, 200); ColumnConfig type = createSortableColumnConfig(ConstantsExplorer.TYPE, ConstantsExplorer.TYPE, 50); ColumnConfig originalPath = createSortableColumnConfig(FileTrashedModel.STOREINFO.ORIGINALPATH.toString(), "Original Path", 200); - ColumnConfig deleteDate = createSortableColumnConfig(FileTrashedModel.STOREINFO.DELETEDATE.toString(), "Delete Date", 50); - ColumnConfig deleteUser = createSortableColumnConfig(FileTrashedModel.STOREINFO.DELETEUSER.toString(), "Delete User", 150); -// ColumnConfig category = createSortableColumnConfig(ConstantsExplorer.SHORTCUTCATEGORY, ConstantsExplorer.SHORTCUTCATEGORY, 100); -// ColumnConfig ownerFullName = createSortableColumnConfig(ConstantsExplorer.OWNERFULLNAME, ConstantsExplorer.OWNER, 100); -// ColumnConfig ownerFullName = createSortableColumnConfig(ConstantsExplorer.OWNERFULLNAME, ConstantsExplorer.OWNER, 100); + ColumnConfig deleteDate = createSortableColumnConfig(FileTrashedModel.STOREINFO.DELETEDATE.toString(), "Deleted Date", 50); + ColumnConfig deleteUser = createSortableColumnConfig(FileTrashedModel.STOREINFO.DELETEUSER.toString(), "Deleted By", 150); ColumnModel cm = new ColumnModel(Arrays.asList(icon, name, type, originalPath, deleteDate, deleteUser)); @@ -294,6 +286,11 @@ public class TrashInfoContainer extends LayoutContainer { store.removeAll(); typeStoreOperation.removeAll(); + + for (FileTrashedModel fileTrashedModel : trashFiles) { + fileTrashedModel.setIcon(); + } + store.add(trashFiles); } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/WindowTrash.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/WindowTrash.java index ceaa3c3..0a68559 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/WindowTrash.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/WindowTrash.java @@ -5,6 +5,7 @@ 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; @@ -95,11 +96,28 @@ public class WindowTrash extends Window { this.trashedFiles = trashFiles; this.trashContainers.updateTrash(trashFiles); } + + public void executeOperationOnTrashContainer(List trashIds, WorkspaceTrashOperation operation) { + + if(operation.equals(WorkspaceTrashOperation.DELETE_PERMANENTLY)){ + deleteListItems(trashIds); + + }else if(operation.equals(WorkspaceTrashOperation.RESTORE)){ + deleteListItems(trashIds); + } + } public List getTrashedFiles() { return trashedFiles; } + private void deleteListItems(List trashIds){ + + for (String identifier : trashIds) { + this.trashContainers.deleteItem(identifier); + } + } + public void maskAccountingInfo(boolean bool){ // if(accountingsContainers!=null){