enhancement: copy with multi-selection is implemented

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@90435 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-01-23 16:20:38 +00:00
parent 798322bd36
commit c97cc55b6c
14 changed files with 241 additions and 51 deletions

View File

@ -523,10 +523,12 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
@Override
public void onRefreshItem(RefreshFolderEvent refreshItemEvent) {
GWT.log("RefreshFolderEvent: "+refreshItemEvent);
if(refreshItemEvent.getFolderTarget()!=null){
if(!refreshItemEvent.isIfExists()){ //CAlled Tree side
if(!refreshItemEvent.isIfExists()){ //Called Tree side
explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(refreshItemEvent.getFolderTarget().getIdentifier(), refreshItemEvent.isExpandFolder());
notifySubscriber(refreshItemEvent);
}
@ -583,15 +585,16 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
@Override
public void onCopyAndPaste(PasteItemEvent pasteItemEvent) {
GWT.log("PasteItemEvent is fired on itemId: "+pasteItemEvent.getItemId()+", DestinationId: "+pasteItemEvent.getFolderDestinationId());
GWT.log("PasteItemEvent is fired on : "+pasteItemEvent.getIds().size()+ "items, DestinationId: "+pasteItemEvent.getFolderDestinationId());
doCopyAndPaste(pasteItemEvent);
}
private void doCopyAndPaste(final PasteItemEvent pasteItemEvent) {
rpcWorkspaceService.copyItem(pasteItemEvent.getItemId(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback<Boolean>() {
Info.display("Info", "Paste working...");
rpcWorkspaceService.copyItems(pasteItemEvent.getIds(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
@ -603,14 +606,17 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
}
new MessageBoxAlert("Error", caught.getMessage(), null);
eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, true, false));
notifySubscriber(pasteItemEvent);
}
@Override
public void onSuccess(Boolean result) {
if(result)
eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, true, false));
eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, false, false));
notifySubscriber(pasteItemEvent);
}

View File

@ -1,5 +1,7 @@
package org.gcube.portlets.user.workspace.client.event;
import java.util.List;
import org.gcube.portlets.user.workspace.client.interfaces.EventsTypeEnum;
import org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface;
@ -8,12 +10,19 @@ import com.google.gwt.event.shared.GwtEvent;
public class CopytemEvent extends GwtEvent<CopytemEventHandler> implements GuiEventInterface{
public static Type<CopytemEventHandler> TYPE = new Type<CopytemEventHandler>();
private String itemId = null;
// private String itemId = null;
private List<String> ids;
public CopytemEvent(String itemId) {
this.itemId = itemId;
// public CopytemEvent(String itemId) {
// this.itemId = itemId;
// }
public CopytemEvent(List<String> ids) {
this.ids = ids;
}
@Override
public Type<CopytemEventHandler> getAssociatedType() {
return TYPE;
@ -25,9 +34,9 @@ public class CopytemEvent extends GwtEvent<CopytemEventHandler> implements GuiEv
}
public String getItemId() {
return itemId;
}
// public String getItemId() {
// return itemId;
// }
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface#getKey()
@ -37,4 +46,12 @@ public class CopytemEvent extends GwtEvent<CopytemEventHandler> implements GuiEv
return EventsTypeEnum.COPY_EVENT;
}
public List<String> getIds() {
return ids;
}
public void setIds(List<String> ids) {
this.ids = ids;
}
}

View File

@ -1,5 +1,7 @@
package org.gcube.portlets.user.workspace.client.event;
import java.util.List;
import org.gcube.portlets.user.workspace.client.interfaces.EventsTypeEnum;
import org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface;
@ -8,11 +10,18 @@ import com.google.gwt.event.shared.GwtEvent;
public class PasteItemEvent extends GwtEvent<PasteItemEventHandler> implements GuiEventInterface{
public static Type<PasteItemEventHandler> TYPE = new Type<PasteItemEventHandler>();
private String itemId = null;
// private String itemId = null;
private String folderDestinationId;
private List<String> ids;
public PasteItemEvent(String itemId, String folderDestinationId) {
this.itemId = itemId;
// public PasteItemEvent(String itemId, String folderDestinationId) {
// this.itemId = itemId;
// this.folderDestinationId = folderDestinationId;
// }
public PasteItemEvent(List<String> ids, String folderDestinationId) {
this.ids = ids;
this.folderDestinationId = folderDestinationId;
}
@ -27,9 +36,9 @@ public class PasteItemEvent extends GwtEvent<PasteItemEventHandler> implements G
}
public String getItemId() {
return itemId;
}
// public String getItemId() {
// return itemId;
// }
public String getFolderDestinationId() {
return folderDestinationId;
@ -43,4 +52,12 @@ public class PasteItemEvent extends GwtEvent<PasteItemEventHandler> implements G
return EventsTypeEnum.PASTED_EVENT;
}
public List<String> getIds() {
return ids;
}
public void setIds(List<String> ids) {
this.ids = ids;
}
}

View File

@ -17,6 +17,13 @@ public class RefreshFolderEvent extends GwtEvent<RefreshItemEventHandler> implem
private boolean ifExists = false;
/**
*
* @param folderTarget
* @param expandFolder - used to expand the folder into tree after refresh
* @param forceRefresh - used to force refresh into grid
* @param ifExists - refresh only if items exists (into tree)
*/
public RefreshFolderEvent(FileModel folderTarget, boolean expandFolder, boolean forceRefresh, boolean ifExists) {
this.folderTarget = folderTarget;
this.expandFolder = expandFolder;
@ -69,4 +76,20 @@ public class RefreshFolderEvent extends GwtEvent<RefreshItemEventHandler> implem
public boolean isIfExists() {
return ifExists;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("RefreshFolderEvent [folderTarget=");
builder.append(folderTarget);
builder.append(", expandFolder=");
builder.append(expandFolder);
builder.append(", forceRefresh=");
builder.append(forceRefresh);
builder.append(", ifExists=");
builder.append(ifExists);
builder.append("]");
return builder.toString();
}
}

View File

@ -175,4 +175,13 @@ public interface GWTWorkspaceService extends RemoteService{
void deleteListItemsForIds(List<String> ids) throws Exception;
/**
* @param idsItem
* @param destinationFolderId
* @return
* @throws Exception
*/
boolean copyItems(List<String> idsItem, String destinationFolderId)
throws Exception;
}

View File

@ -164,4 +164,7 @@ public interface GWTWorkspaceServiceAsync {
void deleteListItemsForIds(List<String> ids, AsyncCallback<Void> callback);
void copyItems(List<String> idsItem, String destinationFolderId,
AsyncCallback<Boolean> callback);
}

View File

@ -0,0 +1,32 @@
/**
*
*/
package org.gcube.portlets.user.workspace.client.util;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.user.workspace.client.model.FileModel;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jan 23, 2014
*
*/
public class FileModelUtils {
public static List<String> convertFileModelsToIds(List<FileModel> filesModel){
if(filesModel==null || filesModel.size()==0)
return new ArrayList<String>(1);
List<String> ids = new ArrayList<String>(filesModel.size());
for (FileModel target : filesModel) {
ids.add(target.getIdentifier());
}
return ids;
}
}

View File

@ -31,6 +31,7 @@ import org.gcube.portlets.user.workspace.client.event.UnShareFolderEvent;
import org.gcube.portlets.user.workspace.client.event.WebDavUrlEvent;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import org.gcube.portlets.user.workspace.client.resources.Resources;
import org.gcube.portlets.user.workspace.client.util.FileModelUtils;
import com.extjs.gxt.ui.client.event.MenuEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
@ -319,11 +320,20 @@ public class ContextMenuTree {
copy.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
for (FileModel target : listSelectedItems) {
if(target.getIdentifier()!=null){
CopyAndPaste.copy(target.getIdentifier());
eventBus.fireEvent(new CopytemEvent(target.getIdentifier()));
}
// //HERE THE MULTI-SELECTION IS NOT ENABLED
// for (FileModel target : listSelectedItems) {
// if(target.getIdentifier()!=null){
// CopyAndPaste.copy(target.getIdentifier()));
// eventBus.fireEvent(new CopytemEvent(target.getIdentifier()));
// }
// }
//
List<String> ids = FileModelUtils.convertFileModelsToIds(listSelectedItems);
if(ids.size()>0){
CopyAndPaste.copy(ids);
eventBus.fireEvent(new CopytemEvent(ids));
}
}
@ -343,8 +353,8 @@ public class ContextMenuTree {
FileModel parentTarget = getDirectoryOrParent(target);
if(parentTarget!=null){
eventBus.fireEvent(new PasteItemEvent(CopyAndPaste.getCopiedfileModelId(), parentTarget.getIdentifier()));
CopyAndPaste.setCopiedfileModelId(null);
eventBus.fireEvent(new PasteItemEvent(CopyAndPaste.getCopiedIdsFilesModel(), parentTarget.getIdentifier()));
CopyAndPaste.setCopiedIdsFileModels(null);
}
@ -782,8 +792,8 @@ public class ContextMenuTree {
}
if(CopyAndPaste.getCopiedfileModelId()!=null)
contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(true); //paste
if(CopyAndPaste.getCopiedIdsFilesModel()!=null)
contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(true); //enable paste button
}
/**

View File

@ -1,21 +1,38 @@
package org.gcube.portlets.user.workspace.client.view.tree;
import java.util.List;
public class CopyAndPaste {
private static String copiedfileModelId = null;
// private static String copiedfileModelId = null;
public static void copy(String fileModelId){
copiedfileModelId = fileModelId;
private static List<String> idsFilesModel = null;
// public static void copy(String fileModelId){
// copiedfileModelId = fileModelId;
// }
public static void copy(List<String> idsFileModel){
idsFilesModel = idsFileModel;
}
public static String getCopiedfileModelId() {
return copiedfileModelId;
public static List<String> getCopiedIdsFilesModel() {
return idsFilesModel;
}
public static void setCopiedfileModelId(String copiedfileModelId) {
CopyAndPaste.copiedfileModelId = copiedfileModelId;
// public static void setCopiedfileModelId(String copiedfileModelId) {
// CopyAndPaste.copiedfileModelId = copiedfileModelId;
// }
// public static String getCopiedfileModelId() {
// return copiedfileModelId;
// }
public static void setCopiedIdsFileModels(List<String> idsFileModel) {
CopyAndPaste.idsFilesModel = idsFileModel;
}
}

View File

@ -1631,6 +1631,56 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
throw new Exception(error);
}
}
@Override
public boolean copyItems(List<String> idsItem, String destinationFolderId) throws Exception {
if(isSessionExpired())
throw new SessionExpiredException();
try {
Workspace workspace = getWorkspace();
boolean error = false;
for (String itemId : idsItem) {
WorkspaceItem sourceItem = workspace.getItem(itemId); //GET SOURCE ITEM BEFORE COPY
String sourceSharedId = sourceItem.getIdSharedFolder();
workspaceLogger.trace("copyItem by id: " + itemId);
WorkspaceItem item = workspace.copy(itemId, destinationFolderId); //copy item
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
checkNotifyAddItemToShare(sourceItem, sourceSharedId, folderDestinationItem);
if(item==null){
error = true;
break;
}
}
if(error)
return false; //Copied is false
return true; //copied is true
}catch (InsufficientPrivilegesException e) {
String error = "An error occurred on copying item, " +e.getMessage() + ". "+ConstantsExplorer.TRY_AGAIN;
throw new Exception(error);
}catch (ItemAlreadyExistException e) {
String error = "An error occurred on copying item, " +e.getMessage();
throw new Exception(error);
} catch (Exception e) {
workspaceLogger.error("Error in server copyItem by id", e);
String error = ConstantsExplorer.SERVER_ERROR +" copying item " + ConstantsExplorer.TRY_AGAIN;
throw new Exception(error);
}
}
@Override
public boolean deleteBulk(String bulkId) throws Exception {

View File

@ -48,10 +48,10 @@ public class HttpRequestUtil {
httpConnection.disconnect();
if (code == 200) {
logger.trace("status code is "+code+" - on url connetction: "+urlConn);
logger.trace("status code is "+code+" - on url connection: "+urlConn);
return true;
}else
logger.warn("status code is "+code+" - on url connetction: "+urlConn);
logger.warn("status code is "+code+" - on url connection: "+urlConn);
// logger.trace("result: "+result);
@ -62,16 +62,16 @@ public class HttpRequestUtil {
return false;
} catch (SocketTimeoutException e) {
logger.error("Error SocketTimeoutException with url " +urlConn);
logger.error("Error SocketTimeoutException with url " +urlConn, e);
return true;
} catch (MalformedURLException e) {
logger.error("Error MalformedURLException with url " +urlConn);
logger.error("Error MalformedURLException with url " +urlConn, e);
throw new Exception("Error MalformedURLException");
} catch (IOException e) {
logger.error("Error IOException with url " +urlConn);
logger.error("Error IOException with url " +urlConn, e);
throw new Exception("Error IOException");
}catch (Exception e) {
logger.error("Error Exception with url " +urlConn);
logger.error("Error Exception with url " +urlConn, e);
throw new Exception("Error Exception");
}
}

View File

@ -74,10 +74,10 @@ public class WsUtil {
/*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
* COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
user=TEST_USER;
// user=TEST_USER;
//UNCOMMENT THIS IN DEVELOP ENVIROMENT
// user = "francesco.mangiacrapa";
user = "francesco.mangiacrapa";
logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
logger.warn("session id: "+sessionID);

View File

@ -145,6 +145,7 @@ public class SinglePublicLinkTest {
}catch (Exception e) {
logger.error("Error getPublicLinkForFolderItemId for item: "+itemId, e);
e.printStackTrace();
throw new Exception(e.getMessage());
}

View File

@ -41,6 +41,8 @@ public class UriResolverReaderRR {
//Query URL parameter
String parameter = "";
private String uriRequest = "";
public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; //PRODUCTION
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //PRODUCTION
public static Logger log = Logger.getLogger(UriResolverReaderRR.class);
@ -146,7 +148,10 @@ public class UriResolverReaderRR {
// id: 370dc1cc-2e5e-4321-bc6f-ad860414db97, name: testupload.txt, ### Public link: smp://Home/francesco.mangiacrapa/Workspace284ee688-e6fb-4080-bbcb-cc7c8cc5c381?5ezvFfBOLqb3YESyI/kesN4T+ZD0mtmc/4sZ0vGMrl0lgx7k85j8o2Q1vF0ezJi/xIGDhncO9jOkV1T8u6Db7GZ/4ePgMws8Jxu8ierJajHBd20bUotElPG3BVG0ODMHf1ztm6rKJIAeb9R/0FEIDQ==
System.out.println("uri is: "+getPublicLinkForFolderItemId("f70f01f9-5a06-4123-b6ec-bd121c1af82f"));
String itemId = "0e875263-f6bc-4945-9435-bfb8774027ca";
// itemId = "f70f01f9-5a06-4123-b6ec-bd121c1af82f";
System.out.println("uri is: "+getPublicLinkForFolderItemId(itemId));
@ -161,14 +166,13 @@ public class UriResolverReaderRR {
try{
String scope = "/gcube/devsec";
ScopeProvider.instance.set("/gcube/devsec");
ScopeProvider.instance.set(DEFAULT_SCOPE);
Workspace workspace = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome("francesco.mangiacrapa")
.getHome("leonardo.candela")
.getWorkspace();
GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
@ -184,9 +188,10 @@ public class UriResolverReaderRR {
System.out.println("smpUri "+smpUri);
System.out.println("get uriResolver...");
UriResolverReaderParameter uriResolver = new UriResolverReaderParameter(scope);
UriResolverReaderParameter uriResolver = new UriResolverReaderParameter(DEFAULT_SCOPE);
String url = uriResolver.resolveAsUriRequest(smpUri, "testResponse!@#$$%^^&&.html", folderItem.getMimeType(), true);
// String url = uriResolver.resolveAsUriRequest(smpUri, "testResponse!@#$$%^^&&.html", folderItem.getMimeType(), true);
String url = uriResolver.resolveAsUriRequest(smpUri, folderItem.getName(), folderItem.getMimeType(), true);
System.out.println("url econded: "+url);
//
// url = uriResolver.resolveAsUriRequest(smpUri, folderItem.getName(), folderItem.getMimeType(), false);
@ -204,7 +209,7 @@ public class UriResolverReaderRR {
// String smpUri = "smp://Home/test.user/Workspace/bla8200ceb0-c525-40e6-bad1-a63f83811d3d?5ezvFfBOLqb3YESyI/kesN4T+ZD0mtmc/4sZ0vGMrl0lgx7k85j8o2Q1vF0ezJi/xIGDhncO9jOkV1T8u6Db7GZ/4ePgMws8Jxu8ierJajHBd20bUotElPG3BVG0ODMHf1ztm6rKJIAeb9R/0FEIDQ==";
UrlShortener urlShortner = new UrlShortener(scope);
UrlShortener urlShortner = new UrlShortener(DEFAULT_SCOPE);
String shortUrl = urlShortner.shorten(url);
System.out.println("url shortUrl: "+shortUrl);