429: Workspace: uploading big files

Task-Url: https://support.d4science.org/issues/429

Workspace Uploader integrated in workspace-tree

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@119408 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-10-05 16:33:14 +00:00
parent 14ce83164f
commit 696ec6bb30
11 changed files with 827 additions and 765 deletions

20
pom.xml
View File

@ -44,8 +44,15 @@
</dependencies>
</dependencyManagement>
<dependencies>
<!-- UNCOMMENT THIS TO RUN IN DEVO MODE -->
<dependency>
<groupId>xerces</groupId>
<artifactId>xerces</artifactId>
<version>2.4.0</version>
</dependency>
<!-- This dependency is needed to use GWT UI BInder without old Xerces
version of gCore complaining -->
<dependency>
@ -54,6 +61,7 @@
<version>2.9.1</version>
<scope>provided</scope>
</dependency>
<!-- Google Web Toolkit (GWT) -->
<dependency>
<groupId>com.google.gwt</groupId>
@ -182,10 +190,18 @@
<version>1.4.5</version>
</dependency>
<!-- FILE UPLOAD-progress-bar -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.portlets.widgets</groupId> -->
<!-- <artifactId>fileupload-progress-bar</artifactId> -->
<!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> -->
<!-- </dependency> -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>fileupload-progress-bar</artifactId>
<artifactId>workspace-uploader</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -14,6 +14,7 @@
<inherits name="org.gcube.portlets.widgets.workspacesharingwidget.WorkspaceSharingWidget" />
<servlet path="/WorkspaceService" class="org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl" />
<inherits name="org.gcube.portlets.widgets.workspaceuploader.WorkspaceUploader"></inherits>
<!--
<servlet path="/ImageService" class="org.gcube.portlets.user.workspace.server.ImageServlet" />
<servlet path="/MetadataService" class="org.gcube.portlets.user.workspace.server.MetadataServlet" />

View File

@ -113,7 +113,6 @@ import org.gcube.portlets.user.workspace.client.model.SmartFolderModel;
import org.gcube.portlets.user.workspace.client.model.SubTree;
import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService;
import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceServiceAsync;
import org.gcube.portlets.user.workspace.client.uploader.FileUploader;
import org.gcube.portlets.user.workspace.client.util.RequestBuilderWorkspaceValidateItem;
import org.gcube.portlets.user.workspace.client.util.WindowOpenParameter;
import org.gcube.portlets.user.workspace.client.view.ExplorerPanel;
@ -135,7 +134,6 @@ 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.client.view.windows.NewBrowserWindow;
import org.gcube.portlets.user.workspace.client.view.windows.WindowImagePreview;
import org.gcube.portlets.user.workspace.client.view.windows.WindowOpenUrl;
import org.gcube.portlets.user.workspace.client.view.windows.accounting.WindowAccountingInfo;
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTExternalImage;
@ -146,15 +144,14 @@ import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
import org.gcube.portlets.user.workspace.shared.UserBean;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEvent;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEventHandler;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadSelectedEvent;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadSelectedEventHandler;
import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing.LOAD_CONTACTS_AS;
import org.gcube.portlets.widgets.workspacesharingwidget.client.MultiDragConstants;
import org.gcube.portlets.widgets.workspacesharingwidget.client.MultiDragContactsEditPermissions;
import org.gcube.portlets.widgets.workspacesharingwidget.client.SimpleMultiDragWorkspaceContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.DialogMultiDragContact;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUploadStream.UPLOAD_TYPE;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUploadStream;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.event.BaseEvent;
@ -169,7 +166,6 @@ import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasWidgets;
@ -188,7 +184,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
private boolean selectRootItem;
private FileUploader fileUploader;
// private FileUploader fileUploader;
public static String myLogin;
public static String myLoginFirstName;
@ -1128,21 +1124,60 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
}
private void doFileUploadEvent(FileUploadEvent fileUploadEvent) {
GWT.log("FileUploadEvent...");
FileModel folder = fileUploadEvent.getTargetFolderModel();
if(folder == null)
folder = explorerPanel.getAsycTreePanel().getRootItem();
String uploadType = null;
if(fileUploadEvent.getUploadTypeToString().equals(UploadType.ARCHIVE.toString())){
// new DialogUpload(ConstantsExplorer.ARCHIVEUPLOADHEADER, folder.getName(), folder, ConstantsExplorer.ARCHIVE);
fileUploader = new FileUploader(eventBus, folder, ConstantsExplorer.ARCHIVE);
uploadType = ConstantsExplorer.ARCHIVE;
}else{
uploadType = ConstantsExplorer.FILE;
}
else
fileUploader = new FileUploader(eventBus, folder, ConstantsExplorer.FILE);
String caption = "Upload ";
UPLOAD_TYPE upType = UPLOAD_TYPE.File;
if(uploadType.compareTo(ConstantsExplorer.ARCHIVE)==0){
caption+= " a zip Archive";
upType = UPLOAD_TYPE.Archive;
}else if(uploadType.compareTo(ConstantsExplorer.FILE)==0){
caption+= "File";
upType = UPLOAD_TYPE.File;
}
caption+= " in: "+folder.getName();
MultipleDilaogUploadStream uploadStream = new MultipleDilaogUploadStream(caption, folder.getIdentifier(), upType);
WorskpaceUploadNotificationListener listener = new WorskpaceUploadNotificationListener() {
@Override
public void onUploadCompleted(String parentId, String itemId) {
GWT.log("Upload completed: [parentID: "+parentId+", itemId: "+itemId+"]");
eventBus.fireEvent(new CompletedFileUploadEvent(parentId, itemId));
}
@Override
public void onUploadAborted(String parentId, String itemId) {
GWT.log("Upload Aborted: [parentID: "+parentId+", itemId: "+itemId+"]");
}
@Override
public void onError(String parentId, String itemId, Throwable throwable) {
GWT.log("Upload Aborted: [parentID: "+parentId+", itemId: "+itemId+"]");
}
};
uploadStream.addWorkspaceUploadNotificationListener(listener);
uploadStream.center();
}
});
/*
eventBus.addHandler(FileUploadSelectedEvent.TYPE, new FileUploadSelectedEventHandler() {
@Override
@ -1194,9 +1229,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
}
});
/**
* get the uploaded file result
*/
eventBus.addHandler(FileUploadCompleteEvent.TYPE, new FileUploadCompleteEventHandler() {
@Override
@ -1209,7 +1242,8 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
fileUploader.submitServletForm(absolutePathOnServer);
}
});
});*/
eventBus.addHandler(CompletedFileUploadEvent.TYPE, new CompletedFileUploadEventHandler() {
@ -1220,14 +1254,19 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
}
private void doCompletedFileUploadEvent(CompletedFileUploadEvent completedFileUploadEvent) {
GWT.log("doCompletedFileUploadEvent...");
// explorerPanel.getAsycTreePanel().reloadAndSelectTreeLevelFromWorkspaceForUplaod(completedFileUploadEvent.getParentFileModel().getIdentifier());
boolean isLevelExpanded = treeLevelIsExpanded(completedFileUploadEvent.getTargetFolderModel().getIdentifier());
boolean isLevelExpanded = treeLevelIsExpanded(completedFileUploadEvent.getParentId());
//REFRESH TREE ONLY IF FOLDER PARENT EXISTS IN TREE
if(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(completedFileUploadEvent.getTargetFolderModel().getIdentifier())!=null){
explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(completedFileUploadEvent.getTargetFolderModel().getIdentifier(), isLevelExpanded);
FileModel parent = explorerPanel.getAsycTreePanel().getFileModelByIdentifier(completedFileUploadEvent.getParentId());
if(parent!=null && completedFileUploadEvent.getItemIdentifier()!=null){
explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(completedFileUploadEvent.getParentId(), isLevelExpanded);
// explorerPanel.getAsycTreePanel().addItemIdAndExpandFolder(parent, completedFileUploadEvent.getItemIdentifier(), isLevelExpanded);
}
completedFileUploadEvent.setParentModel(parent); //SET PARENT
doUpdateWorkspaceSize(new UpdateWorkspaceSizeEvent());
notifySubscriber(completedFileUploadEvent);
}
@ -1418,16 +1457,11 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
msg = ConstantsExplorer.MESSAGE_CONFIRM_DELETE_ITEM + " "+ event.getFileTarget().getName() +"?";
}
MessageBoxConfirm mbc = new MessageBoxConfirm(title, msg);
mbc.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent be) {
// eventBus.fireEvent(new DeleteItemEvent(sel));
//IF NOT CANCELLED
String clickedButton = be.getButtonClicked().getItemId();
if(clickedButton.equals(Dialog.YES)){
@ -1938,7 +1972,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
CompletedFileUploadEvent fileUpEvent = (CompletedFileUploadEvent) event;
sub.addedFile(fileUpEvent.getItemIdentifier(), fileUpEvent.getTargetFolderModel());
sub.addedFile(fileUpEvent.getItemIdentifier(), fileUpEvent.getParentModel());
}else if(event instanceof CreateUrlEvent){

View File

@ -13,11 +13,13 @@ import com.google.gwt.event.shared.GwtEvent;
public class CompletedFileUploadEvent extends GwtEvent<CompletedFileUploadEventHandler> implements GuiEventInterface{
public static Type<CompletedFileUploadEventHandler> TYPE = new Type<CompletedFileUploadEventHandler>();
private FileModel parentFileModel;
private String itemIdentifier;
private String parentId;
private FileModel parentModel;
public CompletedFileUploadEvent(FileModel parent, String itemIdentifier) {
this.parentFileModel = parent;
public CompletedFileUploadEvent(String parentId, String itemIdentifier) {
this.parentId = parentId;
this.itemIdentifier = itemIdentifier;
}
@ -36,13 +38,39 @@ public class CompletedFileUploadEvent extends GwtEvent<CompletedFileUploadEventH
return EventsTypeEnum.COMPLETED_FILE_UPLOAD_EVENT;
}
public FileModel getTargetFolderModel() {
return parentFileModel;
}
public String getItemIdentifier() {
return itemIdentifier;
}
/**
* @return the parentId
*/
public String getParentId() {
return parentId;
}
/**
* @param itemIdentifier the itemIdentifier to set
*/
public void setItemIdentifier(String itemIdentifier) {
this.itemIdentifier = itemIdentifier;
}
/**
* @param parentId the parentId to set
*/
public void setParentId(String parentId) {
this.parentId = parentId;
}
public void setParentModel(FileModel parent){
this.parentModel = parent;
}
/**
* @return the parentModel
*/
public FileModel getParentModel() {
return parentModel;
}
}

View File

@ -5,7 +5,6 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.user.workspace.client.model.BulkCreatorModel;
import org.gcube.portlets.user.workspace.client.model.FileDetailsModel;
import org.gcube.portlets.user.workspace.client.model.FileGridModel;
import org.gcube.portlets.user.workspace.client.model.FileModel;
@ -789,4 +788,6 @@ public interface GWTWorkspaceService extends RemoteService{
*/
void setGcubeItemProperties(String itemId, Map<String, String> properties) throws Exception;
FileModel getItemForFileTree(String itemId) throws Exception;
}

View File

@ -5,7 +5,6 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.user.workspace.client.model.BulkCreatorModel;
import org.gcube.portlets.user.workspace.client.model.FileDetailsModel;
import org.gcube.portlets.user.workspace.client.model.FileGridModel;
import org.gcube.portlets.user.workspace.client.model.FileModel;
@ -252,15 +251,15 @@ public interface GWTWorkspaceServiceAsync {
// void sendTo(List<InfoContactModel> listContacts, List<FileModel> listAttachments, String subject, String text, AsyncCallback<Boolean> callback);
/**
* Send to by id.
*
* @param listContactsId the list contacts id
* @param listAttachmentsId the list attachments id
* @param subject the subject
* @param text the text
* @param callback the callback
*/
void sendToById(List<String> listContactsId, List<String> listAttachmentsId, String subject, String text, AsyncCallback<Boolean> callback);
* Send to by id.
*
* @param listContactsId the list contacts id
* @param listAttachmentsId the list attachments id
* @param subject the subject
* @param text the text
* @param callback the callback
*/
void sendToById(List<String> listContactsId, List<String> listAttachmentsId, String subject, String text, AsyncCallback<Boolean> callback);
/**
* Gets the all messages received.
@ -529,6 +528,12 @@ void sendToById(List<String> listContactsId, List<String> listAttachmentsId, Str
* @return the item for file grid
*/
void getItemForFileGrid(String itemId, AsyncCallback<FileGridModel> callback);
/**
* @param itemId
* @param asyncCallback
*/
void getItemForFileTree(String itemId,AsyncCallback<FileModel> asyncCallback);
/**
* Gets the folder children for file grid by id.
@ -785,4 +790,6 @@ void sendToById(List<String> listContactsId, List<String> listAttachmentsId, Str
void setGcubeItemProperties(String itemId, Map<String, String> properties,
AsyncCallback<Void> callback);
}

View File

@ -1,304 +1,304 @@
package org.gcube.portlets.user.workspace.client.uploader;
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.client.event.CompletedFileUploadEvent;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplayMessage;
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.client.view.windows.MessageBoxWait;
import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.FormEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FileUploadField;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.FormPanel.Encoding;
import com.extjs.gxt.ui.client.widget.form.FormPanel.Method;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Hidden;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
*
*/
public class DialogUpload extends Window {
private final FormPanel formPanel = new FormPanel();
private FileUploadField fileUploadField = new FileUploadField();
private MessageBoxWait messageBoxWait = null;
private boolean isStatusCompleted = false;
private Button btnSubmit = new Button("Submit");
private Button btnCancel = new Button("Cancel");
private Hidden hiddenOverwrite = new Hidden(ConstantsExplorer.IS_OVERWRITE,"false");
private String parentIdentifier = "";
private String parentName = "";
public DialogUpload(String headerTitle, String parentName, final FileModel parent, String fieldLabel){
this.setHeaderVisible(true);
this.setHeading(headerTitle + parentName);
this.parentIdentifier = parent.getIdentifier();
this.parentName = parentName;
this.setStyleAttribute("margin", "10px");
// Create a FormPanel and point it at a service.
// Create a FormPanel and point it at a service.
formPanel.setHeaderVisible(false);
formPanel.setFrame(true);
formPanel.setAction(ConstantsExplorer.UPLOAD_WORKSPACE_SERVICE);
formPanel.setEncoding(Encoding.MULTIPART);
formPanel.setMethod(Method.POST);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);
formPanel.setWidth(400);
// TextField<String> name = new TextField<String>();
// name.setFieldLabel("Name");
// formPanel.add(name);
fileUploadField.setAllowBlank(false);
fileUploadField.setName(ConstantsExplorer.UPLOAD_FORM_ELEMENT);
// Add hidden parameters
formPanel.add(new Hidden(ConstantsExplorer.ID_FOLDER,parent.getIdentifier()));
formPanel.add(new Hidden(ConstantsExplorer.UPLOAD_TYPE,fieldLabel));
formPanel.add(hiddenOverwrite);
// fileUploadField.setFieldLabel(ConstantsExplorer.FILE);
fileUploadField.setFieldLabel(fieldLabel);
formPanel.add(fileUploadField);
formPanel.addButton(btnSubmit);
formPanel.addButton(btnCancel);
// handle the post
formPanel.addListener(Events.Submit, new Listener<FormEvent>() {
public void handleEvent(FormEvent event) {
// When the form submission is successfully completed, this
// event is
// fired. Assuming the service returned a response of type
// text/html,
isStatusCompleted = true;
// Log.trace("onSubmitComplete");
String result = event.getResultHtml();
// Log.trace("Result "+result);
hide();
messageBoxWait.getMessageBoxWait().close();
if (result == null) {
// MessageUtil.showErrorMessage("Error during upload", "An error occurred during file upload.");
new MessageBoxAlert("Error during upload", "An error occurred during file upload.", null);
return;
}
//expected <pre>200:Upload complete</pre>
/*we strip tags added by webserver,
*
* Massi fix because webkit returns
* <pre style="word-wrap: break-word; white-space: pre-wrap;">OK:File france_flag.png(0) imported correctly in /Workspace</pre>
*
* TODO: recall it next time
*/
//String strippedResult = result.replace("<pre>", "").replace("</pre>", ""); //this won't work for webkit
//replaced by new HTML(result).getText()
String strippedResult = new HTML(result).getText();
// com.google.gwt.user.client.Window.alert(result);
// com.google.gwt.user.client.Window.alert("Stripped: " + strippedResult);
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
switch (resultMessage.getStatus()) {
case ERROR:
new MessageBoxAlert("Error during upload", resultMessage.getMessage(), null);
break;
case UNKNOWN:
new MessageBoxAlert("Error during upload", resultMessage.getMessage(), null);
break;
case WARN: {
new MessageBoxAlert("Upload completed with warnings", resultMessage.getMessage(), null);
break;
}
case OK: {
Timer t = new Timer() {
public void run() {
AppControllerExplorer.getEventBus().fireEvent(new CompletedFileUploadEvent(parent, null));
new InfoDisplayMessage("Upload completed successfully", resultMessage.getMessage());
}
};
t.schedule(250);
}
}
}
});
add(formPanel);
this.addListeners();
this.setAutoWidth(true);
this.setAutoHeight(true);
// this.show();
}
private void addListeners() {
btnSubmit.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
if (fileUploadField.getValue()==null || !(fileUploadField.getValue().length()>2)) {
new MessageBoxAlert(ConstantsExplorer.ERROR, ConstantsExplorer.NOFILESPECIFIED, null);
return;
}
// com.google.gwt.user.client.Window.alert("parentIdentifier "+parentIdentifier);
// com.google.gwt.user.client.Window.alert("fileUploadField.getValue() "+fileUploadField.getValue());
// com.google.gwt.user.client.Window.alert("parentName "+parentName);
/*
* TODO: recall: Some browser would write in fileUploadField.getValue() C:\fakepath\$fileName
*/
String normalizedFileName = fileUploadField.getValue();
// com.google.gwt.user.client.Window.alert("fileUploadField.getValue() "+fileUploadField.getValue());
if (normalizedFileName.contains("\\")) {
normalizedFileName = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\")+1); //remove C:\fakepath\ if exists
// com.google.gwt.user.client.Window.alert("normalizedFileName= "+normalizedFileName);
}
final String label = normalizedFileName;
AppControllerExplorer.rpcWorkspaceService.itemExistsInWorkpaceFolder(parentIdentifier, normalizedFileName, new AsyncCallback<String>() {
@Override
public void onSuccess(final String itemId) {
if(itemId!=null){
MessageBoxConfirm msg = new MessageBoxConfirm("Replace "+label+"?", label + " exists in folder "+parentName + ". Overwrite?");
msg.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent be) {
//IF NOT CANCELLED
String clickedButton = be.getButtonClicked().getItemId();
if(clickedButton.equals(Dialog.YES)){
// removeItemAndSubmitForm(itemId);
updateItemSubmitForm(itemId);
}
}
});
}else
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");
}
});
}
});
btnCancel.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
hide();
}
});
}
public void submitForm(){
messageBoxWait = new MessageBoxWait(ConstantsExplorer.PROGRESS, ConstantsExplorer.SAVINGYOURFILE, fileUploadField.getValue());
//Progress bar for upload
final Timer t = new Timer()
{
public void run()
{
if (isStatusCompleted)
{
cancel();
messageBoxWait.getMessageBoxWait().close();
}
}
};
t.scheduleRepeating(500);
formPanel.submit();
}
private void removeItemAndSubmitForm(String itemId){
AppControllerExplorer.rpcWorkspaceService.removeItem(itemId, new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
Info.display("Error", caught.getMessage());
}
@Override
public void onSuccess(Boolean result) {
if(result){
hiddenOverwrite.setValue("true");
submitForm();
}
}
});
}
private void updateItemSubmitForm(String itemId){
hiddenOverwrite.setValue("true");
submitForm();
}
}
//package org.gcube.portlets.user.workspace.client.uploader;
//
//
//import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
//import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
//import org.gcube.portlets.user.workspace.client.event.CompletedFileUploadEvent;
//import org.gcube.portlets.user.workspace.client.model.FileModel;
//import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplayMessage;
//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.client.view.windows.MessageBoxWait;
//import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
//
//import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
//import com.extjs.gxt.ui.client.event.ButtonEvent;
//import com.extjs.gxt.ui.client.event.Events;
//import com.extjs.gxt.ui.client.event.FormEvent;
//import com.extjs.gxt.ui.client.event.Listener;
//import com.extjs.gxt.ui.client.event.MessageBoxEvent;
//import com.extjs.gxt.ui.client.event.SelectionListener;
//import com.extjs.gxt.ui.client.widget.Dialog;
//import com.extjs.gxt.ui.client.widget.Info;
//import com.extjs.gxt.ui.client.widget.Window;
//import com.extjs.gxt.ui.client.widget.button.Button;
//import com.extjs.gxt.ui.client.widget.form.FileUploadField;
//import com.extjs.gxt.ui.client.widget.form.FormPanel;
//import com.extjs.gxt.ui.client.widget.form.FormPanel.Encoding;
//import com.extjs.gxt.ui.client.widget.form.FormPanel.Method;
//import com.google.gwt.user.client.Timer;
//import com.google.gwt.user.client.rpc.AsyncCallback;
//import com.google.gwt.user.client.ui.HTML;
//import com.google.gwt.user.client.ui.Hidden;
//
//
///**
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
// *
// */
//public class DialogUpload extends Window {
//
// private final FormPanel formPanel = new FormPanel();
// private FileUploadField fileUploadField = new FileUploadField();
// private MessageBoxWait messageBoxWait = null;
// private boolean isStatusCompleted = false;
// private Button btnSubmit = new Button("Submit");
// private Button btnCancel = new Button("Cancel");
// private Hidden hiddenOverwrite = new Hidden(ConstantsExplorer.IS_OVERWRITE,"false");
//
//
// private String parentIdentifier = "";
// private String parentName = "";
//
// public DialogUpload(String headerTitle, String parentName, final FileModel parent, String fieldLabel){
//
// this.setHeaderVisible(true);
// this.setHeading(headerTitle + parentName);
// this.parentIdentifier = parent.getIdentifier();
// this.parentName = parentName;
// this.setStyleAttribute("margin", "10px");
//
// // Create a FormPanel and point it at a service.
//
// // Create a FormPanel and point it at a service.
// formPanel.setHeaderVisible(false);
// formPanel.setFrame(true);
// formPanel.setAction(ConstantsExplorer.UPLOAD_WORKSPACE_SERVICE);
// formPanel.setEncoding(Encoding.MULTIPART);
// formPanel.setMethod(Method.POST);
//
// formPanel.setButtonAlign(HorizontalAlignment.CENTER);
// formPanel.setWidth(400);
//
// // TextField<String> name = new TextField<String>();
// // name.setFieldLabel("Name");
// // formPanel.add(name);
//
// fileUploadField.setAllowBlank(false);
// fileUploadField.setName(ConstantsExplorer.UPLOAD_FORM_ELEMENT);
//
// // Add hidden parameters
// formPanel.add(new Hidden(ConstantsExplorer.ID_FOLDER,parent.getIdentifier()));
// formPanel.add(new Hidden(ConstantsExplorer.UPLOAD_TYPE,fieldLabel));
// formPanel.add(hiddenOverwrite);
//
// // fileUploadField.setFieldLabel(ConstantsExplorer.FILE);
// fileUploadField.setFieldLabel(fieldLabel);
// formPanel.add(fileUploadField);
// formPanel.addButton(btnSubmit);
//
// formPanel.addButton(btnCancel);
//
//
// // handle the post
// formPanel.addListener(Events.Submit, new Listener<FormEvent>() {
//
// public void handleEvent(FormEvent event) {
// // When the form submission is successfully completed, this
// // event is
// // fired. Assuming the service returned a response of type
// // text/html,
//
// isStatusCompleted = true;
//
//
// // Log.trace("onSubmitComplete");
// String result = event.getResultHtml();
//
// // Log.trace("Result "+result);
// hide();
//
// messageBoxWait.getMessageBoxWait().close();
//
// if (result == null) {
// // MessageUtil.showErrorMessage("Error during upload", "An error occurred during file upload.");
// new MessageBoxAlert("Error during upload", "An error occurred during file upload.", null);
// return;
// }
//
// //expected <pre>200:Upload complete</pre>
// /*we strip tags added by webserver,
// *
// * Massi fix because webkit returns
// * <pre style="word-wrap: break-word; white-space: pre-wrap;">OK:File france_flag.png(0) imported correctly in /Workspace</pre>
// *
// * TODO: recall it next time
// */
// //String strippedResult = result.replace("<pre>", "").replace("</pre>", ""); //this won't work for webkit
// //replaced by new HTML(result).getText()
// String strippedResult = new HTML(result).getText();
//
//
//// com.google.gwt.user.client.Window.alert(result);
//// com.google.gwt.user.client.Window.alert("Stripped: " + strippedResult);
//
// final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
//
// switch (resultMessage.getStatus()) {
// case ERROR:
// new MessageBoxAlert("Error during upload", resultMessage.getMessage(), null);
// break;
// case UNKNOWN:
// new MessageBoxAlert("Error during upload", resultMessage.getMessage(), null);
// break;
// case WARN: {
// new MessageBoxAlert("Upload completed with warnings", resultMessage.getMessage(), null);
// break;
// }
// case OK: {
// Timer t = new Timer() {
// public void run() {
// AppControllerExplorer.getEventBus().fireEvent(new CompletedFileUploadEvent(parent, null));
// new InfoDisplayMessage("Upload completed successfully", resultMessage.getMessage());
// }
// };
//
// t.schedule(250);
//
// }
// }
// }
// });
//
// add(formPanel);
//
// this.addListeners();
//
// this.setAutoWidth(true);
// this.setAutoHeight(true);
//
//// this.show();
//
// }
//
// private void addListeners() {
//
//
// btnSubmit.addSelectionListener(new SelectionListener<ButtonEvent>() {
// @Override
// public void componentSelected(ButtonEvent ce) {
// if (fileUploadField.getValue()==null || !(fileUploadField.getValue().length()>2)) {
// new MessageBoxAlert(ConstantsExplorer.ERROR, ConstantsExplorer.NOFILESPECIFIED, null);
// return;
// }
//
//// com.google.gwt.user.client.Window.alert("parentIdentifier "+parentIdentifier);
//// com.google.gwt.user.client.Window.alert("fileUploadField.getValue() "+fileUploadField.getValue());
//// com.google.gwt.user.client.Window.alert("parentName "+parentName);
// /*
// * TODO: recall: Some browser would write in fileUploadField.getValue() C:\fakepath\$fileName
// */
// String normalizedFileName = fileUploadField.getValue();
//
//// com.google.gwt.user.client.Window.alert("fileUploadField.getValue() "+fileUploadField.getValue());
// if (normalizedFileName.contains("\\")) {
// normalizedFileName = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\")+1); //remove C:\fakepath\ if exists
//// com.google.gwt.user.client.Window.alert("normalizedFileName= "+normalizedFileName);
// }
// final String label = normalizedFileName;
// AppControllerExplorer.rpcWorkspaceService.itemExistsInWorkpaceFolder(parentIdentifier, normalizedFileName, new AsyncCallback<String>() {
//
// @Override
// public void onSuccess(final String itemId) {
//
// if(itemId!=null){
//
// MessageBoxConfirm msg = new MessageBoxConfirm("Replace "+label+"?", label + " exists in folder "+parentName + ". Overwrite?");
//
//
// msg.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
//
// public void handleEvent(MessageBoxEvent be) {
//
// //IF NOT CANCELLED
// String clickedButton = be.getButtonClicked().getItemId();
//
// if(clickedButton.equals(Dialog.YES)){
//
//// removeItemAndSubmitForm(itemId);
// updateItemSubmitForm(itemId);
// }
//
//
// }
// });
// }else
// 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");
//
// }
//
// });
//
// }
// });
//
//
// btnCancel.addSelectionListener(new SelectionListener<ButtonEvent>() {
// @Override
// public void componentSelected(ButtonEvent ce) {
// hide();
// }
// });
// }
//
//
// public void submitForm(){
//
// messageBoxWait = new MessageBoxWait(ConstantsExplorer.PROGRESS, ConstantsExplorer.SAVINGYOURFILE, fileUploadField.getValue());
//
// //Progress bar for upload
// final Timer t = new Timer()
// {
// public void run()
// {
// if (isStatusCompleted)
// {
// cancel();
// messageBoxWait.getMessageBoxWait().close();
// }
// }
// };
// t.scheduleRepeating(500);
// formPanel.submit();
//
// }
//
//
// private void removeItemAndSubmitForm(String itemId){
//
// AppControllerExplorer.rpcWorkspaceService.removeItem(itemId, new AsyncCallback<Boolean>() {
//
// @Override
// public void onFailure(Throwable caught) {
// Info.display("Error", caught.getMessage());
//
//
// }
//
// @Override
// public void onSuccess(Boolean result) {
// if(result){
// hiddenOverwrite.setValue("true");
// submitForm();
// }
//
// }
//
// });
// }
//
//
// private void updateItemSubmitForm(String itemId){
//
//
// hiddenOverwrite.setValue("true");
// submitForm();
// }
//}
//

View File

@ -1,131 +1,131 @@
/**
*
*/
package org.gcube.portlets.user.workspace.client.uploader;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import org.gcube.portlets.widgets.fileupload.client.view.UploadProgressDialog;
import com.extjs.gxt.ui.client.widget.Info;
import com.google.gwt.event.shared.HandlerManager;
/**
* The Class FileUploader.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 15, 2015
*/
public class FileUploader {
private final UploadProgressDialog dlg;
private FileModel folderParent;
private UpdateServiceUploader updateServiceUploader;
private String uploadType;
/**
* Instantiates a new file uploader.
*
* @param eventBus the event bus
* @param folderParent the folder parent
* @param uploadType the upload type
*/
public FileUploader(HandlerManager eventBus, FileModel folderParent, String uploadType) {
this.folderParent = folderParent;
this.uploadType = uploadType;
/**
* Prepare new servlet uploader
*/
updateServiceUploader = new UpdateServiceUploader(this, folderParent, uploadType);
String caption = "Upload ";
if(uploadType.compareTo(ConstantsExplorer.ARCHIVE)==0)
caption+= " a zip Archive";
else if(uploadType.compareTo(ConstantsExplorer.FILE)==0)
caption+= "File";
caption+= " in: "+folderParent.getName();
dlg = new UploadProgressDialog(caption, eventBus, true);
dlg.center();
dlg.show();
}
/**
* Submit form.
*/
public void submitForm() {
try {
dlg.submitForm();
} catch (Exception e) {
Info.display("Error", "Sorry an error occurred on the server "+e.getLocalizedMessage() + ". Please try again later");
e.printStackTrace();
}
}
/**
* Overwrite.
*/
public void overwrite(){
updateServiceUploader.setOverwrite();
}
/**
* Submit servlet form.
*
* @param absolutePathOnServer the absolute path of the file uploaded on the server
*/
public void submitServletForm(String absolutePathOnServer){
updateServiceUploader.setFileName(absolutePathOnServer);
try {
updateServiceUploader.submitForm();
} catch (Exception e) {
dlg.showRegisteringResult(false);
}
}
/**
* Gets the folder parent.
*
* @return the folder parent
*/
public FileModel getFolderParent() {
return folderParent;
}
/**
* Gets the upload type.
*
* @return the upload type
*/
public String getUploadType() {
return uploadType;
}
/**
* Show registering result.
*
* @param b the b
* @param message the message
*/
public void showRegisteringResult(boolean b, String message) {
this.dlg.showRegisteringResult(b, message);
}
/**
* Show registering result.
*
* @param b the b
*/
public void showRegisteringResult(boolean b) {
this.dlg.showRegisteringResult(b);
}
}
///**
// *
// */
//package org.gcube.portlets.user.workspace.client.uploader;
//
//import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
//import org.gcube.portlets.user.workspace.client.model.FileModel;
//import org.gcube.portlets.widgets.fileupload.client.view.UploadProgressDialog;
//
//import com.extjs.gxt.ui.client.widget.Info;
//import com.google.gwt.event.shared.HandlerManager;
//
//
///**
// * The Class FileUploader.
// *
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
// * Jul 15, 2015
// */
//public class FileUploader {
//
//
// private final UploadProgressDialog dlg;
// private FileModel folderParent;
// private UpdateServiceUploader updateServiceUploader;
// private String uploadType;
//
// /**
// * Instantiates a new file uploader.
// *
// * @param eventBus the event bus
// * @param folderParent the folder parent
// * @param uploadType the upload type
// */
// public FileUploader(HandlerManager eventBus, FileModel folderParent, String uploadType) {
// this.folderParent = folderParent;
// this.uploadType = uploadType;
//
// /**
// * Prepare new servlet uploader
// */
// updateServiceUploader = new UpdateServiceUploader(this, folderParent, uploadType);
//
// String caption = "Upload ";
// if(uploadType.compareTo(ConstantsExplorer.ARCHIVE)==0)
// caption+= " a zip Archive";
// else if(uploadType.compareTo(ConstantsExplorer.FILE)==0)
// caption+= "File";
//
// caption+= " in: "+folderParent.getName();
//
// dlg = new UploadProgressDialog(caption, eventBus, true);
// dlg.center();
// dlg.show();
// }
//
//
// /**
// * Submit form.
// */
// public void submitForm() {
//
// try {
// dlg.submitForm();
// } catch (Exception e) {
// Info.display("Error", "Sorry an error occurred on the server "+e.getLocalizedMessage() + ". Please try again later");
// e.printStackTrace();
// }
// }
//
// /**
// * Overwrite.
// */
// public void overwrite(){
// updateServiceUploader.setOverwrite();
// }
//
// /**
// * Submit servlet form.
// *
// * @param absolutePathOnServer the absolute path of the file uploaded on the server
// */
// public void submitServletForm(String absolutePathOnServer){
//
// updateServiceUploader.setFileName(absolutePathOnServer);
// try {
// updateServiceUploader.submitForm();
// } catch (Exception e) {
// dlg.showRegisteringResult(false);
// }
// }
//
// /**
// * Gets the folder parent.
// *
// * @return the folder parent
// */
// public FileModel getFolderParent() {
// return folderParent;
// }
//
// /**
// * Gets the upload type.
// *
// * @return the upload type
// */
// public String getUploadType() {
// return uploadType;
// }
//
// /**
// * Show registering result.
// *
// * @param b the b
// * @param message the message
// */
// public void showRegisteringResult(boolean b, String message) {
// this.dlg.showRegisteringResult(b, message);
// }
//
//
// /**
// * Show registering result.
// *
// * @param b the b
// */
// public void showRegisteringResult(boolean b) {
// this.dlg.showRegisteringResult(b);
// }
//
//}

View File

@ -1,172 +1,172 @@
package org.gcube.portlets.user.workspace.client.uploader;
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.client.event.CompletedFileUploadEvent;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
import com.extjs.gxt.ui.client.widget.Window;
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.HTML;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jan 20, 2014
*
*/
public class UpdateServiceUploader extends Window{
private FileUploader fileUploaderDlg = null;
private String fileName = "";
private boolean overwrite = false;
private FileModel parent;
private String uploadType;
/**
*
* @param fileUploader
* @param parent
* @param uploadType
*
* By default overwrite paramameter is false
*/
public UpdateServiceUploader(final FileUploader fileUploader, final FileModel parent, String uploadType){
this.fileUploaderDlg = fileUploader;
this.parent = parent;
this.uploadType = uploadType;
}
public static String encodeUrlDelimiters(String s) {
if (s == null) {
return null;
}
s = s.replaceAll(";", "%2F");
s = s.replaceAll("/", "%2F");
s = s.replaceAll(":", "%3A");
s = s.replaceAll("\\?", "%3F");
s = s.replaceAll("&", "%26");
s = s.replaceAll("\\=", "%3D");
s = s.replaceAll("\\+", "%2B");
s = s.replaceAll("\\$", "%24");
s = s.replaceAll(",", "%2C");
s = s.replaceAll("#", "%23");
return s;
}
public void submitForm() throws Exception{
if(fileName == null || fileName.isEmpty())
throw new Exception("File absolute path on server is null");
String parameters = "";
String fileNameEscaped = URL.encodeQueryString(fileName);
parameters+=ConstantsExplorer.UPLOAD_FORM_ELEMENT+"="+fileNameEscaped+"&";
if(parent.getIdentifier()!=null && !parent.getIdentifier().isEmpty())
parameters+=ConstantsExplorer.ID_FOLDER+"="+parent.getIdentifier()+"&";
else
throw new Exception("Parent Folder ID parameter is null or empty");
if(uploadType!=null && !uploadType.isEmpty())
parameters+=ConstantsExplorer.UPLOAD_TYPE+"="+uploadType+"&";
else
throw new Exception("UploadType parameter is null or empty");
parameters+=ConstantsExplorer.IS_OVERWRITE+"="+overwrite;
GWT.log("Encoded parameters are: "+parameters);
// String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+parameters;
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE);
requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
try {
requestBuilder.sendRequest(parameters, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
// int status = response.getStatusCode();
//expected <pre>200:Upload complete</pre>
/*we strip tags added by webserver,
*
* Massi fix because webkit returns
* <pre style="word-wrap: break-word; white-space: pre-wrap;">OK:File france_flag.png(0) imported correctly in /Workspace</pre>
*
* TODO: recall it next time
*/
//String strippedResult = result.replace("<pre>", "").replace("</pre>", ""); //this won't work for webkit
//replaced by new HTML(result).getText()
String strippedResult = new HTML(response.getText()).getText();
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
switch (resultMessage.getStatus()) {
case ERROR:
GWT.log("Error during upload: "+resultMessage.getMessage());
fileUploaderDlg.showRegisteringResult(false, resultMessage.getMessage());
break;
case UNKNOWN:
GWT.log("Error during upload: "+resultMessage.getMessage());
fileUploaderDlg.showRegisteringResult(false, "Error during upload: "+resultMessage.getMessage());
break;
case WARN: {
GWT.log("Upload completed with warnings: "+resultMessage.getMessage());
fileUploaderDlg.showRegisteringResult(false, "Upload completed with warnings: "+resultMessage.getMessage());
break;
}
case OK: {
Timer t = new Timer() {
public void run() {
AppControllerExplorer.getEventBus().fireEvent(new CompletedFileUploadEvent(parent, null));
fileUploaderDlg.showRegisteringResult(true);
}
};
t.schedule(250);
}
}
}
@Override
public void onError(Request request, Throwable exception) {
fileUploaderDlg.showRegisteringResult(false);
return;
}
});
} catch (RequestException e) {
e.printStackTrace();
}
}
public void setOverwrite(){
overwrite = true;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
}
//package org.gcube.portlets.user.workspace.client.uploader;
//
//
//import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
//import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
//import org.gcube.portlets.user.workspace.client.event.CompletedFileUploadEvent;
//import org.gcube.portlets.user.workspace.client.model.FileModel;
//import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
//
//import com.extjs.gxt.ui.client.widget.Window;
//import com.google.gwt.core.client.GWT;
//import com.google.gwt.http.client.Request;
//import com.google.gwt.http.client.RequestBuilder;
//import com.google.gwt.http.client.RequestCallback;
//import com.google.gwt.http.client.RequestException;
//import com.google.gwt.http.client.Response;
//import com.google.gwt.http.client.URL;
//import com.google.gwt.user.client.Timer;
//import com.google.gwt.user.client.ui.HTML;
//
//
///**
// *
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
// * @Jan 20, 2014
// *
// */
//public class UpdateServiceUploader extends Window{
//
// private FileUploader fileUploaderDlg = null;
// private String fileName = "";
// private boolean overwrite = false;
// private FileModel parent;
// private String uploadType;
//
//
// /**
// *
// * @param fileUploader
// * @param parent
// * @param uploadType
// *
// * By default overwrite paramameter is false
// */
// public UpdateServiceUploader(final FileUploader fileUploader, final FileModel parent, String uploadType){
//
// this.fileUploaderDlg = fileUploader;
// this.parent = parent;
// this.uploadType = uploadType;
// }
//
// public static String encodeUrlDelimiters(String s) {
// if (s == null) {
// return null;
// }
// s = s.replaceAll(";", "%2F");
// s = s.replaceAll("/", "%2F");
// s = s.replaceAll(":", "%3A");
// s = s.replaceAll("\\?", "%3F");
// s = s.replaceAll("&", "%26");
// s = s.replaceAll("\\=", "%3D");
// s = s.replaceAll("\\+", "%2B");
// s = s.replaceAll("\\$", "%24");
// s = s.replaceAll(",", "%2C");
// s = s.replaceAll("#", "%23");
// return s;
// }
//
//
// public void submitForm() throws Exception{
//
// if(fileName == null || fileName.isEmpty())
// throw new Exception("File absolute path on server is null");
//
// String parameters = "";
//
// String fileNameEscaped = URL.encodeQueryString(fileName);
// parameters+=ConstantsExplorer.UPLOAD_FORM_ELEMENT+"="+fileNameEscaped+"&";
//
// if(parent.getIdentifier()!=null && !parent.getIdentifier().isEmpty())
// parameters+=ConstantsExplorer.ID_FOLDER+"="+parent.getIdentifier()+"&";
// else
// throw new Exception("Parent Folder ID parameter is null or empty");
//
// if(uploadType!=null && !uploadType.isEmpty())
// parameters+=ConstantsExplorer.UPLOAD_TYPE+"="+uploadType+"&";
// else
// throw new Exception("UploadType parameter is null or empty");
//
// parameters+=ConstantsExplorer.IS_OVERWRITE+"="+overwrite;
//
// GWT.log("Encoded parameters are: "+parameters);
//
//// String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+parameters;
// RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE);
// requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
//
// try {
//
// requestBuilder.sendRequest(parameters, new RequestCallback() {
//
// @Override
// public void onResponseReceived(Request request, Response response) {
//
//// int status = response.getStatusCode();
//
// //expected <pre>200:Upload complete</pre>
// /*we strip tags added by webserver,
// *
// * Massi fix because webkit returns
// * <pre style="word-wrap: break-word; white-space: pre-wrap;">OK:File france_flag.png(0) imported correctly in /Workspace</pre>
// *
// * TODO: recall it next time
// */
// //String strippedResult = result.replace("<pre>", "").replace("</pre>", ""); //this won't work for webkit
// //replaced by new HTML(result).getText()
// String strippedResult = new HTML(response.getText()).getText();
//
// final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
//
// switch (resultMessage.getStatus()) {
// case ERROR:
// GWT.log("Error during upload: "+resultMessage.getMessage());
// fileUploaderDlg.showRegisteringResult(false, resultMessage.getMessage());
// break;
// case UNKNOWN:
// GWT.log("Error during upload: "+resultMessage.getMessage());
// fileUploaderDlg.showRegisteringResult(false, "Error during upload: "+resultMessage.getMessage());
// break;
// case WARN: {
// GWT.log("Upload completed with warnings: "+resultMessage.getMessage());
// fileUploaderDlg.showRegisteringResult(false, "Upload completed with warnings: "+resultMessage.getMessage());
// break;
// }
// case OK: {
// Timer t = new Timer() {
// public void run() {
// AppControllerExplorer.getEventBus().fireEvent(new CompletedFileUploadEvent(parent, null));
// fileUploaderDlg.showRegisteringResult(true);
// }
// };
//
// t.schedule(250);
// }
// }
// }
//
// @Override
// public void onError(Request request, Throwable exception) {
// fileUploaderDlg.showRegisteringResult(false);
// return;
// }
// });
//
// } catch (RequestException e) {
// e.printStackTrace();
// }
// }
//
// public void setOverwrite(){
// overwrite = true;
// }
//
// public String getFileName() {
// return fileName;
// }
//
// public void setFileName(String fileName) {
// this.fileName = fileName;
// }
//}
//

View File

@ -48,6 +48,7 @@ import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel.TreeNode;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -316,8 +317,7 @@ public class AsyncTreePanel extends LayoutContainer {
@Override
public void dragStart(DNDEvent event) {
System.out.println("***Event Start drag");
GWT.log("***Event Start drag");
FileModel sel = treePanel.getSelectionModel().getSelectedItem();
if (sel != null && sel == treePanel.getStore().getRootItems().get(0)) {
@ -333,11 +333,9 @@ public class AsyncTreePanel extends LayoutContainer {
}
if(sel != null && sel.getName()!= null)
System.out.println("Start drag of " + sel.getName());
GWT.log("Start drag of " + sel.getName());
super.dragStart(event);
}
});
@ -349,7 +347,6 @@ public class AsyncTreePanel extends LayoutContainer {
// super.onDragDrop(event);
// }
// @Override
// protected void showFeedback(DNDEvent event) {
// // TODO Auto-generated method stub
@ -397,10 +394,8 @@ public class AsyncTreePanel extends LayoutContainer {
return false;
}
return true;
}
return false;
// TreePanel<FileModel> source = (TreePanel<FileModel>) event.getDragSource().getComponent();
@ -423,34 +418,22 @@ public class AsyncTreePanel extends LayoutContainer {
//Called when drop on folder
@Override
protected void handleAppendDrop(DNDEvent event, @SuppressWarnings("rawtypes") TreeNode item) {
super.handleAppendDrop(event, item);
System.out.println("***Event move handleAppendDrop");
GWT.log("***Event move handleAppendDrop");
List<FileModel> listFileModel = getDragSource(event);
if(listFileModel.size() == 1){
FileModel destination = getDragDestination(item, DragType.APPEND);
if(destination != null){
//REMOVE THIS COMMENT TODO
eventBus.fireEvent(new MoveItemEvent(listFileModel.get(0), (FolderModel) destination));
System.out.println("Destination: " +destination.getName() + " id "+ destination.getIdentifier());
}
}
else{
}else{
//MULTIDRAG
}
// }
System.out.println("***End Event move handleAppendDrop");
GWT.log("***End Event move handleAppendDrop");
}
// @Override
@ -464,91 +447,58 @@ public class AsyncTreePanel extends LayoutContainer {
protected void handleInsertDrop(DNDEvent event, @SuppressWarnings("rawtypes") TreeNode item, int index) {
super.handleInsertDrop(event, item, index);
System.out.println("***Event move handleInsertDrop");
// System.out.println("on handleInsertDrop");
GWT.log("***Event move handleInsertDrop");
List<FileModel> listFileModel = getDragSource(event);
if(listFileModel.size() == 1){ //one element dragged
FileModel destination = getDragDestination(item, DragType.INSERT);
if(destination != null){
System.out.println("Destination: " +destination.getName() + " id "+ destination.getIdentifier());
if(destination != null){
GWT.log("Destination: " +destination.getName() + " id "+ destination.getIdentifier());
//REMOVE THIS COMMENT TODO
eventBus.fireEvent(new MoveItemEvent(listFileModel.get(0), (FolderModel) destination));
}
}
else{
}else{
//multi drag
}
System.out.println("***End Event move handleInsertDrop");
GWT.log("***End Event move handleInsertDrop");
}
private FileModel getDragDestination(@SuppressWarnings("rawtypes") TreeNode item, DragType insertType){
FileModel destination = null;
if(item!=null){
destination = (FileModel) item.getModel();
if(destination != null){
if(insertType.equals(DragType.APPEND))
return destination; //APPEND ON FOLDER
else
return destination.getParentFileModel(); //INSERT BETWEEN FILE - RETUR FOLDER PARENT
}
}
return destination;
}
private List<FileModel> getDragSource(DNDEvent event){
List<FileModel> listDraggedFile = new ArrayList<FileModel>();
if(event.getData() != null){
List<TreeStoreModel> listItemsSource = event.getData();
System.out.println("Number of move " + listItemsSource.size());
GWT.log("Number of move " + listItemsSource.size());
FileModel sourceFileModel = null; //for print
for(TreeStoreModel itemSource : listItemsSource){
listDraggedFile.add((FileModel) itemSource.getModel());
sourceFileModel = (FileModel) itemSource.getModel();
if(sourceFileModel.getParentFileModel()!=null)
System.out.println("Source Name " + sourceFileModel.getName() + " id " + sourceFileModel.getIdentifier() + " end drag " + " Parent Name: " + sourceFileModel.getParentFileModel().getName() + "id " + sourceFileModel.getParentFileModel().getIdentifier());
GWT.log("Source Name " + sourceFileModel.getName() + " id " + sourceFileModel.getIdentifier() + " end drag " + " Parent Name: " + sourceFileModel.getParentFileModel().getName() + "id " + sourceFileModel.getParentFileModel().getIdentifier());
else
System.out.println("Source Name " + sourceFileModel.getName() + " id " + sourceFileModel.getIdentifier() + " end drag ");
System.out.println("Child count: " + itemSource.getChildCount());
GWT.log("Source Name " + sourceFileModel.getName() + " id " + sourceFileModel.getIdentifier() + " end drag ");
GWT.log("Child count: " + itemSource.getChildCount());
}
}
return listDraggedFile;
}
@ -558,8 +508,7 @@ public class AsyncTreePanel extends LayoutContainer {
//// System.out.println("in handle insert");
// }
};
targetTreePanel.setAllowSelfAsSource(true);
targetTreePanel.setFeedback(Feedback.APPEND);
targetTreePanel.setScrollElementId(cp.getId());
@ -648,7 +597,6 @@ public class AsyncTreePanel extends LayoutContainer {
if(be!=null)
deselectItem(treePanel.getSelectionModel().getSelectedItem());
}
});
@ -658,27 +606,19 @@ public class AsyncTreePanel extends LayoutContainer {
if(be != null && !isSubTreeLoaded){
System.out.println("***Event beforeExpand Node");
System.out.println("Expand Folder Model: " + be.getNode().getModel().get(ConstantsExplorer.NAME));
GWT.log("***Event beforeExpand Node");
GWT.log("Expand Folder Model: " + be.getNode().getModel().get(ConstantsExplorer.NAME));
final FolderModel folder = (FolderModel) be.getNode().getModel();
int numChildrenFolder = store.getChildCount(folder);
if (folder!=null){
eventBus.fireEvent(new ExpandFolderEvent(folder));
if (numChildrenFolder==0) {
treePanel.mask(ConstantsExplorer.LOADING,ConstantsExplorer.LOADINGSTYLE);
loadTreeLevelFromWorkspace(folder);
}
}
System.out.println("***End Event beforeExpand Node");
GWT.log("***End Event beforeExpand Node");
}
}
});
@ -688,20 +628,18 @@ public class AsyncTreePanel extends LayoutContainer {
public void handleEvent(TreePanelEvent<FileModel> be) {
System.out.println("***Event Context Menu open");
GWT.log("***Event Context Menu open");
@SuppressWarnings("rawtypes")
TreeNode node = be.getNode();
if(node!=null){
System.out.println("Menu on: " + node.getModel().get(ConstantsExplorer.NAME));
System.out.println("node "+ treePanel.findNode(be.getTarget()));
GWT.log("Menu on: " + node.getModel().get(ConstantsExplorer.NAME));
GWT.log("node "+ treePanel.findNode(be.getTarget()));
}else{
System.out.println("Menu on: null");
System.out.println("node "+ treePanel.findNode(be.getTarget()));
GWT.log("Menu on: null");
GWT.log("node "+ treePanel.findNode(be.getTarget()));
}
List<FileModel> listSelected = treePanel.getSelectionModel().getSelectedItems();
//
if (listSelected != null && listSelected.size() > 0) {
@ -744,6 +682,32 @@ public class AsyncTreePanel extends LayoutContainer {
reloadTreeLevelAndExpandFolder(folder, expandFolder);
}
public void addItemIdAndExpandFolder(final FileModel parent, String itemId, boolean expandFolder){
treePanel.mask(ConstantsExplorer.VALIDATINGOPERATION,ConstantsExplorer.LOADINGSTYLE);
AppControllerExplorer.rpcWorkspaceService.getItemForFileTree(itemId, new AsyncCallback<FileModel>(){
@Override
public void onFailure(Throwable caught) {
if(caught instanceof SessionExpiredException){
GWT.log("Session expired");
eventBus.fireEvent(new SessionExpiredEvent());
return;
}
treePanel.unmask();
new MessageBoxAlert("Error", ConstantsExplorer.SERVER_ERROR + " getting item from workspace." +ConstantsExplorer.TRY_AGAIN, null);
removeAllAndRecoveryRoot();
}
@Override
public void onSuccess(FileModel result) {
GWT.log("GetItemForFileTree adding: "+result);
treePanel.unmask();
store.add(parent,result,false);
}
});
}
private void reloadTreeLevelAndExpandFolder(final FolderModel folder, final boolean expandFolder){
@ -758,26 +722,25 @@ public class AsyncTreePanel extends LayoutContainer {
eventBus.fireEvent(new SessionExpiredEvent());
return;
}
treePanel.unmask();
new MessageBoxAlert("Error", ConstantsExplorer.SERVER_ERROR + " getting folder children items." +ConstantsExplorer.TRY_AGAIN, null);
removeAllAndRecoveryRoot();
}
@Override
public void onSuccess(List<FileModel> result) {
treePanel.unmask();
store.removeAll(folder);
addChildrenToFolder(folder.getIdentifier(), result);
// addChildrenToFolder(folder.getIdentifier(), result);
addChildrenToFolder(folder, result);
setExpandTreeLevel(folder, expandFolder);
}
});
}
private void loadTreeLevelFromWorkspace(final FolderModel folder){
System.out.println("Start RPC - getFolderChildren");
GWT.log("Start RPC - getFolderChildren");
// Log.info("Start RPC - getFolderChildren");
// final CountTimer count = new CountTimer(1000);
@ -794,22 +757,16 @@ public class AsyncTreePanel extends LayoutContainer {
new MessageBoxAlert("Error", ConstantsExplorer.SERVER_ERROR + " getting folder children items. " +ConstantsExplorer.TRY_AGAIN, null);
removeAllAndRecoveryRoot();
}
@Override
public void onSuccess(List<FileModel> result) {
// Log.info("End RPC - getFolderChildren time " + count.getTime());
if(treePanel.isMasked())
treePanel.unmask();
store.removeAll(folder);
addChildrenToFolder(folder, result);
System.out.println("End RPC - getFolderChildren");
GWT.log("End RPC - getFolderChildren");
}
});
@ -895,23 +852,17 @@ public class AsyncTreePanel extends LayoutContainer {
public FileModel getFileModelByIdentifier(String identifier){
return treePanel.getStore().findModel(ConstantsExplorer.IDENTIFIER, identifier);
}
public int getChildrenNumber(String identifier){
// FileModel fileModel = treePanel.getStore().findModel(ConstantsExplorer.IDENTIFIER, identifier);
FolderModel fileModel = (FolderModel) getFileModelByIdentifier(identifier);
return getChildrenNumber(fileModel);
}
private int getChildrenNumber(FolderModel folder){
return store.getChildCount(folder);
}
@ -924,7 +875,6 @@ public class AsyncTreePanel extends LayoutContainer {
FileModel fileTarget = getFileModelByIdentifier(identifier);
if(fileTarget!=null){
return deleteItem(fileTarget);
}
@ -1020,8 +970,7 @@ public class AsyncTreePanel extends LayoutContainer {
* @param bool expand true/false
*/
private void setExpandTreeLevel(FileModel parent, boolean bool) {
treePanel.setExpanded(parent, bool);
treePanel.setExpanded(parent, bool);
}
/**

View File

@ -536,6 +536,32 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getItemForFileTree(java.lang.String)
*/
@Override
public FileModel getItemForFileTree(String itemId) throws Exception {
try {
if(itemId == null)
throw new Exception(IDENTIFIER_IS_NULL);
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(itemId);
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
//BUILD PARENT
WorkspaceFolder folderParent = wsItem.getParent(); //get parent
FileModel wsFolderParent = builder.buildGXTFileModelItem(folderParent, null);
//BUILD ITEM
return builder.buildGXTFileModelItem(wsItem, wsFolderParent);
} catch (Exception e) {
workspaceLogger.error("Error in server during item retrieving, getItemForFileGrid", e);
String error = ConstantsExplorer.SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST;
throw new Exception(error);
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#moveItem(java.lang.String, java.lang.String)
*/