From 52b1bd4fa03b0f0be54a7b029e34a8d8bd275974 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Tue, 6 Oct 2015 10:16:38 +0000 Subject: [PATCH] Refactor with enum WS_UPLOAD_TYPE git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace@119432 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../user/workspace/client/AppController.java | 68 +++++++++++-------- .../toolbars/GxtToolBarItemFunctionality.java | 10 +-- 2 files changed, 43 insertions(+), 35 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 1006bf1..4b1458e 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 @@ -8,6 +8,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.gcube.portlets.user.workspace.client.ConstantsExplorer.ViewSwitchType; +import org.gcube.portlets.user.workspace.client.ConstantsExplorer.WS_UPLOAD_TYPE; import org.gcube.portlets.user.workspace.client.ConstantsExplorer.WsPortletInitOperation; import org.gcube.portlets.user.workspace.client.ConstantsPortlet.ViewSwitchTypeInResult; import org.gcube.portlets.user.workspace.client.event.AccountingHistoryEvent; @@ -1362,40 +1363,47 @@ public class AppController implements SubscriberInterface { } @Override - public void addedFile(String itemIdentifier, FileModel parent) { + public void addedFile(String itemIdentifier, FileModel parent, WS_UPLOAD_TYPE uploadType) { // updateStoreByRpc(parent); - GWT.log("Calling addFileToStoreById "+parent.getIdentifier()); - addFileToStoreById(itemIdentifier, parent); - - } - - //TODO - private void addFileToStoreById(String itemIdentifier, FileModel parent){ - - GxtBreadcrumbPathPanel breadCrumb = this.wsPortlet.getToolBarPath(); - FileModel breadParent = breadCrumb.getLastParent(); + if(parent==null){ + GWT.log("addedFile skipping, parent is null"); + return; + } //UPDATE GRID ONLY IF TREE AND GRID DISPLAYING THE SAME PARENT - if(breadParent!=null && parent!=null && breadParent.getIdentifier().compareTo(parent.getIdentifier())==0){ -// wsPortlet.getGridGroupContainer().mask(ConstantsExplorer.LOADING,ConstantsExplorer.LOADINGSTYLE); - - appContrExplorer.getRpcWorkspaceService().getItemForFileGrid(itemIdentifier, new AsyncCallback() { - - @Override - public void onFailure(Throwable caught) { -// wsPortlet.getGridGroupContainer().unmask(); - - } - - @Override - public void onSuccess(FileGridModel result) { - wsPortlet.getGridGroupContainer().addToStore(result); -// wsPortlet.getGridGroupContainer().unmask(); - } - }); - } - + if(parentIsBreadcrumbLastParent(parent)){ + if(uploadType.equals(WS_UPLOAD_TYPE.File)){ + GWT.log("Calling addFileToStoreById "+parent.getIdentifier()); + addFileToStoreById(itemIdentifier, parent); + }else{ //is ARCHIVE + updateStoreByRpc(parent); + } + } + } + + private boolean parentIsBreadcrumbLastParent(FileModel parent){ + GxtBreadcrumbPathPanel breadCrumb = this.wsPortlet.getToolBarPath(); + FileModel breadParent = breadCrumb.getLastParent(); + return ((breadParent!=null) && (parent!=null) && (breadParent.getIdentifier().compareTo(parent.getIdentifier())==0)); + } + + private void addFileToStoreById(String itemIdentifier, FileModel parent){ + + appContrExplorer.getRpcWorkspaceService().getItemForFileGrid(itemIdentifier, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { +// wsPortlet.getGridGroupContainer().unmask(); + } + + @Override + public void onSuccess(FileGridModel result) { + wsPortlet.getGridGroupContainer().addToStore(result); +// wsPortlet.getGridGroupContainer().unmask(); + } + }); + } @Override diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtToolBarItemFunctionality.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtToolBarItemFunctionality.java index 6789419..4bd8f06 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtToolBarItemFunctionality.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtToolBarItemFunctionality.java @@ -3,6 +3,7 @@ package org.gcube.portlets.user.workspace.client.view.toolbars; import java.util.List; import org.gcube.portlets.user.workspace.client.AppController; +import org.gcube.portlets.user.workspace.client.ConstantsExplorer.WS_UPLOAD_TYPE; import org.gcube.portlets.user.workspace.client.ConstantsPortlet; import org.gcube.portlets.user.workspace.client.ConstantsPortlet.ViewSwitchTypeInResult; import org.gcube.portlets.user.workspace.client.event.ActiveGroupingView; @@ -12,7 +13,6 @@ import org.gcube.portlets.user.workspace.client.event.DoubleClickElementSelected import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent; import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent.DownloadType; import org.gcube.portlets.user.workspace.client.event.FileUploadEvent; -import org.gcube.portlets.user.workspace.client.event.FileUploadEvent.UploadType; import org.gcube.portlets.user.workspace.client.event.GetPublicLinkEvent; import org.gcube.portlets.user.workspace.client.event.GetShareLinkEvent; import org.gcube.portlets.user.workspace.client.event.GridRefreshEvent; @@ -435,9 +435,9 @@ public class GxtToolBarItemFunctionality { final FileGridModel fileGridModel = gridGroupViewContainer.getSelectedItem(); if(fileGridModel!=null) - AppController.getEventBus().fireEvent(new FileUploadEvent(fileGridModel.getParentFileModel(), UploadType.FILE)); + AppController.getEventBus().fireEvent(new FileUploadEvent(fileGridModel.getParentFileModel(), WS_UPLOAD_TYPE.File)); else - AppController.getEventBus().fireEvent(new FileUploadEvent(null, UploadType.FILE)); + AppController.getEventBus().fireEvent(new FileUploadEvent(null, WS_UPLOAD_TYPE.File)); } }); @@ -449,9 +449,9 @@ public class GxtToolBarItemFunctionality { final FileGridModel fileGridModel = gridGroupViewContainer.getSelectedItem(); if(fileGridModel!=null) - AppController.getEventBus().fireEvent(new FileUploadEvent(fileGridModel.getParentFileModel(), UploadType.ARCHIVE)); + AppController.getEventBus().fireEvent(new FileUploadEvent(fileGridModel.getParentFileModel(), WS_UPLOAD_TYPE.Archive)); else - AppController.getEventBus().fireEvent(new FileUploadEvent(null, UploadType.ARCHIVE)); + AppController.getEventBus().fireEvent(new FileUploadEvent(null, WS_UPLOAD_TYPE.Archive)); } });