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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright 2000-2014 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.Widget;
  24. import com.vaadin.client.ApplicationConnection;
  25. import com.vaadin.client.ComponentConnector;
  26. import com.vaadin.client.ConnectorMap;
  27. import com.vaadin.shared.ui.tabsheet.TabState;
  28. public abstract class VTabsheetBase extends ComplexPanel {
  29. /** For internal use only. May be removed or replaced in the future. */
  30. protected ApplicationConnection client;
  31. /** For internal use only. May be removed or replaced in the future. */
  32. protected final ArrayList<String> tabKeys = new ArrayList<String>();
  33. /** For internal use only. May be removed or replaced in the future. */
  34. protected Set<String> disabledTabKeys = new HashSet<String>();
  35. /** For internal use only. May be removed or replaced in the future. */
  36. protected int activeTabIndex = 0;
  37. /** For internal use only. May be removed or replaced in the future. */
  38. protected boolean disabled;
  39. /** For internal use only. May be removed or replaced in the future. */
  40. protected boolean readonly;
  41. /** For internal use only. May be removed or replaced in the future. */
  42. protected AbstractComponentConnector connector;
  43. public VTabsheetBase(String classname) {
  44. setElement(DOM.createDiv());
  45. setStyleName(classname);
  46. }
  47. /**
  48. * @return a list of currently shown Widgets
  49. */
  50. public abstract Iterator<Widget> getWidgetIterator();
  51. /**
  52. * Clears current tabs and contents
  53. */
  54. protected abstract void clearPaintables();
  55. /**
  56. * Implement in extending classes. This method should render needed elements
  57. * and set the visibility of the tab according to the 'selected' parameter.
  58. */
  59. public abstract void renderTab(TabState tabState, int index);
  60. /**
  61. * Implement in extending classes. This method should return the number of
  62. * tabs currently rendered.
  63. */
  64. public abstract int getTabCount();
  65. /**
  66. * Implement in extending classes. This method should return the Paintable
  67. * corresponding to the given index.
  68. */
  69. public abstract ComponentConnector getTab(int index);
  70. /**
  71. * Implement in extending classes. This method should remove the rendered
  72. * tab with the specified index.
  73. */
  74. public abstract void removeTab(int index);
  75. /**
  76. * Returns true if the width of the widget is undefined, false otherwise.
  77. *
  78. * @since 7.2
  79. * @return true if width of the widget is determined by its content
  80. */
  81. protected boolean isDynamicWidth() {
  82. return getConnectorForWidget(this).isUndefinedWidth();
  83. }
  84. /**
  85. * Returns true if the height of the widget is undefined, false otherwise.
  86. *
  87. * @since 7.2
  88. * @return true if width of the height is determined by its content
  89. */
  90. protected boolean isDynamicHeight() {
  91. return getConnectorForWidget(this).isUndefinedHeight();
  92. }
  93. /**
  94. * Sets the connector that should be notified of events etc.
  95. *
  96. * For internal use only. This method may be removed or replaced in the
  97. * future.
  98. *
  99. * @since 7.2
  100. * @param connector
  101. */
  102. public void setConnector(AbstractComponentConnector connector) {
  103. this.connector = connector;
  104. }
  105. /** For internal use only. May be removed or replaced in the future. */
  106. public void clearTabKeys() {
  107. tabKeys.clear();
  108. disabledTabKeys.clear();
  109. }
  110. /** For internal use only. May be removed or replaced in the future. */
  111. public void addTabKey(String key, boolean disabled) {
  112. tabKeys.add(key);
  113. if (disabled) {
  114. disabledTabKeys.add(key);
  115. }
  116. }
  117. /** For internal use only. May be removed or replaced in the future. */
  118. public void setClient(ApplicationConnection client) {
  119. this.client = client;
  120. }
  121. /** For internal use only. May be removed or replaced in the future. */
  122. public void setActiveTabIndex(int activeTabIndex) {
  123. this.activeTabIndex = activeTabIndex;
  124. }
  125. /** For internal use only. May be removed or replaced in the future. */
  126. public void setEnabled(boolean enabled) {
  127. disabled = !enabled;
  128. }
  129. /** For internal use only. May be removed or replaced in the future. */
  130. public void setReadonly(boolean readonly) {
  131. this.readonly = readonly;
  132. }
  133. /** For internal use only. May be removed or replaced in the future. */
  134. protected ComponentConnector getConnectorForWidget(Widget widget) {
  135. return ConnectorMap.get(client).getConnector(widget);
  136. }
  137. /** For internal use only. May be removed or replaced in the future. */
  138. public abstract void selectTab(int index);
  139. }