package org.gcube.portlets.user.geoportaldataentry.client.ui; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEvent; import org.gcube.portlets.user.geoportaldataentry.client.ui.form.GeonaDataEntryMainForm; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter.ORDER; import com.github.gwtbootstrap.client.ui.Dropdown; import com.github.gwtbootstrap.client.ui.NavLink; import com.github.gwtbootstrap.client.ui.Tab; import com.github.gwtbootstrap.client.ui.TextBox; 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.event.shared.HandlerManager; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; /** * The Class GeonaMainTabPanel. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * * Aug 5, 2021 */ public class GeonaMainTabPanel extends Composite { private static final String LABEL_FILTER_SEPARATOR = " - "; private static GeonaMainTabPanelUiBinder uiBinder = GWT.create(GeonaMainTabPanelUiBinder.class); /** * The Interface GeonaMainTabPanelUiBinder. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * * Aug 5, 2021 */ interface GeonaMainTabPanelUiBinder extends UiBinder { } /** The geona main form panel. */ @UiField HTMLPanel geonaMainFormPanel; @UiField HTMLPanel geonaListOfConcessioniPanel; /** The loader. */ @UiField LoaderIcon loader; @UiField NavLink buttCreateNewProject; @UiField NavLink buttonReloadConcessioni; @UiField Tab tabNewProject; @UiField Tab tabGetListOfProjects; @UiField Dropdown dropdownSortBy; @UiField TextBox textBoxSortBy; private HandlerManager appManagerBus; private RECORD_FIELD[] sortByFields; private SortFilter currentSortFilter; /** * Instantiates a new geona main tab panel. * * @param appManagerBus the first name * @param sortByFields the sort by fields * @param initialSortFilter */ public GeonaMainTabPanel(HandlerManager appManagerBus, RECORD_FIELD[] sortByFields, SortFilter initialSortFilter) { initWidget(uiBinder.createAndBindUi(this)); this.appManagerBus = appManagerBus; this.sortByFields = sortByFields; setCurrentSortFilter(initialSortFilter); bindEvents(); } /** * Bind events. */ private void bindEvents() { buttCreateNewProject.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { appManagerBus.fireEvent(new CreateNewProjectEvent()); } }); buttonReloadConcessioni.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); } }); tabGetListOfProjects.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { GeonaRecordsPaginatedView grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, null, currentSortFilter); showListOfConcessioniView(grpw); } }); for (RECORD_FIELD record_FIELD : sortByFields) { // ASC SortFilter sortFilter = new SortFilter(record_FIELD, ORDER.ASC); String labelASC = toLabelFilter(sortFilter); NavLink nav = new NavLink(labelASC); dropdownSortBy.add(nav); nav.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { GWT.log("Sort by: " + sortFilter); setCurrentSortFilter(sortFilter); appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); } }); // //DESC SortFilter sortFilter2 = new SortFilter(record_FIELD, ORDER.DESC); String labelASC2 = toLabelFilter(sortFilter2); NavLink nav2 = new NavLink(labelASC2); dropdownSortBy.add(nav2); nav2.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { GWT.log("Sort by: " + sortFilter2); setCurrentSortFilter(sortFilter2); appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); } }); } } /** * Adds the form panel. * * @param formPanel the form panel */ public void addFormPanel(GeonaDataEntryMainForm formPanel) { geonaMainFormPanel.add(formPanel); } /** * Show list of concessioni view. * * @param grpw the grpw */ public void showListOfConcessioniView(GeonaRecordsPaginatedView grpw) { geonaListOfConcessioniPanel.clear(); VerticalPanel htmllPanel = new VerticalPanel(); htmllPanel.add(grpw.getCellPanel()); htmllPanel.add(grpw.getPagerPanel()); geonaListOfConcessioniPanel.add(htmllPanel); } /** * Sets the loader visible. * * @param txtHTML the txt HTML * @param visible the visible */ public void setLoaderVisible(String txtHTML, boolean visible) { loader.setText(txtHTML); loader.setVisible(visible); } private void setCurrentSortFilter(SortFilter sortFilter) { this.currentSortFilter = sortFilter; this.textBoxSortBy.setText(toLabelFilter(sortFilter)); } /** * To label filter. * * @param sortFilter the sort filter * @return the string */ public String toLabelFilter(SortFilter sortFilter) { String labelFilter = sortFilter.getOrderByField().getDisplayName() + LABEL_FILTER_SEPARATOR + sortFilter.getOrder().name(); GWT.log("Got " + sortFilter); return labelFilter; } /** * To sort filter. * * @param labelFilter the label filter * @return the sort filter */ /*public SortFilter toSortFilter(String labelFilter) { String[] array = labelFilter.split(LABEL_FILTER_SEPARATOR); SortFilter sortFilter = null; try { RECORD_FIELD recordField = RECORD_FIELD.valueOf(array[0]); ORDER orderField = ORDER.valueOf(array[1]); sortFilter = new SortFilter(recordField, orderField); } catch (Exception e) { } GWT.log("Got " + sortFilter); return sortFilter; }*/ public SortFilter getCurrentSortFilter() { return currentSortFilter; } }