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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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
  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. * Sets a callback function that is executed when new rows are added to
  124. * the escalator.
  125. *
  126. * @param consumer
  127. * A Consumer function that receives the newly added table
  128. * row elements.
  129. * @since 8.1
  130. */
  131. public void setNewRowCallback(Consumer<List<TableRowElement>> consumer);
  132. }
  133. /**
  134. * An arbitrary pixel height of a row, before any autodetection for the row
  135. * height has been made.
  136. */
  137. public static final double INITIAL_DEFAULT_ROW_HEIGHT = 20;
  138. /**
  139. * Returns the current {@link EscalatorUpdater} used to render cells.
  140. *
  141. * @return the current escalator updater
  142. */
  143. public EscalatorUpdater getEscalatorUpdater();
  144. /**
  145. * Sets the {@link EscalatorUpdater} to use when displaying data in the
  146. * escalator.
  147. *
  148. * @param escalatorUpdater
  149. * the escalator updater to use to render cells. May not be
  150. * <code>null</code>
  151. * @throws IllegalArgumentException
  152. * if {@code cellRenderer} is <code>null</code>
  153. * @see EscalatorUpdater#NULL
  154. */
  155. public void setEscalatorUpdater(EscalatorUpdater escalatorUpdater)
  156. throws IllegalArgumentException;
  157. /**
  158. * Removes rows at a certain index in the current row container.
  159. *
  160. * @param index
  161. * the index of the first row to be removed
  162. * @param numberOfRows
  163. * the number of rows to remove, starting from the index
  164. * @throws IndexOutOfBoundsException
  165. * if any integer number in the range
  166. * <code>[index..(index+numberOfRows)]</code> is not an existing
  167. * row index
  168. * @throws IllegalArgumentException
  169. * if {@code numberOfRows} is less than 1.
  170. */
  171. public void removeRows(int index, int numberOfRows)
  172. throws IndexOutOfBoundsException, IllegalArgumentException;
  173. /**
  174. * Adds rows at a certain index in this row container.
  175. * <p>
  176. * The new rows will be inserted between the row at the index, and the row
  177. * before (an index of 0 means that the rows are inserted at the beginning).
  178. * Therefore, the rows currently at the index and afterwards will be moved
  179. * downwards.
  180. * <p>
  181. * The contents of the inserted rows will subsequently be queried from the
  182. * escalator updater.
  183. * <p>
  184. * <em>Note:</em> Only the contents of the inserted rows will be rendered.
  185. * If inserting new rows affects the contents of existing rows,
  186. * {@link #refreshRows(int, int)} needs to be called for those rows
  187. * separately.
  188. *
  189. * @param index
  190. * the index of the row before which new rows are inserted, or
  191. * {@link #getRowCount()} to add rows at the end
  192. * @param numberOfRows
  193. * the number of rows to insert after the <code>index</code>
  194. * @see #setEscalatorUpdater(EscalatorUpdater)
  195. * @throws IndexOutOfBoundsException
  196. * if <code>index</code> is not an integer in the range
  197. * <code>[0..{@link #getRowCount()}]</code>
  198. * @throws IllegalArgumentException
  199. * if {@code numberOfRows} is less than 1.
  200. */
  201. public void insertRows(int index, int numberOfRows)
  202. throws IndexOutOfBoundsException, IllegalArgumentException;
  203. /**
  204. * Refreshes a range of rows in the current row container.
  205. * <p>
  206. * The data for the refreshed rows is queried from the current cell
  207. * renderer.
  208. *
  209. * @param index
  210. * the index of the first row that will be updated
  211. * @param numberOfRows
  212. * the number of rows to update, starting from the index
  213. * @see #setEscalatorUpdater(EscalatorUpdater)
  214. * @throws IndexOutOfBoundsException
  215. * if any integer number in the range
  216. * <code>[index..(index+numberOfColumns)]</code> is not an
  217. * existing column index.
  218. * @throws IllegalArgumentException
  219. * if {@code numberOfRows} is less than 1.
  220. */
  221. public void refreshRows(int index, int numberOfRows)
  222. throws IndexOutOfBoundsException, IllegalArgumentException;
  223. /**
  224. * Gets the number of rows in the current row container.
  225. *
  226. * @return the number of rows in the current row container
  227. */
  228. public int getRowCount();
  229. /**
  230. * For internal use only. May be removed or replaced in the future.
  231. *
  232. * @since 8.7
  233. * @return {@code true} if row height calculations have been scheduled
  234. */
  235. public boolean isAutodetectingRowHeightLater();
  236. /**
  237. * The default height of the rows in this RowContainer.
  238. *
  239. * @param px
  240. * the default height in pixels of the rows in this RowContainer
  241. * @throws IllegalArgumentException
  242. * if <code>px &lt; 1</code>
  243. * @see #getDefaultRowHeight()
  244. */
  245. public void setDefaultRowHeight(double px) throws IllegalArgumentException;
  246. /**
  247. * Returns the default height of the rows in this RowContainer.
  248. * <p>
  249. * This value will be equal to {@link #INITIAL_DEFAULT_ROW_HEIGHT} if the
  250. * {@link Escalator} has not yet had a chance to autodetect the row height,
  251. * or no explicit value has yet given via {@link #setDefaultRowHeight(int)}
  252. *
  253. * @return the default height of the rows in this RowContainer, in pixels
  254. * @see #setDefaultRowHeight(int)
  255. */
  256. public double getDefaultRowHeight();
  257. /**
  258. * Returns the cell object which contains information about the cell the
  259. * element is in.
  260. *
  261. * @param element
  262. * The element to get the cell for. If element is not present in
  263. * row container then <code>null</code> is returned.
  264. *
  265. * @return the cell of the element, or <code>null</code> if element is not
  266. * present in the {@link RowContainer}.
  267. */
  268. public Cell getCell(Element element);
  269. /**
  270. * Gets the row element with given logical index. For lazy loaded containers
  271. * such as Escalators BodyRowContainer visibility should be checked before
  272. * calling this function. See {@link Escalator#getVisibleRowRange()}.
  273. *
  274. * @param index
  275. * the logical index of the element to retrieve
  276. * @return the element at position {@code index}
  277. * @throws IndexOutOfBoundsException
  278. * if {@code index} is not valid within container
  279. * @throws IllegalStateException
  280. * if {@code index} is currently not available in the DOM
  281. */
  282. public TableRowElement getRowElement(int index)
  283. throws IndexOutOfBoundsException, IllegalStateException;
  284. /**
  285. * Returns the root element of RowContainer.
  286. *
  287. * @return RowContainer root element
  288. */
  289. public TableSectionElement getElement();
  290. }