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 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright 2000-2016 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;
  17. import java.util.ArrayList;
  18. import java.util.HashSet;
  19. import java.util.Iterator;
  20. import java.util.Set;
  21. import com.google.gwt.user.client.DOM;
  22. import com.google.gwt.user.client.ui.ComplexPanel;
  23. import com.google.gwt.user.client.ui.HasEnabled;
  24. import com.google.gwt.user.client.ui.Widget;
  25. import com.vaadin.client.ApplicationConnection;
  26. import com.vaadin.client.ComponentConnector;
  27. import com.vaadin.client.ConnectorMap;
  28. import com.vaadin.shared.ui.tabsheet.TabState;
  29. public abstract class VTabsheetBase extends ComplexPanel implements HasEnabled {
  30. /** For internal use only. May be removed or replaced in the future. */
  31. protected ApplicationConnection client;
  32. /** For internal use only. May be removed or replaced in the future. */
  33. protected final ArrayList<String> tabKeys = new ArrayList<>();
  34. /** For internal use only. May be removed or replaced in the future. */
  35. protected Set<String> disabledTabKeys = new HashSet<>();
  36. /** For internal use only. May be removed or replaced in the future. */
  37. protected int activeTabIndex = 0;
  38. /** For internal use only. May be removed or replaced in the future. */
  39. protected boolean disabled;
  40. /** For internal use only. May be removed or replaced in the future. */
  41. protected boolean readonly;
  42. /** For internal use only. May be removed or replaced in the future. */
  43. protected AbstractComponentConnector connector;
  44. private boolean tabCaptionsAsHtml = false;
  45. public VTabsheetBase(String classname) {
  46. setElement(DOM.createDiv());
  47. setStyleName(classname);
  48. }
  49. /**
  50. * @return a list of currently shown Widgets
  51. */
  52. public abstract Iterator<Widget> getWidgetIterator();
  53. /**
  54. * Clears current tabs and contents
  55. */
  56. protected abstract void clearPaintables();
  57. /**
  58. * Implement in extending classes. This method should render needed elements
  59. * and set the visibility of the tab according to the 'selected' parameter.
  60. */
  61. public abstract void renderTab(TabState tabState, int index);
  62. /**
  63. * Implement in extending classes. This method should return the number of
  64. * tabs currently rendered.
  65. */
  66. public abstract int getTabCount();
  67. /**
  68. * Implement in extending classes. This method should return the Paintable
  69. * corresponding to the given index.
  70. */
  71. public abstract ComponentConnector getTab(int index);
  72. /**
  73. * Implement in extending classes. This method should remove the rendered
  74. * tab with the specified index.
  75. */
  76. public abstract void removeTab(int index);
  77. /**
  78. * Returns true if the width of the widget is undefined, false otherwise.
  79. *
  80. * @since 7.2
  81. * @return true if width of the widget is determined by its content
  82. */
  83. protected boolean isDynamicWidth() {
  84. return getConnectorForWidget(this).isUndefinedWidth();
  85. }
  86. /**
  87. * Returns true if the height of the widget is undefined, false otherwise.
  88. *
  89. * @since 7.2
  90. * @return true if width of the height is determined by its content
  91. */
  92. protected boolean isDynamicHeight() {
  93. return getConnectorForWidget(this).isUndefinedHeight();
  94. }
  95. /**
  96. * Sets the connector that should be notified of events etc.
  97. *
  98. * For internal use only. This method may be removed or replaced in the
  99. * future.
  100. *
  101. * @since 7.2
  102. * @param connector
  103. */
  104. public void setConnector(AbstractComponentConnector connector) {
  105. this.connector = connector;
  106. }
  107. /** For internal use only. May be removed or replaced in the future. */
  108. public void clearTabKeys() {
  109. tabKeys.clear();
  110. disabledTabKeys.clear();
  111. }
  112. /** For internal use only. May be removed or replaced in the future. */
  113. public void addTabKey(String key, boolean disabled) {
  114. tabKeys.add(key);
  115. if (disabled) {
  116. disabledTabKeys.add(key);
  117. }
  118. }
  119. /** For internal use only. May be removed or replaced in the future. */
  120. public void setClient(ApplicationConnection client) {
  121. this.client = client;
  122. }
  123. /** For internal use only. May be removed or replaced in the future. */
  124. public void setActiveTabIndex(int activeTabIndex) {
  125. this.activeTabIndex = activeTabIndex;
  126. }
  127. /** For internal use only. May be removed or replaced in the future. */
  128. @Override
  129. public void setEnabled(boolean enabled) {
  130. disabled = !enabled;
  131. }
  132. /** For internal use only. May be removed or replaced in the future. */
  133. public void setReadonly(boolean readonly) {
  134. this.readonly = readonly;
  135. }
  136. /** For internal use only. May be removed or replaced in the future. */
  137. protected ComponentConnector getConnectorForWidget(Widget widget) {
  138. return ConnectorMap.get(client).getConnector(widget);
  139. }
  140. /** For internal use only. May be removed or replaced in the future. */
  141. public abstract void selectTab(int index);
  142. @Override
  143. public boolean isEnabled() {
  144. return !disabled;
  145. }
  146. /**
  147. * Sets whether the caption is rendered as HTML.
  148. * <p>
  149. * The default is false, i.e. render tab captions as plain text
  150. *
  151. * @since 7.4
  152. * @param captionAsHtml
  153. * true if the captions are rendered as HTML, false if rendered
  154. * as plain text
  155. */
  156. public void setTabCaptionsAsHtml(boolean tabCaptionsAsHtml) {
  157. this.tabCaptionsAsHtml = tabCaptionsAsHtml;
  158. }
  159. /**
  160. * Checks whether captions are rendered as HTML
  161. *
  162. * The default is false, i.e. render tab captions as plain text
  163. *
  164. * @since 7.4
  165. * @return true if the captions are rendered as HTML, false if rendered as
  166. * plain text
  167. */
  168. public boolean isTabCaptionsAsHtml() {
  169. return tabCaptionsAsHtml;
  170. }
  171. }