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;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.TreeMap;
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.form.generic.CreateMetadataForm;
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 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.
@ -56,16 +58,14 @@ public class GeoPortalDataEntryApp implements EntryPoint {
@Override
public void onSuccess(List<MetaDataProfileBean> result) {
orderedListMetadataProfilesForGeona = setGeoNaFormOrder(result);
Collection<GeoNaFormCardModel> orderedCards = setGeoNaFormsOrder(result);
for (MetaDataProfileBean metaDataProfileBean : orderedListMetadataProfilesForGeona) {
CreateMetadataForm baseForm = new CreateMetadataForm(Arrays.asList(metaDataProfileBean));
boolean repeatibleForm = false;
String theMetaType = metaDataProfileBean.getType().toLowerCase();
if(theMetaType.contains("immagin") || theMetaType.contains("fine scavo")) {
repeatibleForm = true;
}
geoNaMainForm.addForm(baseForm, metaDataProfileBean.getType(),repeatibleForm);
//ordered values
for (GeoNaFormCardModel geonaForm : orderedCards) {
CreateMetadataForm baseForm = new CreateMetadataForm(Arrays.asList(geonaForm.getMetadataProfileBean()));
geonaForm.setMetadataForm(baseForm);
mapForms.put(geonaForm.getFormCardTitle(), geonaForm);
geoNaMainForm.addForm(geonaForm);
}
}
@ -78,36 +78,39 @@ public class GeoPortalDataEntryApp implements EntryPoint {
}
private List<MetaDataProfileBean> setGeoNaFormOrder(List<MetaDataProfileBean> listMetadataProfilesForGeona) {
mapOrderedGeoNaProfiles.clear();
private Collection<GeoNaFormCardModel> setGeoNaFormsOrder(List<MetaDataProfileBean> listMetadataProfilesForGeona) {
TreeMap<Integer, GeoNaFormCardModel> treemapOrderedGeoNaProfiles = new TreeMap<Integer, GeoNaFormCardModel>();
for (MetaDataProfileBean metaDataProfileBean : listMetadataProfilesForGeona) {
String theMetaType = metaDataProfileBean.getType().toLowerCase();
GeoNaFormCardModel geonaForm = new GeoNaFormCardModel(metaDataProfileBean, null, null);
if(theMetaType.contains("relazione di scavo")) {
mapOrderedGeoNaProfiles.put(1, metaDataProfileBean);
}else if(theMetaType.contains("immagin")) {
mapOrderedGeoNaProfiles.put(2, metaDataProfileBean);
}else if(theMetaType.contains("posizionamento")) {
mapOrderedGeoNaProfiles.put(3, metaDataProfileBean);
}else if(theMetaType.contains("fine scavo")) {
mapOrderedGeoNaProfiles.put(4, metaDataProfileBean);
if(theMetaType.contains(ConcessioniFormCardTitle.INFORMAZIONE_DI_PROGETTO.getKey().toLowerCase())) {
geonaForm.setFormCardTitle(ConcessioniFormCardTitle.INFORMAZIONE_DI_PROGETTO);
treemapOrderedGeoNaProfiles.put(ConcessioniFormCardTitle.INFORMAZIONE_DI_PROGETTO.getOrder(), geonaForm);
}else if(theMetaType.contains(ConcessioniFormCardTitle.RELAZIONI_DI_SCAVO.getKey().toLowerCase())) {
geonaForm.setFormCardTitle(ConcessioniFormCardTitle.RELAZIONI_DI_SCAVO);
treemapOrderedGeoNaProfiles.put(ConcessioniFormCardTitle.RELAZIONI_DI_SCAVO.getOrder(), geonaForm);
}else if(theMetaType.contains(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE.getKey().toLowerCase())) {
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());
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;
GWT.log("Map size: "+treemapOrderedGeoNaProfiles.size());
return treemapOrderedGeoNaProfiles.values();
}

View File

@ -4,14 +4,13 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
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 com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.TabPane;
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.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
@ -24,6 +23,8 @@ public class GeonaDataEntryMainForm extends Composite {
interface GeonaDataEntryMainFormUiBinder extends UiBinder<Widget, GeonaDataEntryMainForm> {
}
List<GeoNaFormCardModel> listCards = new ArrayList<GeoNaFormCardModel>();
@UiField
HTMLPanel mainHTMLPanel;
@ -31,7 +32,7 @@ public class GeonaDataEntryMainForm extends Composite {
@UiField
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>();
@ -39,59 +40,27 @@ public class GeonaDataEntryMainForm extends Composite {
initWidget(uiBinder.createAndBindUi(this));
}
public void addForm(final CreateMetadataForm createMetadataForm, String tabHeading, boolean repeatible){
final TabPane tab = new TabPane();
//tab.setActive(false);
tab.setHeading(tabHeading);
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);
}
});
}
public void addForm(GeoNaFormCardModel geonFormModel){
listCards.add(geonFormModel);
addForm(geonFormModel.getMetadataForm(), geonFormModel.getMetadataProfileBean().getType(), geonFormModel.getFormCardTitle().isInternalRepeatibleForm());
}
tab.add(createMetadataForm);
mainTabPanel.add(tab);
private void addForm(final CreateMetadataForm createMetadataForm, String tabHeading, boolean repeatible){
final TabPane tab = new TabPane();
tab.setHeading(tabHeading);
MetadataFormCard mfc = new MetadataFormCard(tab, createMetadataForm, repeatible);
listTabs.add(tab);
mainTabPanel.add(tab);
if(listTabs.size()==1) {
tab.setActive(true);
mainTabPanel.selectTab(0);
}
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);
mapForms.put(tabHeading, mfc);
}
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){

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;
}
}