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 47KB

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