managing the files already uploaded [#24515]

This commit is contained in:
Francesco Mangiacrapa 2023-03-28 16:13:21 +02:00
parent 77c41f2af2
commit a352933b68
5 changed files with 72 additions and 89 deletions

View File

@ -267,6 +267,13 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe
private OPERATION operationPerfom;
/**
* The Enum OPERATION.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 15, 2023
*/
public enum OPERATION {
NEW, UPDATE
}
@ -318,7 +325,7 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe
}
/**
* Instantiates a new creates the dataset form.
* Instantiates a new creates the metadata form.
*
* @param profiles the profiles
* @param eventBus the event bus
@ -326,7 +333,7 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe
* @param listFileUploaded the list file uploaded
*/
public CreateMetadataForm(List<MetaDataProfileBean> profiles, HandlerManager eventBus, OPERATION operation,
List<FileUploaded> listFileUploaded) {
List<? extends FileUploaded> listFileUploaded) {
this(eventBus);
this.operationPerfom = operation;
showLoadingProfiles(true);
@ -345,8 +352,8 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe
/**
* Instantiates a new creates the dataset form.
*
* @param eventBus2
*
* @param eventBus the event bus
*/
private CreateMetadataForm(HandlerManager eventBus) {
initWidget(uiBinder.createAndBindUi(this));
@ -407,7 +414,8 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe
* @param profiles the profiles
* @param listFileUploaded the list file uploaded
*/
private void createDatasetFormBody(final List<MetaDataProfileBean> profiles, List<FileUploaded> listFileUploaded) {
private void createDatasetFormBody(final List<MetaDataProfileBean> profiles,
List<? extends FileUploaded> listFileUploaded) {
if (profiles == null) {
setAlertBlock("An unknow error occurred while retrieving types, sorry", AlertType.ERROR, true);
@ -424,7 +432,8 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe
* @param profiles the profiles
* @param listFileUploaded the file uploaded
*/
private void prepareMetadataList(final List<MetaDataProfileBean> profiles, List<FileUploaded> listFileUploaded) {
private void prepareMetadataList(final List<MetaDataProfileBean> profiles,
List<? extends FileUploaded> listFileUploaded) {
if (profiles != null && !profiles.isEmpty()) {
GWT.log("Building form/s for profile/s: " + profiles);
@ -494,7 +503,7 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe
* @param listFileUploaded the list file uploaded
*/
protected void addFields(String selectedItem, List<MetaDataProfileBean> listProfiles,
List<FileUploaded> listFileUploaded) {
List<? extends FileUploaded> listFileUploaded) {
for (MetaDataProfileBean bean : listProfiles) {
if (bean.getType().equals(selectedItem)) {
@ -877,7 +886,8 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe
if (resourcesTwinPanel != null)
resourcesTwinPanel.freeze(bool);
// TRUE in UPDATE MODE - freeze manage of current content (means file already uploaded)
// TRUE in UPDATE MODE - freeze manage of current content (means file already
// uploaded)
if (uploadedFileBrowse != null) {
uploadedFileBrowse.enableManageOfContent(!bool);
@ -975,8 +985,6 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe
/**
* Notify valid form.
*
* @param genericDatasetBean the generic dataset bean
*/
private void notifyOnEditForm() {
for (GenericFormEventsListener listener : listenersGenericFormEvents) {

View File

@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.List;
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded;
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploadedRemote;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.constants.IconType;
@ -20,40 +21,39 @@ import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
public class UploadedFilesBrowse extends Composite {
public class UploadedFilesBrowse<T extends FileUploaded> extends Composite {
private static UploadedFilesBrowseUiBinder uiBinder = GWT.create(UploadedFilesBrowseUiBinder.class);
interface UploadedFilesBrowseUiBinder extends UiBinder<Widget, UploadedFilesBrowse> {
}
private List<FileUploaded> listFileUploaded;
// private HashMap<Integer, FileUploaded> mapForCCUploading;
private List<T> listFileUploaded;
@UiField
HTMLPanel uploadFileContainer;
private FlexTable table = new FlexTable();
private List<Button> listButtonRemove = new ArrayList<Button>();
private HashMap<Integer, FileUploaded> mapPositionalFU = new HashMap<Integer, FileUploaded>();
private HashMap<Integer, T> mapPositionalFU = new HashMap<Integer, T>();
public UploadedFilesBrowse(List<FileUploaded> fileUploaded) {
public UploadedFilesBrowse(List<T> fileUploaded) {
initWidget(uiBinder.createAndBindUi(this));
this.listFileUploaded = fileUploaded;
// Filling map of files uploaded
int i = 0;
for (FileUploaded file : listFileUploaded) {
for (T file : listFileUploaded) {
mapPositionalFU.put(i, file);
i++;
}
showFileBrowseInteraction(fileUploaded);
showFileBrowseInteraction();
}
private void showFileBrowseInteraction(List<FileUploaded> listFileUploaded) {
private void showFileBrowseInteraction() {
uploadFileContainer.clear();
// pathIndex = pathContentIndex;
// GWT.log("showing pathContentIndex: "+pathContentIndex);
@ -68,12 +68,17 @@ public class UploadedFilesBrowse extends Composite {
int i = 2;
int index = 0;
for (final FileUploaded file : listFileUploaded) {
final int filePointer = index;
table.setHTML(i, 0, file.getFileName());
table.setHTML(i, 1, file.getMimeType());
String link = "<a target=\"_blank\" href=" + file.getUrl() + ">View</a>";
table.setHTML(i, 2, link);
int columnIndex = 0;
table.setHTML(i, columnIndex, file.getFileName());
if (file instanceof FileUploadedRemote) {
FileUploadedRemote fur = (FileUploadedRemote) file;
table.setHTML(i, ++columnIndex, fur.getMimeType());
String link = "<a target=\"_blank\" href=" + fur.getUrl() + ">View</a>";
table.setHTML(i, ++columnIndex, link);
}
final int rowIndexToRem = i;
Button buttonRemoveFile = new Button();
@ -88,7 +93,7 @@ public class UploadedFilesBrowse extends Composite {
}
});
listButtonRemove.add(buttonRemoveFile);
table.setWidget(i, 3, buttonRemoveFile);
table.setWidget(i, ++columnIndex, buttonRemoveFile);
i++;
index++;
}
@ -97,25 +102,25 @@ public class UploadedFilesBrowse extends Composite {
}
}
public void enableManageOfContent(boolean bool) {
for (Button button : listButtonRemove) {
button.setEnabled(bool);
}
double opacity = bool?1:0.8;
double opacity = bool ? 1 : 0.8;
uploadFileContainer.getElement().getStyle().setOpacity(opacity);
}
public List<FileUploaded> getListRemainingFileUploaded() {
public List<T> getListRemainingFileUploaded() {
Collection<FileUploaded> collFileUplaoded = mapPositionalFU.values();
Collection<T> collFileUplaoded = mapPositionalFU.values();
if (collFileUplaoded != null)
return new ArrayList<FileUploaded>(collFileUplaoded);
return new ArrayList<T>(collFileUplaoded);
return null;
}

View File

@ -14,7 +14,7 @@ import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded;
*
* Oct 19, 2020
*/
public class GenericDatasetBean<T extends MetaDataProfileBean> implements Serializable {
public class GenericDatasetBean<T extends MetaDataProfileBean, F extends FileUploaded> implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -5215392381589702647L;
@ -26,7 +26,7 @@ public class GenericDatasetBean<T extends MetaDataProfileBean> implements Serial
private LinkedHashMap<String, List<String>> formDataEntryFields;
/** The files uploaded. */
private List<FileUploaded> filesUploaded;
private List<F> filesUploaded;
/**
* Instantiates a new generic dataset bean.
@ -42,7 +42,7 @@ public class GenericDatasetBean<T extends MetaDataProfileBean> implements Serial
* @param filesUploaded the files uploaded
*/
public GenericDatasetBean(List<T> metadataProfileList, LinkedHashMap<String, List<String>> formDataEntryFields,
List<FileUploaded> filesUploaded) {
List<F> filesUploaded) {
super();
this.metadataProfileList = metadataProfileList;
this.formDataEntryFields = formDataEntryFields;
@ -90,7 +90,7 @@ public class GenericDatasetBean<T extends MetaDataProfileBean> implements Serial
*
* @return the files uploaded
*/
public List<FileUploaded> getFilesUploaded() {
public List<F> getFilesUploaded() {
return filesUploaded;
}
@ -99,7 +99,7 @@ public class GenericDatasetBean<T extends MetaDataProfileBean> implements Serial
*
* @param filesUploaded the new files uploaded
*/
public void setFilesUploaded(List<FileUploaded> filesUploaded) {
public void setFilesUploaded(List<F> filesUploaded) {
this.filesUploaded = filesUploaded;
}

View File

@ -31,10 +31,6 @@ public class FileUploaded implements Serializable, IsSerializable {
private FilePath filePath;
private String url;
private String mimeType;
/**
* Instantiates a new workspace upload file.
*/
@ -129,49 +125,6 @@ public class FileUploaded implements Serializable, IsSerializable {
this.filePath = filePath;
}
/**
* Gets the url.
*
* @return the url
*/
public String getUrl() {
return url;
}
/**
* Sets the url.
*
* @param url the new url
*/
public void setUrl(String url) {
this.url = url;
}
public String getMimeType() {
return mimeType;
}
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("FileUploaded [fileName=");
builder.append(fileName);
builder.append(", tempSystemPath=");
builder.append(tempSystemPath);
builder.append(", createdByUser=");
builder.append(createdByUser);
builder.append(", filePath=");
builder.append(filePath);
builder.append(", url=");
builder.append(url);
builder.append(", mimeType=");
builder.append(mimeType);
builder.append("]");
return builder.toString();
}
}

View File

@ -9,16 +9,18 @@ package org.gcube.portlets.widgets.mpformbuilder.shared.upload;
*/
public class FileUploadedRemote extends FileUploaded {
/**
*
*/
private static final long serialVersionUID = -1700162549065345145L;
private static final long serialVersionUID = 2991541932545131966L;
private String url;
private String mimeType;
/**
* Instantiates a new file uploaded remote.
*/
FileUploadedRemote() {
public FileUploadedRemote() {
}
@ -41,15 +43,30 @@ public class FileUploadedRemote extends FileUploaded {
}
/**
* To string.
* Gets the mime type.
*
* @return the string
* @return the mime type
*/
public String getMimeType() {
return mimeType;
}
/**
* Sets the mime type.
*
* @param mimeType the new mime type
*/
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("FileUploadedRemote [url=");
builder.append(url);
builder.append(", mimeType=");
builder.append(mimeType);
builder.append("]");
return builder.toString();
}