From 26230f7e9f14c1551c85b067de67fb10d6e38272 Mon Sep 17 00:00:00 2001 From: francesco Date: Fri, 2 Oct 2020 16:16:31 +0200 Subject: [PATCH] starting file upload integration --- .classpath | 10 +- .project | 10 +- .../com.gwtplugins.gdt.eclipse.core.prefs | 2 +- .settings/org.eclipse.jdt.core.prefs | 4 +- .settings/org.eclipse.wst.common.component | 23 +- .../MetadataProfileFormBuilder.gwt.xml | 37 +- .../client/ConstantsMPFormBuilder.java | 23 ++ .../client/MetadataProfileFormBuilder.java | 1 + .../form/generic/CreateMetadataForm.java | 186 ++++----- .../form/generic/CreateMetadataForm.ui.xml | 327 +++------------- .../mpformbuilder/client/ui/icons/Images.java | 8 + .../mpformbuilder/client/ui/icons/loading.gif | Bin 0 -> 2533 bytes .../client/ui/upload/DialogUpload.java | 334 ++++++++++++++++ .../client/ui/upload/FileUpload.java | 24 ++ .../client/ui/upload/FileUpload.ui.xml | 11 + .../client/ui/upload/GenerateUUID.java | 72 ++++ .../ui/upload/MultipleDilaogUpload.java | 370 ++++++++++++++++++ .../client/ui/upload/ProgressBar.java | 36 ++ .../client/ui/upload/ProgressBar.ui.xml | 13 + .../upload/WorkspaceUploadNotification.java | 101 +++++ .../WorkspaceUploaderListenerController.java | 174 ++++++++ .../ui/upload/events/NotifyUploadEvent.java | 181 +++++++++ .../events/NotifyUploadEventHandler.java | 21 + .../client/ui/utils/LoaderIcon.java | 62 +++ .../shared/upload/HandlerResultMessage.java | 180 +++++++++ .../shared/upload/UploadEvent.java | 55 +++ .../shared/upload/UploadProgress.java | 86 ++++ .../upload/UploadProgressChangeEvent.java | 125 ++++++ .../shared/upload/WorkspaceUploadFile.java | 169 ++++++++ .../shared/upload/WorkspaceUploaderItem.java | 267 +++++++++++++ .../MetadataProfileFormBuilder.gwt.xml | 37 +- 31 files changed, 2509 insertions(+), 440 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ConstantsMPFormBuilder.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/icons/loading.gif create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/DialogUpload.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/FileUpload.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/FileUpload.ui.xml create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/GenerateUUID.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/MultipleDilaogUpload.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/ProgressBar.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/ProgressBar.ui.xml create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/WorkspaceUploadNotification.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/WorkspaceUploaderListenerController.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/events/NotifyUploadEvent.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/events/NotifyUploadEventHandler.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/utils/LoaderIcon.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/HandlerResultMessage.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/UploadEvent.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/UploadProgress.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/UploadProgressChangeEvent.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/WorkspaceUploadFile.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/WorkspaceUploaderItem.java diff --git a/.classpath b/.classpath index 2db9c0e..d11cec9 100644 --- a/.classpath +++ b/.classpath @@ -1,14 +1,15 @@ - + - + + @@ -18,10 +19,9 @@ - + - @@ -35,5 +35,5 @@ - + diff --git a/.project b/.project index 50a65f1..b49f60e 100644 --- a/.project +++ b/.project @@ -15,11 +15,6 @@ - - org.eclipse.m2e.core.maven2Builder - - - com.gwtplugins.gdt.eclipse.core.webAppProjectValidator @@ -35,6 +30,11 @@ + + org.eclipse.m2e.core.maven2Builder + + + org.eclipse.jem.workbench.JavaEMFNature diff --git a/.settings/com.gwtplugins.gdt.eclipse.core.prefs b/.settings/com.gwtplugins.gdt.eclipse.core.prefs index 692248e..1dd6475 100644 --- a/.settings/com.gwtplugins.gdt.eclipse.core.prefs +++ b/.settings/com.gwtplugins.gdt.eclipse.core.prefs @@ -1,4 +1,4 @@ eclipse.preferences.version=1 -lastWarOutDir=/home/francesco-mangiacrapa/git/metadata-profile-form-builder-widget/target/metadata-profile-form-builder-widget-0.1.0-SNAPSHOT +lastWarOutDir=/home/francesco/git/metadata-profile-form-builder-widget/target/metadata-profile-form-builder-widget-0.1.0-SNAPSHOT warSrcDir=src/main/webapp warSrcDirIsOutput=false diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 8db228c..43c8195 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,11 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index fb41ec3..71203e7 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,13 +1,30 @@ + + + + + + + + + + - - uses - + + + + + + + + + + diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml index a7f617a..9782a54 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml @@ -1,30 +1,37 @@ - - + + - + - - + + - - - + + + + + - + - - - + - - - + + + + + diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ConstantsMPFormBuilder.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ConstantsMPFormBuilder.java new file mode 100644 index 0000000..9260da3 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ConstantsMPFormBuilder.java @@ -0,0 +1,23 @@ +package org.gcube.portlets.widgets.mpformbuilder.client; + +import com.google.gwt.core.client.GWT; + +public class ConstantsMPFormBuilder { + + public static final String WORKSPACE_UPLOADER_SERVLET_STREAM__MODIFIED = GWT.getModuleBaseURL() + "workspaceUploadServletStream"; + + public static final String CURR_GROUP_ID = "currGroupId"; + //public static final String CURR_USER_ID = "currUserId"; + public static final String IS_OVERWRITE = "isOverwrite"; + public static final String UPLOAD_TYPE = "uploadType"; + public static final String ID_FOLDER = "idFolder"; + public static final String UPLOAD_FORM_ELEMENT = "uploadFormElement"; + + public static final String CLIENT_UPLOAD_KEYS = "client_upload_keys"; + public static final String CANCEL_UPLOAD = "cancel_upload"; + public static final String JSON_CLIENT_KEYS = "ClientKeys"; + + public static final int LIMIT_UPLOADS = 50; + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilder.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilder.java index 6f2f197..3e9c34a 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilder.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilder.java @@ -2,6 +2,7 @@ package org.gcube.portlets.widgets.mpformbuilder.client; import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm; +import com.github.gwtbootstrap.client.ui.FileUpload; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.event.shared.HandlerManager; diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/generic/CreateMetadataForm.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/generic/CreateMetadataForm.java index 8c551b6..1c3836a 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/generic/CreateMetadataForm.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/generic/CreateMetadataForm.java @@ -2,10 +2,8 @@ package org.gcube.portlets.widgets.mpformbuilder.client.form.generic; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderService; import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderServiceAsync; @@ -18,9 +16,9 @@ import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.CategoryPanel import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.CustomFieldEntry; import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.MetaDataFieldSkeleton; import org.gcube.portlets.widgets.mpformbuilder.client.ui.resources.AddResourceToDataset; -import org.gcube.portlets.widgets.mpformbuilder.client.ui.tags.TagsPanel; import org.gcube.portlets.widgets.mpformbuilder.client.ui.twincolumnselection.TwinColumnSelectionMainPanel; import org.gcube.portlets.widgets.mpformbuilder.client.ui.utils.InfoIconsLabels; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.utils.LoaderIcon; import org.gcube.portlets.widgets.mpformbuilder.shared.catalogue.OrganizationBean; import org.gcube.portlets.widgets.mpformbuilder.shared.license.LicenseBean; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.CategoryWrapper; @@ -79,7 +77,7 @@ public class CreateMetadataForm extends Composite{ @UiField ControlGroup customFields; @UiField Button addCustomFieldButton; @UiField Button createButton; - @UiField Button resetButton; +// @UiField Button resetButton; @UiField AlertBlock infoBlock; @UiField AlertBlock onContinueAlertBlock; @UiField AlertBlock onCreateAlertBlock; @@ -87,9 +85,11 @@ public class CreateMetadataForm extends Composite{ @UiField ListBox metadataTypeListbox; @UiField Form formFirstStep; @UiField Form formThirdStep; - @UiField Button continueButton; +// @UiField Button continueButton; @UiField Paragraph selectedProfile; - @UiField TagsPanel tagsPanel; + @UiField LoaderIcon loaderProfiles; + @UiField LoaderIcon loaderProfileInformation; + //@UiField TagsPanel tagsPanel; // info panels @UiField Icon infoIconTypes; @@ -99,11 +99,6 @@ public class CreateMetadataForm extends Composite{ @UiField FocusPanel focusPanelCustomFields; @UiField Popover popoverCustomFields; @UiField ControlGroup metadataTypesControlGroup; -// @UiField ControlGroup productTitleGroup; -// @UiField ControlGroup maintainerControlGroup; -// @UiField ControlGroup versionControlGroup; -// @UiField ControlGroup organizationsGroup; -// @UiField ControlGroup groupsControlGroup; private final MetadataProfileFormBuilderServiceAsync formBuilderService = GWT.create(MetadataProfileFormBuilderService.class); @@ -164,6 +159,7 @@ public class CreateMetadataForm extends Composite{ this(eventBus); this.scope = scope; this.genericResourceSecondaryType = genericResourceSecondaryType; + showLoadingProfiles(true); MetadataProfileFormBuilderServiceAsync.Util.getInstance().getProfilesInTheScope(scope, genericResourceSecondaryType, new AsyncCallback>() { @Override @@ -173,6 +169,7 @@ public class CreateMetadataForm extends Composite{ @Override public void onSuccess(List profiles) { createDatasetFormBody(profiles); + showLoadingProfiles(false); } }); @@ -186,7 +183,9 @@ public class CreateMetadataForm extends Composite{ */ public CreateMetadataForm(List profiles, HandlerManager eventBus) { this(eventBus); + showLoadingProfiles(true); createDatasetFormBody(profiles); + showLoadingProfiles(false); } @@ -201,6 +200,16 @@ public class CreateMetadataForm extends Composite{ bind(); prepareInfoIcons(); } + + private void showLoadingProfiles(boolean bool) { + loaderProfiles.setText("Loading Profiles..."); + loaderProfiles.setVisible(bool); + } + + private void showLoadingProfileInformation(boolean bool) { + loaderProfileInformation.setText("Loading Profile Information..."); + loaderProfileInformation.setVisible(bool); + } /** @@ -252,27 +261,29 @@ public class CreateMetadataForm extends Composite{ if(profiles != null && !profiles.isEmpty()){ for(MetaDataProfileBean metadataBean: profiles){ - metadataTypeListbox.addItem(metadataBean.getType()); - - // add handler on select - metadataTypeListbox.addChangeHandler(new ChangeHandler() { - - @Override - public void onChange(ChangeEvent event) { - - String selectedItemText = metadataTypeListbox.getSelectedItemText(); - metadataFieldsPanel.clear(); - if(selectedItemText.equals(NONE_PROFILE)){ - metadataFieldsPanel.setVisible(false); - //receivedBean.setChosenType(null); - }else{ - //receivedBean.setChosenType(selectedItemText); - addFields(selectedItemText, profiles); - } - } - }); } + // add handler on select + metadataTypeListbox.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + + String selectedItemText = metadataTypeListbox.getSelectedItemText(); + metadataFieldsPanel.clear(); + if(selectedItemText.equals(NONE_PROFILE)){ + metadataFieldsPanel.setVisible(false); + //receivedBean.setChosenType(null); + }else{ + //receivedBean.setChosenType(selectedItemText); + showLoadingProfileInformation(true); + formThirdStep.setVisible(true); + selectedProfile.setText("Selected Profile is " + metadataTypeListbox.getSelectedItemText()); + addFields(selectedItemText, profiles); + showLoadingProfileInformation(false); + } + } + }); // // hide elements or show them if needed (groups in profiles cannot be present again in groups listbox) // if(groupsControlGroup.isVisible()){ @@ -422,7 +433,7 @@ public class CreateMetadataForm extends Composite{ * * @param e the e */ - @UiHandler("continueButton") + /*@UiHandler("continueButton") void onContinueButton(ClickEvent e){ // validate data @@ -442,7 +453,7 @@ public class CreateMetadataForm extends Composite{ else selectedProfile.setText("Selected Type is " + metadataTypeListbox.getSelectedItemText()); } - } + }*/ /** * After onContinue ... @@ -482,22 +493,22 @@ public class CreateMetadataForm extends Composite{ * * @param e the e */ - @UiHandler("goBackButtonSecondStep") - void onGoBackButton(ClickEvent e){ - - Window.alert("Called onGoBackButton"); - -// // swap forms -// if(isWorkspaceRequest){ -// formFirstStep.setVisible(hideManageResources()); -// formSecondStep.setVisible(!hideManageResources()); -// }else{ -// formFirstStep.setVisible(true); -// formSecondStep.setVisible(false); -// } -// formThirdStep.setVisible(false); - - } +// @UiHandler("goBackButtonSecondStep") +// void onGoBackButton(ClickEvent e){ +// +// Window.alert("Called onGoBackButton"); +// +//// // swap forms +//// if(isWorkspaceRequest){ +//// formFirstStep.setVisible(hideManageResources()); +//// formSecondStep.setVisible(!hideManageResources()); +//// }else{ +//// formFirstStep.setVisible(true); +//// formSecondStep.setVisible(false); +//// } +//// formThirdStep.setVisible(false); +// +// } // /** // * On continue third step. @@ -531,7 +542,7 @@ public class CreateMetadataForm extends Composite{ } else{ - Set tags = new HashSet(tagsPanel.getTags()); + //Set tags = new HashSet(tagsPanel.getTags()); List groups = new ArrayList(); List groupsToForceCreation = new ArrayList(); Map> customFieldsMap = new HashMap>(); @@ -554,9 +565,9 @@ public class CreateMetadataForm extends Composite{ customFieldsMap.put(key, valuesForThisField); // get also tag/group if it is the case for this field - List tagsField = field.getTagFromThisField(); - if(tagsField != null) - tags.addAll(tagsField); +// List tagsField = field.getTagFromThisField(); +// if(tagsField != null) +// tags.addAll(tagsField); List groupsTitle = field.getGroupTitleFromThisGroup(); if(groupsTitle != null){ @@ -601,7 +612,7 @@ public class CreateMetadataForm extends Composite{ private void prepareInfoIcons() { // tags - tagsPanel.prepareIcon(popupOpenedIds); + //tagsPanel.prepareIcon(popupOpenedIds); // profiles (or types) @@ -662,8 +673,8 @@ public class CreateMetadataForm extends Composite{ onContinueAlertBlock.setText(text); onContinueAlertBlock.setType(type); onContinueAlertBlock.setVisible(true); - continueButton.setEnabled(true); - resetButton.setEnabled(true); +// continueButton.setEnabled(true); +// resetButton.setEnabled(true); // hide after some seconds Timer t = new Timer() { @@ -718,65 +729,6 @@ public class CreateMetadataForm extends Composite{ */ private String validateDataOnContinue() { -// // remove errors -// productTitleGroup.setType(ControlGroupType.NONE); -// maintainerControlGroup.setType(ControlGroupType.NONE); -// versionControlGroup.setType(ControlGroupType.NONE); -// metadataTypesControlGroup.setType(ControlGroupType.NONE); -// organizationsGroup.setType(ControlGroupType.NONE); -// tagsPanel.setGroupPanelType(ControlGroupType.NONE); -// -// String title = titleTextBox.getText().trim(); -// if(title.isEmpty()){ -// productTitleGroup.setType(ControlGroupType.ERROR); -// return "Missing title"; -// } -// -// // better check for the title -// String[] splittedTitle = title.split(" "); -// -// for (String word : splittedTitle) { -// String replaced = word.replaceAll(REGEX_TITLE_PRODUCT_SUBWORD, ""); -// if(!replaced.equals(word)){ -// productTitleGroup.setType(ControlGroupType.ERROR); -// return "Please note not all characters are allowed for the title"; -// } -// } -// -// // email reg expression -// String maintainerMail = maintainerEmailTextbox.getText(); -// if(!maintainerMail.isEmpty() && !maintainerMail.matches(REGEX_MAIL)){ -// maintainerControlGroup.setType(ControlGroupType.ERROR); -// return "Not valid maintainer email"; -// } -// -// // check if version is a number -// try{ -// int number = Integer.valueOf(versionTextbox.getText().trim()); -// if(number <= 0) -// throw new Exception(); -// }catch(Exception e){ -// versionControlGroup.setType(ControlGroupType.ERROR); -// return "Version must be a natural number greater than zero"; -// } -// -// // check if metadata profile is different from none and its mandatory fields have been fulfilled -// if(checkSelectedMetaDataProfile()){ -// metadataTypesControlGroup.setType(ControlGroupType.ERROR); -// return "You must select a Type different frome none"; -// } -// -// if(organizationsListbox.getSelectedItemText() == null){ -// organizationsGroup.setType(ControlGroupType.ERROR); -// return "You must select an organization in which you want to publish"; -// } -// -// // at least one tag.. -// if(tagsPanel.getTags().isEmpty()){ -// tagsPanel.setGroupPanelType(ControlGroupType.ERROR); -// return "Please add at least one meaningful tag for the item"; -// } - return null; } @@ -794,7 +746,7 @@ public class CreateMetadataForm extends Composite{ * * @param e the e */ - @UiHandler("resetButton") + /*@UiHandler("resetButton") void resetFormEvent(ClickEvent e){ // delete custom fields @@ -802,14 +754,14 @@ public class CreateMetadataForm extends Composite{ customField.removeFromParent(); } customFieldEntriesList.clear(); - } + }*/ /** * Disable dataset editable fields once the dataset has been successfully created. */ protected void disableDatasetFields() { - tagsPanel.freeze(); + //tagsPanel.freeze(); addCustomFieldButton.setEnabled(false); metadataTypeListbox.setEnabled(false); diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/generic/CreateMetadataForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/generic/CreateMetadataForm.ui.xml index 2e6f849..f213ac8 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/generic/CreateMetadataForm.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/generic/CreateMetadataForm.ui.xml @@ -1,7 +1,10 @@ + xmlns:g="urn:import:com.google.gwt.user.client.ui" + xmlns:b="urn:import:com.github.gwtbootstrap.client.ui" + xmlns:m="urn:import:org.gcube.portlets.widgets.mpformbuilder.client.ui.tags" + xmlns:f="urn:import:org.gcube.portlets.widgets.mpformbuilder.client.ui.upload" + xmlns:u="urn:import:org.gcube.portlets.widgets.mpformbuilder.client.ui.utils"> .form-main-style { margin-left: 10px; @@ -45,215 +48,33 @@ font-weight: bold; } - .the-margin-left{ + .the-margin-left { margin-left: 5px; } - + + + - Insert Item Information - - * - is required - + Choose a Profile + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - Types: + Profiles: - + - + - + - - - - - - - - - - - - - - - - - - - + - - - - - - - + - Continue - Reset + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -357,7 +124,8 @@ - + - + @@ -384,25 +153,27 @@ - + - - Go to the Item - - + + + + + - Add Resources + + Create - Go - Back + + + diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/icons/Images.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/icons/Images.java index 6ab9cf9..20e38b2 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/icons/Images.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/icons/Images.java @@ -1,13 +1,21 @@ package org.gcube.portlets.widgets.mpformbuilder.client.ui.icons; + + +import com.google.gwt.core.client.GWT; import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.resources.client.ImageResource; public interface Images extends ClientBundle { + public static final Images ICONS = GWT.create(Images.class); + @Source("file.png") ImageResource fileIcon(); @Source("folder.png") ImageResource folderIcon(); + + @Source("loading.gif") + ImageResource loading(); } diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/icons/loading.gif b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/icons/loading.gif new file mode 100644 index 0000000000000000000000000000000000000000..27f0eeec008138a3340f8c6bf8badcd2f5503054 GIT binary patch literal 2533 zcmZwJYfw|^83*t;CnuboBqn%rAq5gb2#|zZz<}W*5(p##L_r0STf#LUmqdt$fEq%$ z1eA*+qJoN|BCZr2Z>!QG=<2Gq*xl*4JL4|Utwp=t(fXzBwAur9+uaV|&zbZ5=6~Mz z`Kz@_ib%aXa0l;*0HpK*0KQ#(D<~X(|NaAQ^HFm8kxk9l;w;o6gu5cbv0ZNNN95kvL>#>N|2&YHU^+y7~lM5@_x3~ zczH4}WAJL-oW;P;EDX+9FW0*Wjn!rrsmWm!|nK203t#ODSEV;X(yq16vUl z6B`#V43Pk;SQ4HKAxZw2B%t4;3G*s#$zA=Q@d-a2|B`HZ{L#%*Tb9PxSr67b3g`O% z6qb7aS^J|x4w|sZ*`+m^76Cca#dIqjo|xIFvJB83P2F`2Tqmba>4mfGD?v>?XJx+I z`|r8Z-Hfl^WDve}AIJb}8o4}belsfv(Aqgwpr&~zP!UQ%S!0D?az|dBPP$RXXyd?# zwz28{S}vpqY3#`8-eRTy;Y693K%4{-W+Y1PUuY1z%SmLxfdeZF?tB!8w*W5Oinh%U zIq!Me#gQ*Rr4fC6Z8&0qjV2l5xq~dXHipfR2e*IGC2Z%la;ImCjLCF9oT+Mu=&Yo| zIWr07#YM|@Ax0p2@t&6AqHJXQkuW~d&PoEUUQT8w#-o~dRkRaIBf7B!3SZ(hL$Rb< zA!IvVpg+th;TxD+`HXRuB@Y*E@F@kG+3VWQpr(4E3=Grcp}EsO$Z?B*+4Id zgTX6;?*14F5F<@_(|U`zM`M>IKXnGr=wum%@-tT~EpUR$n-&w$`3EHKW-ttQs8>IX z55Yl}D;NBYzwLB6EVgeSFk8hbl#Qm~u=R`3NY|N=@=HY`+?K>E=B0g~s zi^#VDdo$Jo>On)tUN5ZHybH1rDgfF+ssgX# zW7MIw{SaCPOm6hbn$R^8mrYgheu?gm8|+ag5cc-2h`I9r7=zVyY5J?^hNxG*K@#>M|09r4FZ4A%X{f+fa8*+lU> zUs@>YOlx-3&PkyMjB@UE=>d;F&ZWot(tkUD<8PihcDn8C8_{^5L+!1!a2HP^-md~1 zO`l&7yrumWN9+OnYy>+ngWYWnRW&xK7Q@eeeFdlt&Lb753Kd&GW>z-HS--)SUXXYS z)248vNHMIq_>CcwFu5c{hvZ45m)+bw`2t~E+luqw_*o1b6E}a1?-LpRDvV~RkQaN% z(S%gH>cPxS1xIlN5Hy+awbPw~RsZxu7z?khJX>e?`0aOBStsD52j7TA*>UEe+2knd z4^g(I7#i?jYAFWH0d|9WXQP)<3-5^9S4X`GABnX5(Ju6zS{Va>;^FxcF2k%Pj9?Q6+ z&w3tBge_&!r8b!Y0n!iVC7)@XgR1*sw=D9?Em(ijv7?$&ouyoU+4~ZRd*e zzUIALzk)Fdos$A@W*do$OA4N7T)9U<|arp8)BULrgKy zu&TSEBm+v+*A)kB-pa6_AIW9YCFIJYO}q?t43Bi21NWZOZso}%2GPhm2uYFF`d*+Q zNu;dP^DByOFN+3ffRX`~qKJ=gF2!@0t8nSjJdxeIfUlV8RgMlpx<(RA_X5w{y)&Xa zz;1E}nb9@;3x&}&({29KW8_BCc#2FjAfh~dvK39aV_W;8Fev!@1_BKwV(XjO9{7da z($4I_s;u3iB+S+h6_~pTVxX2gDuhrX*kI8$6nP>U3dT_ud@2VArE;NSkj`G`Nvbw? z3=3saYDA4Vs!o(Fsig%TqadSkC%#!Zp&yq%ihJ;-KSdB5mzMsbd} literal 0 HcmV?d00001 diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/DialogUpload.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/DialogUpload.java new file mode 100644 index 0000000..858f337 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/DialogUpload.java @@ -0,0 +1,334 @@ +package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload; + + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.portal.clientcontext.client.GCubeClientContext; +import org.gcube.portlets.widgets.mpformbuilder.client.ConstantsMPFormBuilder; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.WorkspaceUploadNotification.WorskpaceUploadNotificationListener; +import org.gcube.portlets.widgets.mpformbuilder.shared.upload.HandlerResultMessage; +import org.gcube.portlets.widgets.mpformbuilder.shared.upload.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.user.client.Window; +import com.google.gwt.user.client.ui.Anchor; +import com.google.gwt.user.client.ui.FileUpload; +import com.google.gwt.user.client.ui.FormPanel; +import com.google.gwt.user.client.ui.HTML; +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.VerticalPanel; + + +/** + * The Class DialogUploadStream. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Sep 24, 2015 + */ +public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotificationListener{ + + //protected final FormPanel formPanel = new FormPanel(); + protected FileUpload fileUpload; + protected Hidden jsonClientKeys; + protected List fakeUploaders = new ArrayList(); + protected WorkspaceUploaderListenerController controller = new WorkspaceUploaderListenerController(); + + /** + * The Enum UPLOAD_TYPE. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Sep 11, 2015 + */ + private HTML LOADING = new HTML("Upload starting..."); + + protected String parentIdentifier = ""; + protected VerticalPanel panel; + private HorizontalPanel hpBottom; +// private MonitorPanel monitorPanel; + protected String clientUploadKey; + private Anchor anchorMyUploads; + + /** + * Instantiates a new dialog upload stream. + * + * @param headerTitle the header title + * @param parentId the parent id + * @param uploadType the upload type + */ + public DialogUpload(){ + //setWidth("400px"); + fileUpload = new FileUpload(); + //fileUpload.getElement().setAttribute("multiple", "multiple"); + this.addStyleName("fileInputUploader"); + setAction(ConstantsMPFormBuilder.WORKSPACE_UPLOADER_SERVLET_STREAM__MODIFIED); + setEncoding(FormPanel.ENCODING_MULTIPART); + setMethod(FormPanel.METHOD_POST); + setWidth("auto"); + + // Create a panel to hold all of the form widgets. + panel = new VerticalPanel(); + setWidget(panel); + + fileUpload.setName(ConstantsMPFormBuilder.UPLOAD_FORM_ELEMENT); + + // Add hidden parameters + panel.add(new Hidden(ConstantsMPFormBuilder.CURR_GROUP_ID, GCubeClientContext.getCurrentContextId())); + + initJsonClientKeys(); + panel.add(jsonClientKeys); + panel.add(fileUpload); + + HorizontalPanel hp = new HorizontalPanel(); +// hp.getElement().setId("hpID"); + hp.getElement().getStyle().setWidth(100, Unit.PCT); + hp.getElement().getStyle().setMarginTop(5, Unit.PX); + hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); + hp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); + + panel.add(hp); + +// hpBottom = new HorizontalPanel(); +// hpBottom.setWidth("100%"); +//// hpBottom.getElement().getStyle().setMarginTop(5, Unit.PX); +// hpBottom.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); +// +// //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 that you want to select

"); +//// msg.getElement().getStyle().setFontSize(10, Unit.PX); +//// hpBottom.add(msg); +// //} +// +// HorizontalPanel hp2 = new HorizontalPanel(); +// hp2.getElement().getStyle().setMarginTop(5, Unit.PX); +//// hp2.getElement().getStyle().setWidth(100, Unit.PCT); +// hp2.addStyleName("align-right-close"); +// +// hpBottom.add(hp2); +// panel.add(hpBottom); + } + + /** + * @return the panel + */ + public VerticalPanel getPanel() { + return panel; + } + + protected void initJsonClientKeys(){ + jsonClientKeys = new Hidden(ConstantsMPFormBuilder.CLIENT_UPLOAD_KEYS,""); + } + + /** + * Bind events. + */ + public void bindEvents(){ + this.addHandlers(); +// this.addListeners(); + } + + /** + * Adds the handlers. + */ + protected void addHandlers() { + + // handle the post + addSubmitCompleteHandler(new SubmitCompleteHandler() { + + @Override + public void onSubmitComplete(SubmitCompleteEvent event) { + GWT.log("onSubmitComplete"); +// isStatusCompleted = true; + String result = event.getResults(); + + if (result == null) { + removeLoading(); + Window.alert("An error occurred during file upload"); + //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); + + switch (resultMessage.getStatus()) { + case ERROR: + removeLoading(); + GWT.log("Error during upload "+resultMessage.getMessage()); + break; + case UNKNOWN: + removeLoading(); + GWT.log("Error during upload "+resultMessage.getMessage()); + break; + case WARN: { + GWT.log("Upload completed with warnings "+resultMessage.getMessage()); + removeLoading(); + break; + } + case SESSION_EXPIRED:{ + GWT.log("Upload aborted due to session expired: "+ resultMessage.getMessage()); + Window.alert("Session expired, please reload the page"); + 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()); +// } +// }; +// +// t.schedule(250); + } + } + } + }); + + //TODO NEVER USED, WE ARE USING MULTIPLE DIALOG UPLOAD + addSubmitHandler(new SubmitHandler() { + + @Override + public void onSubmit(SubmitEvent event) { + GWT.log("SubmitEvent"); + /*addLoading(); + enableButtons(false); + WorkspaceUploaderItem fakeUploader = new WorkspaceUploaderItem(); + fakeUploader.setClientUploadKey(clientUploadKey); + int queueIndex = UploaderMonitor.getInstance().newQueue(); + UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(fakeUploader, fileUpload.getFilename()); + setVisible(false); + removeLoading(); + UploaderMonitor.getInstance().addNewUploaderToQueue(queueIndex, fakeUploader); + UploaderMonitor.getInstance().doStartPollingQueue(queueIndex); + */ + } + }); + + fileUpload.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent 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; + submitForm(); + } + }); + } + + /** + * 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); + } + + /** + * Submit form. + */ + public void submitForm(){ + submit(); + } + + + /** + * Removes the item and submit form. + * + * @param itemId the item id + */ + protected void removeItemAndSubmitForm(String itemId){ + /* + AppControllerExplorer.rpcWorkspaceService.removeItem(itemId, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + Info.display("Error", caught.getMessage()); + + + } + + @Override + public void onSuccess(Boolean result) { + if(result){ + hiddenOverwrite.setValue("true"); + submitForm(); + } + + } + + });*/ + } + + /** + * Update item submit form. + * + * @param itemId the item id + */ + protected void updateItemSubmitForm(String itemId){ + //hiddenOverwrite.setValue("true"); + submitForm(); + } + + /* (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); + } +} + diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/FileUpload.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/FileUpload.java new file mode 100644 index 0000000..c53a849 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/FileUpload.java @@ -0,0 +1,24 @@ +package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.Widget; + +public class FileUpload extends Composite { + + private static FileUploadUiBinder uiBinder = GWT.create(FileUploadUiBinder.class); + + interface FileUploadUiBinder extends UiBinder { + } + + @UiField HTMLPanel fileUploadPanel; + + public FileUpload() { + initWidget(uiBinder.createAndBindUi(this)); + fileUploadPanel.add(new DialogUpload()); + + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/FileUpload.ui.xml b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/FileUpload.ui.xml new file mode 100644 index 0000000..a684d27 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/FileUpload.ui.xml @@ -0,0 +1,11 @@ + + + + .important { + font-weight: bold; + } + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/GenerateUUID.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/GenerateUUID.java new file mode 100644 index 0000000..a041913 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/GenerateUUID.java @@ -0,0 +1,72 @@ +/** + * + */ +package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload; + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Aug 6, 2015 + */ +public class GenerateUUID { + private static final char[] CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray(); + + /** + * Generate a random uuid of the specified length. Example: uuid(15) returns + * "VcydxgltxrVZSTV" + * + * @param len + * the desired number of characters + */ + public static String get(int len) { + return get(len, CHARS.length); + } + + /** + * Generate a random uuid of the specified length, and radix. Examples: + *
    + *
  • uuid(8, 2) returns "01001010" (8 character ID, base=2) + *
  • uuid(8, 10) returns "47473046" (8 character ID, base=10) + *
  • uuid(8, 16) returns "098F4D35" (8 character ID, base=16) + *
+ * + * @param len + * the desired number of characters + * @param radix + * the number of allowable values for each character (must be <= + * 62) + */ + public static String get(int len, int radix) { + if (radix > CHARS.length) { + throw new IllegalArgumentException(); + } + char[] uuid = new char[len]; + // Compact form + for (int i = 0; i < len; i++) { + uuid[i] = CHARS[(int) (Math.random() * radix)]; + } + return new String(uuid); + } + + /** + * Generate a RFC4122, version 4 ID. Example: + * "92329D39-6F5C-4520-ABFC-AAB64544E172" + */ + public static String get() { + char[] uuid = new char[36]; + int r; + + // rfc4122 requires these characters + uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; + uuid[14] = '4'; + + // Fill in random data. At i==19 set the high bits of clock sequence as + // per rfc4122, sec. 4.1.5 + for (int i = 0; i < 36; i++) { + if (uuid[i] == 0) { + r = (int) (Math.random() * 16); + uuid[i] = CHARS[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf]; + } + } + return new String(uuid); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/MultipleDilaogUpload.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/MultipleDilaogUpload.java new file mode 100644 index 0000000..38d322a --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/MultipleDilaogUpload.java @@ -0,0 +1,370 @@ +/** + * + */ +package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.gcube.portlets.widgets.mpformbuilder.client.ConstantsMPFormBuilder; +import org.gcube.portlets.widgets.mpformbuilder.shared.upload.HandlerResultMessage; +import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploadFile; +import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploaderItem; +import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploaderItem.UPLOAD_STATUS; + +import com.google.gwt.core.client.GWT; +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; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.ui.HTML; + +/** + * The Class MultipleDilaogUploadStream. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 2, 2015 + */ +public class MultipleDilaogUpload extends DialogUpload { + + public static final String FILE_DELEMITER = ";"; + private String fileUploadID; + //private MultipleDNDUpload dnd; + public MultipleDilaogUpload instance = this; + private String jsonKeys; + + private String idFolder; + + /** + * Instantiates a new multiple dilaog upload stream. + * + * @param headerTitle + * the header title + * @param parentId + * the parent id + * @param uploadType + * the upload type + */ + public MultipleDilaogUpload() { + fileUploadID = GenerateUUID.get(10, 16); // is tagID + fileUpload.getElement().setId(fileUploadID); + this.addHandlers(); + } + + /** + * Generate new upload client keys. + * + * @param files the files + * @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: "+Arrays.asList(files.toString())); + fakeUploaders = new ArrayList(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 fakeUploaders; + } + + /* + * (non-Javadoc) + * + * @see org.gcube.portlets.widgets.workspaceuploader.client.uploader. + * DialogUploadStream#addHandlers() + */ + @Override + protected void addHandlers() { + + // handle the post + addSubmitCompleteHandler(new SubmitCompleteHandler() { + + @Override + public void onSubmitComplete(SubmitCompleteEvent event) { + GWT.log("onSubmitComplete"); + + // isStatusCompleted = true; + String result = event.getResults(); + + if (result == null) { + removeLoading(); + Window.alert("An error occurred during file upload."); +// 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); + + switch (resultMessage.getStatus()) { + case ERROR: + removeLoading(); + GWT.log("Error during upload " + resultMessage.getMessage()); + break; + case UNKNOWN: + removeLoading(); + GWT.log("Error during upload " + resultMessage.getMessage()); + break; + case WARN: { + GWT.log("Upload completed with warnings "+ resultMessage.getMessage()); + removeLoading(); + break; + } + case SESSION_EXPIRED:{ + GWT.log("Upload aborted due to session expired: "+ resultMessage.getMessage()); + Window.alert("Session expired, please reload the page"); + removeLoading(); + break; + } + case OK: { + } + + } + } + + }); + + addSubmitHandler(new SubmitHandler() { + + @Override + public void onSubmit(SubmitEvent event) { + GWT.log("SubmitEvent"); + addLoading(); + enableButtons(false); + 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; + GWT.log("Current Uploader has id: "+fileUploadID); + String filesSelected = getFilesSelected(fileUploadID, FILE_DELEMITER); + GWT.log("getFilesSelected: " + filesSelected); + files = filesSelected.split(FILE_DELEMITER); + + if(isLimitExceeded(files.length)) + return; + + // GENERATE NEW UPLOADERS + generateFakeUploaders(filesSelected, parentIdentifier); + GWT.log(fakeUploaders.toString()); + createJsonKeyForFiles(); + 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() { +// +// @Override +// public void onSuccess( +// final String itemId) { +// GWT.log("itemExistsInWorkpaceFolder: " +// + itemId); +// if (itemId != null) { +// removeItemAndSubmitForm(itemId); +// updateItemSubmitForm(itemId); +//// if (Window.confirm(label+ " exists in folder. If you continue, a new version will be created")) { +//// 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 > ConstantsMPFormBuilder.LIMIT_UPLOADS) { + Window.alert("Multiple upload limit is " + + ConstantsMPFormBuilder.LIMIT_UPLOADS + + " files"); + //MultipleDilaogUpload.this.hide(); + return true; + } + + return false; + } + + /** + * Adds the new submit to monitor. + */ + public void addNewSubmitToMonitor(){ + GWT.log("addNewSubmitToMonitor..."); + /*int queueIndex = UploaderMonitor.getInstance().newQueue(); + for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) { + UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName()); + setVisible(false); + removeLoading(); + UploaderMonitor.getInstance().addNewUploaderToQueue(queueIndex, workspaceUploaderItem); +// UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem); + } + + UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);*/ + } + + + /** + * Creates the json key for files. + * + * @return the string + */ + protected void createJsonKeyForFiles() { + + try { + JSONObject productObj = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + productObj.put(ConstantsMPFormBuilder.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; + } + } + + /** + * Submit form. + */ + @Override + public void submitForm() { + submit(); + } + + /** + * Gets the files selected. + * + * @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"); + } else { // other browsers + console.log("other browsers"); + iframewindow.stop(); + } + + }-*/; + + + /** + * Gets the files selected. + * + * @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; + }-*/; +} diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/ProgressBar.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/ProgressBar.java new file mode 100644 index 0000000..c2c5ef3 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/ProgressBar.java @@ -0,0 +1,36 @@ +package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.Widget; + +public class ProgressBar extends Composite { + + private static final double COMPLETE_PERECENTAGE = 100d; + private static final double START_PERECENTAGE = 0d; + + private static ProgressBarUiBinder uiBinder = GWT +.create(ProgressBarUiBinder.class); + + interface ProgressBarUiBinder extends UiBinder { } + + @UiField HTML progressBarContainer; + + public ProgressBar() { + initWidget(uiBinder.createAndBindUi(this)); + } + + public void update(int percentage) { + if (percentage > 100) + percentage = 100; + if (percentage < START_PERECENTAGE || percentage > COMPLETE_PERECENTAGE) { + throw new IllegalArgumentException("invalid value for percentage " + percentage); + } else { //cannot use DOM getElemById cus the second time you open the popup it fails + progressBarContainer.getElement().setAttribute("style", "width: "+percentage+"%"); + progressBarContainer.getElement().getFirstChildElement().getFirstChildElement().setInnerText(percentage+"%"); + } + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/ProgressBar.ui.xml b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/ProgressBar.ui.xml new file mode 100644 index 0000000..6fd613c --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/ProgressBar.ui.xml @@ -0,0 +1,13 @@ + + + +
+ + + 0% + + +
+
+
\ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/WorkspaceUploadNotification.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/WorkspaceUploadNotification.java new file mode 100644 index 0000000..3c4c5ac --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/WorkspaceUploadNotification.java @@ -0,0 +1,101 @@ +/** + * + */ +package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload; + +/** + * The Class WorkspaceUploadNotification. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 2, 2015 + */ +public class WorkspaceUploadNotification { + + /** + * The listener interface for receiving worskpaceUploadNotification events. + * The class that is interested in processing a worskpaceUploadNotification + * event implements this interface, and the object created with that class + * is registered with a component using the component's + * addWorskpaceUploadNotificationListener method. When + * the worskpaceUploadNotification event occurs, that object's appropriate + * method is invoked. + * + * @see WorskpaceUploadNotificationEvent + */ + public interface WorskpaceUploadNotificationListener { + + /** + * On upload completed. + * + * @param parentId + * the parent id + * @param itemId + * the item id + */ + void onUploadCompleted(String parentId, String itemId); + + /** + * On upload aborted. + * + * @param parentId + * the parent id + * @param itemId + * the item id + */ + void onUploadAborted(String parentId, String itemId); + + /** + * On error. + * + * @param parentId + * the parent id + * @param itemId + * the item id + * @param throwable + * the throwable + */ + void onError(String parentId, String itemId, Throwable throwable); + + /** + * On overwrite completed. + * + * @param parentId the parent id + * @param itemId the item id + */ + void onOverwriteCompleted(String parentId, String itemId); + } + + /** + * The listener interface for receiving hasWorskpaceUploadNotification + * events. The class that is interested in processing a + * hasWorskpaceUploadNotification event implements this interface, and the + * object created with that class is registered with a component using the + * component's + * addHasWorskpaceUploadNotificationListener method. When + * the hasWorskpaceUploadNotification event occurs, that object's appropriate + * method is invoked. + * + * @see HasWorskpaceUploadNotificationEvent + */ + public interface HasWorskpaceUploadNotificationListener { + + /** + * Adds the workspace upload notification listener. + * + * @param handler + * the handler + */ + public void addWorkspaceUploadNotificationListener( + WorskpaceUploadNotificationListener handler); + + /** + * Removes the workspace upload notification listener. + * + * @param handler + * the handler + */ + public void removeWorkspaceUploadNotificationListener( + WorskpaceUploadNotificationListener handler); + + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/WorkspaceUploaderListenerController.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/WorkspaceUploaderListenerController.java new file mode 100644 index 0000000..b6d3ade --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/WorkspaceUploaderListenerController.java @@ -0,0 +1,174 @@ +/** + * + */ +package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.WorkspaceUploadNotification.WorskpaceUploadNotificationListener; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.events.NotifyUploadEvent; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.events.NotifyUploadEventHandler; + +import com.google.gwt.core.shared.GWT; +import com.google.gwt.event.shared.HandlerManager; + + +/** + * The Class WorkspaceExplorerListenerController. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Oct 5, 2015 + */ +public class WorkspaceUploaderListenerController { + + private static HandlerManager controllerEventBus = null; + + private List listenersUpload = new ArrayList(); + + /** + * Instantiates a new workspace explorer listener controller. + */ + public WorkspaceUploaderListenerController(){ + controllerEventBus = new HandlerManager(null); + bindEvents(); + + } + + /** + * Bind events. + */ + private void bindEvents() { + controllerEventBus.addHandler(NotifyUploadEvent.TYPE, new NotifyUploadEventHandler() { + + @Override + public void onNotifyUpload(final NotifyUploadEvent notifyUploadEvent) { + + if(notifyUploadEvent.getEvent()==null) + return; + + switch(notifyUploadEvent.getEvent()){ + + case UPLOAD_COMPLETED: + GWT.log("NotifyUploadEvent Completed"); + notifyUploadCompleted(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId()); + break; + case ABORTED: + GWT.log("NotifyUploadEvent Aborted"); + notifyUploadAborted(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId()); + break; + case FAILED: + GWT.log("NotifyUploadEvent FAILED"); + notifyUploadError(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId(), new Exception(notifyUploadEvent.getUploadResultMsg())); + break; + case OVERWRITE_COMPLETED: + GWT.log("NotifyUploadEvent OVERWRITE_COMPLETED"); + notifyOverwriteCompleted(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId()); + break; + default: + break; + + } + } + }); + } + + /** + * Gets the event bus. + * + * @return the event bus + */ + public static HandlerManager getEventBus(){ + return controllerEventBus; + } + + /** + * Adds the workspace upload listener. + * + * @param handler the handler + */ + public void addWorkspaceUploadListener(WorskpaceUploadNotificationListener handler) { + this.listenersUpload.add(handler); + } + + /** + * Removes the workspace upload listener. + * + * @param handler the handler + */ + public void removeWorkspaceUploadListener(WorskpaceUploadNotificationListener handler) { + try { + this.listenersUpload.remove(handler); + } catch (Exception e) { + // SILENT + } + } + + /** + * Reset listeners. + */ + public void resetListeners(){ + this.listenersUpload.clear(); + } + + /** + * Notify upload completed. + * + * @param parentId the parent id + * @param itemId the item id + */ + private void notifyUploadCompleted(String parentId, String itemId){ +// listenersSize(); + for (WorskpaceUploadNotificationListener listener : listenersUpload) { + listener.onUploadCompleted(parentId, itemId); + } + } + + /** + * Notify overwrite completed. + * + * @param parentId the parent id + * @param itemId the item id + */ + private void notifyOverwriteCompleted(String parentId, String itemId) { +// listenersSize(); + for (WorskpaceUploadNotificationListener listener : listenersUpload) { + listener.onOverwriteCompleted(parentId, itemId); + } + } + + /** + * Notify upload aborted. + * + * @param parentId the parent id + * @param itemId the item id + */ + private void notifyUploadAborted(String parentId, String itemId){ + for (WorskpaceUploadNotificationListener listener : listenersUpload) { + listener.onUploadAborted(parentId, itemId); + } + } + + /** + * Notify upload error. + * + * @param parentId the parent id + * @param itemId the item id + * @param t the t + */ + private void notifyUploadError(String parentId, String itemId, Throwable t){ + for (WorskpaceUploadNotificationListener listener : listenersUpload) { + listener.onError(parentId, itemId, t); + } + } + + /** + * Listeners size. + * + * @return the int + */ + private int listenersSize(){ + GWT.log("listenersUpload.size() "+listenersUpload.size()); + return listenersUpload.size(); + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/events/NotifyUploadEvent.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/events/NotifyUploadEvent.java new file mode 100644 index 0000000..6f1abb1 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/events/NotifyUploadEvent.java @@ -0,0 +1,181 @@ +package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.events; + +import com.google.gwt.event.shared.GwtEvent; + + +/** + * The Class NotifyUploadEvent. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Oct 5, 2015 + */ +public class NotifyUploadEvent extends GwtEvent { + public static Type TYPE = new Type(); + + /** + * The Enum UPLOAD_EVENT_TYPE. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Oct 5, 2015 + */ + public static enum UPLOAD_EVENT_TYPE { + UPLOAD_COMPLETED, FAILED, ABORTED, OVERWRITE_COMPLETED + } + + private UPLOAD_EVENT_TYPE event; + private String parentId; + private String itemId; + private String uploadResultMsg; + private Throwable exception; + + + /** + * Gets the exception. + * + * @return the exception + */ + public Throwable getException() { + return exception; + } + + /** + * Sets the exception. + * + * @param exception the exception to set + */ + public void setException(Throwable exception) { + this.exception = exception; + } + + /** + * Gets the event. + * + * @return the event + */ + public UPLOAD_EVENT_TYPE getEvent() { + return event; + } + + /** + * Sets the event. + * + * @param event the event to set + */ + public void setEvent(UPLOAD_EVENT_TYPE event) { + this.event = event; + } + + /** + * Instantiates a new notify upload event. + * + * @param event the event + * @param parentId the parent id + * @param itemId the item id + */ + public NotifyUploadEvent(UPLOAD_EVENT_TYPE event, String parentId, String itemId) { + this.parentId = parentId; + this.itemId = itemId; + this.event = event; + } + + /** + * Instantiates a new notify upload event. + * + * @param event the event + * @param parentId the parent id + * @param itemId the item id + * @param e the e + */ + public NotifyUploadEvent(UPLOAD_EVENT_TYPE event, String parentId, String itemId, Throwable e) { + this.parentId = parentId; + this.itemId = itemId; + this.event = event; + this.exception = e; + } + + + /** + * Instantiates a new notify upload event. + * + * @param event the event + * @param parentId the parent id + * @param itemId the item id + * @param uploadResultMsg the upload result msg + * @param e the e + */ + public NotifyUploadEvent(UPLOAD_EVENT_TYPE event, String parentId, String itemId, String uploadResultMsg, Throwable e) { + this.parentId = parentId; + this.itemId = itemId; + this.event = event; + this.uploadResultMsg = uploadResultMsg; + this.exception = e; + } + + /** + * Gets the parent id. + * + * @return the parentId + */ + public String getParentId() { + return parentId; + } + + /** + * Gets the item id. + * + * @return the itemId + */ + public String getItemId() { + return itemId; + } + + /** + * Sets the parent id. + * + * @param parentId the parentId to set + */ + public void setParentId(String parentId) { + this.parentId = parentId; + } + + /** + * Sets the item id. + * + * @param itemId the itemId to set + */ + public void setItemId(String itemId) { + this.itemId = itemId; + } + + + /** + * @return the uploadResultMsg + */ + public String getUploadResultMsg() { + + return uploadResultMsg; + } + + + /* + * (non-Javadoc) + * + * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType() + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared + * .EventHandler) + */ + @Override + protected void dispatch(NotifyUploadEventHandler handler) { + handler.onNotifyUpload(this); + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/events/NotifyUploadEventHandler.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/events/NotifyUploadEventHandler.java new file mode 100644 index 0000000..62172cb --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/upload/events/NotifyUploadEventHandler.java @@ -0,0 +1,21 @@ +package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.events; + +import com.google.gwt.event.shared.EventHandler; + + +/** + * The Interface NotifyUploadEventHandler. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Oct 5, 2015 + */ +public interface NotifyUploadEventHandler extends EventHandler { + + + /** + * On notify upload. + * + * @param notifyUploadEvent the notify upload event + */ + void onNotifyUpload(NotifyUploadEvent notifyUploadEvent); +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/utils/LoaderIcon.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/utils/LoaderIcon.java new file mode 100644 index 0000000..4505b62 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/utils/LoaderIcon.java @@ -0,0 +1,62 @@ +/** + * + */ +package org.gcube.portlets.widgets.mpformbuilder.client.ui.utils; + + +import org.gcube.portlets.widgets.mpformbuilder.client.ui.icons.Images; + +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Image; + +/** + * The Class LoaderIcon. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 19, 2015 + */ +public class LoaderIcon extends HorizontalPanel{ + + + private Image imgLoading = new Image(Images.ICONS.loading()); + private HTML txtLoading = new HTML(""); + + /** + * Instantiates a new loader icon. + * + * @param txtHTML the txt html + */ + public LoaderIcon(String txtHTML) { + this(); + setText(txtHTML); + } + + /** + * Instantiates a new loader icon. + */ + public LoaderIcon() { + setStyleName("marginTop20"); + add(imgLoading); + add(txtLoading); + } + + /** + * Sets the text. + * + * @param txtHTML the new text + */ + public void setText(String txtHTML){ + txtLoading.setHTML(""+txtHTML+""); + } + + /** + * Show. + * + * @param bool the bool + */ + public void show(boolean bool){ + this.setVisible(bool); + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/HandlerResultMessage.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/HandlerResultMessage.java new file mode 100644 index 0000000..2b5a0fd --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/HandlerResultMessage.java @@ -0,0 +1,180 @@ +/** + * + */ +package org.gcube.portlets.widgets.mpformbuilder.shared.upload; + +import java.io.Serializable; + + +/** + * The Class HandlerResultMessage. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * May 10, 2016 + */ +public class HandlerResultMessage implements Serializable{ + + + /** + * + */ + private static final String SEPARATOR = ":"; + protected Status status; + protected String message; + + /** + * The Enum Status. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Aug 3, 2015 + */ + public enum Status { + /** + * If an error occurs. + */ + ERROR, + /** + * If no error occurs. + */ + OK, + /** + * If there was some problems. + */ + WARN, + + /** + * If the result is unknown. + */ + UNKNOWN, + + /** + * If the session is expired. + */ + SESSION_EXPIRED; + } + + + /** + * TO SERIALIZATION. + */ + public HandlerResultMessage() { + } + + /** + * Create a new result message. + * @param status the status. + * @param message the message. + */ + public HandlerResultMessage(Status status, String message) { + this.status = status; + this.message = message; + } + + /** + * Error result. + * + * @param message the message + * @return the handler result message + */ + public static HandlerResultMessage errorResult(String message){ + return new HandlerResultMessage(Status.ERROR, message); + } + + /** + * Ok result. + * + * @param message the message + * @return the handler result message + */ + public static HandlerResultMessage okResult(String message){ + return new HandlerResultMessage(Status.OK, message); + } + + /** + * Warn result. + * + * @param message the message + * @return the handler result message + */ + public static HandlerResultMessage warnResult(String message){ + return new HandlerResultMessage(Status.WARN, message); + } + + + /** + * Session expired result. + * + * @param message the message + * @return the handler result message + */ + public static HandlerResultMessage sessionExpiredResult(String message){ + return new HandlerResultMessage(Status.SESSION_EXPIRED, message); + } + + /** + * Parses the result. + * expected status:message (e.g. OK:Upload aborted) + * @param result the result + * @return the handler result message + */ + public static HandlerResultMessage parseResult(String result){ + //expected status:message + String statusToken = null; + String messageToken = null; + + if(result==null || result.isEmpty()) + return errorResult("result is null or empty"); + + int index = result.indexOf(':'); + if (index>=0){ + statusToken = result.substring(0,index); + if (index events = new ArrayList(); + + /** + * Instantiates a new upload progress. + */ + public UploadProgress() { + } + + /** + * Gets the events. + * + * @return the events + */ + public List getEvents() { + return events; + } + + /** + * Adds the. + * + * @param event the event + */ + public void add(final UploadEvent event) { + events.add(event); + } + + /** + * Gets the last event. + * + * @return the last event + */ + public UploadEvent getLastEvent(){ + if(isEmpty()) + return null; + return events.get(events.size()-1); + } + + /** + * Clear. + */ + public void clear() { + events = new ArrayList(); + } + + /** + * Checks if is empty. + * + * @return true, if is empty + */ + public boolean isEmpty() { + return events.isEmpty(); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("UploadProgress [events="); + builder.append(events); + builder.append("]"); + return builder.toString(); + } +} + + diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/UploadProgressChangeEvent.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/UploadProgressChangeEvent.java new file mode 100644 index 0000000..cc12e85 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/UploadProgressChangeEvent.java @@ -0,0 +1,125 @@ +package org.gcube.portlets.widgets.mpformbuilder.shared.upload; + +import java.io.Serializable; + + +/** + * The Class UploadProgressChangeEvent. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Sep 1, 2015 + */ +public final class UploadProgressChangeEvent implements UploadEvent, Serializable { + + /** + * + */ + private static final long serialVersionUID = -714607581338378280L; + private int readPercentage = -1; + private long readTime = 0L; + private long readBytes = 0L; + private long totalBytes = 0L; + + /** + * Instantiates a new upload progress change event. + */ + public UploadProgressChangeEvent() { + } + + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.workspaceuploader.shared.event.UploadEvent#getReadPercentage() + */ + public int getReadPercentage() { + return readPercentage; + } + + + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.workspaceuploader.shared.event.UploadEvent#setReadPercentage(java.lang.Integer) + */ + public void setReadPercentage(int percentage) { + this.readPercentage = percentage; + } + + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.workspaceuploader.shared.event.UploadEvent#setReadTime(long) + */ + @Override + public void setReadTime(long time) { + this.readTime = time; + + } + + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.workspaceuploader.shared.event.UploadEvent#getReadTime() + */ + @Override + public long getReadTime() { + return readTime; + } + + + /** + * Sets the read bytes. + * + * @param readBytes the readBytes to set + */ + public void setReadBytes(long readBytes) { + + this.readBytes = readBytes; + } + + + /** + * Sets the total bytes. + * + * @param totalBytes the totalBytes to set + */ + public void setTotalBytes(long totalBytes) { + + this.totalBytes = totalBytes; + } + + + /** + * Gets the read bytes. + * + * @return the readBytes + */ + public long getReadBytes() { + + return readBytes; + } + + + /** + * Gets the total bytes. + * + * @return the totalBytes + */ + public long getTotalBytes() { + + return totalBytes; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("UploadProgressChangeEvent [readPercentage="); + builder.append(readPercentage); + builder.append(", readTime="); + builder.append(readTime); + builder.append(", readBytes="); + builder.append(readBytes); + builder.append(", totalBytes="); + builder.append(totalBytes); + builder.append("]"); + return builder.toString(); + } + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/WorkspaceUploadFile.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/WorkspaceUploadFile.java new file mode 100644 index 0000000..56d183f --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/WorkspaceUploadFile.java @@ -0,0 +1,169 @@ +/** + * + */ +package org.gcube.portlets.widgets.mpformbuilder.shared.upload; + +import java.io.Serializable; + +/** + * The Class WorkspaceUploadFile. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Aug 3, 2015 + */ +public class WorkspaceUploadFile implements Serializable{ + + + /** + * + */ + private static final long serialVersionUID = 4693939404459889859L; + private String parentId; + private String fileName; + private String itemId; + private String versionName; + + /** + * Instantiates a new workspace upload file. + */ + public WorkspaceUploadFile() { + } + + + + /** + * Instantiates a new workspace upload file. + * + * @param parentId the parent id + * @param itemId the item id + * @param fileName the file name + * @param versionName the version + */ + public WorkspaceUploadFile(String parentId, String itemId, String fileName, String versionName) { + super(); + this.parentId = parentId; + this.itemId = itemId; + this.fileName = fileName; + this.versionName = versionName; + } + + + + /** + * Gets the version name. + * + * @return the version name + */ + public String getVersionName() { + + return versionName; + } + + + /** + * Sets the version name. + * + * @param versionName the new version name + */ + public void setVersionName(String versionName) { + + this.versionName = versionName; + } + + + + /** + * Sets the item id. + * + * @param itemId the itemId to set + */ + public void setItemId(String itemId) { + this.itemId = itemId; + } + + + /** + * Gets the parent id. + * + * @return the parentId + */ + public String getParentId() { + return parentId; + } + + /** + * Gets the file name. + * + * @return the fileName + */ + public String getFileName() { + return fileName; + } + + /** + * Sets the parent id. + * + * @param parentId the parentId to set + */ + public void setParentId(String parentId) { + this.parentId = parentId; + } + + + + /** + * Gets the item id. + * + * @return the itemId + */ + public String getItemId() { + return itemId; + } + + /** + * Sets the file name. + * + * @param fileName the fileName to set + */ + public void setFileName(String fileName) { + this.fileName = fileName; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + int hash = 31; + hash = hash * 13 + (parentId == null ? 0 : parentId.hashCode()); + hash = hash * 17 + (fileName == null ? 0 : fileName.hashCode()); + hash = hash * 19 + (itemId == null ? 0 : itemId.hashCode()); + return hash; + } + + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("WorkspaceUploadFile [parentId="); + builder.append(parentId); + builder.append(", fileName="); + builder.append(fileName); + builder.append(", itemId="); + builder.append(itemId); + builder.append(", versionName="); + builder.append(versionName); + builder.append("]"); + return builder.toString(); + } + + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/WorkspaceUploaderItem.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/WorkspaceUploaderItem.java new file mode 100644 index 0000000..6a9dfaa --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/upload/WorkspaceUploaderItem.java @@ -0,0 +1,267 @@ +/** + * + */ +package org.gcube.portlets.widgets.mpformbuilder.shared.upload; + +import java.io.Serializable; + +/** + * The Class WorkspaceUploaderItem. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Aug 3, 2015 + */ +public class WorkspaceUploaderItem implements Serializable{ + + + /** + * + */ + private static final long serialVersionUID = -3635794780284917733L; + + /** + * The Enum UPLOAD_STATUS. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Aug 6, 2015 + */ + public static enum UPLOAD_STATUS{ + + WAIT("WAIT", "wait"), + IN_PROGRESS("IN_PROGRESS", "in progress"), + FAILED("FAILED", "failed"), + ABORTED("ABORTED", "aborted"), + COMPLETED("COMPLETED", "completed"); + + protected String id; + protected String label; + + /** + * Instantiates a new upload status. + * + * @param id the id + * @param label the label + */ + private UPLOAD_STATUS(String id, String label) { + this.id = id; + this.label = label; + } + } + + private String identifier; + private WorkspaceUploadFile file; + private UPLOAD_STATUS uploadStatus; + private String statusDescription; + private String clientUploadKey; + private UploadProgress uploadProgress; + private Boolean isOverwrite; +// private Long threadId; + private Boolean erasable; + + /** + * Instantiates a new workspace uploader item. + */ + public WorkspaceUploaderItem() { + } + + /** + * Instantiates a new workspace uploader item. + * + * @param identifier the identifier + */ + public WorkspaceUploaderItem(String identifier) { + this.identifier = identifier; + } + + /** + * Instantiates a new workspace uploader item. + * + * @param identifier the identifier + * @param file the file + * @param status the status + * @param statusDescription the status description + * @param uploadProgress the upload progress + */ + public WorkspaceUploaderItem(String identifier, WorkspaceUploadFile file, UPLOAD_STATUS status, String statusDescription, UploadProgress uploadProgress) { + super(); + this.identifier = identifier; + this.file = file; + this.uploadStatus = status; + this.statusDescription = statusDescription; + this.uploadProgress = uploadProgress; + } + + + /** + * Gets the identifier. + * + * @return the identifier + */ + public String getIdentifier() { + return identifier; + } + + + /** + * Gets the status description. + * + * @return the statusDescription + */ + public String getStatusDescription() { + return statusDescription; + } + + + /** + * Sets the status description. + * + * @param statusDescription the statusDescription to set + */ + public void setStatusDescription(String statusDescription) { + this.statusDescription = statusDescription; + } + + + /** + * Gets the file. + * + * @return the file + */ + public WorkspaceUploadFile getFile() { + return file; + } + + + /** + * Gets the upload status. + * + * @return the uploadStatus + */ + public UPLOAD_STATUS getUploadStatus() { + return uploadStatus; + } + + /** + * Sets the file. + * + * @param file the file to set + */ + public void setFile(WorkspaceUploadFile file) { + this.file = file; + } + + + /** + * Sets the upload status. + * + * @param uploadStatus the uploadStatus to set + */ + public void setUploadStatus(UPLOAD_STATUS uploadStatus) { + this.uploadStatus = uploadStatus; + } + + + /** + * Gets the client upload key. + * + * @return the clientUploadKey + */ + public String getClientUploadKey() { + return clientUploadKey; + } + + + /** + * Sets the client upload key. + * + * @param clientUploadKey the clientUploadKey to set + */ + public void setClientUploadKey(String clientUploadKey) { + this.clientUploadKey = clientUploadKey; + } + + /** + * Gets the upload progress. + * + * @return the uploadProgress + */ + public UploadProgress getUploadProgress() { + return uploadProgress; + } + + /** + * Sets the upload progress. + * + * @param uploadProgress the uploadProgress to set + */ + public void setUploadProgress(UploadProgress uploadProgress) { + this.uploadProgress = uploadProgress; + } + + /** + * @return the isOverwrite + */ + public Boolean getIsOverwrite() { + return isOverwrite; + } + + /** + * @param isOverwrite the isOverwrite to set + */ + public void setIsOverwrite(Boolean isOverwrite) { + this.isOverwrite = isOverwrite; + } + + /** + * Sets the erasable. + * + * @param b the new erasable + */ + public void setErasable(Boolean b) { + this.erasable = b; + } + + + /** + * Checks if is erasable. + * + * @return the erasable + */ + public Boolean isErasable() { + + if(erasable==null) + return false; + + return erasable; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("WorkspaceUploaderItem [identifier="); + builder.append(identifier); + builder.append(", file="); + builder.append(file); + builder.append(", uploadStatus="); + builder.append(uploadStatus); + builder.append(", statusDescription="); + builder.append(statusDescription); + builder.append(", clientUploadKey="); + builder.append(clientUploadKey); +// builder.append(", uploadProgress="); +// builder.append(uploadProgress); + builder.append(", isOverwrite="); + builder.append(isOverwrite); + builder.append(", erasable="); + builder.append(erasable); + builder.append("]"); + return builder.toString(); + } + + + +} diff --git a/src/main/resources/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml b/src/main/resources/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml index a7f617a..9782a54 100644 --- a/src/main/resources/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml +++ b/src/main/resources/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml @@ -1,30 +1,37 @@ - - + + - + - - + + - - - + + + + + - + - - - + - - - + + + + +