Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

VTabsheetBase.java 4.5KB

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