//package org.gcube.portlets.user.geoportaldataentry.client.ui.edit; // //import java.util.ArrayList; //import java.util.Collection; //import java.util.HashMap; //import java.util.List; //import java.util.Map; // //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.LayerConcessioneDV; //import org.gcube.application.geoportalcommon.shared.products.model.RelazioneScavoDV; //import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV; //import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryServiceAsync; //import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform; //import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.ModalConfirm; //import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.StringUtil; //import org.gcube.portlets.widgets.mpformbuilder.client.form.MetaDataField; //import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm.OPERATION; //import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.MetaDataFieldSkeleton; //import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.DialogUpload; //import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; //import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.DataTypeWrapper; //import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper; //import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded; // //import com.github.gwtbootstrap.client.ui.Button; //import com.github.gwtbootstrap.client.ui.ControlGroup; //import com.github.gwtbootstrap.client.ui.Controls; //import com.github.gwtbootstrap.client.ui.Label; //import com.github.gwtbootstrap.client.ui.ListBox; //import com.github.gwtbootstrap.client.ui.constants.IconType; //import com.github.gwtbootstrap.client.ui.constants.LabelType; //import com.google.gwt.core.client.GWT; //import com.google.gwt.dom.client.Document; //import com.google.gwt.dom.client.Style.Unit; //import com.google.gwt.event.dom.client.ChangeEvent; //import com.google.gwt.event.dom.client.ChangeHandler; //import com.google.gwt.event.dom.client.ClickEvent; //import com.google.gwt.event.dom.client.ClickHandler; //import com.google.gwt.event.dom.client.DomEvent; //import com.google.gwt.event.shared.HandlerManager; //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.FlexTable; //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 final String SECTION_PIANTE = "piante"; // // private static final String SECTION_POSIZIONAMENTO_SCAVO = "posizionamentoScavo"; // // private static final String SECTION_RELAZIONE = "relazione"; // // private static final String SECTION_IMMAGINI = "immagini"; // // private static final String SECTION_ABSTRACT_RELAZIONE = "abstract_relazione"; // // private static final String _FORM_WIDTH_FIELDS_SIZE = "730px"; // // 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 { // } // // @UiField // ListBox listBoxPaths; // // @UiField // ControlGroup cgSelectFile; // // @UiField // Controls controlsContent; // // @UiField // HTMLPanel uploadFileContainer; // // @UiField // Button buttonUpdate; // // private List listFileSetPaths; // // private boolean placeholderListBoxPaths = true; // // private BaseConcessioneDV selectedConcessione; // // private ConcessioneDV fullConcessione; // // private boolean placeholderListBoxIndex = true; // // private HandlerManager uiBus = new HandlerManager(null); // // private MetaDataField fieldUploadWidget; // // private Integer pathIndex = null; // // private Map mapForCCUploading = null; // // private Map> mapWSContentListBox = null; // // private HandlerManager editorManagerBus; // // private String profileID; // // // /** // * Instantiates a new update fileset. // * // * @param editorManagerBus the editor manager bus // * @param selectedConcessione the selected concessione // * @param recordType the record type // * @param listFileSetPaths the list file set paths // */ // public UpdateFileset(HandlerManager editorManagerBus, BaseConcessioneDV selectedConcessione, String profileID, List listFileSetPaths) { // initWidget(uiBinder.createAndBindUi(this)); // this.editorManagerBus = editorManagerBus; // this.selectedConcessione = selectedConcessione; // this.profileID = profileID; // this.listFileSetPaths = listFileSetPaths; // listBoxPaths.addItem("Select a section..."); // for (String path : listFileSetPaths) { // listBoxPaths.addItem(path); // } // listBoxPaths.setWidth(_FORM_WIDTH_FIELDS_SIZE); // // // add handler on select // listBoxPaths.addChangeHandler(new ChangeHandler() { // // @Override // public void onChange(ChangeEvent event) { // GWT.log("Profile type selection changed..."); // cgSelectFile.setVisible(false); // // if (placeholderListBoxPaths) { // listBoxPaths.removeItem(0); // this is the placeholder, removing it once // placeholderListBoxPaths = false; // } // showUploadFileGUI(); // } // // }); // // // Window.alert("This part must be revisited"); // //// GeoPortalDataEntryApp.geoportalDataEntryService.getRecord(selectedConcessione.getItemId(), recordType, //// new AsyncCallback() { //// //// @Override //// public void onSuccess(ConcessioneDV theRecord) { //// fullConcessione = theRecord; //// } //// //// @Override //// public void onFailure(Throwable caught) { //// Window.alert(caught.getMessage()); //// } //// }); // // buttonUpdate.addClickHandler(new ClickHandler() { // // @Override // public void onClick(ClickEvent event) { // // String errorMsg = checkValidUpload(); // if (errorMsg == null) { // List listFilesUploaded = new ArrayList(); // List listMetaDataFieldSkeleton = fieldUploadWidget.getListOfMetadataFields(); // for (MetaDataFieldSkeleton field : listMetaDataFieldSkeleton) { // DialogUpload dUpload = (DialogUpload) field.getHolder(); // // adding it only if exists // if (dUpload.getFileUploadingState() != null) // listFilesUploaded.add(dUpload.getFileUploadingState().getFile()); // } // // GenericDatasetBean gdb = new GenericDatasetBean(); // gdb.setFilesUploaded(listFilesUploaded); // // adding it only if exists // // GWT.log("Section selected: " + listBoxPaths.getSelectedItemText()); // GWT.log("Content index selected: " + pathIndex); // GWT.log("FileUploaded selected: " + gdb.getFilesUploaded()); // // List listCurrentContent = new ArrayList(); // if (mapForCCUploading != null) { // Collection currentContent = mapForCCUploading.values(); // if (currentContent != null) // listCurrentContent.addAll(currentContent); // } // // String htmlMsg = "Going to update the section " + listBoxPaths.getSelectedItemText() + ":"; // htmlMsg += "
    "; // htmlMsg += "
  • keeping " + listCurrentContent.size() + " current file/s
  • "; // htmlMsg += "
  • uploading " + listFilesUploaded.size() + " new file/s
  • "; // htmlMsg += "
"; // htmlMsg += "
"; // htmlMsg += "This operation cannot be undone. Would you like to proceed?"; // // GWT.log(htmlMsg); // // final ModalConfirm dialogConfirm = new ModalConfirm(null, "Update Confirm?", htmlMsg); // dialogConfirm.getElement().getStyle().setZIndex(100000); // dialogConfirm.getYesButton().addClickHandler(new ClickHandler() { // // @Override // public void onClick(ClickEvent event) { // dialogConfirm.hide(); // buttonUpdate.setEnabled(false); // // final DialogInform dialogInf = new DialogInform(null, "Updating Project...", ""); // dialogInf.setZIndex(100000); // dialogInf.showLoader("Updating file/s for project: "+fullConcessione.getNome()); // //dialogInf.setWidth("400px"); // // GeoportalDataEntryServiceAsync.Util.getInstance().updateSectionForRecord( // fullConcessione.getItemId(), fullConcessione.getRecordType(), // listBoxPaths.getSelectedItemText(), pathIndex, listCurrentContent, gdb, // new AsyncCallback() { // // @Override // public void onFailure(Throwable caught) { // dialogInf.hideLoader(); // dialogInf.setMsg( // "Sorry error occurred during project update. Error reported: " // + caught.getMessage()); // buttonUpdate.setEnabled(true); // showUploadFileGUI(); // // } // // @Override // public void onSuccess(ConcessioneDV result) { // dialogInf.hideLoader(); // dialogInf.setText("Project updated!"); // dialogInf.setMsg(result.getNome() + " updated correclty"); // dialogInf.center(); // fullConcessione = result; // GWT.log("new concessione: "+fullConcessione); // buttonUpdate.setEnabled(true); // showUploadFileGUI(); // // Window.alert("updateSectionForRecord must be revisited"); // // /* // editorManagerBus.fireEvent( // new OperationPerformedOnItemEvent(Arrays.asList(fullConcessione), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); // // */ // // } // }); // dialogInf.center(); // } // }); // dialogConfirm.show(); // // } else { // Window.alert(errorMsg); // } // // } // }); // // } // // /** // * Show upload file GUI. // */ // private void showUploadFileGUI() { // uploadFileContainer.setVisible(true); // buttonUpdate.setVisible(false); // uploadFileContainer.clear(); // controlsContent.clear(); // placeholderListBoxIndex = true; // fieldUploadWidget = null; // pathIndex = null; // mapForCCUploading = null; // mapWSContentListBox = null; // //// listBoxIndex.clear(); // cgSelectFile.setVisible(true); // // ListBox listBoxContentIndex = new ListBox(); // listBoxContentIndex.setWidth(_FORM_WIDTH_FIELDS_SIZE); // listBoxContentIndex.addItem("Select a content..."); // String section = null; // Integer posizIndex = 0; // if (listBoxPaths.getSelectedItemText().contains(SECTION_ABSTRACT_RELAZIONE)) { // section = SECTION_ABSTRACT_RELAZIONE; // AbstractRelazioneScavoDV ar = fullConcessione.getAbstractRelazioneScavo(); // // if (ar == null) { // showMessage(SECTION_ABSTRACT_RELAZIONE + " NOT AVAILABLE", LabelType.WARNING); //// pathIndex = 0; //// showNewFileUpload(); // return; // } // // fillListBoxToBeReplaced(listBoxContentIndex, section, posizIndex, ar.getTitolo(), // ar.getListWsContent()); // // } else if (listBoxPaths.getSelectedItemText().contains(SECTION_IMMAGINI)) { // section = SECTION_IMMAGINI; // List listImmagini = fullConcessione.getImmaginiRappresentative(); // if (listImmagini == null || listImmagini.isEmpty()) { // showMessage(SECTION_IMMAGINI + " NOT AVAILABLE", LabelType.WARNING); //// pathIndex = 0; //// showNewFileUpload(); // return; // } // // for (UploadedImageDV uploadedImageDV : listImmagini) { // fillListBoxToBeReplaced(listBoxContentIndex, section, posizIndex, StringUtil.ellipsize(uploadedImageDV.getDidascalia(),30), // uploadedImageDV.getListWsContent()); // posizIndex++; // } // // } else if (listBoxPaths.getSelectedItemText().contains(SECTION_RELAZIONE)) { // section = SECTION_RELAZIONE; // RelazioneScavoDV relazioneScavo = fullConcessione.getRelazioneScavo(); // if (relazioneScavo == null) { // showMessage(SECTION_RELAZIONE + " NOT AVAILABLE", LabelType.WARNING); //// pathIndex = 0; //// showNewFileUpload(); // return; // } // // fillListBoxToBeReplaced(listBoxContentIndex, section, posizIndex, relazioneScavo.getTitolo(), // relazioneScavo.getListWsContent()); // // } else if (listBoxPaths.getSelectedItemText().contains(SECTION_POSIZIONAMENTO_SCAVO)) { // section = SECTION_POSIZIONAMENTO_SCAVO; // LayerConcessioneDV posiz = fullConcessione.getPosizionamentoScavo(); // if (posiz == null) { // showMessage(SECTION_POSIZIONAMENTO_SCAVO + " NOT AVAILABLE", LabelType.WARNING); //// pathIndex = 0; //// showNewFileUpload(); // return; // } // // fillListBoxToBeReplaced(listBoxContentIndex, section, posizIndex, posiz.getTitolo(), // posiz.getListWsContent()); // // } else if (listBoxPaths.getSelectedItemText().contains(SECTION_PIANTE)) { // section = SECTION_PIANTE; // List piante = fullConcessione.getPianteFineScavo(); // if (piante == null || piante.isEmpty()) { // showMessage(SECTION_PIANTE + " NOT AVAILABLE", LabelType.WARNING); //// pathIndex = 0; //// showNewFileUpload(); // return; // } // // for (LayerConcessioneDV lcDV : piante) { // fillListBoxToBeReplaced(listBoxContentIndex, SECTION_PIANTE, posizIndex, lcDV.getTitolo(), // lcDV.getListWsContent()); // posizIndex++; // } // // } // // controlsContent.add(listBoxContentIndex); // // if (listBoxContentIndex.getItemCount() == 2) { // // listBoxContentIndex.setSelectedIndex(1); // listBoxContentIndex.setSelectedValue(listBoxContentIndex.getItemText(1)); // // DomEvent.fireNativeEvent(Document.get().createChangeEvent(), listBoxContentIndex); // } // // } // // private void fillListBoxToBeReplaced(ListBox listBoxContentIndex, String section, int posizIndex, String title, // List listWSC) { // GWT.log("fillListBoxToBeReplaced called, posizIndex: "+posizIndex+", listWSC: "+listWSC); // // if(mapWSContentListBox==null) { // mapWSContentListBox = new HashMap>(); // } // // listBoxContentIndex.addItem(title, posizIndex + ""); // mapWSContentListBox.put(posizIndex, listWSC); // // // adding handler once // if (posizIndex == 0) { // // listBoxContentIndex.addChangeHandler(new ChangeHandler() { // // @Override // public void onChange(ChangeEvent event) { // GWT.log("listBoxContentIndex changed, value: "+listBoxContentIndex.getSelectedValue()); // // if (placeholderListBoxIndex) { // listBoxContentIndex.removeItem(0); // this is the placeholder, removing it once // placeholderListBoxIndex = false; // } // int selectedIndex = listBoxContentIndex.getSelectedIndex(); // GWT.log("selected index: "+selectedIndex); // List theListWC = mapWSContentListBox.get(selectedIndex); // // if (theListWC == null || theListWC.isEmpty()) { // uploadFileContainer.clear(); // showMessage(section + " does not contain file!", LabelType.WARNING); // pathIndex = posizIndex; // showNewFileUpload(); // return; // } // // showFileBrowseInteraction(selectedIndex, mapWSContentListBox.get(selectedIndex)); // } // }); // } //// // // } // // private void showFileBrowseInteraction(int pathContentIndex, List listWSC) { // uploadFileContainer.clear(); // pathIndex = pathContentIndex; // GWT.log("showing pathContentIndex: "+pathContentIndex); // GWT.log("showing ws content: "+listWSC); // // // map for current content uploading // mapForCCUploading = new HashMap(listWSC.size()); // int index = 0; // for (WorkspaceContentDV workspaceContentDV : listWSC) { // workspaceContentDV.setCliendId(index); // mapForCCUploading.put(index, workspaceContentDV); // index++; // } // // if (listWSC.size() > 0) { // FlexTable table = new FlexTable(); // table.addStyleName("table-current-content"); // table.setHTML(0, 0, "Current content:"); // table.setHTML(1, 0, "Filename"); // table.setHTML(1, 1, "MimeType"); // table.setHTML(1, 2, "Link"); // // int i = 2; // for (final WorkspaceContentDV wsContent : listWSC) { // table.setHTML(i, 0, wsContent.getName()); // table.setHTML(i, 1, wsContent.getMimetype()); // String link = "View"; // table.setHTML(i, 2, link); // // final int rowIndexToRem = i; // Button buttonRemoveFile = new Button(); // buttonRemoveFile.setIcon(IconType.TRASH); // buttonRemoveFile.setTitle("Remove this file"); // buttonRemoveFile.addClickHandler(new ClickHandler() { // // @Override // public void onClick(ClickEvent event) { // mapForCCUploading.remove(wsContent.getCliendId()); // table.getRowFormatter().getElement(rowIndexToRem).setAttribute("hidden", "hidden"); // } // }); // table.setWidget(i, 3, buttonRemoveFile); // i++; // } // // uploadFileContainer.add(table); // } // // showNewFileUpload(); // } // // // private void showNewFileUpload() { // // HTML label = new HTML(); // label.getElement().getStyle().setMarginTop(10, Unit.PX); // label.getElement().getStyle().setMarginBottom(10, Unit.PX); // label.setHTML("Add new file/s:"); // uploadFileContainer.add(label); // // mDU = new MultipleDilaogUpload(); // // MetadataFieldWrapper uploadField = new MetadataFieldWrapper(); // uploadField.setFieldName("File"); // uploadField.setMandatory(false); // uploadField.setType(DataTypeWrapper.File); // uploadField.setMaxOccurs(1000); // // try { // fieldUploadWidget = new MetaDataField(uploadField, uiBus, OPERATION.NEW); // uploadFileContainer.add(fieldUploadWidget); // // buttonUpdate.setVisible(true); // } catch (Exception e) { // e.printStackTrace(); // } // // } // // /** // * Test if profile data are valid. // * // * @return the string // */ // private String checkValidUpload() { // // if (fieldUploadWidget == null) // return "No file uploaded"; // // for (MetaDataFieldSkeleton field : fieldUploadWidget.getListOfMetadataFields()) { // // field.removeError(); // // String error = field.isFieldValueValid(); // if (error != null) { // field.showError(); // String errorMsg = field.getFieldNameOriginal() + " is not valid. Suggestion: " + error; // return errorMsg; // } // } // // return null; // } // // private void showMessage(String txt, LabelType type) { // Label l = new Label(); // l.setType(type); // l.setText(txt); // uploadFileContainer.add(l); // } // //}