built the main form

This commit is contained in:
Francesco Mangiacrapa 2020-10-09 16:34:23 +02:00
parent 8855c34308
commit c384e9cc3c
3 changed files with 166 additions and 12 deletions

View File

@ -1,7 +1,9 @@
package org.gcube.portlets.user.geoportaldataentry.client;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.TreeMap;
import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaDataEntryMainForm;
import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderServiceAsync;
@ -35,6 +37,11 @@ public class GeoPortalDataEntryApp implements EntryPoint {
private final Messages messages = GWT.create(Messages.class);
private final HandlerManager eventBus = new HandlerManager(null);
private TreeMap<Integer, MetaDataProfileBean> mapOrderedGeoNaProfiles = new TreeMap<Integer, MetaDataProfileBean>();
private List<MetaDataProfileBean> orderedListMetadataProfilesForGeona = null;
/**
* This is the entry point method.
*/
@ -45,17 +52,20 @@ public class GeoPortalDataEntryApp implements EntryPoint {
final GeonaDataEntryMainForm geoNaMainForm = new GeonaDataEntryMainForm();
// CreateMetadataForm baseForm = new CreateMetadataForm(scope, secondaryType, eventBus);
// geoNaMainForm.addWidget(baseForm);
MetadataProfileFormBuilderServiceAsync.Util.getInstance().getProfilesInTheScope(scope, secondaryType, new AsyncCallback<List<MetaDataProfileBean>>() {
@Override
public void onSuccess(List<MetaDataProfileBean> result) {
orderedListMetadataProfilesForGeona = setGeoNaFormOrder(result);
for (MetaDataProfileBean metaDataProfileBean : result) {
CreateMetadataForm baseForm = new CreateMetadataForm(Arrays.asList(metaDataProfileBean), eventBus);
geoNaMainForm.addWidget(baseForm);
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);
}
}
@ -67,4 +77,38 @@ public class GeoPortalDataEntryApp implements EntryPoint {
RootPanel.get(DIV_PORTLET_ID).add(geoNaMainForm);
}
private List<MetaDataProfileBean> setGeoNaFormOrder(List<MetaDataProfileBean> listMetadataProfilesForGeona) {
mapOrderedGeoNaProfiles.clear();
for (MetaDataProfileBean metaDataProfileBean : listMetadataProfilesForGeona) {
String theMetaType = metaDataProfileBean.getType().toLowerCase();
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);
}
}
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;
}
}

View File

@ -1,6 +1,17 @@
package org.gcube.portlets.user.geoportaldataentry.client.ui;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
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;
@ -15,15 +26,97 @@ public class GeonaDataEntryMainForm extends Composite {
}
@UiField
HTMLPanel baseHtmlPanel;
HTMLPanel mainHTMLPanel;
@UiField
TabPanel mainTabPanel;
private LinkedHashMap<String,List<CreateMetadataForm>> mapForms = new LinkedHashMap<String,List<CreateMetadataForm>>();
private List<TabPane> listTabs = new ArrayList<TabPane>();
public GeonaDataEntryMainForm() {
initWidget(uiBinder.createAndBindUi(this));
}
public void addWidget(Widget w) {
baseHtmlPanel.add(w);
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);
}
});
}
tab.add(createMetadataForm);
mainTabPanel.add(tab);
listTabs.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);
}
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){
GWT.log("Selecting tab index: "+ index +" of "+listTabs.size());
if(listTabs.size()<index) {
mainTabPanel.selectTab(index);
}
}
/**
* 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);
// }
// }
}
}

View File

@ -1,11 +1,28 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.important {
font-weight: bold;
}
.custom-page-header {
padding: 10px;
background-color: #f5f5f5;
margin: 20px 0 30px;
border-bottom: 1px solid #eee;
}
</ui:style>
<g:HTMLPanel ui:field="baseHtmlPanel">
<g:HTMLPanel ui:field="mainHTMLPanel">
<b:PageHeader subtext="data entry facility"
styleName="{style.custom-page-header}">GeoNa</b:PageHeader>
<b:TabPanel ui:field="mainTabPanel" tabPosition="left">
</b:TabPanel>
<!-- <b:AlertBlock type="DEFAULT" close="false"> -->
<b:FormActions>
<b:Button type="PRIMARY" icon="SAVE" ui:field="buttonSave">Save</b:Button>
</b:FormActions>
<!-- </b:AlertBlock> -->
</g:HTMLPanel>
</ui:UiBinder>