You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TabSheetExample.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.tests.book;
  5. import com.vaadin.ui.Button;
  6. import com.vaadin.ui.CustomComponent;
  7. import com.vaadin.ui.Label;
  8. import com.vaadin.ui.TabSheet;
  9. import com.vaadin.ui.Button.ClickEvent;
  10. import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
  11. public class TabSheetExample extends CustomComponent implements
  12. Button.ClickListener, TabSheet.SelectedTabChangeListener {
  13. TabSheet tabsheet = new TabSheet();
  14. Button tab1 = new Button("Push this button");
  15. Label tab2 = new Label("Contents of Second Tab");
  16. Label tab3 = new Label("Contents of Third Tab");
  17. TabSheetExample() {
  18. setCompositionRoot(tabsheet);
  19. // Listen for changes in tab selection.
  20. tabsheet.addListener(this);
  21. // First tab contains a button, for which we
  22. // listen button click events.
  23. tab1.addListener(this);
  24. // This will cause a selectedTabChange() call.
  25. tabsheet.addTab(tab1, "First Tab", null);
  26. // A tab that is initially invisible.
  27. tabsheet.addTab(tab2, "Second Tab", null);
  28. tabsheet.getTab(tab2).setVisible(false);
  29. // A tab that is initially disabled.
  30. tabsheet.addTab(tab3, "Third tab", null);
  31. tabsheet.getTab(tab3).setEnabled(false);
  32. }
  33. public void buttonClick(ClickEvent event) {
  34. // Enable the invisible and disabled tabs.
  35. tabsheet.getTab(tab2).setVisible(true);
  36. tabsheet.getTab(tab3).setEnabled(true);
  37. // Change selection automatically to second tab.
  38. tabsheet.setSelectedTab(tab2);
  39. }
  40. public void selectedTabChange(SelectedTabChangeEvent event) {
  41. // Cast to a TabSheet. This isn't really necessary in
  42. // this example, as we have only one TabSheet component,
  43. // but would be useful if there were multiple TabSheets.
  44. final TabSheet source = (TabSheet) event.getSource();
  45. if (source == tabsheet) {
  46. // If the first tab was selected.
  47. if (source.getSelectedTab() == tab1) {
  48. // The 2. and 3. tabs may not have been set yet.
  49. if (tabsheet.getTab(tab2) != null
  50. && tabsheet.getTab(tab3) != null) {
  51. tabsheet.getTab(tab2).setVisible(false);
  52. tabsheet.getTab(tab3).setEnabled(false);
  53. }
  54. }
  55. }
  56. }
  57. }