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.

TabsheetConnector.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui.tabsheet;
  17. import com.google.gwt.dom.client.Element;
  18. import com.google.gwt.user.client.DOM;
  19. import com.vaadin.client.ApplicationConnection;
  20. import com.vaadin.client.ComponentConnector;
  21. import com.vaadin.client.ConnectorHierarchyChangeEvent;
  22. import com.vaadin.client.TooltipInfo;
  23. import com.vaadin.client.UIDL;
  24. import com.vaadin.client.Util;
  25. import com.vaadin.client.ui.SimpleManagedLayout;
  26. import com.vaadin.client.ui.VTabsheet;
  27. import com.vaadin.client.ui.layout.MayScrollChildren;
  28. import com.vaadin.shared.ui.Connect;
  29. import com.vaadin.shared.ui.tabsheet.TabsheetState;
  30. import com.vaadin.ui.TabSheet;
  31. @Connect(TabSheet.class)
  32. public class TabsheetConnector extends TabsheetBaseConnector implements
  33. SimpleManagedLayout, MayScrollChildren {
  34. // Can't use "style" as it's already in use
  35. @Override
  36. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  37. if (isRealUpdate(uidl)) {
  38. // Handle stylename changes before generics (might affect size
  39. // calculations)
  40. getWidget().handleStyleNames(uidl, getState());
  41. }
  42. super.updateFromUIDL(uidl, client);
  43. if (!isRealUpdate(uidl)) {
  44. return;
  45. }
  46. // tabs; push or not
  47. if (!isUndefinedWidth()) {
  48. DOM.setStyleAttribute(getWidget().tabs, "overflow", "hidden");
  49. } else {
  50. getWidget().showAllTabs();
  51. DOM.setStyleAttribute(getWidget().tabs, "width", "");
  52. DOM.setStyleAttribute(getWidget().tabs, "overflow", "visible");
  53. getWidget().updateDynamicWidth();
  54. }
  55. if (!isUndefinedHeight()) {
  56. // Must update height after the styles have been set
  57. getWidget().updateContentNodeHeight();
  58. getWidget().updateOpenTabSize();
  59. }
  60. getWidget().iLayout();
  61. getWidget().waitingForResponse = false;
  62. }
  63. @Override
  64. public VTabsheet getWidget() {
  65. return (VTabsheet) super.getWidget();
  66. }
  67. @Override
  68. public TabsheetState getState() {
  69. return (TabsheetState) super.getState();
  70. }
  71. @Override
  72. public void updateCaption(ComponentConnector component) {
  73. /* Tabsheet does not render its children's captions */
  74. }
  75. @Override
  76. public void layout() {
  77. VTabsheet tabsheet = getWidget();
  78. tabsheet.updateContentNodeHeight();
  79. if (isUndefinedWidth()) {
  80. tabsheet.contentNode.getStyle().setProperty("width", "");
  81. } else {
  82. int contentWidth = tabsheet.getOffsetWidth()
  83. - tabsheet.getContentAreaBorderWidth();
  84. if (contentWidth < 0) {
  85. contentWidth = 0;
  86. }
  87. tabsheet.contentNode.getStyle().setProperty("width",
  88. contentWidth + "px");
  89. }
  90. tabsheet.updateOpenTabSize();
  91. if (isUndefinedWidth()) {
  92. tabsheet.updateDynamicWidth();
  93. }
  94. tabsheet.iLayout();
  95. }
  96. @Override
  97. public TooltipInfo getTooltipInfo(Element element) {
  98. TooltipInfo info = null;
  99. // Find a tooltip for the tab, if the element is a tab
  100. if (element != getWidget().getElement()) {
  101. Object node = Util.findWidget(
  102. (com.google.gwt.user.client.Element) element,
  103. VTabsheet.TabCaption.class);
  104. if (node != null) {
  105. VTabsheet.TabCaption caption = (VTabsheet.TabCaption) node;
  106. info = caption.getTooltipInfo();
  107. }
  108. }
  109. // If not tab tooltip was found, use the default
  110. if (info == null) {
  111. info = super.getTooltipInfo(element);
  112. }
  113. return info;
  114. }
  115. @Override
  116. public boolean hasTooltip() {
  117. /*
  118. * Tab tooltips are not processed until updateFromUIDL, so we can't be
  119. * sure that there are no tooltips during onStateChange when this method
  120. * is used.
  121. */
  122. return true;
  123. }
  124. @Override
  125. public void onConnectorHierarchyChange(
  126. ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) {
  127. // TODO Move code from updateFromUIDL to this method
  128. }
  129. }