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.

Ticket2289.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.vaadin.tests.tickets;
  2. import com.vaadin.server.LegacyApplication;
  3. import com.vaadin.ui.Accordion;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.Button.ClickEvent;
  6. import com.vaadin.ui.CustomComponent;
  7. import com.vaadin.ui.HorizontalLayout;
  8. import com.vaadin.ui.Label;
  9. import com.vaadin.ui.LegacyWindow;
  10. import com.vaadin.ui.TabSheet;
  11. import com.vaadin.ui.VerticalLayout;
  12. public class Ticket2289 extends LegacyApplication {
  13. TabSheet ts = null;
  14. Accordion acc = null;
  15. @Override
  16. public void init() {
  17. LegacyWindow w = new LegacyWindow();
  18. setMainWindow(w);
  19. VerticalLayout ol = new VerticalLayout();
  20. w.setContent(ol);
  21. Button b = new Button("close current tab");
  22. b.addListener(new Button.ClickListener() {
  23. @Override
  24. public void buttonClick(ClickEvent event) {
  25. closeCurrentTab();
  26. }
  27. });
  28. ol.addComponent(b);
  29. b = new Button("close first tab");
  30. b.addListener(new Button.ClickListener() {
  31. @Override
  32. public void buttonClick(ClickEvent event) {
  33. closeFirstTab();
  34. }
  35. });
  36. ol.addComponent(b);
  37. ts = new TabSheet();
  38. ts.setSizeUndefined();
  39. ts.setWidth("300px");
  40. ts.addTab(new MyTab("tab one"), "Caption1", null);
  41. ts.addTab(new MyTab("tab two"), "Caption2", null);
  42. ts.addTab(new MyTab("tab three"), "Caption3", null);
  43. ts.addTab(new MyTab("tab four"), "Caption4", null);
  44. ts.addTab(new MyTab("tab five"), "Caption5", null);
  45. acc = new Accordion();
  46. acc.setSizeUndefined();
  47. acc.addTab(new MyTab("tab one"), "Caption1", null);
  48. acc.addTab(new MyTab("tab two"), "Caption2", null);
  49. acc.addTab(new MyTab("tab three"), "Caption3", null);
  50. acc.addTab(new MyTab("tab four"), "Caption4", null);
  51. ol.addComponent(acc);
  52. ts = null;
  53. // ol.addComponent(ts);
  54. }
  55. private void closeCurrentTab() {
  56. if (ts != null) {
  57. MyTab m = (MyTab) ts.getSelectedTab();
  58. if (m != null) {
  59. ts.removeComponent(m);
  60. }
  61. }
  62. if (acc != null) {
  63. MyTab m = (MyTab) acc.getSelectedTab();
  64. if (m != null) {
  65. acc.removeComponent(m);
  66. }
  67. }
  68. }
  69. private void closeFirstTab() {
  70. if (ts != null) {
  71. ts.removeComponent(ts.getComponentIterator().next());
  72. }
  73. if (acc != null) {
  74. acc.removeComponent(acc.getComponentIterator().next());
  75. }
  76. }
  77. }
  78. class MyTab extends CustomComponent {
  79. public MyTab(String text) {
  80. setSizeUndefined();
  81. HorizontalLayout ol = new HorizontalLayout();
  82. setCompositionRoot(ol);
  83. ol.addComponent(new Label(text));
  84. }
  85. }