2021-09-20 18:08:43 +02:00
|
|
|
package org.gcube.portlets.user.geoportaldataentry.client.ui.edit;
|
|
|
|
|
2022-09-14 10:21:13 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV;
|
2022-09-12 15:09:43 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV;
|
2022-09-14 10:12:07 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV;
|
2022-09-14 10:21:13 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM;
|
2022-09-12 15:09:43 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp;
|
2022-09-14 10:21:13 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.OperationPerformedOnItemEvent;
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.OperationPerformedOnItemEventHandler;
|
2021-09-22 11:38:52 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.edit.jseditor.JSONEditorWrapper;
|
2022-09-14 10:12:07 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform;
|
2021-09-22 11:38:52 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon;
|
2021-09-20 18:08:43 +02:00
|
|
|
|
2023-05-03 11:29:45 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Alert;
|
2021-09-22 11:38:52 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
|
|
|
import com.github.gwtbootstrap.client.ui.Tab;
|
2023-05-03 11:29:45 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
2021-09-20 18:08:43 +02:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2022-09-12 15:09:43 +02:00
|
|
|
import com.google.gwt.core.client.Scheduler;
|
|
|
|
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
|
|
|
import com.google.gwt.dom.client.Style.Visibility;
|
2021-09-22 11:38:52 +02:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
2021-09-27 15:28:36 +02:00
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
2021-09-20 18:08:43 +02:00
|
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
|
|
import com.google.gwt.user.client.Random;
|
2022-09-12 15:09:43 +02:00
|
|
|
import com.google.gwt.user.client.Timer;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2021-09-20 18:08:43 +02:00
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
|
|
import com.google.gwt.user.client.ui.FlowPanel;
|
2021-10-06 16:01:39 +02:00
|
|
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
2023-05-03 11:29:45 +02:00
|
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
2021-09-20 18:08:43 +02:00
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class EditModeRecord.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
* Sep 17, 2021
|
|
|
|
*/
|
|
|
|
public class EditModeRecord extends Composite {
|
|
|
|
|
|
|
|
private static EditModeRecordUiBinder uiBinder = GWT.create(EditModeRecordUiBinder.class);
|
|
|
|
|
2021-09-22 11:38:52 +02:00
|
|
|
@UiField
|
|
|
|
Tab tabRawUpdate;
|
2021-10-06 16:01:39 +02:00
|
|
|
|
2021-09-29 16:13:39 +02:00
|
|
|
@UiField
|
|
|
|
Tab tabUploadFiles;
|
2021-09-22 11:38:52 +02:00
|
|
|
|
2021-09-20 18:08:43 +02:00
|
|
|
@UiField
|
|
|
|
FlowPanel rawUpdatePanel;
|
|
|
|
|
|
|
|
@UiField
|
2021-10-06 16:01:39 +02:00
|
|
|
HTMLPanel filesUpdatePanel;
|
2021-09-20 18:08:43 +02:00
|
|
|
|
2021-09-22 11:38:52 +02:00
|
|
|
@UiField
|
|
|
|
Button buttonJSONUpdate;
|
|
|
|
|
2022-09-12 15:09:43 +02:00
|
|
|
private ResultDocumentDV selectedProject;
|
2021-09-20 18:08:43 +02:00
|
|
|
|
2021-09-22 11:38:52 +02:00
|
|
|
private JSONEditorWrapper jsEditor;
|
|
|
|
|
2021-09-27 15:28:36 +02:00
|
|
|
private HandlerManager appManagerBus;
|
2021-11-26 16:05:05 +01:00
|
|
|
|
2021-10-06 16:01:39 +02:00
|
|
|
private final HandlerManager editorManagerBus = new HandlerManager(null);
|
2021-09-27 15:28:36 +02:00
|
|
|
|
2023-05-03 11:29:45 +02:00
|
|
|
private int modalHeight;
|
|
|
|
|
2021-09-20 18:08:43 +02:00
|
|
|
/**
|
|
|
|
* The Interface EditModeRecordUiBinder.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
* Sep 17, 2021
|
|
|
|
*/
|
|
|
|
interface EditModeRecordUiBinder extends UiBinder<Widget, EditModeRecord> {
|
|
|
|
}
|
|
|
|
|
2023-05-03 11:29:45 +02:00
|
|
|
public EditModeRecord(HandlerManager appManagerBus, ResultDocumentDV selectedProject, int modalHeight) {
|
2021-09-20 18:08:43 +02:00
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
2023-05-03 11:29:45 +02:00
|
|
|
this.modalHeight = modalHeight;
|
2022-09-12 15:09:43 +02:00
|
|
|
this.selectedProject = selectedProject;
|
2021-09-27 15:28:36 +02:00
|
|
|
this.appManagerBus = appManagerBus;
|
2023-05-03 11:29:45 +02:00
|
|
|
this.filesUpdatePanel.setHeight((modalHeight - 50) + "px");
|
|
|
|
// filesUpdatePanel.getElement().modalHeight().setProperty("maxHeight",
|
|
|
|
// "550px");
|
2021-09-22 11:38:52 +02:00
|
|
|
|
2022-09-14 10:12:07 +02:00
|
|
|
// TODO Must be instanceUpdateFilesetEditor
|
2022-09-12 15:09:43 +02:00
|
|
|
tabUploadFiles.asWidget().getElement().getStyle().setVisibility(Visibility.HIDDEN);
|
2022-09-14 10:12:07 +02:00
|
|
|
|
2021-09-22 11:38:52 +02:00
|
|
|
instanceJSONEditor();
|
2021-09-27 18:32:19 +02:00
|
|
|
instanceUpdateFilesetEditor();
|
2021-09-22 11:38:52 +02:00
|
|
|
bindEvents();
|
|
|
|
}
|
2021-09-20 18:08:43 +02:00
|
|
|
|
2021-09-27 18:32:19 +02:00
|
|
|
private void instanceUpdateFilesetEditor() {
|
|
|
|
|
2022-09-14 10:12:07 +02:00
|
|
|
// Window.alert("instanceUpdateFilesetEditor must be revisited");
|
2021-09-27 18:32:19 +02:00
|
|
|
|
2022-09-12 15:09:43 +02:00
|
|
|
/*
|
|
|
|
* GeoPortalDataEntryApp.geoportalDataEntryService.readFileSetPaths(new
|
|
|
|
* AsyncCallback<FileSetPathsDV>() {
|
|
|
|
*
|
|
|
|
* @Override public void onFailure(Throwable caught) { // TODO Auto-generated
|
|
|
|
* method stub
|
|
|
|
*
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* @Override public void onSuccess(FileSetPathsDV fileSetPaths) { UpdateFileset
|
|
|
|
* updateFileset = new UpdateFileset(editorManagerBus, selectedProject,
|
|
|
|
* recordType, fileSetPaths.getFileSetPaths());
|
|
|
|
* filesUpdatePanel.add(updateFileset); } });
|
|
|
|
*/
|
2021-09-27 18:32:19 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-01-30 14:47:33 +01:00
|
|
|
public void noUpdateMode() {
|
|
|
|
buttonJSONUpdate.setVisible(false);
|
|
|
|
}
|
|
|
|
|
2021-09-22 11:38:52 +02:00
|
|
|
private void instanceJSONEditor() {
|
2021-09-27 15:28:36 +02:00
|
|
|
|
2021-09-22 11:38:52 +02:00
|
|
|
rawUpdatePanel.clear();
|
2023-05-03 11:29:45 +02:00
|
|
|
|
|
|
|
final HorizontalPanel hpLoader = new HorizontalPanel();
|
|
|
|
final LoaderIcon lc = new LoaderIcon("Loading Project... please wait");
|
|
|
|
hpLoader.add(lc);
|
|
|
|
rawUpdatePanel.add(hpLoader);
|
2021-09-20 18:08:43 +02:00
|
|
|
final FlowPanel fp = new FlowPanel();
|
2021-09-22 11:38:52 +02:00
|
|
|
fp.getElement().setId("jsoneditor" + Random.nextInt());
|
2023-05-03 11:29:45 +02:00
|
|
|
fp.setHeight((modalHeight - 160) + "px");
|
2021-09-20 18:08:43 +02:00
|
|
|
rawUpdatePanel.add(fp);
|
2021-09-27 15:28:36 +02:00
|
|
|
|
2022-09-12 15:09:43 +02:00
|
|
|
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
|
|
public void execute() {
|
2021-09-22 11:38:52 +02:00
|
|
|
|
2022-09-12 15:09:43 +02:00
|
|
|
GeoPortalDataEntryApp.geoportalDataEntryService.getJSONDocumentInTheProject(
|
|
|
|
selectedProject.getProfileID(), selectedProject.getId(), new AsyncCallback<String>() {
|
2021-09-22 11:38:52 +02:00
|
|
|
|
|
|
|
@Override
|
2022-09-12 15:09:43 +02:00
|
|
|
public void onSuccess(String jsonData) {
|
2023-05-03 11:29:45 +02:00
|
|
|
hpLoader.clear();
|
2022-09-12 15:09:43 +02:00
|
|
|
GWT.log("Instance JSON Editor with: " + jsonData);
|
|
|
|
jsEditor = JSONEditorWrapper.init(fp.getElement().getId());
|
|
|
|
jsEditor.setName(selectedProject.getId());
|
|
|
|
jsEditor.set(jsonData);
|
|
|
|
|
|
|
|
new Timer() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
jsEditor.setMode("tree");
|
|
|
|
|
|
|
|
}
|
|
|
|
}.schedule(200);
|
2021-09-22 11:38:52 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-09-12 15:09:43 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2023-05-03 11:29:45 +02:00
|
|
|
rawUpdatePanel.clear();
|
|
|
|
Alert alert = new Alert(
|
|
|
|
"Sorry, I cannot show the source Project with id '" + selectedProject.getId()
|
|
|
|
+ "' Refresh an try again. Error: " + caught.getMessage(),
|
|
|
|
AlertType.ERROR);
|
|
|
|
alert.setClose(false);
|
|
|
|
rawUpdatePanel.add(alert);
|
2021-09-20 18:08:43 +02:00
|
|
|
|
2022-09-12 15:09:43 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|
2021-09-22 11:38:52 +02:00
|
|
|
|
2021-09-20 18:08:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind events.
|
|
|
|
*/
|
|
|
|
private void bindEvents() {
|
2021-11-26 16:05:05 +01:00
|
|
|
|
2021-09-22 11:38:52 +02:00
|
|
|
buttonJSONUpdate.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
rawUpdatePanel.getElement().addClassName("disable-div");
|
|
|
|
buttonJSONUpdate.setEnabled(false);
|
|
|
|
final LoaderIcon loader = new LoaderIcon("Updating the project...");
|
|
|
|
tabRawUpdate.add(loader);
|
2022-09-14 10:12:07 +02:00
|
|
|
GeoPortalDataEntryApp.geoportalDataEntryService.updateRecord(selectedProject.getProfileID(),
|
|
|
|
selectedProject.getId(), jsEditor.getText(), new AsyncCallback<ProjectDV>() {
|
2022-09-12 15:09:43 +02:00
|
|
|
|
2022-09-14 10:12:07 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
buttonJSONUpdate.setEnabled(true);
|
|
|
|
try {
|
|
|
|
rawUpdatePanel.getElement().removeClassName("disable-div");
|
|
|
|
tabRawUpdate.remove(loader);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO: handle exception
|
|
|
|
}
|
2022-09-14 10:21:13 +02:00
|
|
|
|
|
|
|
editorManagerBus.fireEvent(new OperationPerformedOnItemEvent<ResultDocumentDV>(
|
|
|
|
selectedProject.getProfileID(), Arrays.asList(selectedProject),
|
|
|
|
ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
|
2021-09-22 11:38:52 +02:00
|
|
|
|
2022-09-14 10:12:07 +02:00
|
|
|
}
|
2021-11-26 16:05:05 +01:00
|
|
|
|
2022-09-14 10:12:07 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(ProjectDV result) {
|
|
|
|
buttonJSONUpdate.setEnabled(true);
|
|
|
|
try {
|
|
|
|
rawUpdatePanel.getElement().removeClassName("disable-div");
|
|
|
|
tabRawUpdate.remove(loader);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO: handle exception
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogInform di = new DialogInform(null, "Project updated!",
|
|
|
|
"Project ID '" + result.getId() + "' updated correctly");
|
|
|
|
di.setZIndex(100000);
|
|
|
|
di.center();
|
2022-09-14 10:21:13 +02:00
|
|
|
|
|
|
|
editorManagerBus.fireEvent(new OperationPerformedOnItemEvent<ResultDocumentDV>(
|
|
|
|
selectedProject.getProfileID(), Arrays.asList(selectedProject),
|
|
|
|
ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
|
2021-10-06 16:01:39 +02:00
|
|
|
|
2022-09-14 10:12:07 +02:00
|
|
|
}
|
|
|
|
});
|
2021-11-26 16:05:05 +01:00
|
|
|
|
2021-10-06 16:01:39 +02:00
|
|
|
}
|
|
|
|
});
|
2022-09-14 10:12:07 +02:00
|
|
|
|
2022-09-14 10:21:13 +02:00
|
|
|
editorManagerBus.addHandler(OperationPerformedOnItemEvent.TYPE, new OperationPerformedOnItemEventHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <T extends DocumentDV> void onDoActionPerformedFired(
|
|
|
|
OperationPerformedOnItemEvent<T> actionPerformedOnItemEvent) {
|
|
|
|
ACTION_PERFORMED_ON_ITEM action = actionPerformedOnItemEvent.getAction();
|
|
|
|
List<T> items = actionPerformedOnItemEvent.getSelectItems();
|
|
|
|
|
|
|
|
if (items != null) {
|
|
|
|
instanceJSONEditor();
|
|
|
|
|
2022-09-14 10:38:17 +02:00
|
|
|
appManagerBus.fireEvent(new OperationPerformedOnItemEvent<ResultDocumentDV>(
|
2022-09-14 10:21:13 +02:00
|
|
|
selectedProject.getProfileID(), (List<ResultDocumentDV>) items, action));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2021-09-20 18:08:43 +02:00
|
|
|
}
|
|
|
|
}
|