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.

Container.java 41KB

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