127 lines
4.3 KiB
Java
127 lines
4.3 KiB
Java
package org.gcube.portlets.user.geoportaldataentry.client.ui.edit;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
|
|
import org.gcube.application.geoportaldatamapper.shared.MetaDataProfileBeanExt;
|
|
import org.gcube.application.geoportaldatamapper.shared.ProjectEdit;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryServiceAsync;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardModel;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon;
|
|
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm.OPERATION;
|
|
|
|
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;
|
|
import com.google.gwt.user.client.ui.ScrollPanel;
|
|
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
|
|
ScrollPanel scrollSectionContent;
|
|
|
|
@UiField
|
|
HTMLPanel htmlPanelContainer;
|
|
|
|
@UiField
|
|
HTMLPanel alertHTMLPanel;
|
|
|
|
@UiField
|
|
ControlGroup controlsControlGroup;
|
|
|
|
public static final String PLACEHOLDER_LIST_BOX = "Select section...";
|
|
|
|
private LoaderIcon loaderProjectSections = new LoaderIcon("Loading Project sections..., please wait");
|
|
|
|
public UpdateRecord(HandlerManager editorManagerBus, String profileID, String projectID) {
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
htmlPanelContainer.setVisible(false);
|
|
|
|
alertHTMLPanel.add(loaderProjectSections);
|
|
|
|
scrollSectionContent.getElement().getStyle().setProperty("maxHeight", "500px");
|
|
|
|
GeoportalDataEntryServiceAsync.Util.getInstance().getProjectEdit(profileID, projectID,
|
|
new AsyncCallback<ProjectEdit>() {
|
|
|
|
@Override
|
|
public void onSuccess(ProjectEdit result) {
|
|
htmlPanelContainer.setVisible(true);
|
|
|
|
try {
|
|
alertHTMLPanel.remove(loaderProjectSections);
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
listBoxSections.addItem(PLACEHOLDER_LIST_BOX, PLACEHOLDER_LIST_BOX);
|
|
|
|
for (final MetaDataProfileBeanExt profileBean : result.getTheProfileBeans()) {
|
|
listBoxSections.addItem(profileBean.getType(), profileBean.getType());
|
|
}
|
|
|
|
listBoxSections.addChangeHandler(new ChangeHandler() {
|
|
|
|
@Override
|
|
public void onChange(ChangeEvent event) {
|
|
MetaDataProfileBeanExt selectedBean = result.getTheProfileBeans()
|
|
.get(listBoxSections.getSelectedIndex() - 1); // -1 because the first element is
|
|
// the PLACEHOLDER "Select
|
|
// section..."
|
|
GWT.log("Change handler fired " + selectedBean);
|
|
controlsControlGroup.setVisible(true);
|
|
scrollSectionContent.clear();
|
|
|
|
GcubeProfileDV gcubeProfile = selectedBean.getGcubeProfileDV();
|
|
|
|
GeoNaFormCardModel formcard = GeoPortalDataEntryApp.buildNewFormCardModelFromProfile(
|
|
gcubeProfile, 1, selectedBean, OPERATION.UPDATE, editorManagerBus);
|
|
scrollSectionContent.add(formcard.getMetadataForm());
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
htmlPanelContainer.setVisible(true);
|
|
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);
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|