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

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