429: Workspace: uploading big files

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

Removed button "Upload" added change handler on file upload

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@119619 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-10-12 15:07:58 +00:00
parent 08d79d87da
commit 0ad8b4a54f
2 changed files with 171 additions and 152 deletions

View File

@ -16,12 +16,13 @@ import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
@ -33,6 +34,7 @@ import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Hidden;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
@ -44,8 +46,6 @@ import com.google.gwt.user.client.ui.VerticalPanel;
*/
public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNotificationListener{
private DialogUpload INSTANCE = this;
protected Button btnUpload = new Button("Upload");
private Hidden hiddenOverwrite = new Hidden(ConstantsWorkspaceUploader.IS_OVERWRITE,"false");
protected final FormPanel formPanel = new FormPanel();
protected FileUpload fileUpload;
@ -64,7 +64,7 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
protected String parentIdentifier = "";
protected VerticalPanel panel;
private HorizontalPanel hpButtons;
private HorizontalPanel hpBottom;
// private MonitorPanel monitorPanel;
protected String clientUploadKey;
private Anchor anchorMyUploads;
@ -108,10 +108,16 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
panel.add(jsonClientKeys);
panel.add(fileUpload);
hpButtons = new HorizontalPanel();
hpButtons.getElement().getStyle().setMarginTop(10, Unit.PX);
hpButtons.add(btnUpload);
panel.add(hpButtons);
hpBottom = new HorizontalPanel();
hpBottom.getElement().getStyle().setMarginTop(10, Unit.PX);
if(uploadType.equals(UPLOAD_TYPE.File)){
HTML msg = new HTML("To select multiple files, press and hold down the Ctrl key, and then click each item <br/> that you want to select");
msg.getElement().getStyle().setFontSize(10, Unit.PX);
hpBottom.add(msg);
}
panel.add(hpBottom);
HorizontalPanel hp = new HorizontalPanel();
hp.getElement().setId("hpID");
@ -141,7 +147,7 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
*/
public void bindEvents(){
this.addHandlers();
this.addListeners();
// this.addListeners();
}
/**
@ -225,46 +231,12 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
}
});
}
/**
* Adds the loading.
*/
protected void addLoading(){
panel.add(LOADING);
}
/**
* Removes the loading.
*/
protected void removeLoading(){
try{
panel.remove(LOADING);
}catch(Exception e){
}
}
/**
* Enable buttons.
*
* @param bool the bool
*/
protected void enableButtons(boolean bool){
btnUpload.setEnabled(bool);
// btnCancel.setEnabled(bool);
// upload.setEnabled(bool);
}
/**
* Adds the listeners.
*/
protected void addListeners() {
btnUpload.addClickHandler(new ClickHandler() {
fileUpload.addChangeHandler(new ChangeHandler() {
@Override
public void onClick(ClickEvent event) {
public void onChange(ChangeEvent event) {
GWT.log("btnSubmit click");
if (fileUpload.getFilename()==null || !(fileUpload.getFilename().length()>2)) {
GWT.log("No file specified ");
@ -302,10 +274,88 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
}
});
}
}
});
}
/**
* Adds the loading.
*/
protected void addLoading(){
panel.add(LOADING);
}
/**
* Removes the loading.
*/
protected void removeLoading(){
try{
panel.remove(LOADING);
}catch(Exception e){
}
}
/**
* Enable buttons.
*
* @param bool the bool
*/
protected void enableButtons(boolean bool){
// btnUpload.setEnabled(bool);
// btnCancel.setEnabled(bool);
// upload.setEnabled(bool);
}
/**
* Adds the listeners.
*/
/*protected void addListeners() {
btnUpload.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
GWT.log("btnSubmit click");
if (fileUpload.getFilename()==null || !(fileUpload.getFilename().length()>2)) {
GWT.log("No file specified ");
return;
}
GWT.log("fileUpload.getFilename() "+fileUpload.getFilename());
//TODO: recall: Some browser would write in fileUploadField.getValue() C:\fakepath\$fileName
String normalizedFileName = fileUpload.getFilename();
if (normalizedFileName.contains("\\")) {
normalizedFileName = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\")+1); //remove C:\fakepath\ if exists
}
final String label = normalizedFileName;
WorkspaceUploaderServiceAsync.Util.getInstance().itemExistsInWorkpaceFolder(parentIdentifier, normalizedFileName, 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());
}
});
}
});
}*/
/**
* Submit form.

View File

@ -15,8 +15,8 @@ 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.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
@ -53,95 +53,6 @@ public class MultipleDilaogUpload extends DialogUpload {
fileUploadID = GenerateUUID.get(10, 16); //is tagID
fileUpload.getElement().setId(fileUploadID);
this.addHandlers();
this.addListeners();
}
/**
* Adds the listeners.
*/
@Override
protected void addListeners() {
btnUpload.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
GWT.log("btnSubmit click");
if (fileUpload.getFilename()==null || !(fileUpload.getFilename().length()>2)) {
GWT.log("No file specified ");
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
}
}
//GENERATE NEW UPLOADERS
generateFakeUploaders(files, parentIdentifier);
GWT.log(fakeUploaders.toString());
String jsonKeys = createJsonKeyForFiles(fakeUploaders);
GWT.log(jsonKeys);
if(jsonKeys==null){
Window.alert("Sorry an error occurred during file/s submit. Try again");
return;
}
//ADD TO FORM PANEL
// initJsonClientKeys();
jsonClientKeys.setValue(jsonKeys);
//CASE 1 FILE
if(files.length==1){
/*
* TODO: 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
submitForm();
}
});
/*
btnCancel.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
hide();
}
});*/
}
/**
@ -165,7 +76,6 @@ public class MultipleDilaogUpload extends DialogUpload {
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUploadStream#addHandlers()
*/
@ -230,25 +140,84 @@ public class MultipleDilaogUpload extends DialogUpload {
enableButtons(false);
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
setVisible(false);
removeLoading();
UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
//WAITING 0.1 SEC TO FIRST UPDATES
/*new Timer() {
@Override
public void run() {
removeLoading();
UploaderMonitor.getInstance().pollWorkspaceUploaderId(workspaceUploaderItem.getClientUploadKey());
}
}.schedule(100);*/
}
}
});
fileUpload.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
GWT.log("browse return...");
if (fileUpload.getFilename()==null || !(fileUpload.getFilename().length()>2)) {
GWT.log("No file specified ");
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
}
}
//GENERATE NEW UPLOADERS
generateFakeUploaders(files, parentIdentifier);
GWT.log(fakeUploaders.toString());
String jsonKeys = createJsonKeyForFiles(fakeUploaders);
GWT.log(jsonKeys);
if(jsonKeys==null){
Window.alert("Sorry an error occurred during file/s submit. Try again");
return;
}
//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
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
submitForm();
}
});
}
/**