package org.gcube.portlets.widgets.ckancontentmoderator.client.ui; import java.util.ArrayList; import java.util.List; import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.util.UtilFunct; import com.github.gwtbootstrap.client.ui.Tab; import com.github.gwtbootstrap.client.ui.TabPanel; import com.github.gwtbootstrap.client.ui.constants.IconType; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; 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; import com.google.gwt.user.client.ui.Widget; // TODO: Auto-generated Javadoc /** * The Class MainTabPanel. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * * Jun 18, 2021 */ public class MainTabPanel extends Composite { private static MainTabPanelUiBinder uiBinder = GWT.create(MainTabPanelUiBinder.class); /** * The Interface MainTabPanelUiBinder. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * * Jun 18, 2021 */ interface MainTabPanelUiBinder extends UiBinder { } private List results = new ArrayList(); @UiField TabPanel mainTabPanel; @UiField Tab homeTab; /** * Instantiates a new main tab panel. */ public MainTabPanel() { initWidget(uiBinder.createAndBindUi(this)); results.add(homeTab); } /** * Adds the home widget. * * @param w the w */ public void addHomeWidget(Widget w) { homeTab.add(w); } /** * Adds the tab. * * @param heading the heading * @param w the w * @return the tab */ public Tab addTab(String heading, Widget w) { Tab tab = new Tab(); tab.setIcon(IconType.BOOK); tab.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // TODO Auto-generated method stub } }); String shortTitle = UtilFunct.ellipsis(heading, 20, false); tab.asWidget().setTitle(heading); tab.setHeading(shortTitle); if (w != null) tab.add(w); results.add(tab); mainTabPanel.add(tab); activeTabPanels(false); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { mainTabPanel.selectTab(results.size() - 1); } }); return tab; } /** * Active tab panels. * * @param bool the bool */ private void activeTabPanels(boolean bool) { for (Tab tab : results) { tab.setActive(false); } } /** * Count tab. * * @return the int */ public int countTab() { return results.size(); } /** * Close tabs. */ public void closeTabs() { int tabSize = results.size(); GWT.log("tab size is: " + tabSize); for (int i = 1; i < tabSize; i++) { //each remove shifts any subsequent elements to the left, so I'm removing always the first element mainTabPanel.remove(1); results.remove(1); } //selecting Home Tab selectTab(0); } private void selectTab(int tabIndex) { if (tabIndex <= results.size()) { mainTabPanel.selectTab(tabIndex); } } }