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

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