105 lines
2.9 KiB
Java
105 lines
2.9 KiB
Java
package org.gcube.portlets.user.geoportaldataentry.client.ui;
|
|
|
|
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.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;
|
|
|
|
public class GeonaDataEntryMainForm extends Composite {
|
|
|
|
private static GeonaDataEntryMainFormUiBinder uiBinder = GWT.create(GeonaDataEntryMainFormUiBinder.class);
|
|
|
|
interface GeonaDataEntryMainFormUiBinder extends UiBinder<Widget, GeonaDataEntryMainForm> {
|
|
}
|
|
|
|
private List<GeoNaFormCardModel> listCards = new ArrayList<GeoNaFormCardModel>();
|
|
|
|
@UiField
|
|
HTMLPanel mainHTMLPanel;
|
|
|
|
@UiField
|
|
TabPanel mainTabPanel;
|
|
|
|
private LinkedHashMap<String,MetadataFormCard> mapForms = new LinkedHashMap<String,MetadataFormCard>();
|
|
|
|
private List<Tab> listTabs = new ArrayList<Tab>();
|
|
|
|
public GeonaDataEntryMainForm() {
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
}
|
|
|
|
public void addForm(GeoNaFormCardModel geonFormModel, boolean isFormRepeatible){
|
|
listCards.add(geonFormModel);
|
|
addForm(geonFormModel.getMetadataForm(), geonFormModel.getMetadataProfileBean().getType(), isFormRepeatible);
|
|
}
|
|
|
|
|
|
private void addForm(final CreateMetadataForm createMetadataForm, String tabHeading, boolean repeatible){
|
|
final Tab tab = new Tab();
|
|
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);
|
|
}
|
|
|
|
mapForms.put(tabHeading, mfc);
|
|
}
|
|
|
|
|
|
public void selectTab(int index){
|
|
|
|
GWT.log("Selecting tab index: "+ index +" of "+listTabs.size());
|
|
|
|
if(listTabs.size()<index) {
|
|
mainTabPanel.selectTab(index);
|
|
|
|
}
|
|
}
|
|
|
|
@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.
|
|
*
|
|
* @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);
|
|
// }
|
|
// }
|
|
}
|
|
|
|
}
|