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

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