added geona cards

This commit is contained in:
francesco 2020-10-12 13:04:01 +02:00
parent c384e9cc3c
commit 6db78bb549
5 changed files with 259 additions and 81 deletions

View File

@ -0,0 +1,40 @@
package org.gcube.portlets.user.geoportaldataentry.client;
public enum ConcessioniFormCardTitle {
INFORMAZIONE_DI_PROGETTO("Informazioni", "Informazioni di Progetto", 1, false),
RELAZIONI_DI_SCAVO("Relazione di Scavo", "Relazioni di Scavo", 2, false),
IMMAGINI_RAPPRESENTATIVE("Immagini Rappresentative", "Immagini Rappresentative", 3, true),
POSIZIONAMENTO_DELL_AREA_DI_INDAGINE("Posizionamento", "Posizionamento dell'Area di Indagine", 4, false),
PIANTA_DI_FINE_SCAVO("Pianta di Fine Scavo", "Pianta di Fine Scavo", 5, true);
private String key;
private String title;
private Integer order;
private boolean internalRepeatibleForm;
private ConcessioniFormCardTitle(String key, String title, int order, boolean internalRepeatibleForm) {
this.key = key;
this.title = title;
this.order = order;
this.internalRepeatibleForm = internalRepeatibleForm;
}
public String getKey() {
return key;
}
public String getTitle() {
return title;
}
public Integer getOrder() {
return order;
}
public boolean isInternalRepeatibleForm() {
return internalRepeatibleForm;
}
}

View File

@ -1,11 +1,13 @@
package org.gcube.portlets.user.geoportaldataentry.client; package org.gcube.portlets.user.geoportaldataentry.client;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.TreeMap; import java.util.TreeMap;
import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaDataEntryMainForm; import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaDataEntryMainForm;
import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardModel;
import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderServiceAsync; import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderServiceAsync;
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm; import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
@ -38,9 +40,9 @@ public class GeoPortalDataEntryApp implements EntryPoint {
private final HandlerManager eventBus = new HandlerManager(null); private final HandlerManager eventBus = new HandlerManager(null);
private TreeMap<Integer, MetaDataProfileBean> mapOrderedGeoNaProfiles = new TreeMap<Integer, MetaDataProfileBean>(); private LinkedHashMap<ConcessioniFormCardTitle, GeoNaFormCardModel> mapForms = new LinkedHashMap<ConcessioniFormCardTitle, GeoNaFormCardModel>();
private List<MetaDataProfileBean> orderedListMetadataProfilesForGeona = null; //private List<MetaDataProfileBean> orderedListMetadataProfilesForGeona = null;
/** /**
* This is the entry point method. * This is the entry point method.
@ -56,16 +58,14 @@ public class GeoPortalDataEntryApp implements EntryPoint {
@Override @Override
public void onSuccess(List<MetaDataProfileBean> result) { public void onSuccess(List<MetaDataProfileBean> result) {
orderedListMetadataProfilesForGeona = setGeoNaFormOrder(result); Collection<GeoNaFormCardModel> orderedCards = setGeoNaFormsOrder(result);
for (MetaDataProfileBean metaDataProfileBean : orderedListMetadataProfilesForGeona) { //ordered values
CreateMetadataForm baseForm = new CreateMetadataForm(Arrays.asList(metaDataProfileBean)); for (GeoNaFormCardModel geonaForm : orderedCards) {
boolean repeatibleForm = false; CreateMetadataForm baseForm = new CreateMetadataForm(Arrays.asList(geonaForm.getMetadataProfileBean()));
String theMetaType = metaDataProfileBean.getType().toLowerCase(); geonaForm.setMetadataForm(baseForm);
if(theMetaType.contains("immagin") || theMetaType.contains("fine scavo")) { mapForms.put(geonaForm.getFormCardTitle(), geonaForm);
repeatibleForm = true; geoNaMainForm.addForm(geonaForm);
}
geoNaMainForm.addForm(baseForm, metaDataProfileBean.getType(),repeatibleForm);
} }
} }
@ -78,36 +78,39 @@ public class GeoPortalDataEntryApp implements EntryPoint {
} }
private List<MetaDataProfileBean> setGeoNaFormOrder(List<MetaDataProfileBean> listMetadataProfilesForGeona) { private Collection<GeoNaFormCardModel> setGeoNaFormsOrder(List<MetaDataProfileBean> listMetadataProfilesForGeona) {
mapOrderedGeoNaProfiles.clear(); TreeMap<Integer, GeoNaFormCardModel> treemapOrderedGeoNaProfiles = new TreeMap<Integer, GeoNaFormCardModel>();
for (MetaDataProfileBean metaDataProfileBean : listMetadataProfilesForGeona) { for (MetaDataProfileBean metaDataProfileBean : listMetadataProfilesForGeona) {
String theMetaType = metaDataProfileBean.getType().toLowerCase(); String theMetaType = metaDataProfileBean.getType().toLowerCase();
GeoNaFormCardModel geonaForm = new GeoNaFormCardModel(metaDataProfileBean, null, null);
if(theMetaType.contains("relazione di scavo")) { if(theMetaType.contains(ConcessioniFormCardTitle.INFORMAZIONE_DI_PROGETTO.getKey().toLowerCase())) {
mapOrderedGeoNaProfiles.put(1, metaDataProfileBean); geonaForm.setFormCardTitle(ConcessioniFormCardTitle.INFORMAZIONE_DI_PROGETTO);
}else if(theMetaType.contains("immagin")) { treemapOrderedGeoNaProfiles.put(ConcessioniFormCardTitle.INFORMAZIONE_DI_PROGETTO.getOrder(), geonaForm);
mapOrderedGeoNaProfiles.put(2, metaDataProfileBean); }else if(theMetaType.contains(ConcessioniFormCardTitle.RELAZIONI_DI_SCAVO.getKey().toLowerCase())) {
}else if(theMetaType.contains("posizionamento")) { geonaForm.setFormCardTitle(ConcessioniFormCardTitle.RELAZIONI_DI_SCAVO);
mapOrderedGeoNaProfiles.put(3, metaDataProfileBean); treemapOrderedGeoNaProfiles.put(ConcessioniFormCardTitle.RELAZIONI_DI_SCAVO.getOrder(), geonaForm);
}else if(theMetaType.contains("fine scavo")) { }else if(theMetaType.contains(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE.getKey().toLowerCase())) {
mapOrderedGeoNaProfiles.put(4, metaDataProfileBean); geonaForm.setFormCardTitle(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE);
treemapOrderedGeoNaProfiles.put(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE.getOrder(), geonaForm);
}else if(theMetaType.contains(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE.getKey().toLowerCase())) {
geonaForm.setFormCardTitle(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE);
treemapOrderedGeoNaProfiles.put(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE.getOrder(), geonaForm);
}else if(theMetaType.contains(ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO.getKey().toLowerCase())) {
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);
} }
} }
GWT.log("Map size: "+mapOrderedGeoNaProfiles.size()); GWT.log("Map size: "+treemapOrderedGeoNaProfiles.size());
return treemapOrderedGeoNaProfiles.values();
List<MetaDataProfileBean> orderedList = new ArrayList<MetaDataProfileBean>(mapOrderedGeoNaProfiles.size());
orderedList.addAll(mapOrderedGeoNaProfiles.values());
GWT.log("List ordered size: "+orderedList.size());
for (MetaDataProfileBean metaDataProfileBean : orderedList) {
GWT.log("Title: "+metaDataProfileBean.getTitle() + ", type: "+metaDataProfileBean.getType());
}
return orderedList;
} }

View File

@ -4,14 +4,13 @@ import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardModel;
import org.gcube.portlets.user.geoportaldataentry.client.ui.card.MetadataFormCard;
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm; import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.TabPane; import com.github.gwtbootstrap.client.ui.TabPane;
import com.github.gwtbootstrap.client.ui.TabPanel; import com.github.gwtbootstrap.client.ui.TabPanel;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
@ -25,13 +24,15 @@ public class GeonaDataEntryMainForm extends Composite {
interface GeonaDataEntryMainFormUiBinder extends UiBinder<Widget, GeonaDataEntryMainForm> { interface GeonaDataEntryMainFormUiBinder extends UiBinder<Widget, GeonaDataEntryMainForm> {
} }
List<GeoNaFormCardModel> listCards = new ArrayList<GeoNaFormCardModel>();
@UiField @UiField
HTMLPanel mainHTMLPanel; HTMLPanel mainHTMLPanel;
@UiField @UiField
TabPanel mainTabPanel; TabPanel mainTabPanel;
private LinkedHashMap<String,List<CreateMetadataForm>> mapForms = new LinkedHashMap<String,List<CreateMetadataForm>>(); private LinkedHashMap<String,MetadataFormCard> mapForms = new LinkedHashMap<String,MetadataFormCard>();
private List<TabPane> listTabs = new ArrayList<TabPane>(); private List<TabPane> listTabs = new ArrayList<TabPane>();
@ -39,59 +40,27 @@ public class GeonaDataEntryMainForm extends Composite {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
} }
public void addForm(GeoNaFormCardModel geonFormModel){
listCards.add(geonFormModel);
addForm(geonFormModel.getMetadataForm(), geonFormModel.getMetadataProfileBean().getType(), geonFormModel.getFormCardTitle().isInternalRepeatibleForm());
}
public void addForm(final CreateMetadataForm createMetadataForm, String tabHeading, boolean repeatible){
private void addForm(final CreateMetadataForm createMetadataForm, String tabHeading, boolean repeatible){
final TabPane tab = new TabPane(); final TabPane tab = new TabPane();
//tab.setActive(false);
tab.setHeading(tabHeading); tab.setHeading(tabHeading);
MetadataFormCard mfc = new MetadataFormCard(tab, createMetadataForm, repeatible);
if(repeatible) {
Button buttonAddNew = new Button("Add New...");
tab.add(buttonAddNew);
buttonAddNew.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
CreateMetadataForm newForm = new CreateMetadataForm(createMetadataForm.getMetadataProfiles());
tab.add(newForm);
indexingForms(newForm);
}
});
}
tab.add(createMetadataForm);
mainTabPanel.add(tab);
listTabs.add(tab); listTabs.add(tab);
mainTabPanel.add(tab);
if(listTabs.size()==1) { if(listTabs.size()==1) {
tab.setActive(true); tab.setActive(true);
mainTabPanel.selectTab(0); mainTabPanel.selectTab(0);
} }
mapForms.put(tabHeading, mfc);
String theMetadataType = createMetadataForm.getMetadataProfiles().get(0).getType();
List<CreateMetadataForm> listMF = mapForms.get(theMetadataType);
if(listMF==null) {
listMF = new ArrayList<CreateMetadataForm>();
}
listMF.add(createMetadataForm);
mapForms.put(theMetadataType, listMF);
indexingForms(createMetadataForm);
} }
private void indexingForms(CreateMetadataForm createMetadataForm) {
String theMetadataType = createMetadataForm.getMetadataProfiles().get(0).getType();
List<CreateMetadataForm> listMF = mapForms.get(theMetadataType);
if(listMF==null) {
listMF = new ArrayList<CreateMetadataForm>();
}
listMF.add(createMetadataForm);
mapForms.put(theMetadataType, listMF);
}
public void selectTab(int index){ public void selectTab(int index){

View File

@ -0,0 +1,55 @@
package org.gcube.portlets.user.geoportaldataentry.client.ui.card;
import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitle;
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
public class GeoNaFormCardModel {
private MetaDataProfileBean metadataProfileBean;
private CreateMetadataForm metadataForm;
private ConcessioniFormCardTitle formCardTitle;
public GeoNaFormCardModel() {
}
public GeoNaFormCardModel(MetaDataProfileBean metadataProfileBean, CreateMetadataForm metadataForm,
ConcessioniFormCardTitle formCardTitle) {
super();
this.metadataProfileBean = metadataProfileBean;
this.metadataForm = metadataForm;
this.formCardTitle = formCardTitle;
}
public MetaDataProfileBean getMetadataProfileBean() {
return metadataProfileBean;
}
public void setMetadataProfileBean(MetaDataProfileBean metadataProfileBean) {
this.metadataProfileBean = metadataProfileBean;
}
public CreateMetadataForm getMetadataForm() {
return metadataForm;
}
public void setMetadataForm(CreateMetadataForm metadataForm) {
this.metadataForm = metadataForm;
}
public ConcessioniFormCardTitle getFormCardTitle() {
return formCardTitle;
}
public void setFormCardTitle(ConcessioniFormCardTitle formCardTitle) {
this.formCardTitle = formCardTitle;
}
@Override
public String toString() {
return "GeoNaForm [metadataProfileBean=" + metadataProfileBean + ", metadataForm=" + metadataForm
+ ", formCardTitle=" + formCardTitle + "]";
}
}

View File

@ -0,0 +1,111 @@
package org.gcube.portlets.user.geoportaldataentry.client.ui.card;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm;
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.GenericFormEvents.GenericFormEventsListener;
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.constants.IconType;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
public class MetadataFormCard implements GenericFormEventsListener{
private String heading;
private TabPane tab;
private boolean repeatible;
private List<CreateMetadataForm> listForms = new ArrayList<CreateMetadataForm>();
public MetadataFormCard(TabPane tab, CreateMetadataForm createMetadataForm, boolean repeatible) {
this.tab = tab;
this.repeatible = repeatible;
this.buildCard(createMetadataForm);
}
private void buildCard(final CreateMetadataForm createMetadataForm) {
if(repeatible) {
Button buttonAddNew = new Button("Add New...");
tab.add(buttonAddNew);
buttonAddNew.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
CreateMetadataForm newForm = new CreateMetadataForm(createMetadataForm.getMetadataProfiles());
addNewForm(newForm);
}
});
}
addNewForm(createMetadataForm);
}
private void addNewForm(final CreateMetadataForm newForm) {
newForm.addListener(this);
tab.add(newForm);
listForms.add(newForm);
if(listForms.size()>1) {
final Button buttonRemoveLatestForm = new Button("Remove");
buttonRemoveLatestForm.setIcon(IconType.TRASH);
tab.add(buttonRemoveLatestForm);
buttonRemoveLatestForm.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
tab.remove(newForm);
listForms.remove(newForm);
tab.remove(buttonRemoveLatestForm);
}
});
}
}
public List<CreateMetadataForm> getListForms() {
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;
}
/**
* Validate form.
*
* @return true, if successful
*/
public boolean validateForm() {
for (CreateMetadataForm createMetadataForm : listForms) {
if(!createMetadataForm.isFormDataValid())
return false;
}
return true;
}
}