From b6c28417e6e745370ef9f2d32fc17511af3b3e0e Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Fri, 8 Jan 2016 11:36:41 +0000 Subject: [PATCH] fixed #1333 git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@122156 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/AppControllerExplorer.java | 69 ------------------- .../server/GWTWorkspaceServiceImpl.java | 50 +++++++++++--- 2 files changed, 41 insertions(+), 78 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java index 47b6fa9..96f9656 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java @@ -986,75 +986,6 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt uploadStream.center(); } }); - - /* - eventBus.addHandler(FileUploadSelectedEvent.TYPE, new FileUploadSelectedEventHandler() { - - @Override - public void onFileSelected(FileUploadSelectedEvent event) { - String fileName = event.getSelectedFileName(); - GWT.log("selected file name: " + fileName); - - try { - - String normalizedFileName = fileName; - if (normalizedFileName.contains("\\")) { - normalizedFileName = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\")+1); //remove C:\fakepath\ if exists - } - - final String label = normalizedFileName; - - GWT.log("normalizedFileName file name: "+normalizedFileName); - - AppControllerExplorer.rpcWorkspaceService.itemExistsInWorkpaceFolder(fileUploader.getFolderParent().getIdentifier(), normalizedFileName, new AsyncCallback() { - - @Override - public void onSuccess(final String itemId) { - - if(itemId!=null){ - boolean result = Window.confirm(label + " exists in folder "+fileUploader.getFolderParent().getName() + ". Overwrite?"); - if(result){ - fileUploader.overwrite(); - fileUploader.submitForm(); - } - }else - fileUploader.submitForm(); //ITEM does NOT EXIST SO SUBMIT FORM; - - } - - @Override - public void onFailure(Throwable caught) { - Info.display("Error", "Sorry an error occurred on the server "+caught.getLocalizedMessage() + ". Please try again later"); - caught.printStackTrace(); - } - - }); - - } catch (Exception e) { - Info.display("Error", "Sorry an error occurred on the server "+e.getLocalizedMessage() + ". Please try again later"); - e.printStackTrace(); - } - - - } - }); - - - eventBus.addHandler(FileUploadCompleteEvent.TYPE, new FileUploadCompleteEventHandler() { - - @Override - public void onUploadComplete(FileUploadCompleteEvent event) { - - //the filename and its path on server are returned to the client - String fileName = event.getUploadedFileInfo().getFilename(); - String absolutePathOnServer = event.getUploadedFileInfo().getAbsolutePath(); - GWT.log(fileName + " uploaded on Server here: " + absolutePathOnServer); - - fileUploader.submitServletForm(absolutePathOnServer); - } - });*/ - - eventBus.addHandler(CompletedFileUploadEvent.TYPE, new CompletedFileUploadEventHandler() { diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index db42504..280e71b 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -1929,21 +1929,58 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT workspaceLogger.debug("get List Parents By Item Identifier "+ itemIdentifier +", include Item As (Last) Parent: "+includeItemAsParent); if(itemIdentifier==null) - return new ArrayList(); + return new ArrayList(); //empty list try { Workspace workspace = getWorkspace(); GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder(); List parents = workspace.getParentsById(itemIdentifier); - WorkspaceItem lastItem = parents.get(parents.size()-1); + workspaceLogger.debug("parents returned by HL, size: "+ parents.size()); String nameSpecialFolder = getNameForSpecialFolder(); + switch (parents.size()) { + case 0: // itemIdentifier is ROOT + workspaceLogger.trace("itemIdentifier isRoot..."); + if (includeItemAsParent) { //ADDIND ROOT + WorkspaceFolder wsFolder =(WorkspaceFolder) workspace.getItem(itemIdentifier); + FolderModel root = builder.buildGXTFolderModelItemHandleSpecialFolder(wsFolder, null, nameSpecialFolder); + List listParents = new ArrayList(1); + listParents.add(root); +// workspaceLogger.trace("returning: "+listParents.toString()); + return listParents; + } + else{ + workspaceLogger.trace("returning empty list"); + return new ArrayList(); // empty list + } + + case 1: //itemIdentifier is first level from root + workspaceLogger.trace("itemIdentifier is first level..."); + List listParents = new ArrayList(); + WorkspaceFolder wsRootFolder = (WorkspaceFolder) parents.get(0); //isRoot + FolderModel root = builder.buildGXTFolderModelItemHandleSpecialFolder(wsRootFolder, null, nameSpecialFolder); + FolderModel parent = null; + if(includeItemAsParent){ + WorkspaceFolder wsFolder1 =(WorkspaceFolder) workspace.getItem(itemIdentifier); //root + parent =builder.buildGXTFolderModelItemHandleSpecialFolder(wsFolder1, null, nameSpecialFolder); + } + listParents.add(root); + if(parent!=null) + listParents.add(parent); +// workspaceLogger.trace("returning: "+listParents.toString()); + return listParents; + + default: + break; + } + + WorkspaceItem lastItem = parents.get(parents.size()-1); FileModel[] arrayParents; //CONVERTING LAST ELEMENT IF NECESSARY workspaceLogger.trace("converting last element.."); - if(includeItemAsParent==true && lastItem.isFolder()){ //FIX BUG #298 + if(includeItemAsParent && lastItem.isFolder()){ //FIX BUG #298 arrayParents = new FileModel[parents.size()]; workspaceLogger.debug("including last item into path: "+lastItem.getName()); arrayParents[parents.size()-1] = builder.buildGXTFolderModelItemHandleSpecialFolder((WorkspaceFolder) lastItem, null, nameSpecialFolder); @@ -1956,21 +1993,16 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT WorkspaceFolder wsFolder = (WorkspaceFolder) parents.get(i); arrayParents[i] = builder.buildGXTFolderModelItemHandleSpecialFolder(wsFolder, null, nameSpecialFolder); } - -// Collections.reverse(listParents); - + //SET PARENTS workspaceLogger.trace("setting parents.."); for(int i=0; i(Arrays.asList(arrayParents)); - workspaceLogger.trace("list parents returning size: "+arrayParents.length); if(arrayParents[0]==null){ //EXIT BY BREAK IN CASE OF SPECIAL FOLDER List breadcrumbs = new ArrayList(arrayParents.length-1);