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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  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. public boolean removeItem(Object itemId)
  654. throws UnsupportedOperationException;
  655. }
  656. /**
  657. * Interface that is implemented by containers which allow reducing their
  658. * visible contents based on a set of filters. This interface has been
  659. * renamed from {@link Filterable}, and implementing the new
  660. * {@link Filterable} instead of or in addition to {@link SimpleFilterable}
  661. * is recommended. This interface might be removed in future Vaadin
  662. * versions.
  663. * <p>
  664. * When a set of filters are set, only items that match all the filters are
  665. * included in the visible contents of the container. Still new items that
  666. * do not match filters can be added to the container. Multiple filters can
  667. * be added and the container remembers the state of the filters. When
  668. * multiple filters are added, all filters must match for an item to be
  669. * visible in the container.
  670. * </p>
  671. * <p>
  672. * When an {@link Ordered} or {@link Indexed} container is filtered, all
  673. * operations of these interfaces should only use the filtered contents and
  674. * the filtered indices to the container.
  675. * </p>
  676. * <p>
  677. * How filtering is performed when a {@link Hierarchical} container
  678. * implements {@link SimpleFilterable} is implementation specific and should
  679. * be documented in the implementing class.
  680. * </p>
  681. * <p>
  682. * Adding items (if supported) to a filtered {@link Ordered} or
  683. * {@link Indexed} container should insert them immediately after the
  684. * indicated visible item. The unfiltered position of items added at index
  685. * 0, at index {@link com.vaadin.data.Container#size()} or at an undefined
  686. * position is up to the implementation.
  687. * </p>
  688. * <p>
  689. * The functionality of SimpleFilterable can be implemented using the
  690. * {@link Filterable} API and {@link SimpleStringFilter}.
  691. * </p>
  692. *
  693. * @since 5.0 (renamed from Filterable to SimpleFilterable in 6.6)
  694. */
  695. public interface SimpleFilterable extends Container, Serializable {
  696. /**
  697. * Add a filter for given property.
  698. *
  699. * The API {@link Filterable#addContainerFilter(Filter)} is recommended
  700. * instead of this method. A {@link SimpleStringFilter} can be used with
  701. * the new API to implement the old string filtering functionality.
  702. *
  703. * The filter accepts items for which toString() of the value of the
  704. * given property contains or starts with given filterString. Other
  705. * items are not visible in the container when filtered.
  706. *
  707. * If a container has multiple filters, only items accepted by all
  708. * filters are visible.
  709. *
  710. * @param propertyId
  711. * Property for which the filter is applied to.
  712. * @param filterString
  713. * String that must match the value of the property
  714. * @param ignoreCase
  715. * Determine if the casing can be ignored when comparing
  716. * strings.
  717. * @param onlyMatchPrefix
  718. * Only match prefixes; no other matches are included.
  719. */
  720. public void addContainerFilter(Object propertyId, String filterString,
  721. boolean ignoreCase, boolean onlyMatchPrefix);
  722. /**
  723. * Remove all filters from all properties.
  724. */
  725. public void removeAllContainerFilters();
  726. /**
  727. * Remove all filters from the given property.
  728. *
  729. * @param propertyId
  730. * for which to remove filters
  731. */
  732. public void removeContainerFilters(Object propertyId);
  733. }
  734. /**
  735. * Filter interface for container filtering.
  736. *
  737. * If a filter does not support in-memory filtering,
  738. * {@link #passesFilter(Item)} should throw
  739. * {@link UnsupportedOperationException}.
  740. *
  741. * Lazy containers must be able to map filters to their internal
  742. * representation (e.g. SQL or JPA 2.0 Criteria).
  743. *
  744. * An {@link UnsupportedFilterException} can be thrown by the container if a
  745. * particular filter is not supported by the container.
  746. *
  747. * An {@link Filter} should implement {@link #equals(Object)} and
  748. * {@link #hashCode()} correctly to avoid duplicate filter registrations
  749. * etc.
  750. *
  751. * @see Filterable
  752. *
  753. * @since 6.6
  754. */
  755. public interface Filter extends Serializable {
  756. /**
  757. * Check if an item passes the filter (in-memory filtering).
  758. *
  759. * @param itemId
  760. * identifier of the item being filtered; may be null when
  761. * the item is being added to the container
  762. * @param item
  763. * the item being filtered
  764. * @return true if the item is accepted by this filter
  765. * @throws UnsupportedOperationException
  766. * if the filter cannot be used for in-memory filtering
  767. */
  768. public boolean passesFilter(Object itemId, Item item)
  769. throws UnsupportedOperationException;
  770. /**
  771. * Check if a change in the value of a property can affect the filtering
  772. * result. May always return true, at the cost of performance.
  773. *
  774. * If the filter cannot determine whether it may depend on the property
  775. * or not, should return true.
  776. *
  777. * @param propertyId
  778. * @return true if the filtering result may/does change based on changes
  779. * to the property identified by propertyId
  780. */
  781. public boolean appliesToProperty(Object propertyId);
  782. }
  783. /**
  784. * Interface that is implemented by containers which allow reducing their
  785. * visible contents based on a set of filters.
  786. * <p>
  787. * When a set of filters are set, only items that match all the filters are
  788. * included in the visible contents of the container. Still new items that
  789. * do not match filters can be added to the container. Multiple filters can
  790. * be added and the container remembers the state of the filters. When
  791. * multiple filters are added, all filters must match for an item to be
  792. * visible in the container.
  793. * </p>
  794. * <p>
  795. * When an {@link Ordered} or {@link Indexed} container is filtered, all
  796. * operations of these interfaces should only use the filtered and sorted
  797. * contents and the filtered indices to the container. Indices or item
  798. * identifiers in the public API refer to the visible view unless otherwise
  799. * stated. However, the <code>addItem*()</code> methods may add items that
  800. * will be filtered out after addition or moved to another position based on
  801. * sorting.
  802. * </p>
  803. * <p>
  804. * How filtering is performed when a {@link Hierarchical} container
  805. * implements {@link Filterable} is implementation specific and should be
  806. * documented in the implementing class.
  807. * </p>
  808. * <p>
  809. * Adding items (if supported) to a filtered {@link Ordered} or
  810. * {@link Indexed} container should insert them immediately after the
  811. * indicated visible item. However, the unfiltered position of items added
  812. * at index 0, at index {@link com.vaadin.data.Container#size()} or at an
  813. * undefined position is up to the implementation.
  814. * </p>
  815. *
  816. * <p>
  817. * This API replaces the old Filterable interface, renamed to
  818. * {@link SimpleFilterable} in Vaadin 6.6.
  819. * </p>
  820. *
  821. * @since 6.6
  822. */
  823. public interface Filterable extends Container, Serializable {
  824. /**
  825. * Adds a filter for the container.
  826. *
  827. * If a container has multiple filters, only items accepted by all
  828. * filters are visible.
  829. *
  830. * @throws UnsupportedFilterException
  831. * if the filter is not supported by the container
  832. */
  833. public void addContainerFilter(Filter filter)
  834. throws UnsupportedFilterException;
  835. /**
  836. * Removes a filter from the container.
  837. *
  838. * This requires that the equals() method considers the filters as
  839. * equivalent (same instance or properly implemented equals() method).
  840. */
  841. public void removeContainerFilter(Filter filter);
  842. /**
  843. * Remove all active filters from the container.
  844. */
  845. public void removeAllContainerFilters();
  846. }
  847. /**
  848. * Interface implemented by viewer classes capable of using a Container as a
  849. * data source.
  850. */
  851. public interface Viewer extends Serializable {
  852. /**
  853. * Sets the Container that serves as the data source of the viewer.
  854. *
  855. * @param newDataSource
  856. * The new data source Item
  857. */
  858. public void setContainerDataSource(Container newDataSource);
  859. /**
  860. * Gets the Container serving as the data source of the viewer.
  861. *
  862. * @return data source Container
  863. */
  864. public Container getContainerDataSource();
  865. }
  866. /**
  867. * <p>
  868. * Interface implemented by the editor classes supporting editing the
  869. * Container. Implementing this interface means that the Container serving
  870. * as the data source of the editor can be modified through it.
  871. * </p>
  872. * <p>
  873. * Note that not implementing the <code>Container.Editor</code> interface
  874. * does not restrict the class from editing the Container contents
  875. * internally.
  876. * </p>
  877. */
  878. public interface Editor extends Container.Viewer, Serializable {
  879. }
  880. /* Contents change event */
  881. /**
  882. * An <code>Event</code> object specifying the Container whose Item set has
  883. * changed (items added, removed or reordered).
  884. *
  885. * A simple property value change is not an item set change.
  886. */
  887. public interface ItemSetChangeEvent extends Serializable {
  888. /**
  889. * Gets the Property where the event occurred.
  890. *
  891. * @return source of the event
  892. */
  893. public Container getContainer();
  894. }
  895. /**
  896. * Container Item set change listener interface.
  897. *
  898. * An item set change refers to addition, removal or reordering of items in
  899. * the container. A simple property value change is not an item set change.
  900. */
  901. public interface ItemSetChangeListener extends Serializable {
  902. /**
  903. * Lets the listener know a Containers visible (filtered and/or sorted,
  904. * if applicable) Item set has changed.
  905. *
  906. * @param event
  907. * change event text
  908. */
  909. public void containerItemSetChange(Container.ItemSetChangeEvent event);
  910. }
  911. /**
  912. * The interface for adding and removing <code>ItemSetChangeEvent</code>
  913. * listeners. By implementing this interface a class explicitly announces
  914. * that it will generate a <code>ItemSetChangeEvent</code> when its contents
  915. * are modified.
  916. *
  917. * An item set change refers to addition, removal or reordering of items in
  918. * the container. A simple property value change is not an item set change.
  919. *
  920. * <p>
  921. * Note: The general Java convention is not to explicitly declare that a
  922. * class generates events, but to directly define the
  923. * <code>addListener</code> and <code>removeListener</code> methods. That
  924. * way the caller of these methods has no real way of finding out if the
  925. * class really will send the events, or if it just defines the methods to
  926. * be able to implement an interface.
  927. * </p>
  928. */
  929. public interface ItemSetChangeNotifier extends Serializable {
  930. /**
  931. * Adds an Item set change listener for the object.
  932. *
  933. * @param listener
  934. * listener to be added
  935. */
  936. public void addListener(Container.ItemSetChangeListener listener);
  937. /**
  938. * Removes the Item set change listener from the object.
  939. *
  940. * @param listener
  941. * listener to be removed
  942. */
  943. public void removeListener(Container.ItemSetChangeListener listener);
  944. }
  945. /* Property set change event */
  946. /**
  947. * An <code>Event</code> object specifying the Container whose Property set
  948. * has changed.
  949. *
  950. * A property set change means the addition, removal or other structural
  951. * changes to the properties of a container. Changes concerning the set of
  952. * items in the container and their property values are not property set
  953. * changes.
  954. */
  955. public interface PropertySetChangeEvent extends Serializable {
  956. /**
  957. * Retrieves the Container whose contents have been modified.
  958. *
  959. * @return Source Container of the event.
  960. */
  961. public Container getContainer();
  962. }
  963. /**
  964. * The listener interface for receiving <code>PropertySetChangeEvent</code>
  965. * objects.
  966. *
  967. * A property set change means the addition, removal or other structural
  968. * change of the properties (supported property IDs) of a container. Changes
  969. * concerning the set of items in the container and their property values
  970. * are not property set changes.
  971. */
  972. public interface PropertySetChangeListener extends Serializable {
  973. /**
  974. * Notifies this listener that the set of property IDs supported by the
  975. * Container has changed.
  976. *
  977. * @param event
  978. * Change event.
  979. */
  980. public void containerPropertySetChange(
  981. Container.PropertySetChangeEvent event);
  982. }
  983. /**
  984. * <p>
  985. * The interface for adding and removing <code>PropertySetChangeEvent</code>
  986. * listeners. By implementing this interface a class explicitly announces
  987. * that it will generate a <code>PropertySetChangeEvent</code> when the set
  988. * of property IDs supported by the container is modified.
  989. * </p>
  990. *
  991. * <p>
  992. * A property set change means the addition, removal or other structural
  993. * changes to the properties of a container. Changes concerning the set of
  994. * items in the container and their property values are not property set
  995. * changes.
  996. * </p>
  997. *
  998. * <p>
  999. * Note that the general Java convention is not to explicitly declare that a
  1000. * class generates events, but to directly define the
  1001. * <code>addListener</code> and <code>removeListener</code> methods. That
  1002. * way the caller of these methods has no real way of finding out if the
  1003. * class really will send the events, or if it just defines the methods to
  1004. * be able to implement an interface.
  1005. * </p>
  1006. */
  1007. public interface PropertySetChangeNotifier extends Serializable {
  1008. /**
  1009. * Registers a new Property set change listener for this Container.
  1010. *
  1011. * @param listener
  1012. * The new Listener to be registered
  1013. */
  1014. public void addListener(Container.PropertySetChangeListener listener);
  1015. /**
  1016. * Removes a previously registered Property set change listener.
  1017. *
  1018. * @param listener
  1019. * Listener to be removed
  1020. */
  1021. public void removeListener(Container.PropertySetChangeListener listener);
  1022. }
  1023. }