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.

VTabsheetBase.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package com.vaadin.terminal.gwt.client.ui;
  2. import java.util.ArrayList;
  3. import java.util.HashSet;
  4. import java.util.Iterator;
  5. import java.util.Set;
  6. import com.google.gwt.user.client.DOM;
  7. import com.google.gwt.user.client.ui.ComplexPanel;
  8. import com.google.gwt.user.client.ui.Widget;
  9. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  10. import com.vaadin.terminal.gwt.client.Container;
  11. import com.vaadin.terminal.gwt.client.Paintable;
  12. import com.vaadin.terminal.gwt.client.UIDL;
  13. abstract class VTabsheetBase extends ComplexPanel implements Container {
  14. String id;
  15. ApplicationConnection client;
  16. protected final ArrayList tabKeys = new ArrayList();
  17. protected int activeTabIndex = 0;
  18. protected boolean disabled;
  19. protected boolean readonly;
  20. protected Set disabledTabKeys = new HashSet();
  21. protected boolean cachedUpdate = false;
  22. public VTabsheetBase(String classname) {
  23. setElement(DOM.createDiv());
  24. setStylePrimaryName(classname);
  25. }
  26. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  27. this.client = client;
  28. // Ensure correct implementation
  29. cachedUpdate = client.updateComponent(this, uidl, true);
  30. if (cachedUpdate) {
  31. return;
  32. }
  33. // Update member references
  34. id = uidl.getId();
  35. disabled = uidl.hasAttribute("disabled");
  36. // Render content
  37. final UIDL tabs = uidl.getChildUIDL(0);
  38. // Paintables in the TabSheet before update
  39. ArrayList oldPaintables = new ArrayList();
  40. for (Iterator iterator = getPaintableIterator(); iterator.hasNext();) {
  41. oldPaintables.add(iterator.next());
  42. }
  43. // Clear previous values
  44. tabKeys.clear();
  45. disabledTabKeys.clear();
  46. int index = 0;
  47. for (final Iterator it = tabs.getChildIterator(); it.hasNext();) {
  48. final UIDL tab = (UIDL) it.next();
  49. final String key = tab.getStringAttribute("key");
  50. final boolean selected = tab.getBooleanAttribute("selected");
  51. final boolean hidden = tab.getBooleanAttribute("hidden");
  52. if (tab.getBooleanAttribute("disabled")) {
  53. disabledTabKeys.add(key);
  54. }
  55. tabKeys.add(key);
  56. if (selected) {
  57. activeTabIndex = index;
  58. }
  59. renderTab(tab, index, selected, hidden);
  60. index++;
  61. }
  62. int tabCount = getTabCount();
  63. while (tabCount-- > index) {
  64. removeTab(index);
  65. }
  66. for (int i = 0; i < getTabCount(); i++) {
  67. Paintable p = getTab(i);
  68. oldPaintables.remove(p);
  69. }
  70. // Perform unregister for any paintables removed during update
  71. for (Iterator iterator = oldPaintables.iterator(); iterator.hasNext();) {
  72. Object oldPaintable = iterator.next();
  73. if (oldPaintable instanceof Paintable) {
  74. Widget w = (Widget) oldPaintable;
  75. if (w.isAttached()) {
  76. w.removeFromParent();
  77. }
  78. client.unregisterPaintable((Paintable) oldPaintable);
  79. }
  80. }
  81. }
  82. /**
  83. * @return a list of currently shown Paintables
  84. */
  85. abstract protected Iterator getPaintableIterator();
  86. /**
  87. * Clears current tabs and contents
  88. */
  89. abstract protected void clearPaintables();
  90. /**
  91. * Implement in extending classes. This method should render needed elements
  92. * and set the visibility of the tab according to the 'selected' parameter.
  93. */
  94. protected abstract void renderTab(final UIDL tabUidl, int index,
  95. boolean selected, boolean hidden);
  96. /**
  97. * Implement in extending classes. This method should render any previously
  98. * non-cached content and set the activeTabIndex property to the specified
  99. * index.
  100. */
  101. protected abstract void selectTab(int index, final UIDL contentUidl);
  102. /**
  103. * Implement in extending classes. This method should return the number of
  104. * tabs currently rendered.
  105. */
  106. protected abstract int getTabCount();
  107. /**
  108. * Implement in extending classes. This method should return the Paintable
  109. * corresponding to the given index.
  110. */
  111. protected abstract Paintable getTab(int index);
  112. /**
  113. * Implement in extending classes. This method should remove the rendered
  114. * tab with the specified index.
  115. */
  116. protected abstract void removeTab(int index);
  117. }