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.

RowContainer.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * Copyright 2000-2018 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.v7.client.widget.escalator;
  17. import com.google.gwt.dom.client.Element;
  18. import com.google.gwt.dom.client.TableRowElement;
  19. import com.google.gwt.dom.client.TableSectionElement;
  20. import com.vaadin.v7.client.widgets.Escalator;
  21. /**
  22. * A representation of the rows in each of the sections (header, body and
  23. * footer) in an {@link Escalator}.
  24. *
  25. * @since 7.4
  26. * @author Vaadin Ltd
  27. * @see Escalator#getHeader()
  28. * @see Escalator#getBody()
  29. * @see Escalator#getFooter()
  30. * @see SpacerContainer
  31. */
  32. public interface RowContainer {
  33. /**
  34. * The row container for the body section in an {@link Escalator}.
  35. * <p>
  36. * The body section can contain both rows and spacers.
  37. *
  38. * @since 7.5.0
  39. * @author Vaadin Ltd
  40. * @see Escalator#getBody()
  41. */
  42. public interface BodyRowContainer extends RowContainer {
  43. /**
  44. * Marks a spacer and its height.
  45. * <p>
  46. * If a spacer is already registered with the given row index, that
  47. * spacer will be updated with the given height.
  48. * <p>
  49. * <em>Note:</em> The row index for a spacer will change if rows are
  50. * inserted or removed above the current position. Spacers will also be
  51. * removed alongside their associated rows
  52. *
  53. * @param rowIndex
  54. * the row index for the spacer to modify. The affected
  55. * spacer is underneath the given index. Use -1 to insert a
  56. * spacer before the first row
  57. * @param height
  58. * the pixel height of the spacer. If {@code height} is
  59. * negative, the affected spacer (if exists) will be removed
  60. * @throws IllegalArgumentException
  61. * if {@code rowIndex} is not a valid row index
  62. * @see #insertRows(int, int)
  63. * @see #removeRows(int, int)
  64. */
  65. void setSpacer(int rowIndex, double height)
  66. throws IllegalArgumentException;
  67. /**
  68. * Sets a new spacer updater.
  69. * <p>
  70. * Spacers that are currently visible will be updated, i.e.
  71. * {@link SpacerUpdater#destroy(Spacer) destroyed} with the previous
  72. * one, and {@link SpacerUpdater#init(Spacer) initialized} with the new
  73. * one.
  74. *
  75. * @param spacerUpdater
  76. * the new spacer updater
  77. * @throws IllegalArgumentException
  78. * if {@code spacerUpdater} is {@code null}
  79. */
  80. void setSpacerUpdater(SpacerUpdater spacerUpdater)
  81. throws IllegalArgumentException;
  82. /**
  83. * Gets the spacer updater currently in use.
  84. * <p>
  85. * {@link SpacerUpdater#NULL} is the default.
  86. *
  87. * @return the spacer updater currently in use. Never <code>null</code>
  88. */
  89. SpacerUpdater getSpacerUpdater();
  90. /**
  91. * {@inheritDoc}
  92. * <p>
  93. * Any spacers underneath {@code index} will be offset and "pushed"
  94. * down. This also modifies the row index they are associated with.
  95. */
  96. @Override
  97. public void insertRows(int index, int numberOfRows)
  98. throws IndexOutOfBoundsException, IllegalArgumentException;
  99. /**
  100. * {@inheritDoc}
  101. * <p>
  102. * Any spacers underneath {@code index} will be offset and "pulled" up.
  103. * This also modifies the row index they are associated with. Any
  104. * spacers in the removed range will also be closed and removed.
  105. */
  106. @Override
  107. public void removeRows(int index, int numberOfRows)
  108. throws IndexOutOfBoundsException, IllegalArgumentException;
  109. }
  110. /**
  111. * An arbitrary pixel height of a row, before any autodetection for the row
  112. * height has been made.
  113. */
  114. public static final double INITIAL_DEFAULT_ROW_HEIGHT = 20;
  115. /**
  116. * Returns the current {@link EscalatorUpdater} used to render cells.
  117. *
  118. * @return the current escalator updater
  119. */
  120. public EscalatorUpdater getEscalatorUpdater();
  121. /**
  122. * Sets the {@link EscalatorUpdater} to use when displaying data in the
  123. * escalator.
  124. *
  125. * @param escalatorUpdater
  126. * the escalator updater to use to render cells. May not be
  127. * <code>null</code>
  128. * @throws IllegalArgumentException
  129. * if {@code cellRenderer} is <code>null</code>
  130. * @see EscalatorUpdater#NULL
  131. */
  132. public void setEscalatorUpdater(EscalatorUpdater escalatorUpdater)
  133. throws IllegalArgumentException;
  134. /**
  135. * Removes rows at a certain index in the current row container.
  136. *
  137. * @param index
  138. * the index of the first row to be removed
  139. * @param numberOfRows
  140. * the number of rows to remove, starting from the index
  141. * @throws IndexOutOfBoundsException
  142. * if any integer number in the range
  143. * <code>[index..(index+numberOfRows)]</code> is not an existing
  144. * row index
  145. * @throws IllegalArgumentException
  146. * if {@code numberOfRows} is less than 1.
  147. */
  148. public void removeRows(int index, int numberOfRows)
  149. throws IndexOutOfBoundsException, IllegalArgumentException;
  150. /**
  151. * Adds rows at a certain index in this row container.
  152. * <p>
  153. * The new rows will be inserted between the row at the index, and the row
  154. * before (an index of 0 means that the rows are inserted at the beginning).
  155. * Therefore, the rows currently at the index and afterwards will be moved
  156. * downwards.
  157. * <p>
  158. * The contents of the inserted rows will subsequently be queried from the
  159. * escalator updater.
  160. * <p>
  161. * <em>Note:</em> Only the contents of the inserted rows will be rendered.
  162. * If inserting new rows affects the contents of existing rows,
  163. * {@link #refreshRows(int, int)} needs to be called for those rows
  164. * separately.
  165. *
  166. * @param index
  167. * the index of the row before which new rows are inserted, or
  168. * {@link #getRowCount()} to add rows at the end
  169. * @param numberOfRows
  170. * the number of rows to insert after the <code>index</code>
  171. * @see #setEscalatorUpdater(EscalatorUpdater)
  172. * @throws IndexOutOfBoundsException
  173. * if <code>index</code> is not an integer in the range
  174. * <code>[0..{@link #getRowCount()}]</code>
  175. * @throws IllegalArgumentException
  176. * if {@code numberOfRows} is less than 1.
  177. */
  178. public void insertRows(int index, int numberOfRows)
  179. throws IndexOutOfBoundsException, IllegalArgumentException;
  180. /**
  181. * Refreshes a range of rows in the current row container.
  182. * <p>
  183. * The data for the refreshed rows is queried from the current cell
  184. * renderer.
  185. *
  186. * @param index
  187. * the index of the first row that will be updated
  188. * @param numberOfRows
  189. * the number of rows to update, starting from the index
  190. * @see #setEscalatorUpdater(EscalatorUpdater)
  191. * @throws IndexOutOfBoundsException
  192. * if any integer number in the range
  193. * <code>[index..(index+numberOfColumns)]</code> is not an
  194. * existing column index.
  195. * @throws IllegalArgumentException
  196. * if {@code numberOfRows} is less than 1.
  197. */
  198. public void refreshRows(int index, int numberOfRows)
  199. throws IndexOutOfBoundsException, IllegalArgumentException;
  200. /**
  201. * Gets the number of rows in the current row container.
  202. *
  203. * @return the number of rows in the current row container
  204. */
  205. public int getRowCount();
  206. /**
  207. * This method calculates the current row count directly from the DOM.
  208. * <p>
  209. * While the container is stable, this value should equal to
  210. * {@link #getRowCount()}, but while row counts are being updated, these two
  211. * values might differ for a short while.
  212. * <p>
  213. * Any extra content, such as spacers for the body, should not be included
  214. * in this count.
  215. *
  216. * @since 8.7
  217. *
  218. * @return the actual DOM count of rows
  219. */
  220. public int getDomRowCount();
  221. /**
  222. * The default height of the rows in this RowContainer.
  223. *
  224. * @param px
  225. * the default height in pixels of the rows in this RowContainer
  226. * @throws IllegalArgumentException
  227. * if <code>px &lt; 1</code>
  228. * @see #getDefaultRowHeight()
  229. */
  230. public void setDefaultRowHeight(double px) throws IllegalArgumentException;
  231. /**
  232. * Returns the default height of the rows in this RowContainer.
  233. * <p>
  234. * This value will be equal to {@link #INITIAL_DEFAULT_ROW_HEIGHT} if the
  235. * {@link Escalator} has not yet had a chance to autodetect the row height,
  236. * or no explicit value has yet given via {@link #setDefaultRowHeight(int)}
  237. *
  238. * @return the default height of the rows in this RowContainer, in pixels
  239. * @see #setDefaultRowHeight(int)
  240. */
  241. public double getDefaultRowHeight();
  242. /**
  243. * Returns the cell object which contains information about the cell the
  244. * element is in.
  245. *
  246. * @param element
  247. * The element to get the cell for. If element is not present in
  248. * row container then <code>null</code> is returned.
  249. *
  250. * @return the cell of the element, or <code>null</code> if element is not
  251. * present in the {@link RowContainer}.
  252. */
  253. public Cell getCell(Element element);
  254. /**
  255. * Gets the row element with given logical index. For lazy loaded containers
  256. * such as Escalators BodyRowContainer visibility should be checked before
  257. * calling this function. See {@link Escalator#getVisibleRowRange()}.
  258. *
  259. * @param index
  260. * the logical index of the element to retrieve
  261. * @return the element at position {@code index}
  262. * @throws IndexOutOfBoundsException
  263. * if {@code index} is not valid within container
  264. * @throws IllegalStateException
  265. * if {@code index} is currently not available in the DOM
  266. */
  267. public TableRowElement getRowElement(int index)
  268. throws IndexOutOfBoundsException, IllegalStateException;
  269. /**
  270. * Returns the root element of RowContainer.
  271. *
  272. * @return RowContainer root element
  273. */
  274. public TableSectionElement getElement();
  275. }