geoportal-data-entry-app/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java

306 lines
9.1 KiB
Java
Raw Normal View History

2021-09-27 18:32:19 +02:00
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;
2021-09-28 17:31:16 +02:00
import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.model.RelazioneScavoDV;
2021-09-27 18:32:19 +02:00
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;
2021-09-28 17:31:16 +02:00
import com.github.gwtbootstrap.client.ui.Button;
2021-09-27 18:32:19 +02:00
import com.github.gwtbootstrap.client.ui.ControlGroup;
2021-09-28 17:31:16 +02:00
import com.github.gwtbootstrap.client.ui.Controls;
2021-09-27 18:32:19 +02:00
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;
2021-09-28 17:31:16 +02:00
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
2021-09-27 18:32:19 +02:00
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 {
2021-09-29 11:08:15 +02:00
private static final String _700PX = "700px";
2021-09-28 17:31:16 +02:00
private static final String UPLOAD_MISSING_FILE = "You must upload a file";
2021-09-27 18:32:19 +02:00
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
2021-09-28 17:31:16 +02:00
ControlGroup cgSelectFile;
2021-09-27 18:32:19 +02:00
@UiField
2021-09-28 17:31:16 +02:00
Controls controlsContent;
2021-09-27 18:32:19 +02:00
@UiField
HTMLPanel uploadFileContainer;
2021-09-28 17:31:16 +02:00
@UiField
Button buttonUpdate;
2021-09-27 18:32:19 +02:00
private List<String> listFileSetPaths;
private boolean placeholderRemoved = false;
private String recordId;
private BaseConcessioneDV selectedConcessione;
private ConcessioneDV fullConcessione;
private RECORD_TYPE recordType;
2021-09-28 17:31:16 +02:00
private MultipleDilaogUpload mDU;
private ChangeHandler listBoxIndexHandler;
2021-09-27 18:32:19 +02:00
/**
* 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);
}
2021-09-29 11:08:15 +02:00
listBoxPaths.setWidth(_700PX);
2021-09-27 18:32:19 +02:00
// 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());
}
});
2021-09-28 17:31:16 +02:00
buttonUpdate.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (mDU != null) {
if (checkValidUpload()) {
Window.alert("I can save...");
} else {
Window.alert("New file not found. " + UPLOAD_MISSING_FILE);
}
}
}
});
2021-09-27 18:32:19 +02:00
}
/**
* Show upload file GUI.
*/
private void showUploadFileGUI() {
uploadFileContainer.setVisible(true);
2021-09-28 17:31:16 +02:00
buttonUpdate.setVisible(false);
2021-09-27 18:32:19 +02:00
uploadFileContainer.clear();
2021-09-28 17:31:16 +02:00
controlsContent.clear();
2021-09-27 18:32:19 +02:00
2021-09-28 17:31:16 +02:00
// listBoxIndex.clear();
2021-09-27 18:32:19 +02:00
cgSelectFile.setVisible(true);
2021-09-28 17:31:16 +02:00
ListBox listBoxIndex = new ListBox();
2021-09-29 11:08:15 +02:00
listBoxIndex.setWidth(_700PX);
2021-09-28 17:31:16 +02:00
listBoxIndex.addItem("Select a content...");
2021-09-27 18:32:19 +02:00
if (listBoxPaths.getSelectedItemText().contains("abstract_relazione")) {
AbstractRelazioneScavoDV ar = fullConcessione.getAbstractRelazioneScavo();
if (ar == null) {
2021-09-28 17:31:16 +02:00
showMessage("abstract_relazione" + " NOT AVAILABLE", LabelType.WARNING);
2021-09-27 18:32:19 +02:00
return;
}
2021-09-28 17:31:16 +02:00
int posizIndex = 0;
fillListBoxToBeReplaced(listBoxIndex, "abstract_relazione", posizIndex, ar.getTitolo(),
ar.getListWsContent());
2021-09-27 18:32:19 +02:00
} else if (listBoxPaths.getSelectedItemText().contains("immagini")) {
List<UploadedImageDV> listImmagini = fullConcessione.getImmaginiRappresentative();
if (listImmagini == null || listImmagini.isEmpty()) {
2021-09-28 17:31:16 +02:00
showMessage("immagini" + " NOT AVAILABLE", LabelType.WARNING);
2021-09-27 18:32:19 +02:00
return;
}
2021-09-28 17:31:16 +02:00
int posizIndex = 0;
2021-09-27 18:32:19 +02:00
for (UploadedImageDV uploadedImageDV : listImmagini) {
2021-09-28 17:31:16 +02:00
fillListBoxToBeReplaced(listBoxIndex, "immagini", posizIndex, uploadedImageDV.getTitolo(),
uploadedImageDV.getListWsContent());
posizIndex++;
}
} else if (listBoxPaths.getSelectedItemText().contains("relazione")) {
RelazioneScavoDV realzione = fullConcessione.getRelazioneScavo();
if (realzione == null || realzione.getListWsContent() == null) {
showMessage("relazione" + " NOT AVAILABLE", LabelType.WARNING);
return;
}
int posizIndex = 0;
fillListBoxToBeReplaced(listBoxIndex, "relazione", posizIndex, realzione.getTitolo(),
realzione.getListWsContent());
} else if (listBoxPaths.getSelectedItemText().contains("posizionamentoScavo")) {
LayerConcessioneDV posiz = fullConcessione.getPosizionamentoScavo();
if (posiz == null || posiz.getListWsContent() == null || posiz.getListWsContent().isEmpty()) {
showMessage("posizionamentoScavo" + " NOT AVAILABLE", LabelType.WARNING);
return;
}
int posizIndex = 0;
fillListBoxToBeReplaced(listBoxIndex, "posizionamentoScavo", posizIndex, posiz.getTitolo(),
posiz.getListWsContent());
} else if (listBoxPaths.getSelectedItemText().contains("piante")) {
List<LayerConcessioneDV> piante = fullConcessione.getPianteFineScavo();
if (piante == null || piante.isEmpty()) {
showMessage("piante" + " NOT AVAILABLE", LabelType.WARNING);
return;
}
int posizIndex = 0;
for (LayerConcessioneDV lcDV : piante) {
fillListBoxToBeReplaced(listBoxIndex, "piante", posizIndex, lcDV.getTitolo(), lcDV.getListWsContent());
posizIndex++;
2021-09-27 18:32:19 +02:00
}
}
2021-09-28 17:31:16 +02:00
controlsContent.add(listBoxIndex);
2021-09-27 18:32:19 +02:00
2021-09-28 17:31:16 +02:00
// if (listBoxIndex.getItemCount() > 1) {
// listBoxIndex.addChangeHandler(new ChangeHandler() {
//
// @Override
// public void onChange(ChangeEvent event) {
// showFileBrowseInteraction();
// }
// });
// }
2021-09-27 18:32:19 +02:00
}
2021-09-28 17:31:16 +02:00
private void fillListBoxToBeReplaced(ListBox listBoxIndex, String section, int posizIndex, String title,
List<WorkspaceContentDV> listWSC) {
2021-09-27 18:32:19 +02:00
2021-09-28 17:31:16 +02:00
// ListBox listBoxIndex = new ListBox();
// listBoxIndex.addItem("Select a content...");
2021-09-27 18:32:19 +02:00
if (listWSC == null || listWSC.isEmpty()) {
showMessage(section + " DOES NOT CONTAIN FILES", LabelType.WARNING);
return;
}
2021-09-28 17:31:16 +02:00
listBoxIndex.addItem(title, posizIndex + "");
// adding handler once
if (posizIndex == 0) {
listBoxIndex.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
showFileBrowseInteraction();
}
});
}
//
// controlsContent.add(listBoxIndex);
2021-09-27 18:32:19 +02:00
for (WorkspaceContentDV wsContent : listWSC) {
String name = wsContent.getName() == null || wsContent.getName().isEmpty() ? wsContent.getLink()
: wsContent.getName();
}
}
2021-09-28 17:31:16 +02:00
private void showFileBrowseInteraction() {
2021-09-27 18:32:19 +02:00
uploadFileContainer.clear();
HTML label = new HTML();
2021-09-28 17:31:16 +02:00
label.setHTML("With new one:");
2021-09-27 18:32:19 +02:00
uploadFileContainer.add(label);
2021-09-28 17:31:16 +02:00
mDU = new MultipleDilaogUpload();
uploadFileContainer.add(mDU);
buttonUpdate.setVisible(true);
}
private boolean checkValidUpload() {
GWT.log("Checking is valid File");
if (mDU.getFileUploadingState() != null && mDU.getFileUploadingState().getFile() != null) {
return mDU.getFileUploadingState().getFile().getTempSystemPath() != null;
}
return false;
2021-09-27 18:32:19 +02:00
}
private void showMessage(String txt, LabelType type) {
Label l = new Label();
l.setType(type);
l.setText(txt);
uploadFileContainer.add(l);
}
}