553: Workspace: Drag Files Into the Workspace from the Desktop

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

Merged with private version

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@120096 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-10-29 14:12:37 +00:00
parent 4b332ec6f8
commit 1e396f21a5
12 changed files with 1397 additions and 254 deletions

View File

@ -1,6 +1,8 @@
package org.gcube.portlets.widgets.workspaceuploader.client;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.ScriptInjector;
@ -35,6 +37,8 @@ public class WorkspaceUploader implements EntryPoint {
.inject();
}
// ScriptInjector.fromUrl("http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js")
// .setWindow(ScriptInjector.TOP_WINDOW)
// .inject();
@ -54,14 +58,14 @@ public class WorkspaceUploader implements EntryPoint {
enableUpload(true);
} else {
Window.alert("An error occurred on recovering workspace, try again later");
enableUpload(false);
enableUpload(true);
}
}
@Override
public void onFailure(Throwable caught) {
Window.alert("An error occurred on recovering workspace, try again later");
enableUpload(false);
enableUpload(true);
}
});
@ -75,14 +79,45 @@ public class WorkspaceUploader implements EntryPoint {
// }
// });
buttonDirect.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
MultipleDilaogUpload uploadStream = new MultipleDilaogUpload(headerTitle, parentId, org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE.File);
uploadStream.initFileReader();
uploadStream.center();
}
});
final MultipleDNDUpload dnd = new MultipleDNDUpload();
buttonDirect.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// MultipleDilaogUpload uploadStream = new MultipleDilaogUpload(headerTitle, parentId, org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE.File);
// uploadStream.initFileReader();
// uploadStream.center();
dnd.setParameters(parentId, UPLOAD_TYPE.File);
}
});
RootPanel.get("workspace-uploader").add(dnd);
// Scheduler.get().scheduleDeferred(new ScheduledCommand() {
//
// @Override
// public void execute() {
// dnd.initFileReader();
//
// }
// });
// RootPanel.get("workspace-uploader").add(buttonUploader);
RootPanel.get("workspace-uploader").add(buttonDirect);

View File

@ -6,88 +6,84 @@ package org.gcube.portlets.widgets.workspaceuploader.client.resource;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Image;
/**
* The Class WorkspaceUploaderResources.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 24, 2015
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Sep 24, 2015
*/
public class WorkspaceUploaderResources {
public static final WorkspaceUploaderIcons ICONS = GWT.create(WorkspaceUploaderIcons.class);
/**
* Gets the image loading.
*
* @return the image loading
*/
public static Image getImageLoading(){
public static Image getImageLoading() {
return new Image(ICONS.loading());
}
/**
* Gets the image failed.
*
* @return the image failed
*/
public static Image getImageFailed(){
public static Image getImageFailed() {
return new Image(ICONS.failed());
}
/**
* Gets the image completed.
*
* @return the image completed
*/
public static Image getImageCompleted(){
public static Image getImageCompleted() {
return new Image(ICONS.completed());
}
/**
* Gets the image cancel.
*
* @return the image cancel
*/
public static Image getImageCancel(){
public static Image getImageCancel() {
return new Image(ICONS.cancel());
}
/**
* Gets the image cancel red.
*
* @return the image cancel red
*/
public static Image getImageCancelRed(){
public static Image getImageCancelRed() {
return new Image(ICONS.cancelRed());
}
/**
* Gets the image close win.
*
* @return the image close win
*/
public static Image getImageCloseWin(){
public static Image getImageCloseWin() {
return new Image(ICONS.closeWin());
}
/**
* Gets the image wait.
*
* @return the image wait
*/
public static Image getImageWait(){
public static Image getImageWait() {
return new Image(ICONS.waitIcon());
}
/**
* Gets the image upload.
*
* @return the image upload
*/
public static Image getImageUpload(){
public static Image getImageUpload() {
return new Image(ICONS.uploadIcon());
}
}

View File

@ -68,6 +68,7 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
// private MonitorPanel monitorPanel;
protected String clientUploadKey;
private Anchor anchorMyUploads;
protected UPLOAD_TYPE uploadType;
/**
* Instantiates a new dialog upload stream.
@ -86,6 +87,7 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
fileUpload.getElement().setAttribute("multiple", "multiple");
this.parentIdentifier = parentId;
this.uploadType = uploadType;
this.addStyleName("fileInputUploader");
formPanel.setAction(ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM);
formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
@ -158,6 +160,13 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
add(formPanel);
}
/**
* @return the panel
*/
public VerticalPanel getPanel() {
return panel;
}
protected void initJsonClientKeys(){
jsonClientKeys = new Hidden(ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS,"");
}

View File

@ -167,7 +167,7 @@ public class MonitorPanel extends ScrollPanel{
mapPanels.put(uploader.getClientUploadKey(), upv);
VerticalPanel upvPanel = upv.getPanel();
upvPanel.addStyleName("upladerMargin");
vpListUpload.add(upvPanel);
vpListUpload.insert(upvPanel, 0);
updateNumberUpload();
}

View File

@ -4,11 +4,11 @@
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.client.DialogResult;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderServiceAsync;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload;
import org.gcube.portlets.widgets.workspaceuploader.shared.HandlerResultMessage;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploadFile;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
@ -28,43 +28,75 @@ import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitHandler;
import com.google.gwt.user.client.ui.HTML;
/**
* The Class MultipleDilaogUploadStream.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Oct 2, 2015
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 2, 2015
*/
public class MultipleDilaogUpload extends DialogUpload {
private static final String FILE_DELEMITER = ";";
public static final String FILE_DELEMITER = ";";
private String fileUploadID;
private MultipleDNDUpload dnd;
public MultipleDilaogUpload instance = this;
private String jsonKeys;
private String idFolder;
private UPLOAD_TYPE type;
private String servlet = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM;
/**
* Instantiates a new multiple dilaog upload stream.
*
* @param headerTitle the header title
* @param parentId the parent id
* @param uploadType the upload type
* @param headerTitle
* the header title
* @param parentId
* the parent id
* @param uploadType
* the upload type
*/
public MultipleDilaogUpload(String headerTitle, String parentId, UPLOAD_TYPE uploadType) {
super(headerTitle, parentId, uploadType);
fileUploadID = GenerateUUID.get(10, 16); //is tagID
this.type =uploadType;
this.idFolder = parentId;
fileUploadID = GenerateUUID.get(10, 16); // is tagID
fileUpload.getElement().setId(fileUploadID);
this.addHandlers();
// exportGenerateFakeUploaders();
// exportCreateJsonKeyForFiles();
// exportAddNewSubmitToMonitor();
}
/**
* Generate new upload client keys.
*
* @param files the files
* @param parentId the parent id
* @param files the files
* @param parentId the parent id
* @return the list
*/
private void generateFakeUploaders(String[] files, String parentId){
public void generateFakeUploaders(String filesSelected, String parentId) {
if(filesSelected==null || filesSelected.isEmpty())
return;
String[] files = filesSelected.split(FILE_DELEMITER);
// NORMALIZE FILE NAMES
for (int i = 0; i < files.length; i++) {
String normalizedFileName = files[i];
if (normalizedFileName.contains("\\")) {
files[i] = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\") + 1); // remove
// C:\fakepath\
// if
// exists
}
}
GWT.log("generating fake uploaders on: "+files.toString());
fakeUploaders = new ArrayList<WorkspaceUploaderItem>(files.length);
for (int i = 0; i <files.length; i++){
for (int i = 0; i < files.length; i++) {
WorkspaceUploaderItem fakeItem = new WorkspaceUploaderItem();
fakeItem.setClientUploadKey(GenerateUUID.get());
fakeItem.setUploadStatus(UPLOAD_STATUS.WAIT);
@ -74,288 +106,526 @@ public class MultipleDilaogUpload extends DialogUpload {
fakeItem.setFile(fakeFile);
fakeUploaders.add(fakeItem);
}
GWT.log("fakeUploaders generated: "+fakeUploaders.toString());
// return fakeUploaders;
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUploadStream#addHandlers()
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.workspaceuploader.client.uploader.
* DialogUploadStream#addHandlers()
*/
@Override
protected void addHandlers() {
// handle the post
// handle the post
formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
GWT.log("onSubmitComplete");
GWT.log("onSubmitComplete");
hide();
// isStatusCompleted = true;
// isStatusCompleted = true;
String result = event.getResults();
if (result == null) {
if (result == null) {
removeLoading();
new DialogResult(null, "Error during upload", "An error occurred during file upload.").center();
new DialogResult(null, "Error during upload",
"An error occurred during file upload.").center();
return;
}
String strippedResult = new HTML(result).getText();
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
final HandlerResultMessage resultMessage = HandlerResultMessage
.parseResult(strippedResult);
switch (resultMessage.getStatus()) {
case ERROR:
case ERROR:
removeLoading();
GWT.log("Error during upload "+resultMessage.getMessage());
GWT.log("Error during upload " + resultMessage.getMessage());
break;
case UNKNOWN:
case UNKNOWN:
removeLoading();
GWT.log("Error during upload "+resultMessage.getMessage());
GWT.log("Error during upload " + resultMessage.getMessage());
break;
case WARN: {
GWT.log("Upload completed with warnings "+resultMessage.getMessage());
GWT.log("Upload completed with warnings "
+ resultMessage.getMessage());
removeLoading();
break;
}
case OK: {
// removeLoading();
// UploaderMonitor.getInstance().pollWorkspaceUploaderId(resultMessage.getMessage());
/*Timer t = new Timer() {
public void run() {
GWT.log("Upload started with id: "+resultMessage.getMessage());
UploaderMonitor.getInstance().pollWorkspaceUploaderId(resultMessage.getMessage());
}
};
// removeLoading();
// UploaderMonitor.getInstance().pollWorkspaceUploaderId(resultMessage.getMessage());
t.schedule(250);*/
/*
* Timer t = new Timer() { public void run() {
* GWT.log("Upload started with id: "
* +resultMessage.getMessage());
* UploaderMonitor.getInstance(
* ).pollWorkspaceUploaderId(resultMessage.getMessage()); }
* };
*
* t.schedule(250);
*/
}
}
}
}
});
formPanel.addSubmitHandler(new SubmitHandler() {
@Override
public void onSubmit(SubmitEvent event) {
GWT.log("SubmitEvent");
GWT.log("SubmitEvent");
addLoading();
enableButtons(false);
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
setVisible(false);
removeLoading();
UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
}
/*new Timer() {
@Override
public void run() {
stopIFrame(formPanel.getTarget());
}
}.schedule(500);*/
addNewSubmitToMonitor();
}
});
fileUpload.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
GWT.log("browse return...");
if (fileUpload.getFilename()==null || fileUpload.getFilename().isEmpty()) {
GWT.log("No file specified ");
MultipleDilaogUpload.this.hide();
return;
}
String[] files = null;
String filesSelected = getFilesSelected(fileUploadID, FILE_DELEMITER);
GWT.log("getFilesSelected: "+filesSelected);
files = filesSelected.split(FILE_DELEMITER);
if(files.length > ConstantsWorkspaceUploader.LIMIT_UPLOADS){
Window.alert("Multiple upload limit is "+ConstantsWorkspaceUploader.LIMIT_UPLOADS + " files");
GWT.log("browse return...");
if (fileUpload.getFilename() == null
|| fileUpload.getFilename().isEmpty()) {
GWT.log("No file specified ");
MultipleDilaogUpload.this.hide();
return;
}
String[] files = null;
String filesSelected = getFilesSelected(fileUploadID, FILE_DELEMITER);
// GWT.log("getFilesSelected: " + filesSelected);
files = filesSelected.split(FILE_DELEMITER);
//NORMALIZE FILE NAMES
for (int i=0; i<files.length; i++) {
String normalizedFileName = files[i];
if (normalizedFileName.contains("\\")) {
files[i] = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\")+1); //remove C:\fakepath\ if exists
}
}
if(isLimitExceeded(files.length))
return;
//GENERATE NEW UPLOADERS
generateFakeUploaders(files, parentIdentifier);
// if (files.length > ConstantsWorkspaceUploader.LIMIT_UPLOADS) {
// Window.alert("Multiple upload limit is "
// + ConstantsWorkspaceUploader.LIMIT_UPLOADS
// + " files");
// MultipleDilaogUpload.this.hide();
// return;
// }
// GENERATE NEW UPLOADERS
generateFakeUploaders(filesSelected, parentIdentifier);
GWT.log(fakeUploaders.toString());
String jsonKeys = createJsonKeyForFiles(fakeUploaders);
createJsonKeyForFiles();
GWT.log(jsonKeys);
if(jsonKeys==null){
if (jsonKeys == null) {
Window.alert("Sorry an error occurred during file/s submit. Try again");
return;
}
//ADD TO FORM PANEL
// initJsonClientKeys();
// ADD TO FORM PANEL
// initJsonClientKeys();
jsonClientKeys.setValue(jsonKeys);
//CASE 1 FILE
if(files.length==1){
//recall: Some browser would write in fileUploadField.getValue() C:\fakepath\$fileName
// CASE 1 FILE
if (files.length == 1) {
// recall: Some browser would write in
// fileUploadField.getValue() C:\fakepath\$fileName
final String label = files[0];
WorkspaceUploaderServiceAsync.Util.getInstance().itemExistsInWorkpaceFolder(parentIdentifier, label, new AsyncCallback<String>() {
@Override
public void onSuccess(final String itemId) {
GWT.log("itemExistsInWorkpaceFolder: "+itemId);
if(itemId!=null){
// HANDLE OWERWRITE
if(Window.confirm(label + " exists in folder. Overwrite?")){
removeItemAndSubmitForm(itemId);
updateItemSubmitForm(itemId);
}
}else
submitForm(); //ITEM does NOT EXIST SO SUBMIT FORM;
}
@Override
public void onFailure(Throwable caught) {
GWT.log("Sorry an error occurred on the server "+caught.getLocalizedMessage() + ". Please try again later");
Window.alert(caught.getMessage());
}
});
}else
WorkspaceUploaderServiceAsync.Util.getInstance()
.itemExistsInWorkpaceFolder(parentIdentifier,
label, new AsyncCallback<String>() {
@Override
public void onSuccess(
final String itemId) {
GWT.log("itemExistsInWorkpaceFolder: "
+ itemId);
if (itemId != null) {
// HANDLE OWERWRITE
if (Window
.confirm(label
+ " exists in folder. Overwrite?")) {
removeItemAndSubmitForm(itemId);
updateItemSubmitForm(itemId);
}
} else
submitForm(); // ITEM does NOT
// EXIST SO
// SUBMIT FORM;
}
@Override
public void onFailure(Throwable caught) {
GWT.log("Sorry an error occurred on the server "
+ caught.getLocalizedMessage()
+ ". Please try again later");
Window.alert(caught.getMessage());
}
});
} else
submitForm();
}
});
}
/**
* Checks if is limit exceeded.
*
* @param numbOfFiles the numb of files
* @return true, if is limit exceeded
*/
public boolean isLimitExceeded(int numbOfFiles){
if (numbOfFiles > ConstantsWorkspaceUploader.LIMIT_UPLOADS) {
Window.alert("Multiple upload limit is "
+ ConstantsWorkspaceUploader.LIMIT_UPLOADS
+ " files");
MultipleDilaogUpload.this.hide();
return true;
}
return false;
}
/**
* Adds the new submit to monitor.
*/
public void addNewSubmitToMonitor(){
GWT.log("addNewSubmitToMonitor...");
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
setVisible(false);
removeLoading();
UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
}
}
/**
* Creates the json key for files.
*
* @param fakeFiles the fake files
* @return the string
*/
protected String createJsonKeyForFiles(List<WorkspaceUploaderItem> fakeFiles){
try {
JSONObject productObj = new JSONObject();
JSONArray jsonArray = new JSONArray();
productObj.put(ConstantsWorkspaceUploader.JSON_CLIENT_KEYS, jsonArray);
for (int i=0; i<fakeFiles.size(); i++){
WorkspaceUploaderItem file = fakeFiles.get(i);
JSONObject obj = new JSONObject();
obj.put(file.getClientUploadKey(), new JSONString(file.getFile().getFileName()));
jsonArray.set(i, obj);
}
return productObj.toString();
}catch (Exception e) {
GWT.log("error "+e.getMessage());
return null;
}
protected void createJsonKeyForFiles() {
try {
JSONObject productObj = new JSONObject();
JSONArray jsonArray = new JSONArray();
productObj.put(ConstantsWorkspaceUploader.JSON_CLIENT_KEYS, jsonArray);
// GWT.log("Creating json keys on fakeUploaders: "+fakeUploaders.toString());
for (int i = 0; i < fakeUploaders.size(); i++) {
WorkspaceUploaderItem file = fakeUploaders.get(i);
JSONObject obj = new JSONObject();
obj.put(file.getClientUploadKey(), new JSONString(file.getFile().getFileName()));
jsonArray.set(i, obj);
}
jsonKeys = productObj.toString();
GWT.log("updated jsonKeys: "+jsonKeys);
} catch (Exception e) {
GWT.log("error " + e.getMessage());
jsonKeys = null;
}
}
// /**
// * Export generate fake uploaders.
// */
// public native void exportGenerateFakeUploaders() /*-{
// var that = this;
// $wnd.add = $entry(function(files,parentId) {
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::generateFakeUploaders([Ljava/lang/String;Ljava/lang/String;)(files,parentId);
// });
// }-*/;
//
// /**
// * Export create json key for files.
// */
// public native void exportCreateJsonKeyForFiles() /*-{
// var that = this;
// $wnd.add = $entry(function() {
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::createJsonKeyForFiles()();
// });
// }-*/;
//
// /**
// * Export create json key for files.
// */
// public native void exportAddNewSubmitToMonitor() /*-{
// var that = this;
// $wnd.add = $entry(function() {
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::addNewSubmitToMonitor()();
// });
// }-*/;
/**
* Submit form.
*/
@Override
public void submitForm(){
public void submitForm() {
formPanel.submit();
// for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
//
// UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
// setVisible(false);
// removeLoading();
//// UploaderMonitor.getInstance().pollWorkspaceUploaderId(workspaceUploaderItem.getClientUploadKey());
//
// //WAITING 0.1 SEC TO FIRST UPDATES
// /*new Timer() {
//
// @Override
// public void run() {
// removeLoading();
// UploaderMonitor.getInstance().pollWorkspaceUploaderId(workspaceUploaderItem.getClientUploadKey());
//
// }
// }.schedule(100);*/
// }
// for (final WorkspaceUploaderItem workspaceUploaderItem :
// fakeUploaders) {
//
// UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem,
// workspaceUploaderItem.getFile().getFileName());
// setVisible(false);
// removeLoading();
// //
// UploaderMonitor.getInstance().pollWorkspaceUploaderId(workspaceUploaderItem.getClientUploadKey());
//
// //WAITING 0.1 SEC TO FIRST UPDATES
// /*new Timer() {
//
// @Override
// public void run() {
// removeLoading();
// UploaderMonitor.getInstance().pollWorkspaceUploaderId(workspaceUploaderItem.getClientUploadKey());
//
// }
// }.schedule(100);*/
// }
}
/* TEST
private void showCancel(){
DialogBox box = new DialogBox();
box.setSize("200px","200px");
Button abort = new Button("abort");
abort.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String iFrameName = formPanel.getTarget();
GWT.log("iFrameName "+iFrameName);
stopIFrame(iFrameName);
}
});
box.add(abort);
box.show();
}*/
/**
* Gets the files selected.
*
* @param tagId the tag id
* @param fileDelimiter the file delimiter
* @param iFrameName the i frame name
* @return the files selected
*/
private static native String stopIFrame(final String iFrameName) /*-{
console.log("iFrameName: "+iFrameName);
// var iframe= window.frames[iFrameName];
var iframe= $wnd.$('iframe[name='+iFrameName+']', parent.document)[0];
var iframewindow= iframe.contentWindow? iframe.contentWindow : iframe.contentDocument.defaultView;
if(iframe==null)
console.log("iframe is null");
else
console.log("iframe is not null");
if (navigator.appName == 'Microsoft Internet Explorer' && iframewindow.document.execCommand)
{ // IE browsers
console.log("IE browsers");
iframewindow.document.execCommand("Stop");
}
console.log("iFrameName: " + iFrameName);
// var iframe= window.frames[iFrameName];
var iframe = $wnd.$('iframe[name=' + iFrameName + ']', parent.document)[0];
var iframewindow = iframe.contentWindow ? iframe.contentWindow
: iframe.contentDocument.defaultView;
if (iframe == null)
console.log("iframe is null");
else
{ // other browsers
console.log("other browsers");
iframewindow.stop();
}
console.log("iframe is not null");
if (navigator.appName == 'Microsoft Internet Explorer'
&& iframewindow.document.execCommand) { // IE browsers
console.log("IE browsers");
iframewindow.document.execCommand("Stop");
} else { // other browsers
console.log("other browsers");
iframewindow.stop();
}
}-*/;
/**
* Gets the parent id.
*
* @return the parentId
*/
public String getParentId() {
return parentIdentifier;
}
/**
* Gets the upload type.
*
* @return the uploadType
*/
public UPLOAD_TYPE getUploadType() {
return uploadType;
}
// public native void exportParentId() /*-{
// var that = this;
// $wnd.add = $entry(function() {
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::getParentId();
// });
// }-*/;
//
// public native void exportUploadType() /*-{
// var that = this;
// $wnd.add = $entry(function() {
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::getUploadType();
// });
// }-*/;
/**
* Gets the files selected.
*
* @param tagId the tag id
* @param tagId
* the tag id
* @param fileDelimiter
* the file delimiter
* @return the files selected
*/
public static native String getFilesSelected(final String tagId,
final String fileDelimiter) /*-{
var count = $wnd.$("#" + tagId)[0].files.length;
console.log(count);
var out = "";
for (i = 0; i < count; i++) {
var file = $wnd.$("#" + tagId)[0].files[i];
// out += file.name + fileDelimiter + file.size + fileDelimiter;
out += file.name + fileDelimiter;
}
return out;
}-*/;
/**
* Inits the file reader.
*/
public void initFileReader() {
initW3CFileReader(instance, MultipleDilaogUpload.FILE_DELEMITER);
}
/**
* Gets the files selected.
*
* @param instance the instance
* @param fileDelimiter the file delimiter
* @return the files selected
*/
public static native String getFilesSelected(final String tagId, final String fileDelimiter) /*-{
var count = $wnd.$("#"+tagId)[0].files.length;
console.log(count);
var out = "";
for (i = 0; i < count; i++) {
var file = $wnd.$("#"+tagId)[0].files[i];
// out += file.name + fileDelimiter + file.size + fileDelimiter;
out += file.name + fileDelimiter;
}
return out;
public static native String initW3CFileReader(MultipleDilaogUpload instance, String fileDelimiter) /*-{
console.log("initW3CFileReader");
if (window.FileReader) {
console.log("before load");
var drop = $wnd.$('#drop_target')[0];
console.log("drop is " + drop);
function cancel(e) {
if (e.preventDefault) {
e.preventDefault();
}
return false;
}
function addEventHandler(obj, evt, handler) {
if (obj.addEventListener) {
// W3C method
obj.addEventListener(evt, handler, false);
} else if (obj.attachEvent) {
// IE method.
obj.attachEvent('on' + evt, handler);
} else {
// Old school method.
obj['on' + evt] = handler;
}
}
addEventHandler(drop, 'drop', function(e) {
e = e || window.event; // get window.event if e argument missing (in IE)
if (e.preventDefault) {
e.preventDefault();
} // stops the browser from redirecting off to the image.
var servlet = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::servlet;
var opts = {
url : servlet,
type : "POST",
processData : false
};
var idfolder = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::idFolder;
console.log("idfolder: " + idfolder);
var uploadType = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::type;
console.log("uploadType: " + uploadType);
var dt = e.dataTransfer;
var files = dt.files;
var filesSelected = "";
for (i = 0; i < files.length; i++) {
filesSelected += files[i].name + fileDelimiter;
}
console.log("filesSelected: " + filesSelected);
// var files = filese
// var files = filesSelected.split(fileDelimiter);
console.log("files: " + files);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::isLimitExceeded(I)(files.length);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::generateFakeUploaders(Ljava/lang/String;Ljava/lang/String;)(filesSelected,idfolder);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::createJsonKeyForFiles()();
var jsonKeys = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::jsonKeys;
console.log("jsonKeys: " + jsonKeys);
for (var i = 0; i < files.length; i++) {
var file = files[i];
// var reader = new FileReader();
var xhr = new XMLHttpRequest();
// var upload = xhr.upload;
// upload.fileIndex = i;
// upload.fileObj = file;
// upload.downloadStartTime = new Date().getTime();
// upload.currentStart = upload.downloadStartTime;
// upload.currentProgress = 0;
// upload.startData = 0;
// console.log("upload: " + upload.toString());
// add listeners
// upload.addEventListener("progress", progress, false);
// upload.addEventListener("load", load, false);
xhr.open(opts.type, opts.url, true);
// var boundary = "AJAX--------------" + (new Date).getTime();
// var contentType = "multipart/form-data; boundary=" + boundary;
// xhr.setRequestHeader("Content-Type", contentType);
// Use native function(Chrome 5+ ,Safari 5+ and Firefox 4+), for dealing
// with multipart/form-data and boundray generation
var formdata = new FormData(); // see
// https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Using_FormData_objects
// 'file' can be any string which you would like to associte with
// uploaded file even for example file.type eg:
// formdata.append(file.type, file);
// formdata.append(file.fileName, file);
formdata.append("isOverwrite", "false");
// $wnd.exportCreateJsonKeyForFiles();
//
// $wnd.exportAddNewSubmitToMonitor();
formdata.append("client_upload_keys", jsonKeys);
formdata.append("uploadType", uploadType);
formdata.append("idFolder", idfolder);
formdata.append('uploadFormElement', file);
xhr.send(formdata);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::addNewSubmitToMonitor()();
// reader.readAsText(file);
}
return false;
})
// Tells the browser that we *can* drop on this target
addEventHandler(drop, 'dragover', cancel);
addEventHandler(drop, 'dragenter', cancel);
} else {
$wnd.$('#drop_target')[0].innerHTML = 'Your browser does not support the HTML5 FileReader.';
}
}-*/;
}

View File

@ -0,0 +1,144 @@
/**
*
*/
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploadFile;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem.UPLOAD_STATUS;
import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.user.client.Window;
/**
* The Class WorkspaceFieldsUpload.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Oct 20, 2015
*/
public class WorkspaceFieldsUploadManager {
//FORM FIELD TO UPLOAD INTO WORKSPACE
private String jsonKeys;
public static final String FILE_DELEMITER = ";";
private List<WorkspaceUploaderItem> fakeUploaders = new ArrayList<WorkspaceUploaderItem>();
public WorkspaceFieldsUploadManager() {
}
/**
* Checks if is limit exceeded.
*
* @param numbOfFiles the numb of files
* @return true, if is limit exceeded
*/
public boolean isLimitExceeded(int numbOfFiles){
if (numbOfFiles > ConstantsWorkspaceUploader.LIMIT_UPLOADS) {
Window.alert("Multiple upload limit is "
+ ConstantsWorkspaceUploader.LIMIT_UPLOADS
+ " files");
return true;
}
return false;
}
/**
* Adds the new submit to monitor.
*/
public void addNewSubmitToMonitor(){
GWT.log("addNewSubmitToMonitor...");
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
}
}
/**
* Creates the json key for files.
*
* @return the string
*/
public void createJsonKeyForFiles() {
try {
JSONObject productObj = new JSONObject();
JSONArray jsonArray = new JSONArray();
productObj.put(ConstantsWorkspaceUploader.JSON_CLIENT_KEYS, jsonArray);
// GWT.log("Creating json keys on fakeUploaders: "+fakeUploaders.toString());
for (int i = 0; i < fakeUploaders.size(); i++) {
WorkspaceUploaderItem file = fakeUploaders.get(i);
JSONObject obj = new JSONObject();
obj.put(file.getClientUploadKey(), new JSONString(file.getFile().getFileName()));
jsonArray.set(i, obj);
}
jsonKeys = productObj.toString();
GWT.log("updated jsonKeys: "+jsonKeys);
} catch (Exception e) {
GWT.log("error " + e.getMessage());
jsonKeys = null;
}
}
/**
* Generate new upload client keys.
*
* @param filesSelected the files selected
* @param parentId the parent id
* @return the list
*/
public void generateFakeUploaders(String filesSelected, String parentId) {
if(filesSelected==null || filesSelected.isEmpty())
return;
String[] files = filesSelected.split(FILE_DELEMITER);
// NORMALIZE FILE NAMES
for (int i = 0; i < files.length; i++) {
String normalizedFileName = files[i];
if (normalizedFileName.contains("\\")) {
files[i] = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\") + 1); // remove
// C:\fakepath\
// if
// exists
}
}
GWT.log("generating fake uploaders on: "+files.toString());
fakeUploaders = new ArrayList<WorkspaceUploaderItem>(files.length);
for (int i = 0; i < files.length; i++) {
WorkspaceUploaderItem fakeItem = new WorkspaceUploaderItem();
fakeItem.setClientUploadKey(GenerateUUID.get());
fakeItem.setUploadStatus(UPLOAD_STATUS.WAIT);
WorkspaceUploadFile fakeFile = new WorkspaceUploadFile();
fakeFile.setFileName(files[i]);
fakeFile.setParentId(parentId);
fakeItem.setFile(fakeFile);
fakeUploaders.add(fakeItem);
}
GWT.log("fakeUploaders generated: "+fakeUploaders.toString());
}
/**
* @return the jsonKeys
*/
public String getJsonKeys() {
return jsonKeys;
}
}

View File

@ -0,0 +1,615 @@
/**
*
*/
package org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop;
import java.util.HashMap;
import java.util.Map;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceExplorerListenerController;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.WorkspaceFieldsUploadManager;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* The Class MultipleDNDUpload.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Oct 28, 2015
*/
public class MultipleDNDUpload extends LayoutPanel implements
HasWorskpaceUploadNotificationListener {
// private WorkspaceFieldsUploadManager fields;
private String idFolder;
private UPLOAD_TYPE type;
// private String jsonKeys;
private String servlet = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM;
public static final String FILE_DELEMITER = ";";
private Widget onlyChild;
private Map<String, WorkspaceFieldsUploadManager> fields = new HashMap<String, WorkspaceFieldsUploadManager>();
private Map<String, String> jsonKeys = new HashMap<String, String>();
protected WorkspaceExplorerListenerController controller = new WorkspaceExplorerListenerController();
private String currentJsonKey;
private boolean isLimitExceeded;
/**
* Instantiates a new DND file reader.
*/
public MultipleDNDUpload() {
this.getElement().setId("drop_target");
HTML html = new HTML(
"<div id=\"drop_target_outer\"><div id=\"drop_target_inner\"></div></div>");
html.getElement().setClassName("container-drop_target");
this.add(html);
// ScriptInjector.fromUrl("workspaceuploader/dndhtmlfileupload.js")
// .setWindow(ScriptInjector.TOP_WINDOW).inject();
}
/**
* Adds the unique container. You must add a unique panel in order to DND
* works fine.
*
* @param w
* the w
*/
public void addUniqueContainer(Widget w) {
if (onlyChild != null) {
try {
remove(onlyChild);
} catch (Exception e) {
}
}
onlyChild = w;
onlyChild.getElement().setId("drop_target_only_child");
super.add(onlyChild);
}
/**
* Sets the parameters.
*
* @param parentId
* the parent id
* @param uploadType
* the upload type
*/
public void setParameters(String parentId, UPLOAD_TYPE uploadType) {
this.idFolder = parentId;
this.type = uploadType;
}
/**
* Sets the visible child.
*
* @param bool
* the new visible child
*/
public void setVisibleOnlyChild(boolean bool) {
if (onlyChild != null) {
onlyChild.setVisible(bool);
}
}
/*
* (non-Javadoc)
*
* @see com.google.gwt.user.client.ui.Widget#onLoad()
*/
@Override
protected void onLoad() {
super.onLoad();
initW3CFileReader(this, FILE_DELEMITER);
}
/**
* Inits the workspace fields.
*
* @param uploadUUID
* the upload uuid
*/
private void initWorkspaceFields(String uploadUUID) {
fields.put(uploadUUID, new WorkspaceFieldsUploadManager());
}
/**
* Limit is exceeded.
*
* @param numbOfFiles the numb of files
* @return true, if successful
*/
private boolean limitIsExceeded(int numbOfFiles) {
GWT.log("# of items dropped: " + numbOfFiles);
if (numbOfFiles > ConstantsWorkspaceUploader.LIMIT_UPLOADS) {
Window.alert("Multiple upload limit is "
+ ConstantsWorkspaceUploader.LIMIT_UPLOADS + " files");
return isLimitExceeded = true;
}
return isLimitExceeded = false;
}
/**
* Sets the limit exceeded.
*
* @param isLimitExceeded the isLimitExceeded to set
*/
private void setLimitExceeded(boolean isLimitExceeded) {
this.isLimitExceeded = isLimitExceeded;
}
/**
* Adds the new submit to monitor.
*
* @param uploadUUID
* the upload uuid
*/
private void addNewSubmitToMonitor(String uploadUUID) {
WorkspaceFieldsUploadManager field = getField(uploadUUID);
field.addNewSubmitToMonitor();
}
/**
* Creates the json key for files.
*
* @param uploadUUID
* the upload uuid
*/
private void createJsonKeyForFiles(String uploadUUID) {
WorkspaceFieldsUploadManager field = getField(uploadUUID);
field.createJsonKeyForFiles();
}
/**
* Generate fake uploaders.
*
* @param filesSelected
* the files selected
* @param parentId
* the parent id
* @param uploadUUID
* the upload uuid
*/
private void generateFakeUploaders(String filesSelected, String parentId,
String uploadUUID) {
WorkspaceFieldsUploadManager field = getField(uploadUUID);
field.generateFakeUploaders(filesSelected, parentId);
}
/**
* Gets the fields.
*
* @param uploadUUID
* the upload uuid
* @return the fields
*/
private WorkspaceFieldsUploadManager getField(String uploadUUID) {
return fields.get(uploadUUID);
}
/**
* Update json keys.
*
* @param uploadUUID
* the upload uuid
*/
private void updateJsonKeys(String uploadUUID) {
WorkspaceFieldsUploadManager field = getField(uploadUUID);
jsonKeys.put(uploadUUID, field.getJsonKeys());
// this.jsonKeys = field.getJsonKeys();
}
/**
* Sets the current json ke value.
*
* @param uploadUUID
* the new current json ke value
*/
public void setCurrentJsonKeValue(String uploadUUID) {
currentJsonKey = jsonKeys.get(uploadUUID);
}
/**
* Fire error.
*
* @param msg
* the msg
*/
private void showAlert(String msg) {
Window.alert(msg);
resetPanel(this);
}
/**
* Reset.
*/
private void reset() {
resetPanel(this);
}
/**
* Gets the upload type.
*
* @return the upload type
*/
public UPLOAD_TYPE getUploadType() {
return type;
}
/**
* Reset panel.
*
* @param instance
* the instance
*/
private static native void resetPanel(MultipleDNDUpload instance) /*-{
var drop = $wnd.$('#drop_target')[0];
if (drop === null || drop === undefined) {
return;
}
drop.className = "over-false";
$wnd.$('#drop_target_inner')[0].className = "";
$wnd.$('#drop_target_outer')[0].style.display = "none";
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::setVisibleOnlyChild(Z)(true);
}-*/;
/**
* Gets the files selected.
*
* @param instance
* the instance
* @param fileDelimiter
* the file delimiter
* @return the files selected
*/
public static native void initW3CFileReader(MultipleDNDUpload instance,
String fileDelimiter) /*-{
console.log("initW3CFileReader");
function generateUUID() {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
function(c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
return uuid;
}
//DROP CHECK IF CONTAINS FILES
function containsFiles(items) {
// if (dataTransfer.types) {
// for (var i = 0; i < dataTransfer.types.length; i++) {
// console.log("dataTransfer.types[i] "+dataTransfer.types[i]);
// if (dataTransfer.types[i] != "Files") {
// return false;
// }
// }
// }
// return true;
if (items) {
for (i = 0; i < items.length; i++) {
entry = items[i]
if (entry.getAsEntry) { //Standard HTML5 API
entry = entry.getAsEntry();
} else if (entry.webkitGetAsEntry) { //WebKit implementation of HTML5 API.
entry = entry.webkitGetAsEntry();
}
if (entry.isFile) {
console.log("entry is file");
//Handle FileEntry
// readFile(entry, uploadFile);
} else if (entry.isDirectory) {
console.log("entry is directory");
return false;
//Handle DirectoryEntry
// readFileTree(entry, uploadFile);
}
}
return true;
}
return false;
}
if (window.FileReader) {
console.log("before load");
var drop = $wnd.$('#drop_target')[0];
$wnd.$('#drop_target_outer')[0].style.display = "none";
console.log("drop is " + drop);
function cancel(e) {
if (e.preventDefault) {
e.preventDefault();
}
return false;
}
function addEventHandler(obj, evt, handler) {
if (obj.addEventListener) {
// W3C method
obj.addEventListener(evt, handler, false);
} else if (obj.attachEvent) {
// IE method.
obj.attachEvent('on' + evt, handler);
} else {
// Old school method.
obj['on' + evt] = handler;
}
}
function containsFiles(event) {
if (event.dataTransfer.types) {
for (var i = 0; i < event.dataTransfer.types.length; i++) {
if (event.dataTransfer.types[i] == "Files") {
return true;
}
}
}
return false;
}
function isFolder(file) {
if (file != null && !file.type && file.size % 4096 == 0) {
return true;
}
return false;
}
addEventHandler(
drop,
'dragenter',
function(e) {
console.log('dragenter');
drop.className = "over-true";
$wnd.$('#drop_target_inner')[0].className = "";
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::setVisibleOnlyChild(Z)(false);
e.preventDefault();
if (containsFiles(e)) {
console.log("The drag event contains files");
// The drag event contains files
// Do something
} else {
console.log("The drag event doesn't contain files");
// The drag event doesn't contain files
// Do something else
}
});
// Event Listener for when the dragged file leaves the drop zone.
addEventHandler(
drop,
'dragleave',
function(e) {
console.log('dragleave');
drop.className = "over-false";
$wnd.$('#drop_target_inner')[0].className = "";
$wnd.$('#drop_target_outer')[0].style.display = "none";
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::setVisibleOnlyChild(Z)(true);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::setLimitExceeded(Z)(false);
});
addEventHandler(drop, 'dragover', function(e) {
e = e || window.event; // get window.event if e argument missing (in IE)
if (e.preventDefault) {
e.preventDefault();
} //
console.log('dragover');
drop.className = "over-true";
$wnd.$('#drop_target_outer')[0].style.display = "inline";
});
addEventHandler(
drop,
'drop',
function(e) {
e = e || window.event; // get window.event if e argument missing (in IE)
if (e.preventDefault) {
e.preventDefault();
} // stops the browser from redirecting off to the image.
var uploadUUID = generateUUID();
console.log("uploadKey: " + uploadUUID);
//NEW WORKSPACE FIELDS
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::initWorkspaceFields(Ljava/lang/String;)(uploadUUID);
var servlet = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::servlet;
var opts = {
url : servlet,
type : "POST",
processData : false
};
var idfolder = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::idFolder;
console.log("idfolder: " + idfolder);
var uploadType = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::type;
console.log("uploadType: " + uploadType);
if (idfolder === null || idfolder === undefined
|| uploadType === null
|| uploadType === undefined) {
$wnd.$('#drop_target_inner')[0].className = "drop_target_inner_error";
var error = "Folder destionation or upload type not specified";
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::showAlert(Ljava/lang/String;)(error);
return;
}
var dt = e.dataTransfer;
//dt.dropEffect = 'copy';
var files = dt.files;
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::limitIsExceeded(I)(files.length);
var limitExceeded = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::isLimitExceeded;
if(limitExceeded){
console.log("limitExceeded, return");
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::reset()();
return;
}
if (files.length == 0) {
console.log("No file dragged, return");
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::reset()();
return;
}
console.log("# of file/s: " + files.length);
var numFolder = 0;
for (var i = 0; i < files.length; i++) {
var file = files[i];
var filesSelected = files[i].name + fileDelimiter;
if (!isFolder(file)) {
console.log("filesSelected: " + filesSelected);
// var files = filese
// var files = filesSelected.split(fileDelimiter);
console.log("files: " + files);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::generateFakeUploaders(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)(filesSelected,idfolder,uploadUUID);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::createJsonKeyForFiles(Ljava/lang/String;)(uploadUUID);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::updateJsonKeys(Ljava/lang/String;)(uploadUUID);
var jsonKeysMap = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::jsonKeys;
console.log("jsonKeysMap: " + jsonKeysMap);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::setCurrentJsonKeValue(Ljava/lang/String;)(uploadUUID);
var keyVal = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::currentJsonKey;
console.log("keyVal: " + keyVal);
var xhr = new XMLHttpRequest();
// var upload = xhr.upload;
// upload.fileIndex = i;
// upload.fileObj = file;
// upload.downloadStartTime = new Date().getTime();
// upload.currentStart = upload.downloadStartTime;
// upload.currentProgress = 0;
// upload.startData = 0;
// console.log("upload: " + upload.toString());
// add listeners
// upload.addEventListener("progress", progress, false);
// upload.addEventListener("load", load, false);
xhr.open(opts.type, opts.url, true);
// var boundary = "AJAX--------------" + (new Date).getTime();
// var contentType = "multipart/form-data; boundary=" + boundary;
// xhr.setRequestHeader("Content-Type", contentType);
// Use native function(Chrome 5+ ,Safari 5+ and Firefox 4+), for dealing
// with multipart/form-data and boundray generation
var formdata = new FormData(); // see
// https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Using_FormData_objects
// 'file' can be any string which you would like to associte with
// uploaded file even for example file.type eg:
// formdata.append(file.type, file);
// formdata.append(file.fileName, file);
formdata.append("isOverwrite", "false");
// $wnd.exportCreateJsonKeyForFiles();
//
// $wnd.exportAddNewSubmitToMonitor();
formdata.append("client_upload_keys", keyVal);
formdata.append("uploadType", uploadType);
formdata.append("idFolder", idfolder);
formdata.append('uploadFormElement', file);
xhr.send(formdata);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::addNewSubmitToMonitor(Ljava/lang/String;)(uploadUUID);
// reader.readAsText(file);
}else{
numFolder++;
}
}
if(numFolder>0){
var msg;
if(numFolder==files.length){
msg = "Is not possible to upload a folder";
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::showAlert(Ljava/lang/String;)(msg);
return;
}
var msg = "Ignored ";
msg += numFolder > 1? numFolder+" folders": numFolder+" folder";
msg+= " during upload";
console.log(msg);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::showAlert(Ljava/lang/String;)(msg);
}
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::reset()();
});
// Tells the browser that we *can* drop on this target
// addEventHandler(drop, 'dragover', cancel);
// addEventHandler(drop, 'dragenter', cancel);
} else {
$wnd.$('#drop_target')[0].innerHTML = 'Your browser does not support the HTML5 FileReader.';
}
}-*/;
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.workspaceuploader.client.
* WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#
* addWorkspaceUploadNotificationListener
* (org.gcube.portlets.widgets.workspaceuploader
* .client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener)
*/
@Override
public void addWorkspaceUploadNotificationListener(
WorskpaceUploadNotificationListener handler) {
controller.addWorkspaceUploadListener(handler);
}
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.workspaceuploader.client.
* WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#
* removeWorkspaceUploadNotificationListener
* (org.gcube.portlets.widgets.workspaceuploader
* .client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener)
*/
@Override
public void removeWorkspaceUploadNotificationListener(
WorskpaceUploadNotificationListener handler) {
controller.removeWorkspaceUploadListener(handler);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@ -117,4 +117,73 @@ h1 {
/* .baloonGoTop :HOVER { */
/* cursor: pointer; */
/* color: #FFF; */
/* } */
/* } */
.container-drop_target {
/* position: relative; */
}
.textbox:hover {
opacity: 1;
}
.text {
padding-top: 50px;
}
#drop_target_outer {
/* position: fixed; */
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#drop_target_inner {
width: 50%;
height: 50%;
/* text-align: center; */
/* vertical-align: middle; */
top: 25%;
background-image: url("dropfilehere.png");
background-repeat: no-repeat;
background-position: center;
margin: 0 auto;
position: relative;
/* background: orange; */
}
/* Demo One */
#drop_target {
/* border: 5px dashed #D9D9D9; */ /* border-radius: 10px; */
/* padding: 50%; */ /* text-align: center; */ /* display: none; */
width: 100%;
height: 100%;
/* height: 20px; */
}
.over-true {
/* border: 3px dashed #D9D9D9; */
border-radius: 5px;
/* padding: 50%; */
text-align: center;
background-color: #FFF !important;
}
.over-false {
background: none;
}
/* .display-true {
display: inline-flex;
}
.display-false {
display: none;
} */
/* Demo One */
.drop_target_inner_error {
background-image: url("status-error.png") !important;
}

View File

@ -159,21 +159,23 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
logger.error("ERROR: multipart request not found");
sendError(response, "ERROR: multipart request not found");
}
HttpSession session = request.getSession();
logger.debug("UPLOAD-SERVLET (" + session.getId() + ") new upload request received.");
String destinationId = null;
String uploadType = null;
boolean isOverwrite = false;
// String clientUploadKey = null;
FileItemStream uploadItem = null;
ArrayList<String> listClientUploadKeys = null;
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
try {
logger.info("UPLOAD-SERVLET starting");
HttpSession session = request.getSession();
logger.info("UPLOAD-SERVLET session: "+session);
logger.debug("UPLOAD-SERVLET (" + session.getId() + ") new upload request received.");
String destinationId = null;
String uploadType = null;
boolean isOverwrite = false;
// String clientUploadKey = null;
FileItemStream uploadItem = null;
ArrayList<String> listClientUploadKeys = null;
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
/**
* An iterator to instances of <code>FileItemStream</code>
* parsed from the request, in the order that they were
@ -230,6 +232,10 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
logger.error("Error processing request in upload servlet", e);
sendError(response, "Internal error: Error during request processing");
return;
} catch (Exception e) {
logger.error("Error processing request in upload servlet", e);
sendError(response, "Internal error: Error during request processing");
return;
}
}

View File

@ -17,7 +17,6 @@ import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.widgets.workspaceuploader.server.WorkspaceUploadServletStream;
import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploaderProducer;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;