updated valid form events

This commit is contained in:
francesco 2020-10-12 16:46:17 +02:00
parent 6db78bb549
commit ccde169dfb
4 changed files with 96 additions and 36 deletions

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.user.geoportaldataentry.client;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
@ -40,7 +41,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
private final HandlerManager eventBus = new HandlerManager(null);
private LinkedHashMap<ConcessioniFormCardTitle, GeoNaFormCardModel> mapForms = new LinkedHashMap<ConcessioniFormCardTitle, GeoNaFormCardModel>();
private LinkedHashMap<String, GeoNaFormCardModel> mapForms = new LinkedHashMap<String, GeoNaFormCardModel>();
//private List<MetaDataProfileBean> orderedListMetadataProfilesForGeona = null;
@ -64,8 +65,14 @@ public class GeoPortalDataEntryApp implements EntryPoint {
for (GeoNaFormCardModel geonaForm : orderedCards) {
CreateMetadataForm baseForm = new CreateMetadataForm(Arrays.asList(geonaForm.getMetadataProfileBean()));
geonaForm.setMetadataForm(baseForm);
mapForms.put(geonaForm.getFormCardTitle(), geonaForm);
geoNaMainForm.addForm(geonaForm);
String key = geonaForm.getMetadataProfileBean().getType();
boolean isFormRepeatible = false;
if(geonaForm.getFormCardTitle()!=null) {
key = geonaForm.getFormCardTitle().getTitle();
isFormRepeatible = geonaForm.getFormCardTitle().isInternalRepeatibleForm();
}
geoNaMainForm.addForm(geonaForm,isFormRepeatible);
mapForms.put(key, geonaForm);
}
}
@ -81,6 +88,8 @@ public class GeoPortalDataEntryApp implements EntryPoint {
private Collection<GeoNaFormCardModel> setGeoNaFormsOrder(List<MetaDataProfileBean> listMetadataProfilesForGeona) {
TreeMap<Integer, GeoNaFormCardModel> treemapOrderedGeoNaProfiles = new TreeMap<Integer, GeoNaFormCardModel>();
List<GeoNaFormCardModel> listUnknownType = new ArrayList<GeoNaFormCardModel>();
for (MetaDataProfileBean metaDataProfileBean : listMetadataProfilesForGeona) {
@ -103,12 +112,18 @@ public class GeoPortalDataEntryApp implements EntryPoint {
geonaForm.setFormCardTitle(ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO);
treemapOrderedGeoNaProfiles.put(ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO.getOrder(), geonaForm);
}else {
Integer highestKey = treemapOrderedGeoNaProfiles.lastKey();
highestKey = highestKey+1;
treemapOrderedGeoNaProfiles.put(highestKey, geonaForm);
//adding to unknown list
listUnknownType.add(geonaForm);
}
}
//adding unknown types
for (GeoNaFormCardModel geoNaFormCardModel : listUnknownType) {
Integer highestKey = treemapOrderedGeoNaProfiles.lastKey();
highestKey++;
treemapOrderedGeoNaProfiles.put(highestKey, geoNaFormCardModel);
}
GWT.log("Map size: "+treemapOrderedGeoNaProfiles.size());
return treemapOrderedGeoNaProfiles.values();

View File

@ -8,11 +8,13 @@ import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardMo
import org.gcube.portlets.user.geoportaldataentry.client.ui.card.MetadataFormCard;
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm;
import com.github.gwtbootstrap.client.ui.TabPane;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
@ -24,7 +26,7 @@ public class GeonaDataEntryMainForm extends Composite {
interface GeonaDataEntryMainFormUiBinder extends UiBinder<Widget, GeonaDataEntryMainForm> {
}
List<GeoNaFormCardModel> listCards = new ArrayList<GeoNaFormCardModel>();
private List<GeoNaFormCardModel> listCards = new ArrayList<GeoNaFormCardModel>();
@UiField
HTMLPanel mainHTMLPanel;
@ -34,20 +36,20 @@ public class GeonaDataEntryMainForm extends Composite {
private LinkedHashMap<String,MetadataFormCard> mapForms = new LinkedHashMap<String,MetadataFormCard>();
private List<TabPane> listTabs = new ArrayList<TabPane>();
private List<Tab> listTabs = new ArrayList<Tab>();
public GeonaDataEntryMainForm() {
initWidget(uiBinder.createAndBindUi(this));
}
public void addForm(GeoNaFormCardModel geonFormModel){
public void addForm(GeoNaFormCardModel geonFormModel, boolean isFormRepeatible){
listCards.add(geonFormModel);
addForm(geonFormModel.getMetadataForm(), geonFormModel.getMetadataProfileBean().getType(), geonFormModel.getFormCardTitle().isInternalRepeatibleForm());
addForm(geonFormModel.getMetadataForm(), geonFormModel.getMetadataProfileBean().getType(), isFormRepeatible);
}
private void addForm(final CreateMetadataForm createMetadataForm, String tabHeading, boolean repeatible){
final TabPane tab = new TabPane();
final Tab tab = new Tab();
tab.setHeading(tabHeading);
MetadataFormCard mfc = new MetadataFormCard(tab, createMetadataForm, repeatible);
listTabs.add(tab);
@ -72,6 +74,17 @@ public class GeonaDataEntryMainForm extends Composite {
}
}
@UiHandler("buttonSave")
void saveData(ClickEvent e){
for (String metadataType : mapForms.keySet()) {
MetadataFormCard card = mapForms.get(metadataType);
boolean isValid = card.validateForm();
card.setValidCard(isValid);
}
}
/**
* Sets the ative after.

View File

@ -8,7 +8,7 @@ public class GeoNaFormCardModel {
private MetaDataProfileBean metadataProfileBean;
private CreateMetadataForm metadataForm;
private ConcessioniFormCardTitle formCardTitle;
private ConcessioniFormCardTitle formCardTitle; //matching with metadata profile type
public GeoNaFormCardModel() {

View File

@ -8,22 +8,54 @@ import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.GenericFormE
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.TabPane;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
public class MetadataFormCard implements GenericFormEventsListener{
public class MetadataFormCard {
private String heading;
private TabPane tab;
private Tab tab;
private boolean repeatible;
private List<CreateMetadataForm> listForms = new ArrayList<CreateMetadataForm>();
public MetadataFormCard(TabPane tab, CreateMetadataForm createMetadataForm, boolean repeatible) {
private MetadataFormCardEventHandler formCardEventHandler = new MetadataFormCardEventHandler();
private class MetadataFormCardEventHandler implements GenericFormEventsListener{
@Override
public void onFormDataValid(GenericDatasetBean genericDatasetBean) {
setTabStatus();
}
@Override
public void onFormDataEdit() {
resetTabStatus();
}
@Override
public void onFormAborted() {
// TODO Auto-generated method stub
}
@Override
public void onValidationError(Throwable throwable, String errorMsg) {
// TODO Auto-generated method stub
}
}
public MetadataFormCard(Tab tab, CreateMetadataForm createMetadataForm, boolean repeatible) {
this.tab = tab;
this.repeatible = repeatible;
this.buildCard(createMetadataForm);
createMetadataForm.addListener(formCardEventHandler);
}
private void buildCard(final CreateMetadataForm createMetadataForm) {
@ -46,7 +78,6 @@ public class MetadataFormCard implements GenericFormEventsListener{
}
private void addNewForm(final CreateMetadataForm newForm) {
newForm.addListener(this);
tab.add(newForm);
listForms.add(newForm);
@ -72,24 +103,6 @@ public class MetadataFormCard implements GenericFormEventsListener{
return listForms;
}
@Override
public void onFormDataValid(GenericDatasetBean genericDatasetBean) {
// TODO Auto-generated method stub
}
@Override
public void onAbortedForm() {
// TODO Auto-generated method stub
}
@Override
public void onValidationError(Throwable throwable, String errorMsg) {
// TODO Auto-generated method stub
}
public String getHeading() {
return heading;
}
@ -108,4 +121,23 @@ public class MetadataFormCard implements GenericFormEventsListener{
return true;
}
public void setValidCard(boolean bool) {
if(bool)
tab.setIcon(IconType.OK_SIGN);
else
tab.setIcon(IconType.REMOVE_SIGN);
}
private void setTabStatus() {
boolean isValid = validateForm();
if(isValid)
tab.setIcon(IconType.OK_SIGN);
else
tab.setIcon(IconType.REMOVE_SIGN);
}
private void resetTabStatus() {
tab.setIcon(null);
}
}