Suggestion: TabSheet improvement - "Add new tab" button

Hello,

At the moment i need provide the possibility to add new tab dynamically.
The UI pattern that i would like to provide is equals to the firefox “Open a new tab” option - A button, with
+
caption, at the end of all tab captions.
Maybe when this button was clicked, an event may be fired… something like…


public void getNewTabComponent(Event event) {
      if (canAddNewtab()) {
         return createMayNewComponentTab();      
      }
      return null;
}

Best regards

I didn’t worked with the TabSheet yet… but if it have a listenner you can make a tab with “+” and when you click it, you create a new tab and show it… I will try that latter ok!?

s

Flavio S. Truzzi

Hello Flavio,

At the moment, i made my own TabSheetPlus… and it is in sync with your sugestion.


public abstract class TabSheetPlus extends TabSheet {

	private CssLayout plusTab;
	private Component lastTab;

	protected abstract Component getNewTabComponent();

	public TabSheetPlus() {
		plusTab = new CssLayout();
		plusTab.setCaption("+");
		addComponent(plusTab);
		addListener(new TabSheet.SelectedTabChangeListener() {

			public void selectedTabChange(SelectedTabChangeEvent event) {
				Component selectedTab = getSelectedTab();
				if (selectedTab.getCaption() != null && selectedTab.getCaption().equals("+")) {
					setSelectedTab((lastTab != null ? lastTab : getComponentIterator().next()));
					Component newTabComponent = getNewTabComponent();
					if (newTabComponent != null) {
						addTab(newTabComponent);
						setSelectedTab(newTabComponent);
					}
				} else {
					lastTab = selectedTab;
				}
			}
		});
	}

	@Override
	public Tab addTab(Component c, String caption, Resource icon) {
		removeComponent(plusTab);
		Tab tab = super.addTab(c, caption, icon);
		super.addTab(plusTab, plusTab.getCaption(), null);
		return tab;
	}

Thanks!

One option would be to use Henrik’s
DetachedTabs
component.

-Henri

It also a good idea to add a feature request ticket to the trac, so that there’s some official reference to this request. It might of course get turned down, but at least someone’s have to make a descision.


Vaadin trac

// Jonas

Ticket added:
http://dev.vaadin.com/ticket/5034

tbsheet = new TabSheet();
tbsheet.setSizeFull();
try {
String query = "select * from test ";
Statement stmt = helper.getConnection().createStatement();
ResultSet rs = stmt.executeQuery(query);
tbsheet.removeAllComponents();
while (rs.next()) {
if (rs.getString(“Menu”).equals(“Snapshot”)) {
tbsheet.addTab(new sView(), rs.getString(“Menu”));
} else
tbsheet.addTab(new mview(), rs.getString(“Menu”));
}
tbsheet.addTab(new mview(), “+”);

        }
    catch (SQLException e) {
        e.printStackTrace();
    } finally {
        helper.closeConnection();
    }

use https://vaadin.com/directory#!addon/dynamictabsheet