選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

VTabsheetBase.java 6.4KB

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