2020-10-12 13:04:01 +02:00
|
|
|
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;
|
2020-10-12 16:46:17 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Tab;
|
2020-10-12 13:04:01 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class MetadataFormCard.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
|
|
*
|
|
|
|
* Oct 12, 2020
|
|
|
|
*/
|
2020-10-12 16:46:17 +02:00
|
|
|
public class MetadataFormCard {
|
2020-10-12 13:04:01 +02:00
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/** The heading. */
|
2020-10-12 13:04:01 +02:00
|
|
|
private String heading;
|
2020-10-12 17:42:55 +02:00
|
|
|
|
|
|
|
/** The tab. */
|
2020-10-12 16:46:17 +02:00
|
|
|
private Tab tab;
|
2020-10-12 17:42:55 +02:00
|
|
|
|
|
|
|
/** The repeatible. */
|
2020-10-12 13:04:01 +02:00
|
|
|
private boolean repeatible;
|
2020-10-12 17:42:55 +02:00
|
|
|
|
|
|
|
/** The list forms. */
|
2020-10-12 13:04:01 +02:00
|
|
|
private List<CreateMetadataForm> listForms = new ArrayList<CreateMetadataForm>();
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/** The form card event handler. */
|
2020-10-12 16:46:17 +02:00
|
|
|
private MetadataFormCardEventHandler formCardEventHandler = new MetadataFormCardEventHandler();
|
2020-10-12 17:42:55 +02:00
|
|
|
|
|
|
|
/** The geona form model. */
|
|
|
|
private GeoNaFormCardModel geonaFormModel;
|
2020-10-12 16:46:17 +02:00
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/**
|
|
|
|
* The Class MetadataFormCardEventHandler.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
|
|
*
|
|
|
|
* Oct 12, 2020
|
|
|
|
*/
|
2020-10-12 16:46:17 +02:00
|
|
|
private class MetadataFormCardEventHandler implements GenericFormEventsListener{
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/**
|
|
|
|
* On form data valid.
|
|
|
|
*
|
|
|
|
* @param genericDatasetBean the generic dataset bean
|
|
|
|
*/
|
2020-10-12 16:46:17 +02:00
|
|
|
@Override
|
|
|
|
public void onFormDataValid(GenericDatasetBean genericDatasetBean) {
|
|
|
|
setTabStatus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/**
|
|
|
|
* On form data edit.
|
|
|
|
*/
|
2020-10-12 16:46:17 +02:00
|
|
|
@Override
|
|
|
|
public void onFormDataEdit() {
|
|
|
|
resetTabStatus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/**
|
|
|
|
* On form aborted.
|
|
|
|
*/
|
2020-10-12 16:46:17 +02:00
|
|
|
@Override
|
|
|
|
public void onFormAborted() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/**
|
|
|
|
* On validation error.
|
|
|
|
*
|
|
|
|
* @param throwable the throwable
|
|
|
|
* @param errorMsg the error msg
|
|
|
|
*/
|
2020-10-12 16:46:17 +02:00
|
|
|
@Override
|
|
|
|
public void onValidationError(Throwable throwable, String errorMsg) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/**
|
|
|
|
* Instantiates a new metadata form card.
|
|
|
|
*
|
|
|
|
* @param tab the tab
|
|
|
|
* @param geonaFormModel the geona form model
|
|
|
|
*/
|
|
|
|
public MetadataFormCard(Tab tab, GeoNaFormCardModel geonaFormModel) {
|
2020-10-12 13:04:01 +02:00
|
|
|
this.tab = tab;
|
2020-10-12 17:42:55 +02:00
|
|
|
this.geonaFormModel = geonaFormModel;
|
|
|
|
this.repeatible = geonaFormModel.getFormCardTitle().isInternalRepeatibleForm();
|
|
|
|
this.buildCard(geonaFormModel.getMetadataForm());
|
|
|
|
geonaFormModel.getMetadataForm().addListener(formCardEventHandler);
|
2020-10-12 13:04:01 +02:00
|
|
|
}
|
2020-10-12 17:42:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the card.
|
|
|
|
*
|
|
|
|
* @param createMetadataForm the create metadata form
|
|
|
|
*/
|
2020-10-12 13:04:01 +02:00
|
|
|
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);
|
2020-10-12 17:42:55 +02:00
|
|
|
//newForm.getCreateButton().setFocus(true);
|
2020-10-12 13:04:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addNewForm(createMetadataForm);
|
|
|
|
}
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/**
|
|
|
|
* Adds the new form.
|
|
|
|
*
|
|
|
|
* @param newForm the new form
|
|
|
|
*/
|
2020-10-12 13:04:01 +02:00
|
|
|
private void addNewForm(final CreateMetadataForm newForm) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/**
|
|
|
|
* Gets the list forms.
|
|
|
|
*
|
|
|
|
* @return the list forms
|
|
|
|
*/
|
2020-10-12 13:04:01 +02:00
|
|
|
public List<CreateMetadataForm> getListForms() {
|
|
|
|
return listForms;
|
|
|
|
}
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/**
|
|
|
|
* Gets the heading.
|
|
|
|
*
|
|
|
|
* @return the heading
|
|
|
|
*/
|
2020-10-12 13:04:01 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/**
|
|
|
|
* Sets the valid card.
|
|
|
|
*
|
|
|
|
* @param bool the new valid card
|
|
|
|
*/
|
2020-10-12 16:46:17 +02:00
|
|
|
public void setValidCard(boolean bool) {
|
|
|
|
if(bool)
|
|
|
|
tab.setIcon(IconType.OK_SIGN);
|
|
|
|
else
|
|
|
|
tab.setIcon(IconType.REMOVE_SIGN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/**
|
|
|
|
* Sets the tab status.
|
|
|
|
*/
|
2020-10-12 16:46:17 +02:00
|
|
|
private void setTabStatus() {
|
|
|
|
boolean isValid = validateForm();
|
|
|
|
if(isValid)
|
|
|
|
tab.setIcon(IconType.OK_SIGN);
|
|
|
|
else
|
2020-10-12 17:42:55 +02:00
|
|
|
tab.setIcon(IconType.MINUS_SIGN);
|
2020-10-12 16:46:17 +02:00
|
|
|
}
|
|
|
|
|
2020-10-12 17:42:55 +02:00
|
|
|
/**
|
|
|
|
* Reset tab status.
|
|
|
|
*/
|
2020-10-12 16:46:17 +02:00
|
|
|
private void resetTabStatus() {
|
|
|
|
tab.setIcon(null);
|
|
|
|
}
|
2020-10-12 17:42:55 +02:00
|
|
|
|
|
|
|
public GeoNaFormCardModel getGeonaFormModel() {
|
|
|
|
return geonaFormModel;
|
|
|
|
}
|
2020-10-12 13:04:01 +02:00
|
|
|
}
|