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.

Item.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.data;
  5. import java.io.Serializable;
  6. import java.util.Collection;
  7. /**
  8. * <p>
  9. * Provides a mechanism for handling a set of Properties, each associated to a
  10. * locally unique non-null identifier. The interface is split into subinterfaces
  11. * to enable a class to implement only the functionalities it needs.
  12. * </p>
  13. *
  14. * @author Vaadin Ltd
  15. * @since 3.0
  16. */
  17. public interface Item extends Serializable {
  18. /**
  19. * Gets the Property corresponding to the given Property ID stored in the
  20. * Item. If the Item does not contain the Property, <code>null</code> is
  21. * returned.
  22. *
  23. * @param id
  24. * identifier of the Property to get
  25. * @return the Property with the given ID or <code>null</code>
  26. */
  27. public Property<?> getItemProperty(Object id);
  28. /**
  29. * Gets the collection of IDs of all Properties stored in the Item.
  30. *
  31. * @return unmodifiable collection containing IDs of the Properties stored
  32. * the Item
  33. */
  34. public Collection<?> getItemPropertyIds();
  35. /**
  36. * Tries to add a new Property into the Item.
  37. *
  38. * <p>
  39. * This functionality is optional.
  40. * </p>
  41. *
  42. * @param id
  43. * ID of the new Property
  44. * @param property
  45. * the Property to be added and associated with the id
  46. * @return <code>true</code> if the operation succeeded, <code>false</code>
  47. * if not
  48. * @throws UnsupportedOperationException
  49. * if the operation is not supported.
  50. */
  51. public boolean addItemProperty(Object id, Property property)
  52. throws UnsupportedOperationException;
  53. /**
  54. * Removes the Property identified by ID from the Item.
  55. *
  56. * <p>
  57. * This functionality is optional.
  58. * </p>
  59. *
  60. * @param id
  61. * ID of the Property to be removed
  62. * @return <code>true</code> if the operation succeeded
  63. * @throws UnsupportedOperationException
  64. * if the operation is not supported. <code>false</code> if not
  65. */
  66. public boolean removeItemProperty(Object id)
  67. throws UnsupportedOperationException;
  68. /**
  69. * Interface implemented by viewer classes capable of using an Item as a
  70. * data source.
  71. */
  72. public interface Viewer extends Serializable {
  73. /**
  74. * Sets the Item that serves as the data source of the viewer.
  75. *
  76. * @param newDataSource
  77. * The new data source Item
  78. */
  79. public void setItemDataSource(Item newDataSource);
  80. /**
  81. * Gets the Item serving as the data source of the viewer.
  82. *
  83. * @return data source Item
  84. */
  85. public Item getItemDataSource();
  86. }
  87. /**
  88. * Interface implemented by the <code>Editor</code> classes capable of
  89. * editing the Item. Implementing this interface means that the Item serving
  90. * as the data source of the editor can be modified through it.
  91. * <p>
  92. * Note : Not implementing the <code>Item.Editor</code> interface does not
  93. * restrict the class from editing the contents of an internally.
  94. * </p>
  95. */
  96. public interface Editor extends Item.Viewer, Serializable {
  97. }
  98. /* Property set change event */
  99. /**
  100. * An <code>Event</code> object specifying the Item whose contents has been
  101. * changed through the <code>Property</code> interface.
  102. * <p>
  103. * Note: The values stored in the Properties may change without triggering
  104. * this event.
  105. * </p>
  106. */
  107. public interface PropertySetChangeEvent extends Serializable {
  108. /**
  109. * Retrieves the Item whose contents has been modified.
  110. *
  111. * @return source Item of the event
  112. */
  113. public Item getItem();
  114. }
  115. /**
  116. * The listener interface for receiving <code>PropertySetChangeEvent</code>
  117. * objects.
  118. */
  119. public interface PropertySetChangeListener extends Serializable {
  120. /**
  121. * Notifies this listener that the Item's property set has changed.
  122. *
  123. * @param event
  124. * Property set change event object
  125. */
  126. public void itemPropertySetChange(Item.PropertySetChangeEvent event);
  127. }
  128. /**
  129. * The interface for adding and removing <code>PropertySetChangeEvent</code>
  130. * listeners. By implementing this interface a class explicitly announces
  131. * that it will generate a <code>PropertySetChangeEvent</code> when its
  132. * Property set is modified.
  133. * <p>
  134. * Note : The general Java convention is not to explicitly declare that a
  135. * class generates events, but to directly define the
  136. * <code>addListener</code> and <code>removeListener</code> methods. That
  137. * way the caller of these methods has no real way of finding out if the
  138. * class really will send the events, or if it just defines the methods to
  139. * be able to implement an interface.
  140. * </p>
  141. */
  142. public interface PropertySetChangeNotifier extends Serializable {
  143. /**
  144. * Registers a new property set change listener for this Item.
  145. *
  146. * @param listener
  147. * The new Listener to be registered.
  148. */
  149. public void addListener(Item.PropertySetChangeListener listener);
  150. /**
  151. * Removes a previously registered property set change listener.
  152. *
  153. * @param listener
  154. * Listener to be removed.
  155. */
  156. public void removeListener(Item.PropertySetChangeListener listener);
  157. }
  158. }