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.

VTabsheetBasePaintable.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui;
  5. import java.util.ArrayList;
  6. import java.util.Iterator;
  7. import com.google.gwt.user.client.ui.Widget;
  8. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  9. import com.vaadin.terminal.gwt.client.UIDL;
  10. import com.vaadin.terminal.gwt.client.VPaintableMap;
  11. import com.vaadin.terminal.gwt.client.VPaintableWidget;
  12. public abstract class VTabsheetBasePaintable extends
  13. VAbstractPaintableWidgetContainer {
  14. @Override
  15. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  16. getWidgetForPaintable().client = client;
  17. // Ensure correct implementation
  18. super.updateFromUIDL(uidl, client);
  19. if (!isRealUpdate(uidl)) {
  20. return;
  21. }
  22. // Update member references
  23. getWidgetForPaintable().id = uidl.getId();
  24. getWidgetForPaintable().disabled = uidl.hasAttribute("disabled");
  25. // Render content
  26. final UIDL tabs = uidl.getChildUIDL(0);
  27. // Paintables in the TabSheet before update
  28. ArrayList<Widget> oldWidgets = new ArrayList<Widget>();
  29. for (Iterator<Widget> iterator = getWidgetForPaintable()
  30. .getWidgetIterator(); iterator.hasNext();) {
  31. oldWidgets.add(iterator.next());
  32. }
  33. // Clear previous values
  34. getWidgetForPaintable().tabKeys.clear();
  35. getWidgetForPaintable().disabledTabKeys.clear();
  36. int index = 0;
  37. for (final Iterator<Object> it = tabs.getChildIterator(); it.hasNext();) {
  38. final UIDL tab = (UIDL) it.next();
  39. final String key = tab.getStringAttribute("key");
  40. final boolean selected = tab.getBooleanAttribute("selected");
  41. final boolean hidden = tab.getBooleanAttribute("hidden");
  42. if (tab.getBooleanAttribute("disabled")) {
  43. getWidgetForPaintable().disabledTabKeys.add(key);
  44. }
  45. getWidgetForPaintable().tabKeys.add(key);
  46. if (selected) {
  47. getWidgetForPaintable().activeTabIndex = index;
  48. }
  49. getWidgetForPaintable().renderTab(tab, index, selected, hidden);
  50. index++;
  51. }
  52. int tabCount = getWidgetForPaintable().getTabCount();
  53. while (tabCount-- > index) {
  54. getWidgetForPaintable().removeTab(index);
  55. }
  56. for (int i = 0; i < getWidgetForPaintable().getTabCount(); i++) {
  57. VPaintableWidget p = getWidgetForPaintable().getTab(i);
  58. // During the initial rendering the paintable might be null (this is
  59. // weird...)
  60. if (p != null) {
  61. oldWidgets.remove(p.getWidgetForPaintable());
  62. }
  63. }
  64. // Perform unregister for any paintables removed during update
  65. for (Iterator<Widget> iterator = oldWidgets.iterator(); iterator
  66. .hasNext();) {
  67. Widget oldWidget = iterator.next();
  68. VPaintableWidget oldPaintable = VPaintableMap.get(client)
  69. .getPaintable(oldWidget);
  70. if (oldWidget.isAttached()) {
  71. oldWidget.removeFromParent();
  72. }
  73. VPaintableMap.get(client).unregisterPaintable(oldPaintable);
  74. }
  75. }
  76. @Override
  77. public VTabsheetBase getWidgetForPaintable() {
  78. return (VTabsheetBase) super.getWidgetForPaintable();
  79. }
  80. }