Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Container.java 48KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  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.v7.data;
  17. import java.io.Serializable;
  18. import java.util.Collection;
  19. import java.util.List;
  20. import com.vaadin.data.provider.AbstractBackEndDataProvider;
  21. import com.vaadin.data.provider.DataProvider;
  22. import com.vaadin.data.provider.ListDataProvider;
  23. import com.vaadin.data.provider.Query;
  24. import com.vaadin.server.SerializableComparator;
  25. import com.vaadin.v7.data.util.filter.SimpleStringFilter;
  26. import com.vaadin.v7.data.util.filter.UnsupportedFilterException;
  27. /**
  28. * <p>
  29. * A specialized set of identified Items. Basically the Container is a set of
  30. * {@link Item}s, but it imposes certain constraints on its contents. These
  31. * constraints state the following:
  32. * </p>
  33. *
  34. * <ul>
  35. * <li>All Items in the Container must have the same number of Properties.
  36. * <li>All Items in the Container must have the same Property ID's (see
  37. * {@link Item#getItemPropertyIds()}).
  38. * <li>All Properties in the Items corresponding to the same Property ID must
  39. * have the same data type.
  40. * <li>All Items within a container are uniquely identified by their non-null
  41. * IDs.
  42. * </ul>
  43. *
  44. * <p>
  45. * The Container can be visualized as a representation of a relational database
  46. * table. Each Item in the Container represents a row in the table, and all
  47. * cells in a column (identified by a Property ID) have the same data type. Note
  48. * that as with the cells in a database table, no Property in a Container may be
  49. * empty, though they may contain <code>null</code> values.
  50. * </p>
  51. *
  52. * <p>
  53. * Note that though uniquely identified, the Items in a Container are not
  54. * necessarily {@link Container.Ordered ordered} or {@link Container.Indexed
  55. * indexed}.
  56. * </p>
  57. *
  58. * <p>
  59. * Containers can derive Item ID's from the item properties or use other,
  60. * container specific or user specified identifiers.
  61. * </p>
  62. *
  63. * <p>
  64. * If a container is {@link Filterable filtered} or {@link Sortable sorted},
  65. * most of the the methods of the container interface and its subinterfaces
  66. * (container size, {@link #containsId(Object)}, iteration and indices etc.)
  67. * relate to the filtered and sorted view, not to the full container contents.
  68. * See individual method javadoc for exceptions to this (adding and removing
  69. * items).
  70. * </p>
  71. *
  72. * <p>
  73. * <img src=doc-files/Container_full.gif>
  74. * </p>
  75. *
  76. * <p>
  77. * The Container interface is split to several subinterfaces so that a class can
  78. * implement only the ones it needs.
  79. * </p>
  80. *
  81. * @author Vaadin Ltd
  82. * @since 3.0
  83. *
  84. * @deprecated As of 8.0, replaced by {@link DataProvider}
  85. */
  86. @Deprecated
  87. public interface Container extends Serializable {
  88. /**
  89. * Gets the {@link Item} with the given Item ID from the Container. If the
  90. * Container does not contain the requested Item, <code>null</code> is
  91. * returned.
  92. * <p>
  93. * Containers should not return Items that are filtered out.
  94. *
  95. * @param itemId
  96. * ID of the {@link Item} to retrieve
  97. * @return the {@link Item} with the given ID or <code>null</code> if the
  98. * Item is not found in the Container
  99. */
  100. public Item getItem(Object itemId);
  101. /**
  102. * Gets the ID's of all Properties stored in the Container. The ID's cannot
  103. * be modified through the returned collection.
  104. *
  105. * @return unmodifiable collection of Property IDs
  106. */
  107. public Collection<?> getContainerPropertyIds();
  108. /**
  109. * Gets the ID's of all visible (after filtering and sorting) Items stored
  110. * in the Container. The ID's cannot be modified through the returned
  111. * collection.
  112. * <p>
  113. * If the container is {@link Ordered}, the collection returned by this
  114. * method should follow that order. If the container is {@link Sortable},
  115. * the items should be in the sorted order.
  116. * <p>
  117. * Calling this method for large lazy containers can be an expensive
  118. * operation and should be avoided when practical.
  119. *
  120. * @return unmodifiable collection of Item IDs
  121. */
  122. public Collection<?> getItemIds();
  123. /**
  124. * Gets the Property identified by the given itemId and propertyId from the
  125. * Container. If the Container does not contain the item or it is filtered
  126. * out, or the Container does not have the Property, <code>null</code> is
  127. * returned.
  128. *
  129. * @param itemId
  130. * ID of the visible Item which contains the Property
  131. * @param propertyId
  132. * ID of the Property to retrieve
  133. * @return Property with the given ID or <code>null</code>
  134. */
  135. public Property getContainerProperty(Object itemId, Object propertyId);
  136. /**
  137. * Gets the data type of all Properties identified by the given Property ID.
  138. *
  139. * @param propertyId
  140. * ID identifying the Properties
  141. * @return data type of the Properties
  142. */
  143. public Class<?> getType(Object propertyId);
  144. /**
  145. * Gets the number of visible Items in the Container.
  146. * <p>
  147. * Filtering can hide items so that they will not be visible through the
  148. * container API.
  149. *
  150. * @return number of Items in the Container
  151. */
  152. public int size();
  153. /**
  154. * Tests if the Container contains the specified Item.
  155. * <p>
  156. * Filtering can hide items so that they will not be visible through the
  157. * container API, and this method should respect visibility of items (i.e.
  158. * only indicate visible items as being in the container) if feasible for
  159. * the container.
  160. *
  161. * @param itemId
  162. * ID the of Item to be tested
  163. * @return boolean indicating if the Container holds the specified Item
  164. */
  165. public boolean containsId(Object itemId);
  166. /**
  167. * Creates a new Item with the given ID in the Container.
  168. *
  169. * <p>
  170. * The new Item is returned, and it is ready to have its Properties
  171. * modified. Returns <code>null</code> if the operation fails or the
  172. * Container already contains a Item with the given ID.
  173. * </p>
  174. *
  175. * <p>
  176. * This functionality is optional.
  177. * </p>
  178. *
  179. * @param itemId
  180. * ID of the Item to be created
  181. * @return Created new Item, or <code>null</code> in case of a failure
  182. * @throws UnsupportedOperationException
  183. * if adding an item with an explicit item ID is not supported
  184. * by the container
  185. */
  186. public Item addItem(Object itemId) throws UnsupportedOperationException;
  187. /**
  188. * Creates a new Item into the Container, and assign it an automatic ID.
  189. *
  190. * <p>
  191. * The new ID is returned, or <code>null</code> if the operation fails.
  192. * After a successful call you can use the {@link #getItem(Object ItemId)
  193. * <code>getItem</code>}method to fetch the Item.
  194. * </p>
  195. *
  196. * <p>
  197. * This functionality is optional.
  198. * </p>
  199. *
  200. * @return ID of the newly created Item, or <code>null</code> in case of a
  201. * failure
  202. * @throws UnsupportedOperationException
  203. * if adding an item without an explicit item ID is not
  204. * supported by the container
  205. */
  206. public Object addItem() throws UnsupportedOperationException;
  207. /**
  208. * Removes the Item identified by <code>ItemId</code> from the Container.
  209. *
  210. * <p>
  211. * Containers that support filtering should also allow removing an item that
  212. * is currently filtered out.
  213. * </p>
  214. *
  215. * <p>
  216. * This functionality is optional.
  217. * </p>
  218. *
  219. * @param itemId
  220. * ID of the Item to remove
  221. * @return <code>true</code> if the operation succeeded, <code>false</code>
  222. * if not
  223. * @throws UnsupportedOperationException
  224. * if the container does not support removing individual items
  225. */
  226. public boolean removeItem(Object itemId)
  227. throws UnsupportedOperationException;
  228. /**
  229. * Adds a new Property to all Items in the Container. The Property ID, data
  230. * type and default value of the new Property are given as parameters.
  231. * <p>
  232. * This functionality is optional.
  233. *
  234. * @param propertyId
  235. * ID of the Property
  236. * @param type
  237. * Data type of the new Property
  238. * @param defaultValue
  239. * The value all created Properties are initialized to
  240. * @return <code>true</code> if the operation succeeded, <code>false</code>
  241. * if not
  242. * @throws UnsupportedOperationException
  243. * if the container does not support explicitly adding container
  244. * properties
  245. */
  246. public boolean addContainerProperty(Object propertyId, Class<?> type,
  247. Object defaultValue) throws UnsupportedOperationException;
  248. /**
  249. * Removes a Property specified by the given Property ID from the Container.
  250. * Note that the Property will be removed from all Items in the Container.
  251. * <p>
  252. * This functionality is optional.
  253. *
  254. * @param propertyId
  255. * ID of the Property to remove
  256. * @return <code>true</code> if the operation succeeded, <code>false</code>
  257. * if not
  258. * @throws UnsupportedOperationException
  259. * if the container does not support removing container
  260. * properties
  261. */
  262. public boolean removeContainerProperty(Object propertyId)
  263. throws UnsupportedOperationException;
  264. /**
  265. * Removes all Items from the Container.
  266. *
  267. * <p>
  268. * Note that Property ID and type information is preserved. This
  269. * functionality is optional.
  270. * </p>
  271. *
  272. * @return <code>true</code> if the operation succeeded, <code>false</code>
  273. * if not
  274. * @throws UnsupportedOperationException
  275. * if the container does not support removing all items
  276. */
  277. public boolean removeAllItems() throws UnsupportedOperationException;
  278. /**
  279. * Interface for Container classes whose {@link Item}s can be traversed in
  280. * order.
  281. *
  282. * <p>
  283. * If the container is filtered or sorted, the traversal applies to the
  284. * filtered and sorted view.
  285. * </p>
  286. * <p>
  287. * The <code>addItemAfter()</code> methods should apply filters to the added
  288. * item after inserting it, possibly hiding it immediately. If the container
  289. * is being sorted, they may add items at the correct sorted position
  290. * instead of the given position. See also {@link Filterable} and
  291. * {@link Sortable} for more information.
  292. * </p>
  293. */
  294. @Deprecated
  295. public interface Ordered extends Container {
  296. /**
  297. * Gets the ID of the Item following the Item that corresponds to
  298. * <code>itemId</code>. If the given Item is the last or not found in
  299. * the Container, <code>null</code> is returned.
  300. *
  301. * @param itemId
  302. * ID of a visible Item in the Container
  303. * @return ID of the next visible Item or <code>null</code>
  304. */
  305. public Object nextItemId(Object itemId);
  306. /**
  307. * Gets the ID of the Item preceding the Item that corresponds to
  308. * <code>itemId</code>. If the given Item is the first or not found in
  309. * the Container, <code>null</code> is returned.
  310. *
  311. * @param itemId
  312. * ID of a visible Item in the Container
  313. * @return ID of the previous visible Item or <code>null</code>
  314. */
  315. public Object prevItemId(Object itemId);
  316. /**
  317. * Gets the ID of the first Item in the Container.
  318. *
  319. * @return ID of the first visible Item in the Container
  320. */
  321. public Object firstItemId();
  322. /**
  323. * Gets the ID of the last Item in the Container..
  324. *
  325. * @return ID of the last visible Item in the Container
  326. */
  327. public Object lastItemId();
  328. /**
  329. * Tests if the Item corresponding to the given Item ID is the first
  330. * Item in the Container.
  331. *
  332. * @param itemId
  333. * ID of an Item in the Container
  334. * @return <code>true</code> if the Item is first visible item in the
  335. * Container, <code>false</code> if not
  336. */
  337. public boolean isFirstId(Object itemId);
  338. /**
  339. * Tests if the Item corresponding to the given Item ID is the last Item
  340. * in the Container.
  341. *
  342. * @return <code>true</code> if the Item is last visible item in the
  343. * Container, <code>false</code> if not
  344. */
  345. public boolean isLastId(Object itemId);
  346. /**
  347. * Adds a new item after the given item.
  348. * <p>
  349. * Adding an item after null item adds the item as first item of the
  350. * ordered container.
  351. * </p>
  352. *
  353. * @see Ordered Ordered: adding items in filtered or sorted containers
  354. *
  355. * @param previousItemId
  356. * Id of the visible item in ordered container after which to
  357. * insert the new item.
  358. * @return item id the the created new item or null if the operation
  359. * fails.
  360. * @throws UnsupportedOperationException
  361. * if the operation is not supported by the container
  362. */
  363. public Object addItemAfter(Object previousItemId)
  364. throws UnsupportedOperationException;
  365. /**
  366. * Adds a new item after the given item.
  367. * <p>
  368. * Adding an item after null item adds the item as first item of the
  369. * ordered container.
  370. * </p>
  371. *
  372. * @see Ordered Ordered: adding items in filtered or sorted containers
  373. *
  374. * @param previousItemId
  375. * Id of the visible item in ordered container after which to
  376. * insert the new item.
  377. * @param newItemId
  378. * Id of the new item to be added.
  379. * @return new item or null if the operation fails.
  380. * @throws UnsupportedOperationException
  381. * if the operation is not supported by the container
  382. */
  383. public Item addItemAfter(Object previousItemId, Object newItemId)
  384. throws UnsupportedOperationException;
  385. }
  386. /**
  387. * Interface for Container classes whose {@link Item}s can be sorted.
  388. * <p>
  389. * When an {@link Ordered} or {@link Indexed} container is sorted, all
  390. * relevant operations of these interfaces should only use the filtered and
  391. * sorted contents and the filtered indices to the container. Indices or
  392. * item identifiers in the public API refer to the visible view unless
  393. * otherwise stated. However, the <code>addItem*()</code> methods may add
  394. * items that will be filtered out after addition or moved to another
  395. * position based on sorting.
  396. * </p>
  397. * <p>
  398. * How sorting is performed when a {@link Hierarchical} container implements
  399. * {@link Sortable} is implementation specific and should be documented in
  400. * the implementing class. However, the recommended approach is sorting the
  401. * roots and the sets of children of each item separately.
  402. * </p>
  403. * <p>
  404. * Depending on the container type, sorting a container may permanently
  405. * change the internal order of items in the container.
  406. * </p>
  407. *
  408. * @deprecated As of 8.0, sorting is integrated into {@link DataProvider}
  409. * and {@link Query#getSortOrders()}. For in-memory case, you
  410. * can use also
  411. * {@link ListDataProvider#setSortComparator(SerializableComparator)}.
  412. * For back-end DataProviders, see
  413. * {@link AbstractBackEndDataProvider#setSortOrders(List)}.
  414. */
  415. @Deprecated
  416. public interface Sortable extends Ordered {
  417. /**
  418. * Sorts the container items.
  419. * <p>
  420. * Sorting a container can irreversibly change the order of its items or
  421. * only change the order temporarily, depending on the container.
  422. *
  423. * @param propertyId
  424. * Array of container property IDs, whose values are used to
  425. * sort the items in container as primary, secondary, ...
  426. * sorting criterion. All of the item IDs must be in the
  427. * collection returned by
  428. * {@link #getSortableContainerPropertyIds()}
  429. * @param ascending
  430. * Array of sorting order flags corresponding to each
  431. * property ID used in sorting. If this array is shorter than
  432. * propertyId array, ascending order is assumed for items
  433. * where the order is not specified. Use <code>true</code> to
  434. * sort in ascending order, <code>false</code> to use
  435. * descending order.
  436. */
  437. void sort(Object[] propertyId, boolean[] ascending);
  438. /**
  439. * Gets the container property IDs which can be used to sort the items.
  440. *
  441. * @return the IDs of the properties that can be used for sorting the
  442. * container
  443. */
  444. Collection<?> getSortableContainerPropertyIds();
  445. }
  446. /**
  447. * Interface for Container classes whose {@link Item}s can be accessed by
  448. * their position in the container.
  449. * <p>
  450. * If the container is filtered or sorted, all indices refer to the filtered
  451. * and sorted view. However, the <code>addItemAt()</code> methods may add
  452. * items that will be filtered out after addition or moved to another
  453. * position based on sorting.
  454. * </p>
  455. */
  456. @Deprecated
  457. public interface Indexed extends Ordered {
  458. /**
  459. * Gets the index of the Item corresponding to the itemId. The following
  460. * is <code>true</code> for the returned index: 0 <= index < size(), or
  461. * index = -1 if there is no visible item with that id in the container.
  462. *
  463. * @param itemId
  464. * ID of an Item in the Container
  465. * @return index of the Item, or -1 if (the filtered and sorted view of)
  466. * the Container does not include the Item
  467. */
  468. public int indexOfId(Object itemId);
  469. /**
  470. * Get the item id for the item at the position given by
  471. * <code>index</code>.
  472. * <p>
  473. *
  474. * @param index
  475. * the index of the requested item id
  476. * @return the item id of the item at the given index
  477. * @throws IndexOutOfBoundsException
  478. * if <code>index</code> is outside the range of the
  479. * container. (i.e.
  480. * <code>index &lt; 0 || container.size()-1 &lt; index</code>
  481. * )
  482. */
  483. public Object getIdByIndex(int index);
  484. /**
  485. * Get <code>numberOfItems</code> consecutive item ids from the
  486. * container, starting with the item id at <code>startIndex</code>.
  487. * <p>
  488. * Implementations should return at most <code>numberOfItems</code> item
  489. * ids, but can contain less if the container has less items than
  490. * required to fulfill the request. The returned list must hence contain
  491. * all of the item ids from the range:
  492. * <p>
  493. * <code>startIndex</code> to
  494. * <code>max(startIndex + (numberOfItems-1), container.size()-1)</code>.
  495. * <p>
  496. * For quick migration to new API see:
  497. * {@link ContainerHelpers#getItemIdsUsingGetIdByIndex(int, int, Indexed)}
  498. *
  499. * @param startIndex
  500. * the index for the first item which id to include
  501. * @param numberOfItems
  502. * the number of consecutive item ids to get from the given
  503. * start index, must be >= 0
  504. * @return List containing the requested item ids or empty list if
  505. * <code>numberOfItems</code> == 0; not null
  506. *
  507. * @throws IllegalArgumentException
  508. * if <code>numberOfItems</code> is < 0
  509. * @throws IndexOutOfBoundsException
  510. * if <code>startIndex</code> is outside the range of the
  511. * container. (i.e.
  512. * <code>startIndex &lt; 0 || container.size()-1 &lt; startIndex</code>
  513. * )
  514. *
  515. * @since 7.0
  516. */
  517. public List<?> getItemIds(int startIndex, int numberOfItems);
  518. /**
  519. * Adds a new item at given index (in the filtered view).
  520. * <p>
  521. * The indices of the item currently in the given position and all the
  522. * following items are incremented.
  523. * </p>
  524. * <p>
  525. * This method should apply filters to the added item after inserting
  526. * it, possibly hiding it immediately. If the container is being sorted,
  527. * the item may be added at the correct sorted position instead of the
  528. * given position. See {@link Indexed}, {@link Ordered},
  529. * {@link Filterable} and {@link Sortable} for more information.
  530. * </p>
  531. *
  532. * @param index
  533. * Index (in the filtered and sorted view) to add the new
  534. * item.
  535. * @return item id of the created item or null if the operation fails.
  536. * @throws UnsupportedOperationException
  537. * if the operation is not supported by the container
  538. */
  539. public Object addItemAt(int index) throws UnsupportedOperationException;
  540. /**
  541. * Adds a new item at given index (in the filtered view).
  542. * <p>
  543. * The indexes of the item currently in the given position and all the
  544. * following items are incremented.
  545. * </p>
  546. * <p>
  547. * This method should apply filters to the added item after inserting
  548. * it, possibly hiding it immediately. If the container is being sorted,
  549. * the item may be added at the correct sorted position instead of the
  550. * given position. See {@link Indexed}, {@link Filterable} and
  551. * {@link Sortable} for more information.
  552. * </p>
  553. *
  554. * @param index
  555. * Index (in the filtered and sorted view) at which to add
  556. * the new item.
  557. * @param newItemId
  558. * Id of the new item to be added.
  559. * @return new {@link Item} or null if the operation fails.
  560. * @throws UnsupportedOperationException
  561. * if the operation is not supported by the container
  562. */
  563. public Item addItemAt(int index, Object newItemId)
  564. throws UnsupportedOperationException;
  565. /**
  566. * An <code>Event</code> object specifying information about the added
  567. * items.
  568. *
  569. * @since 7.4
  570. */
  571. @Deprecated
  572. public interface ItemAddEvent extends ItemSetChangeEvent {
  573. /**
  574. * Gets the item id of the first added item.
  575. *
  576. * @return item id of the first added item
  577. */
  578. public Object getFirstItemId();
  579. /**
  580. * Gets the index of the first added item.
  581. *
  582. * @return index of the first added item
  583. */
  584. public int getFirstIndex();
  585. /**
  586. * Gets the number of the added items.
  587. *
  588. * @return the number of added items.
  589. */
  590. public int getAddedItemsCount();
  591. }
  592. /**
  593. * An <code>Event</code> object specifying information about the removed
  594. * items.
  595. *
  596. * @since 7.4
  597. */
  598. @Deprecated
  599. public interface ItemRemoveEvent extends ItemSetChangeEvent {
  600. /**
  601. * Gets the item id of the first removed item.
  602. *
  603. * @return item id of the first removed item
  604. */
  605. public Object getFirstItemId();
  606. /**
  607. * Gets the index of the first removed item.
  608. *
  609. * @return index of the first removed item
  610. */
  611. public int getFirstIndex();
  612. /**
  613. * Gets the number of the removed items.
  614. *
  615. * @return the number of removed items
  616. */
  617. public int getRemovedItemsCount();
  618. }
  619. }
  620. /**
  621. * <p>
  622. * Interface for <code>Container</code> classes whose Items can be arranged
  623. * hierarchically. This means that the Items in the container belong in a
  624. * tree-like structure, with the following quirks:
  625. * </p>
  626. *
  627. * <ul>
  628. * <li>The Item structure may have more than one root elements
  629. * <li>The Items in the hierarchy can be declared explicitly to be able or
  630. * unable to have children.
  631. * </ul>
  632. *
  633. * @deprecated See {@code HierarchicalDataProvider} and its implementations.
  634. */
  635. @Deprecated
  636. public interface Hierarchical extends Container {
  637. /**
  638. * Gets the IDs of all Items that are children of the specified Item.
  639. * The returned collection is unmodifiable.
  640. *
  641. * @param itemId
  642. * ID of the Item whose children the caller is interested in
  643. * @return An unmodifiable {@link java.util.Collection collection}
  644. * containing the IDs of all other Items that are children in
  645. * the container hierarchy; {@code null} if item does not have
  646. * any children.
  647. */
  648. public Collection<?> getChildren(Object itemId);
  649. /**
  650. * Gets the ID of the parent Item of the specified Item.
  651. *
  652. * @param itemId
  653. * ID of the Item whose parent the caller wishes to find out.
  654. * @return the ID of the parent Item. Will be <code>null</code> if the
  655. * specified Item is a root element.
  656. */
  657. public Object getParent(Object itemId);
  658. /**
  659. * Gets the IDs of all Items in the container that don't have a parent.
  660. * Such items are called <code>root</code> Items. The returned
  661. * collection is unmodifiable.
  662. *
  663. * @return An unmodifiable {@link java.util.Collection collection}
  664. * containing IDs of all root elements of the container
  665. */
  666. public Collection<?> rootItemIds();
  667. /**
  668. * <p>
  669. * Sets the parent of an Item. The new parent item must exist and be
  670. * able to have children. (
  671. * <code>{@link #areChildrenAllowed(Object)} == true</code> ). It is
  672. * also possible to detach a node from the hierarchy (and thus make it
  673. * root) by setting the parent <code>null</code>.
  674. * </p>
  675. *
  676. * <p>
  677. * This operation is optional.
  678. * </p>
  679. *
  680. * @param itemId
  681. * ID of the item to be set as the child of the Item
  682. * identified with <code>newParentId</code>
  683. * @param newParentId
  684. * ID of the Item that's to be the new parent of the Item
  685. * identified with <code>itemId</code>
  686. * @return <code>true</code> if the operation succeeded,
  687. * <code>false</code> if not
  688. */
  689. public boolean setParent(Object itemId, Object newParentId)
  690. throws UnsupportedOperationException;
  691. /**
  692. * Tests if the Item with given ID can have children.
  693. *
  694. * @param itemId
  695. * ID of the Item in the container whose child capability is
  696. * to be tested
  697. * @return <code>true</code> if the specified Item exists in the
  698. * Container and it can have children, <code>false</code> if
  699. * it's not found from the container or it can't have children.
  700. */
  701. public boolean areChildrenAllowed(Object itemId);
  702. /**
  703. * <p>
  704. * Sets the given Item's capability to have children. If the Item
  705. * identified with <code>itemId</code> already has children and
  706. * <code>{@link #areChildrenAllowed(Object)}</code> is false this method
  707. * fails and <code>false</code> is returned.
  708. * </p>
  709. * <p>
  710. * The children must be first explicitly removed with
  711. * {@link #setParent(Object itemId, Object newParentId)}or
  712. * {@link Container#removeItem(Object itemId)}.
  713. * </p>
  714. *
  715. * <p>
  716. * This operation is optional. If it is not implemented, the method
  717. * always returns <code>false</code>.
  718. * </p>
  719. *
  720. * @param itemId
  721. * ID of the Item in the container whose child capability is
  722. * to be set
  723. * @param areChildrenAllowed
  724. * boolean value specifying if the Item can have children or
  725. * not
  726. * @return <code>true</code> if the operation succeeded,
  727. * <code>false</code> if not
  728. */
  729. public boolean setChildrenAllowed(Object itemId,
  730. boolean areChildrenAllowed)
  731. throws UnsupportedOperationException;
  732. /**
  733. * Tests if the Item specified with <code>itemId</code> is a root Item.
  734. * The hierarchical container can have more than one root and must have
  735. * at least one unless it is empty. The
  736. * {@link #getParent(Object itemId)} method always returns
  737. * <code>null</code> for root Items.
  738. *
  739. * @param itemId
  740. * ID of the Item whose root status is to be tested
  741. * @return <code>true</code> if the specified Item is a root,
  742. * <code>false</code> if not
  743. */
  744. public boolean isRoot(Object itemId);
  745. /**
  746. * <p>
  747. * Tests if the Item specified with <code>itemId</code> has child Items
  748. * or if it is a leaf. The {@link #getChildren(Object itemId)} method
  749. * always returns <code>null</code> for leaf Items.
  750. * </p>
  751. *
  752. * <p>
  753. * Note that being a leaf does not imply whether or not an Item is
  754. * allowed to have children.
  755. * </p>
  756. *
  757. * @param itemId
  758. * ID of the Item to be tested
  759. * @return <code>true</code> if the specified Item has children,
  760. * <code>false</code> if not (is a leaf)
  761. */
  762. public boolean hasChildren(Object itemId);
  763. /**
  764. * <p>
  765. * Removes the Item identified by <code>ItemId</code> from the
  766. * Container.
  767. * </p>
  768. *
  769. * <p>
  770. * Note that this does not remove any children the item might have.
  771. * </p>
  772. *
  773. * @param itemId
  774. * ID of the Item to remove
  775. * @return <code>true</code> if the operation succeeded,
  776. * <code>false</code> if not
  777. */
  778. @Override
  779. public boolean removeItem(Object itemId)
  780. throws UnsupportedOperationException;
  781. }
  782. /**
  783. * Interface that is implemented by containers which allow reducing their
  784. * visible contents based on a set of filters. This interface has been
  785. * renamed from {@link Filterable}, and implementing the new
  786. * {@link Filterable} instead of or in addition to {@link SimpleFilterable}
  787. * is recommended. This interface might be removed in future Vaadin
  788. * versions.
  789. * <p>
  790. * When a set of filters are set, only items that match all the filters are
  791. * included in the visible contents of the container. Still new items that
  792. * do not match filters can be added to the container. Multiple filters can
  793. * be added and the container remembers the state of the filters. When
  794. * multiple filters are added, all filters must match for an item to be
  795. * visible in the container.
  796. * </p>
  797. * <p>
  798. * When an {@link Ordered} or {@link Indexed} container is filtered, all
  799. * operations of these interfaces should only use the filtered contents and
  800. * the filtered indices to the container.
  801. * </p>
  802. * <p>
  803. * How filtering is performed when a {@link Hierarchical} container
  804. * implements {@link SimpleFilterable} is implementation specific and should
  805. * be documented in the implementing class.
  806. * </p>
  807. * <p>
  808. * Adding items (if supported) to a filtered {@link Ordered} or
  809. * {@link Indexed} container should insert them immediately after the
  810. * indicated visible item. The unfiltered position of items added at index
  811. * 0, at index {@link Container#size()} or at an undefined position is up to
  812. * the implementation.
  813. * </p>
  814. * <p>
  815. * The functionality of SimpleFilterable can be implemented using the
  816. * {@link Filterable} API and {@link SimpleStringFilter}.
  817. * </p>
  818. *
  819. * @since 5.0 (renamed from Filterable to SimpleFilterable in 6.6)
  820. */
  821. @Deprecated
  822. public interface SimpleFilterable extends Container, Serializable {
  823. /**
  824. * Add a filter for given property.
  825. * <p>
  826. * The API {@link Filterable#addContainerFilter(Filter)} is recommended
  827. * instead of this method. A {@link SimpleStringFilter} can be used with
  828. * the new API to implement the old string filtering functionality.
  829. * <p>
  830. * The filter accepts items for which toString() of the value of the
  831. * given property contains or starts with given filterString. Other
  832. * items are not visible in the container when filtered.
  833. * <p>
  834. * If a container has multiple filters, only items accepted by all
  835. * filters are visible.
  836. *
  837. * @param propertyId
  838. * Property for which the filter is applied to.
  839. * @param filterString
  840. * String that must match the value of the property
  841. * @param ignoreCase
  842. * Determine if the casing can be ignored when comparing
  843. * strings.
  844. * @param onlyMatchPrefix
  845. * Only match prefixes; no other matches are included.
  846. */
  847. public void addContainerFilter(Object propertyId, String filterString,
  848. boolean ignoreCase, boolean onlyMatchPrefix);
  849. /**
  850. * Remove all filters from all properties.
  851. */
  852. public void removeAllContainerFilters();
  853. /**
  854. * Remove all filters from the given property.
  855. *
  856. * @param propertyId
  857. * for which to remove filters
  858. */
  859. public void removeContainerFilters(Object propertyId);
  860. }
  861. /**
  862. * Filter interface for container filtering.
  863. * <p>
  864. * If a filter does not support in-memory filtering,
  865. * {@link #passesFilter(Item)} should throw
  866. * {@link UnsupportedOperationException}.
  867. * <p>
  868. * Lazy containers must be able to map filters to their internal
  869. * representation (e.g. SQL or JPA 2.0 Criteria).
  870. * <p>
  871. * An {@link UnsupportedFilterException} can be thrown by the container if a
  872. * particular filter is not supported by the container.
  873. * <p>
  874. * An {@link Filter} should implement {@link #equals(Object)} and
  875. * {@link #hashCode()} correctly to avoid duplicate filter registrations
  876. * etc.
  877. *
  878. * @see Filterable
  879. *
  880. * @since 6.6
  881. *
  882. * @deprecated As of 8.0, the whole filtering feature is integrated into
  883. * {@link DataProvider}. For in-memory case
  884. * ({@link ListDataProvider}), use predicates as filters. For
  885. * back-end DataProviders, filters are specific to the
  886. * implementation.
  887. */
  888. @Deprecated
  889. public interface Filter extends Serializable {
  890. /**
  891. * Check if an item passes the filter (in-memory filtering).
  892. *
  893. * @param itemId
  894. * identifier of the item being filtered; may be null when
  895. * the item is being added to the container
  896. * @param item
  897. * the item being filtered
  898. * @return true if the item is accepted by this filter
  899. * @throws UnsupportedOperationException
  900. * if the filter cannot be used for in-memory filtering
  901. */
  902. public boolean passesFilter(Object itemId, Item item)
  903. throws UnsupportedOperationException;
  904. /**
  905. * Check if a change in the value of a property can affect the filtering
  906. * result. May always return true, at the cost of performance.
  907. *
  908. * If the filter cannot determine whether it may depend on the property
  909. * or not, should return true.
  910. *
  911. * @param propertyId
  912. * @return true if the filtering result may/does change based on changes
  913. * to the property identified by propertyId
  914. */
  915. public boolean appliesToProperty(Object propertyId);
  916. }
  917. /**
  918. * Interface that is implemented by containers which allow reducing their
  919. * visible contents based on a set of filters.
  920. * <p>
  921. * When a set of filters are set, only items that match all the filters are
  922. * included in the visible contents of the container. Still new items that
  923. * do not match filters can be added to the container. Multiple filters can
  924. * be added and the container remembers the state of the filters. When
  925. * multiple filters are added, all filters must match for an item to be
  926. * visible in the container.
  927. * </p>
  928. * <p>
  929. * When an {@link Ordered} or {@link Indexed} container is filtered, all
  930. * operations of these interfaces should only use the filtered and sorted
  931. * contents and the filtered indices to the container. Indices or item
  932. * identifiers in the public API refer to the visible view unless otherwise
  933. * stated. However, the <code>addItem*()</code> methods may add items that
  934. * will be filtered out after addition or moved to another position based on
  935. * sorting.
  936. * </p>
  937. * <p>
  938. * How filtering is performed when a {@link Hierarchical} container
  939. * implements {@link Filterable} is implementation specific and should be
  940. * documented in the implementing class.
  941. * </p>
  942. * <p>
  943. * Adding items (if supported) to a filtered {@link Ordered} or
  944. * {@link Indexed} container should insert them immediately after the
  945. * indicated visible item. However, the unfiltered position of items added
  946. * at index 0, at index {@link Container#size()} or at an undefined position
  947. * is up to the implementation.
  948. * </p>
  949. *
  950. * <p>
  951. * This API replaces the old Filterable interface, renamed to
  952. * {@link SimpleFilterable} in Vaadin 6.6.
  953. * </p>
  954. *
  955. * @since 6.6
  956. */
  957. @Deprecated
  958. public interface Filterable extends Container, Serializable {
  959. /**
  960. * Adds a filter for the container.
  961. * <p>
  962. * If a container has multiple filters, only items accepted by all
  963. * filters are visible.
  964. *
  965. * @throws UnsupportedFilterException
  966. * if the filter is not supported by the container
  967. */
  968. public void addContainerFilter(Filter filter)
  969. throws UnsupportedFilterException;
  970. /**
  971. * Removes a filter from the container.
  972. * <p>
  973. * This requires that the equals() method considers the filters as
  974. * equivalent (same instance or properly implemented equals() method).
  975. */
  976. public void removeContainerFilter(Filter filter);
  977. /**
  978. * Remove all active filters from the container.
  979. */
  980. public void removeAllContainerFilters();
  981. /**
  982. * Returns the filters which have been applied to the container
  983. *
  984. * @return A collection of filters which have been applied to the
  985. * container. An empty collection if no filters have been
  986. * applied.
  987. * @since 7.1
  988. */
  989. public Collection<Filter> getContainerFilters();
  990. }
  991. /**
  992. * Interface implemented by viewer classes capable of using a Container as a
  993. * data source.
  994. */
  995. @Deprecated
  996. public interface Viewer extends Serializable {
  997. /**
  998. * Sets the Container that serves as the data source of the viewer.
  999. *
  1000. * @param newDataSource
  1001. * The new data source Item
  1002. */
  1003. public void setContainerDataSource(Container newDataSource);
  1004. /**
  1005. * Gets the Container serving as the data source of the viewer.
  1006. *
  1007. * @return data source Container
  1008. */
  1009. public Container getContainerDataSource();
  1010. }
  1011. /**
  1012. * <p>
  1013. * Interface implemented by the editor classes supporting editing the
  1014. * Container. Implementing this interface means that the Container serving
  1015. * as the data source of the editor can be modified through it.
  1016. * </p>
  1017. * <p>
  1018. * Note that not implementing the <code>Container.Editor</code> interface
  1019. * does not restrict the class from editing the Container contents
  1020. * internally.
  1021. * </p>
  1022. */
  1023. @Deprecated
  1024. public interface Editor extends Container.Viewer, Serializable {
  1025. }
  1026. /* Contents change event */
  1027. /**
  1028. * An <code>Event</code> object specifying the Container whose Item set has
  1029. * changed (items added, removed or reordered).
  1030. *
  1031. * A simple property value change is not an item set change.
  1032. */
  1033. @Deprecated
  1034. public interface ItemSetChangeEvent extends Serializable {
  1035. /**
  1036. * Gets the Property where the event occurred.
  1037. *
  1038. * @return source of the event
  1039. */
  1040. public Container getContainer();
  1041. }
  1042. /**
  1043. * Container Item set change listener interface.
  1044. * <p>
  1045. * An item set change refers to addition, removal or reordering of items in
  1046. * the container. A simple property value change is not an item set change.
  1047. */
  1048. @Deprecated
  1049. public interface ItemSetChangeListener extends Serializable {
  1050. /**
  1051. * Lets the listener know a Containers visible (filtered and/or sorted,
  1052. * if applicable) Item set has changed.
  1053. *
  1054. * @param event
  1055. * change event text
  1056. */
  1057. public void containerItemSetChange(Container.ItemSetChangeEvent event);
  1058. }
  1059. /**
  1060. * The interface for adding and removing <code>ItemSetChangeEvent</code>
  1061. * listeners. By implementing this interface a class explicitly announces
  1062. * that it will generate a <code>ItemSetChangeEvent</code> when its contents
  1063. * are modified.
  1064. * <p>
  1065. * An item set change refers to addition, removal or reordering of items in
  1066. * the container. A simple property value change is not an item set change.
  1067. *
  1068. * <p>
  1069. * Note: The general Java convention is not to explicitly declare that a
  1070. * class generates events, but to directly define the
  1071. * <code>addListener</code> and <code>removeListener</code> methods. That
  1072. * way the caller of these methods has no real way of finding out if the
  1073. * class really will send the events, or if it just defines the methods to
  1074. * be able to implement an interface.
  1075. * </p>
  1076. */
  1077. @Deprecated
  1078. public interface ItemSetChangeNotifier extends Serializable {
  1079. /**
  1080. * Adds an Item set change listener for the object.
  1081. *
  1082. * @param listener
  1083. * listener to be added
  1084. */
  1085. public void addItemSetChangeListener(
  1086. Container.ItemSetChangeListener listener);
  1087. /**
  1088. * @deprecated As of 7.0, replaced by
  1089. * {@link #addItemSetChangeListener(ItemSetChangeListener)}
  1090. **/
  1091. @Deprecated
  1092. public void addListener(Container.ItemSetChangeListener listener);
  1093. /**
  1094. * Removes the Item set change listener from the object.
  1095. *
  1096. * @param listener
  1097. * listener to be removed
  1098. */
  1099. public void removeItemSetChangeListener(
  1100. Container.ItemSetChangeListener listener);
  1101. /**
  1102. * @deprecated As of 7.0, replaced by
  1103. * {@link #removeItemSetChangeListener(ItemSetChangeListener)}
  1104. **/
  1105. @Deprecated
  1106. public void removeListener(Container.ItemSetChangeListener listener);
  1107. }
  1108. /* Property set change event */
  1109. /**
  1110. * An <code>Event</code> object specifying the Container whose Property set
  1111. * has changed.
  1112. * <p>
  1113. * A property set change means the addition, removal or other structural
  1114. * changes to the properties of a container. Changes concerning the set of
  1115. * items in the container and their property values are not property set
  1116. * changes.
  1117. */
  1118. @Deprecated
  1119. public interface PropertySetChangeEvent extends Serializable {
  1120. /**
  1121. * Retrieves the Container whose contents have been modified.
  1122. *
  1123. * @return Source Container of the event.
  1124. */
  1125. public Container getContainer();
  1126. }
  1127. /**
  1128. * The listener interface for receiving <code>PropertySetChangeEvent</code>
  1129. * objects.
  1130. * <p>
  1131. * A property set change means the addition, removal or other structural
  1132. * change of the properties (supported property IDs) of a container. Changes
  1133. * concerning the set of items in the container and their property values
  1134. * are not property set changes.
  1135. */
  1136. @Deprecated
  1137. public interface PropertySetChangeListener extends Serializable {
  1138. /**
  1139. * Notifies this listener that the set of property IDs supported by the
  1140. * Container has changed.
  1141. *
  1142. * @param event
  1143. * Change event.
  1144. */
  1145. public void containerPropertySetChange(
  1146. Container.PropertySetChangeEvent event);
  1147. }
  1148. /**
  1149. * <p>
  1150. * The interface for adding and removing <code>PropertySetChangeEvent</code>
  1151. * listeners. By implementing this interface a class explicitly announces
  1152. * that it will generate a <code>PropertySetChangeEvent</code> when the set
  1153. * of property IDs supported by the container is modified.
  1154. * </p>
  1155. *
  1156. * <p>
  1157. * A property set change means the addition, removal or other structural
  1158. * changes to the properties of a container. Changes concerning the set of
  1159. * items in the container and their property values are not property set
  1160. * changes.
  1161. * </p>
  1162. *
  1163. * <p>
  1164. * Note that the general Java convention is not to explicitly declare that a
  1165. * class generates events, but to directly define the
  1166. * <code>addListener</code> and <code>removeListener</code> methods. That
  1167. * way the caller of these methods has no real way of finding out if the
  1168. * class really will send the events, or if it just defines the methods to
  1169. * be able to implement an interface.
  1170. * </p>
  1171. */
  1172. @Deprecated
  1173. public interface PropertySetChangeNotifier extends Serializable {
  1174. /**
  1175. * Registers a new Property set change listener for this Container.
  1176. *
  1177. * @param listener
  1178. * The new Listener to be registered
  1179. */
  1180. public void addPropertySetChangeListener(
  1181. Container.PropertySetChangeListener listener);
  1182. /**
  1183. * @deprecated As of 7.0, replaced by
  1184. * {@link #addPropertySetChangeListener(PropertySetChangeListener)}
  1185. **/
  1186. @Deprecated
  1187. public void addListener(Container.PropertySetChangeListener listener);
  1188. /**
  1189. * Removes a previously registered Property set change listener.
  1190. *
  1191. * @param listener
  1192. * Listener to be removed
  1193. */
  1194. public void removePropertySetChangeListener(
  1195. Container.PropertySetChangeListener listener);
  1196. /**
  1197. * @deprecated As of 7.0, replaced by
  1198. * {@link #removePropertySetChangeListener(PropertySetChangeListener)}
  1199. **/
  1200. @Deprecated
  1201. public void removeListener(
  1202. Container.PropertySetChangeListener listener);
  1203. }
  1204. }