2022-12-07 09:43:48 +01:00
|
|
|
package org.gcube.portlets.user.geoportaldataentry.client.ui.edit;
|
|
|
|
|
2022-12-12 17:28:44 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
|
2022-12-07 09:43:48 +01:00
|
|
|
import org.gcube.application.geoportaldatamapper.shared.MetaDataProfileBeanExt;
|
|
|
|
import org.gcube.application.geoportaldatamapper.shared.ProjectEdit;
|
2022-12-12 17:28:44 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp;
|
2022-12-07 09:43:48 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryServiceAsync;
|
2022-12-12 17:28:44 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardModel;
|
2022-12-07 09:43:48 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon;
|
2022-12-12 17:28:44 +01:00
|
|
|
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm.OPERATION;
|
2022-12-07 09:43:48 +01:00
|
|
|
|
|
|
|
import com.github.gwtbootstrap.client.ui.Alert;
|
|
|
|
import com.github.gwtbootstrap.client.ui.ControlGroup;
|
|
|
|
import com.github.gwtbootstrap.client.ui.ListBox;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
|
|
|
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.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.HTMLPanel;
|
2022-12-12 17:28:44 +01:00
|
|
|
import com.google.gwt.user.client.ui.ScrollPanel;
|
2022-12-07 09:43:48 +01:00
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
|
|
public class UpdateRecord extends Composite {
|
|
|
|
|
|
|
|
private static UpdateRecordUiBinder uiBinder = GWT.create(UpdateRecordUiBinder.class);
|
|
|
|
|
|
|
|
interface UpdateRecordUiBinder extends UiBinder<Widget, UpdateRecord> {
|
|
|
|
}
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
ListBox listBoxSections;
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
HTMLPanel htmlSectionContent;
|
2022-12-12 17:28:44 +01:00
|
|
|
|
|
|
|
@UiField
|
|
|
|
ScrollPanel scrollPanelContainer;
|
2022-12-07 09:43:48 +01:00
|
|
|
|
|
|
|
@UiField
|
|
|
|
HTMLPanel alertHTMLPanel;
|
2022-12-12 17:28:44 +01:00
|
|
|
|
2022-12-07 09:43:48 +01:00
|
|
|
@UiField
|
|
|
|
ControlGroup controlsControlGroup;
|
|
|
|
|
|
|
|
private LoaderIcon loaderProjectSections = new LoaderIcon("Loading Project sections..., please wait");
|
|
|
|
|
|
|
|
public UpdateRecord(HandlerManager editorManagerBus, String profileID, String projectID) {
|
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
|
2022-12-12 17:28:44 +01:00
|
|
|
scrollPanelContainer.setVisible(false);
|
|
|
|
|
2022-12-07 09:43:48 +01:00
|
|
|
alertHTMLPanel.add(loaderProjectSections);
|
|
|
|
|
|
|
|
GeoportalDataEntryServiceAsync.Util.getInstance().getProjectEdit(profileID, projectID,
|
|
|
|
new AsyncCallback<ProjectEdit>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(ProjectEdit result) {
|
2022-12-12 17:28:44 +01:00
|
|
|
scrollPanelContainer.setVisible(true);
|
2022-12-07 09:43:48 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
alertHTMLPanel.remove(loaderProjectSections);
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-12-12 17:28:44 +01:00
|
|
|
listBoxSections.addItem("Select section...", "Select section...");
|
|
|
|
|
2022-12-07 09:43:48 +01:00
|
|
|
for (final MetaDataProfileBeanExt profileBean : result.getTheProfileBeans()) {
|
|
|
|
listBoxSections.addItem(profileBean.getType(), profileBean.getType());
|
|
|
|
}
|
|
|
|
|
2022-12-12 17:28:44 +01:00
|
|
|
listBoxSections.addChangeHandler(new ChangeHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChange(ChangeEvent event) {
|
|
|
|
MetaDataProfileBeanExt selectedBean = result.getTheProfileBeans()
|
|
|
|
.get(listBoxSections.getSelectedIndex());
|
|
|
|
GWT.log("Change handler fired " + selectedBean);
|
|
|
|
controlsControlGroup.setVisible(true);
|
|
|
|
htmlSectionContent.clear();
|
|
|
|
|
|
|
|
GcubeProfileDV gcubeProfile = selectedBean.getGcubeProfileDV();
|
|
|
|
|
|
|
|
GeoNaFormCardModel formcard = GeoPortalDataEntryApp.buildNewFormCardModelFromProfile(gcubeProfile, 1, selectedBean, OPERATION.UPDATE, editorManagerBus);
|
|
|
|
htmlSectionContent.add(formcard.getMetadataForm());
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-12-07 09:43:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2022-12-12 17:28:44 +01:00
|
|
|
scrollPanelContainer.setVisible(true);
|
2022-12-07 09:43:48 +01:00
|
|
|
alertHTMLPanel.remove(loaderProjectSections);
|
|
|
|
|
|
|
|
String errorMsg = caught.getMessage();
|
|
|
|
Alert alert = new Alert(errorMsg, AlertType.ERROR);
|
|
|
|
alert.setClose(false);
|
|
|
|
try {
|
|
|
|
alertHTMLPanel.remove(loaderProjectSections);
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
alertHTMLPanel.add(alert);
|
|
|
|
Window.alert(errorMsg);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|