Java 类com.vaadin.ui.TabSheet.CloseHandler 实例源码

项目:vaadin-fluent-api    文件:FTabSheetTest.java   
@Test
public void test2() {
    FVerticalLayout c1 = new FVerticalLayout();
    FHorizontalLayout c2 = new FHorizontalLayout();
    FGridLayout c3 = new FGridLayout();
    FCssLayout c4 = new FCssLayout();
    FVerticalLayout c5 = new FVerticalLayout();

    FTabSheet tabSheet = new FTabSheet().withCaption("My TabSheet")
                                        .withSelectedTabChangeListener(event -> System.out.println("tab changed"))
                                        .withTab(c1)
                                        .withTab(c2, 0)
                                        .withTab(c3, "tab 3")
                                        .withTab(c4, "tab 4", VaadinIcons.ADD_DOCK)
                                        .withTab(c5, "tab 5", VaadinIcons.COMMENTS, 1)
                                        .withSelectedTab(0)
                                        .withTabsVisible(false)
                                        .withCloseHandler(new CloseHandler() {

                                            private static final long serialVersionUID = 6764130489982068799L;

                                            @Override
                                            public void onTabClose(TabSheet tabsheet, Component tabContent) {
                                                System.out.println("tab closed");
                                            }
                                        });

    tabSheet.removeComponent(c5);

    assertEquals("My TabSheet", tabSheet.getCaption());
    assertEquals(1, tabSheet.getListeners(SelectedTabChangeEvent.class).size());
    assertEquals(4, tabSheet.getComponentCount());
    assertEquals(c1, tabSheet.getTab(1).getComponent());
    assertEquals(c2, tabSheet.getTab(0).getComponent());
    assertEquals(c3, tabSheet.getTab(2).getComponent());
    assertEquals(c4, tabSheet.getTab(3).getComponent());
    assertNull(tabSheet.getTab(c5));
    assertEquals(c2, tabSheet.getSelectedTab());
    assertFalse(tabSheet.isTabCaptionsAsHtml());
    assertFalse(tabSheet.isTabsVisible());

}
项目:vaadin-fluent-api    文件:FluentTabSheet.java   
/**
 * Provide a custom {@link CloseHandler} for this TabSheet if you wish to
 * perform some additional tasks when a user clicks on a tabs close button,
 * e.g. show a confirmation dialogue before removing the tab.
 *
 * To remove the tab, if you provide your own close handler, you must call
 * {@link #removeComponent(Component)} yourself.
 *
 * The default CloseHandler for TabSheet will only remove the tab.
 *
 * @param handler
 *              the close handler
 * @return this for method chaining
 * @see TabSheet#setCloseHandler(CloseHandler)
 */
@SuppressWarnings("unchecked")
public default THIS withCloseHandler(CloseHandler handler) {
    ((TabSheet) this).setCloseHandler(handler);
    return (THIS) this;
}