2020-10-08 16:06:58 +02:00
|
|
|
package org.gcube.portlets.user.geoportaldataentry.client.ui;
|
|
|
|
|
2020-10-09 16:34:23 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
|
2020-10-20 09:58:56 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.SaveGeonaDataFormsEvent;
|
2020-10-12 13:04:01 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardModel;
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.card.MetadataFormCard;
|
2020-10-12 17:42:55 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
2020-10-09 16:34:23 +02:00
|
|
|
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm;
|
2020-10-12 17:42:55 +02:00
|
|
|
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
|
2020-10-09 16:34:23 +02:00
|
|
|
|
2020-10-13 11:52:50 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.AlertBlock;
|
2020-10-21 16:16:53 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
2020-10-12 16:46:17 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Tab;
|
2020-10-09 16:34:23 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.TabPanel;
|
2020-10-13 11:52:50 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
2020-10-08 16:06:58 +02:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2020-10-12 16:46:17 +02:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
2020-10-20 09:58:56 +02:00
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
2020-10-08 16:06:58 +02:00
|
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
|
import com.google.gwt.uibinder.client.UiField;
|
2020-10-12 16:46:17 +02:00
|
|
|
import com.google.gwt.uibinder.client.UiHandler;
|
2020-10-13 11:52:50 +02:00
|
|
|
import com.google.gwt.user.client.Timer;
|
2020-10-08 16:06:58 +02:00
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
|
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
|
|
public class GeonaDataEntryMainForm extends Composite {
|
|
|
|
|
|
|
|
private static GeonaDataEntryMainFormUiBinder uiBinder = GWT.create(GeonaDataEntryMainFormUiBinder.class);
|
|
|
|
|
|
|
|
interface GeonaDataEntryMainFormUiBinder extends UiBinder<Widget, GeonaDataEntryMainForm> {
|
|
|
|
}
|
2020-10-12 13:04:01 +02:00
|
|
|
|
2020-10-12 16:46:17 +02:00
|
|
|
private List<GeoNaFormCardModel> listCards = new ArrayList<GeoNaFormCardModel>();
|
2020-10-08 16:06:58 +02:00
|
|
|
|
|
|
|
@UiField
|
2020-10-09 16:34:23 +02:00
|
|
|
HTMLPanel mainHTMLPanel;
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
TabPanel mainTabPanel;
|
|
|
|
|
2020-10-13 11:52:50 +02:00
|
|
|
@UiField
|
|
|
|
AlertBlock alertFormAction;
|
|
|
|
|
2020-10-21 16:16:53 +02:00
|
|
|
@UiField
|
|
|
|
Button buttonSave;
|
|
|
|
|
2020-10-12 13:04:01 +02:00
|
|
|
private LinkedHashMap<String,MetadataFormCard> mapForms = new LinkedHashMap<String,MetadataFormCard>();
|
2020-10-09 16:34:23 +02:00
|
|
|
|
2020-10-12 16:46:17 +02:00
|
|
|
private List<Tab> listTabs = new ArrayList<Tab>();
|
2020-10-08 16:06:58 +02:00
|
|
|
|
2020-10-20 09:58:56 +02:00
|
|
|
private HandlerManager appManagerBus;
|
|
|
|
|
|
|
|
public GeonaDataEntryMainForm(HandlerManager appManagerBus) {
|
2020-10-08 16:06:58 +02:00
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
2020-10-20 09:58:56 +02:00
|
|
|
this.appManagerBus = appManagerBus;
|
2020-10-08 16:06:58 +02:00
|
|
|
}
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
public void addForm(String tabHeading, GeoNaFormCardModel geonFormModel){
|
2020-10-12 13:04:01 +02:00
|
|
|
listCards.add(geonFormModel);
|
2020-10-12 17:42:55 +02:00
|
|
|
createNewCard(tabHeading, geonFormModel);
|
2020-10-12 13:04:01 +02:00
|
|
|
}
|
|
|
|
|
2020-10-09 16:34:23 +02:00
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
private void createNewCard(String tabHeading, final GeoNaFormCardModel geonFormModel){
|
2020-10-12 16:46:17 +02:00
|
|
|
final Tab tab = new Tab();
|
2020-10-09 16:34:23 +02:00
|
|
|
tab.setHeading(tabHeading);
|
2020-10-12 17:42:55 +02:00
|
|
|
//MetadataFormCard mfc = new MetadataFormCard(tab, createMetadataForm, repeatible);
|
2020-10-20 09:58:56 +02:00
|
|
|
MetadataFormCard mfc = new MetadataFormCard(tab,geonFormModel,appManagerBus);
|
2020-10-09 16:34:23 +02:00
|
|
|
listTabs.add(tab);
|
2020-10-12 13:04:01 +02:00
|
|
|
mainTabPanel.add(tab);
|
2020-10-09 16:34:23 +02:00
|
|
|
|
|
|
|
if(listTabs.size()==1) {
|
|
|
|
tab.setActive(true);
|
|
|
|
mainTabPanel.selectTab(0);
|
|
|
|
}
|
|
|
|
|
2020-10-12 13:04:01 +02:00
|
|
|
mapForms.put(tabHeading, mfc);
|
2020-10-09 16:34:23 +02:00
|
|
|
}
|
|
|
|
|
2020-10-20 09:58:56 +02:00
|
|
|
public void reset() {
|
|
|
|
mapForms.clear();
|
|
|
|
mainTabPanel.clear();
|
|
|
|
listTabs.clear();
|
|
|
|
}
|
|
|
|
|
2020-10-09 16:34:23 +02:00
|
|
|
|
|
|
|
public void selectTab(int index){
|
|
|
|
|
|
|
|
GWT.log("Selecting tab index: "+ index +" of "+listTabs.size());
|
|
|
|
|
|
|
|
if(listTabs.size()<index) {
|
|
|
|
mainTabPanel.selectTab(index);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-12 16:46:17 +02:00
|
|
|
@UiHandler("buttonSave")
|
|
|
|
void saveData(ClickEvent e){
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
boolean canSave = true;
|
|
|
|
|
2020-10-12 16:46:17 +02:00
|
|
|
for (String metadataType : mapForms.keySet()) {
|
|
|
|
MetadataFormCard card = mapForms.get(metadataType);
|
|
|
|
boolean isValid = card.validateForm();
|
|
|
|
card.setValidCard(isValid);
|
2020-10-12 17:42:55 +02:00
|
|
|
if(isValid==false)
|
|
|
|
canSave = false;
|
2020-10-12 16:46:17 +02:00
|
|
|
}
|
|
|
|
|
2020-10-20 09:58:56 +02:00
|
|
|
List<GeoNaFormDataObject> listGeonaFormObjects = new ArrayList<GeoNaFormDataObject>();
|
2020-10-12 17:42:55 +02:00
|
|
|
|
|
|
|
if(canSave) {
|
|
|
|
for (String metadataType : mapForms.keySet()) {
|
|
|
|
MetadataFormCard card = mapForms.get(metadataType);
|
|
|
|
List<GenericDatasetBean> listGDB = new ArrayList<GenericDatasetBean>(card.getListForms().size());
|
|
|
|
for (CreateMetadataForm form : card.getListForms()) {
|
|
|
|
listGDB.add(form.getFormDataBean());
|
|
|
|
|
|
|
|
}
|
2020-10-20 09:58:56 +02:00
|
|
|
listGeonaFormObjects.add(new GeoNaFormDataObject(listGDB, card.getGeonaFormModel().getFormCardTitle()));
|
2020-10-12 17:42:55 +02:00
|
|
|
}
|
2020-10-20 09:58:56 +02:00
|
|
|
appManagerBus.fireEvent(new SaveGeonaDataFormsEvent(listGeonaFormObjects));
|
2020-10-13 11:52:50 +02:00
|
|
|
}else {
|
|
|
|
showAlertOnSaveAction("Detected errors, please fix it/them", AlertType.ERROR, true);
|
2020-10-12 17:42:55 +02:00
|
|
|
}
|
2020-10-13 11:52:50 +02:00
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
|
2020-10-20 15:25:26 +02:00
|
|
|
//Window.alert("I can save: "+listGeonaFormObjects);
|
2020-10-13 11:52:50 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-09 11:08:15 +01:00
|
|
|
public void showAlertOnSaveAction(String text, AlertType type, boolean hideAfterAWhile){
|
2020-10-12 17:42:55 +02:00
|
|
|
|
2020-10-13 11:52:50 +02:00
|
|
|
//Window.alert("Called alertOnCreate");
|
|
|
|
alertFormAction.setText(text);
|
|
|
|
alertFormAction.setType(type);
|
|
|
|
alertFormAction.setVisible(true);
|
|
|
|
//goBackButtonSecondStep.setEnabled(true);
|
|
|
|
|
|
|
|
if(hideAfterAWhile){
|
|
|
|
// hide after some seconds
|
|
|
|
Timer t = new Timer() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
alertFormAction.setVisible(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
t.schedule(10000);
|
|
|
|
}
|
2020-10-12 16:46:17 +02:00
|
|
|
}
|
|
|
|
|
2020-10-21 16:16:53 +02:00
|
|
|
public void enableButtonSave(boolean enabled) {
|
|
|
|
buttonSave.setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2020-10-09 16:34:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the ative after.
|
|
|
|
*
|
|
|
|
* @param index the index
|
|
|
|
* @param bool the bool
|
|
|
|
*/
|
|
|
|
public void setAtiveAfter(int index, boolean bool){
|
|
|
|
|
|
|
|
// if(listTabs.size()<index) {
|
|
|
|
// for (int i = index; i < listTabs.size(); i++) {
|
|
|
|
// listTabs.get(i).setEnabled(bool);
|
|
|
|
// }
|
|
|
|
// }
|
2020-10-08 16:06:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|