124 lines
2.5 KiB
Java
124 lines
2.5 KiB
Java
|
package org.gcube.portlets.widgets.ckancontentmoderator.client.ui;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
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.core.client.Scheduler;
|
||
|
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
||
|
import com.google.gwt.dom.client.Element;
|
||
|
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;
|
||
|
|
||
|
/**
|
||
|
* 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<Widget, MainTabPanel> {
|
||
|
}
|
||
|
|
||
|
private List<Tab> results = new ArrayList<Tab>();
|
||
|
|
||
|
@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.addClickHandler(new ClickHandler() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(ClickEvent event) {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
});
|
||
|
tab.setHeading(heading);
|
||
|
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); //+1 because the first tab is "Home"
|
||
|
|
||
|
}
|
||
|
});
|
||
|
|
||
|
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();
|
||
|
}
|
||
|
|
||
|
}
|