200 lines
5.8 KiB
Java
200 lines
5.8 KiB
Java
package org.gcube.portlets.user.geoportaldataentry.client.ui.edit;
|
|
|
|
import java.util.List;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV;
|
|
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
|
|
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV;
|
|
import org.gcube.application.geoportalcommon.shared.products.model.AbstractRelazioneScavoDV;
|
|
import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp;
|
|
import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.MultipleDilaogUpload;
|
|
|
|
import com.github.gwtbootstrap.client.ui.ControlGroup;
|
|
import com.github.gwtbootstrap.client.ui.Label;
|
|
import com.github.gwtbootstrap.client.ui.ListBox;
|
|
import com.github.gwtbootstrap.client.ui.constants.LabelType;
|
|
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.uibinder.client.UiBinder;
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
import com.google.gwt.user.client.Window;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
/**
|
|
* The Class UpdateFileset.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
*
|
|
* Sep 27, 2021
|
|
*/
|
|
public class UpdateFileset extends Composite {
|
|
|
|
private static UpdateFilesetUiBinder uiBinder = GWT.create(UpdateFilesetUiBinder.class);
|
|
|
|
/**
|
|
* The Interface UpdateFilesetUiBinder.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
*
|
|
* Sep 27, 2021
|
|
*/
|
|
interface UpdateFilesetUiBinder extends UiBinder<Widget, UpdateFileset> {
|
|
}
|
|
|
|
@UiField
|
|
ListBox listBoxPaths;
|
|
|
|
@UiField
|
|
ListBox listBoxIndex;
|
|
|
|
@UiField
|
|
ControlGroup cgSelectFile;
|
|
|
|
@UiField
|
|
HTMLPanel uploadFileContainer;
|
|
|
|
private List<String> listFileSetPaths;
|
|
|
|
private boolean placeholderRemoved = false;
|
|
|
|
private String recordId;
|
|
|
|
private BaseConcessioneDV selectedConcessione;
|
|
|
|
private ConcessioneDV fullConcessione;
|
|
|
|
private RECORD_TYPE recordType;
|
|
|
|
/**
|
|
* Instantiates a new update fileset.
|
|
*
|
|
* @param listFileSetPaths the list file set paths
|
|
*/
|
|
public UpdateFileset(BaseConcessioneDV selectedConcessione, RECORD_TYPE recordType, List<String> listFileSetPaths) {
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
this.selectedConcessione = selectedConcessione;
|
|
this.recordType = recordType;
|
|
this.listFileSetPaths = listFileSetPaths;
|
|
listBoxPaths.addItem("Select a section...");
|
|
for (String path : listFileSetPaths) {
|
|
listBoxPaths.addItem(path);
|
|
}
|
|
|
|
// add handler on select
|
|
listBoxPaths.addChangeHandler(new ChangeHandler() {
|
|
|
|
@Override
|
|
public void onChange(ChangeEvent event) {
|
|
GWT.log("Profile type selection changed...");
|
|
cgSelectFile.setVisible(false);
|
|
|
|
if (!placeholderRemoved) {
|
|
listBoxPaths.removeItem(0); // this is the placeholder
|
|
placeholderRemoved = true;
|
|
}
|
|
showUploadFileGUI();
|
|
}
|
|
|
|
});
|
|
|
|
GeoPortalDataEntryApp.geoportalDataEntryService.getRecord(selectedConcessione.getItemId(), recordType,
|
|
new AsyncCallback<ConcessioneDV>() {
|
|
|
|
@Override
|
|
public void onSuccess(ConcessioneDV theRecord) {
|
|
fullConcessione = theRecord;
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
Window.alert(caught.getMessage());
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
* Show upload file GUI.
|
|
*/
|
|
private void showUploadFileGUI() {
|
|
uploadFileContainer.setVisible(true);
|
|
uploadFileContainer.clear();
|
|
|
|
listBoxIndex.clear();
|
|
cgSelectFile.setVisible(true);
|
|
|
|
if (listBoxPaths.getSelectedItemText().contains("abstract_relazione")) {
|
|
AbstractRelazioneScavoDV ar = fullConcessione.getAbstractRelazioneScavo();
|
|
if (ar == null) {
|
|
showMessage("abstract_relazione " + " NOT AVAILABLE", LabelType.WARNING);
|
|
return;
|
|
}
|
|
fillListBoxToBeReplaced("abstract_relazione", ar.getListWsContent());
|
|
} else if (listBoxPaths.getSelectedItemText().contains("immagini")) {
|
|
List<UploadedImageDV> listImmagini = fullConcessione.getImmaginiRappresentative();
|
|
if (listImmagini == null || listImmagini.isEmpty()) {
|
|
showMessage("immagini " + " NOT AVAILABLE", LabelType.WARNING);
|
|
return;
|
|
}
|
|
for (UploadedImageDV uploadedImageDV : listImmagini) {
|
|
fillListBoxToBeReplaced("immagini", uploadedImageDV.getListWsContent());
|
|
}
|
|
|
|
}
|
|
|
|
if (listBoxIndex.getItemCount() > 1) {
|
|
listBoxIndex.addChangeHandler(new ChangeHandler() {
|
|
|
|
@Override
|
|
public void onChange(ChangeEvent event) {
|
|
showFileUploadInteraction();
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
private void fillListBoxToBeReplaced(String section, List<WorkspaceContentDV> listWSC) {
|
|
|
|
listBoxIndex.clear();
|
|
|
|
listBoxIndex.addItem("Select a file...");
|
|
|
|
if (listWSC == null || listWSC.isEmpty()) {
|
|
showMessage(section + " DOES NOT CONTAIN FILES", LabelType.WARNING);
|
|
return;
|
|
}
|
|
|
|
for (WorkspaceContentDV wsContent : listWSC) {
|
|
String name = wsContent.getName() == null || wsContent.getName().isEmpty() ? wsContent.getLink()
|
|
: wsContent.getName();
|
|
listBoxIndex.addItem(name);
|
|
}
|
|
}
|
|
|
|
private void showFileUploadInteraction() {
|
|
uploadFileContainer.clear();
|
|
HTML label = new HTML();
|
|
label.setHTML("<i>Going to replace the file into section: " + listBoxIndex.getSelectedItemText() + " with</i>");
|
|
|
|
uploadFileContainer.add(label);
|
|
MultipleDilaogUpload holder = new MultipleDilaogUpload();
|
|
uploadFileContainer.add(holder);
|
|
}
|
|
|
|
private void showMessage(String txt, LabelType type) {
|
|
Label l = new Label();
|
|
l.setType(type);
|
|
l.setText(txt);
|
|
uploadFileContainer.add(l);
|
|
}
|
|
|
|
}
|