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