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

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