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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. * Checks whether the given rowIndex contains a spacer.
  72. *
  73. * @param rowIndex
  74. * the row index for the queried spacer.
  75. * @return {@code true} if spacer for given row index exists,
  76. * {@code false} otherwise
  77. * @since 8.9
  78. */
  79. boolean spacerExists(int rowIndex);
  80. /**
  81. * Sets a new spacer updater.
  82. * <p>
  83. * Spacers that are currently visible will be updated, i.e.
  84. * {@link SpacerUpdater#destroy(Spacer) destroyed} with the previous
  85. * one, and {@link SpacerUpdater#init(Spacer) initialized} with the new
  86. * one.
  87. *
  88. * @param spacerUpdater
  89. * the new spacer updater
  90. * @throws IllegalArgumentException
  91. * if {@code spacerUpdater} is {@code null}
  92. */
  93. void setSpacerUpdater(SpacerUpdater spacerUpdater)
  94. throws IllegalArgumentException;
  95. /**
  96. * Gets the spacer updater currently in use.
  97. * <p>
  98. * {@link SpacerUpdater#NULL} is the default.
  99. *
  100. * @return the spacer updater currently in use. Never <code>null</code>
  101. */
  102. SpacerUpdater getSpacerUpdater();
  103. /**
  104. * {@inheritDoc}
  105. * <p>
  106. * Any spacers underneath {@code index} will be offset and "pushed"
  107. * down. This also modifies the row index they are associated with.
  108. */
  109. @Override
  110. public void insertRows(int index, int numberOfRows)
  111. throws IndexOutOfBoundsException, IllegalArgumentException;
  112. /**
  113. * {@inheritDoc}
  114. * <p>
  115. * Any spacers underneath {@code index} will be offset and "pulled" up.
  116. * This also modifies the row index they are associated with. Any
  117. * spacers in the removed range will also be closed and removed.
  118. */
  119. @Override
  120. public void removeRows(int index, int numberOfRows)
  121. throws IndexOutOfBoundsException, IllegalArgumentException;
  122. /**
  123. * Recalculates and updates the positions of rows and spacers within the
  124. * given range and ensures there is no gap below the rows if there are
  125. * enough rows to fill the space. Recalculates the scrollbars for
  126. * virtual viewport.
  127. *
  128. * @param index
  129. * logical index of the first row to reposition
  130. * @param numberOfRows
  131. * the number of rows to reposition
  132. * @since 8.9
  133. */
  134. public void updateRowPositions(int index, int numberOfRows);
  135. /**
  136. * Sets a callback function that is executed when new rows are added to
  137. * the escalator.
  138. *
  139. * @param consumer
  140. * A Consumer function that receives the newly added table
  141. * row elements.
  142. * @since 8.1
  143. */
  144. public void setNewRowCallback(Consumer<List<TableRowElement>> consumer);
  145. }
  146. /**
  147. * An arbitrary pixel height of a row, before any autodetection for the row
  148. * height has been made.
  149. */
  150. public static final double INITIAL_DEFAULT_ROW_HEIGHT = 20;
  151. /**
  152. * Returns the current {@link EscalatorUpdater} used to render cells.
  153. *
  154. * @return the current escalator updater
  155. */
  156. public EscalatorUpdater getEscalatorUpdater();
  157. /**
  158. * Sets the {@link EscalatorUpdater} to use when displaying data in the
  159. * escalator.
  160. *
  161. * @param escalatorUpdater
  162. * the escalator updater to use to render cells. May not be
  163. * <code>null</code>
  164. * @throws IllegalArgumentException
  165. * if {@code cellRenderer} is <code>null</code>
  166. * @see EscalatorUpdater#NULL
  167. */
  168. public void setEscalatorUpdater(EscalatorUpdater escalatorUpdater)
  169. throws IllegalArgumentException;
  170. /**
  171. * Removes rows at a certain index in the current row container.
  172. *
  173. * @param index
  174. * the index of the first row to be removed
  175. * @param numberOfRows
  176. * the number of rows to remove, starting from the index
  177. * @throws IndexOutOfBoundsException
  178. * if any integer number in the range
  179. * <code>[index..(index+numberOfRows)]</code> is not an existing
  180. * row index
  181. * @throws IllegalArgumentException
  182. * if {@code numberOfRows} is less than 1.
  183. */
  184. public void removeRows(int index, int numberOfRows)
  185. throws IndexOutOfBoundsException, IllegalArgumentException;
  186. /**
  187. * Adds rows at a certain index in this row container.
  188. * <p>
  189. * The new rows will be inserted between the row at the index, and the row
  190. * before (an index of 0 means that the rows are inserted at the beginning).
  191. * Therefore, the rows currently at the index and afterwards will be moved
  192. * downwards.
  193. * <p>
  194. * The contents of the inserted rows will subsequently be queried from the
  195. * escalator updater.
  196. * <p>
  197. * <em>Note:</em> Only the contents of the inserted rows will be rendered.
  198. * If inserting new rows affects the contents of existing rows,
  199. * {@link #refreshRows(int, int)} needs to be called for those rows
  200. * separately.
  201. *
  202. * @param index
  203. * the index of the row before which new rows are inserted, or
  204. * {@link #getRowCount()} to add rows at the end
  205. * @param numberOfRows
  206. * the number of rows to insert after the <code>index</code>
  207. * @see #setEscalatorUpdater(EscalatorUpdater)
  208. * @throws IndexOutOfBoundsException
  209. * if <code>index</code> is not an integer in the range
  210. * <code>[0..{@link #getRowCount()}]</code>
  211. * @throws IllegalArgumentException
  212. * if {@code numberOfRows} is less than 1.
  213. */
  214. public void insertRows(int index, int numberOfRows)
  215. throws IndexOutOfBoundsException, IllegalArgumentException;
  216. /**
  217. * Refreshes a range of rows in the current row container.
  218. * <p>
  219. * The data for the refreshed rows is queried from the current cell
  220. * renderer.
  221. *
  222. * @param index
  223. * the index of the first row that will be updated
  224. * @param numberOfRows
  225. * the number of rows to update, starting from the index
  226. * @see #setEscalatorUpdater(EscalatorUpdater)
  227. * @throws IndexOutOfBoundsException
  228. * if any integer number in the range
  229. * <code>[index..(index+numberOfColumns)]</code> is not an
  230. * existing column index.
  231. * @throws IllegalArgumentException
  232. * if {@code numberOfRows} is less than 1.
  233. */
  234. public void refreshRows(int index, int numberOfRows)
  235. throws IndexOutOfBoundsException, IllegalArgumentException;
  236. /**
  237. * Gets the number of rows in the current row container.
  238. *
  239. * @return the number of rows in the current row container
  240. */
  241. public int getRowCount();
  242. /**
  243. * For internal use only. May be removed or replaced in the future.
  244. *
  245. * @since 8.7
  246. * @return {@code true} if row height calculations have been scheduled
  247. */
  248. public boolean isAutodetectingRowHeightLater();
  249. /**
  250. * The default height of the rows in this RowContainer.
  251. *
  252. * @param px
  253. * the default height in pixels of the rows in this RowContainer
  254. * @throws IllegalArgumentException
  255. * if <code>px &lt; 1</code>
  256. * @see #getDefaultRowHeight()
  257. */
  258. public void setDefaultRowHeight(double px) throws IllegalArgumentException;
  259. /**
  260. * Returns the default height of the rows in this RowContainer.
  261. * <p>
  262. * This value will be equal to {@link #INITIAL_DEFAULT_ROW_HEIGHT} if the
  263. * {@link Escalator} has not yet had a chance to autodetect the row height,
  264. * or no explicit value has yet given via {@link #setDefaultRowHeight(int)}
  265. *
  266. * @return the default height of the rows in this RowContainer, in pixels
  267. * @see #setDefaultRowHeight(int)
  268. */
  269. public double getDefaultRowHeight();
  270. /**
  271. * Returns the cell object which contains information about the cell the
  272. * element is in.
  273. *
  274. * @param element
  275. * The element to get the cell for. If element is not present in
  276. * row container then <code>null</code> is returned.
  277. *
  278. * @return the cell of the element, or <code>null</code> if element is not
  279. * present in the {@link RowContainer}.
  280. */
  281. public Cell getCell(Element element);
  282. /**
  283. * Gets the row element with given logical index. For lazy loaded containers
  284. * such as Escalators BodyRowContainer visibility should be checked before
  285. * calling this function. See {@link Escalator#getVisibleRowRange()}.
  286. *
  287. * @param index
  288. * the logical index of the element to retrieve
  289. * @return the element at position {@code index}
  290. * @throws IndexOutOfBoundsException
  291. * if {@code index} is not valid within container
  292. * @throws IllegalStateException
  293. * if {@code index} is currently not available in the DOM
  294. */
  295. public TableRowElement getRowElement(int index)
  296. throws IndexOutOfBoundsException, IllegalStateException;
  297. /**
  298. * Returns the root element of RowContainer.
  299. *
  300. * @return RowContainer root element
  301. */
  302. public TableSectionElement getElement();
  303. }