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.

Property.java 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.data;
  5. import java.io.Serializable;
  6. /**
  7. * <p>
  8. * The <code>Property</code> is a simple data object that contains one typed
  9. * value. This interface contains methods to inspect and modify the stored value
  10. * and its type, and the object's read-only state.
  11. * </p>
  12. *
  13. * <p>
  14. * The <code>Property</code> also defines the events
  15. * <code>ReadOnlyStatusChangeEvent</code> and <code>ValueChangeEvent</code>, and
  16. * the associated <code>listener</code> and <code>notifier</code> interfaces.
  17. * </p>
  18. *
  19. * <p>
  20. * The <code>Property.Viewer</code> interface should be used to attach the
  21. * Property to an external data source. This way the value in the data source
  22. * can be inspected using the <code>Property</code> interface.
  23. * </p>
  24. *
  25. * <p>
  26. * The <code>Property.editor</code> interface should be implemented if the value
  27. * needs to be changed through the implementing class.
  28. * </p>
  29. *
  30. * @author Vaadin Ltd
  31. * @version
  32. * @VERSION@
  33. * @since 3.0
  34. */
  35. public interface Property extends Serializable {
  36. /**
  37. * Gets the value stored in the Property. The returned object is compatible
  38. * with the class returned by getType().
  39. *
  40. * @return the value stored in the Property
  41. */
  42. public Object getValue();
  43. /**
  44. * Sets the value of the Property.
  45. * <p>
  46. * Implementing this functionality is optional. If the functionality is
  47. * missing, one should declare the Property to be in read-only mode and
  48. * throw <code>Property.ReadOnlyException</code> in this function.
  49. * </p>
  50. * Note : It is not required, but highly recommended to support setting the
  51. * value also as a <code>String</code> in addition to the native type of the
  52. * Property (as given by the <code>getType</code> method). If the
  53. * <code>String</code> conversion fails or is unsupported, the method should
  54. * throw <code>Property.ConversionException</code>. The string conversion
  55. * should at least understand the format returned by the
  56. * <code>toString</code> method of the Property.
  57. *
  58. * @param newValue
  59. * New value of the Property. This should be assignable to the
  60. * type returned by getType, but also String type should be
  61. * supported
  62. *
  63. * @throws Property.ReadOnlyException
  64. * if the object is in read-only mode
  65. * @throws Property.ConversionException
  66. * if newValue can't be converted into the Property's native
  67. * type directly or through String
  68. */
  69. public void setValue(Object newValue) throws Property.ReadOnlyException,
  70. Property.ConversionException;
  71. /**
  72. * Returns the value of the Property in human readable textual format. The
  73. * return value should be assignable to the <code>setValue</code> method if
  74. * the Property is not in read-only mode.
  75. *
  76. * @return <code>String</code> representation of the value stored in the
  77. * Property
  78. */
  79. public String toString();
  80. /**
  81. * Returns the type of the Property. The methods <code>getValue</code> and
  82. * <code>setValue</code> must be compatible with this type: one must be able
  83. * to safely cast the value returned from <code>getValue</code> to the given
  84. * type and pass any variable assignable to this type as an argument to
  85. * <code>setValue</code>.
  86. *
  87. * @return type of the Property
  88. */
  89. public Class<?> getType();
  90. /**
  91. * Tests if the Property is in read-only mode. In read-only mode calls to
  92. * the method <code>setValue</code> will throw
  93. * <code>ReadOnlyException</code> and will not modify the value of the
  94. * Property.
  95. *
  96. * @return <code>true</code> if the Property is in read-only mode,
  97. * <code>false</code> if it's not
  98. */
  99. public boolean isReadOnly();
  100. /**
  101. * Sets the Property's read-only mode to the specified status.
  102. *
  103. * This functionality is optional, but all properties must implement the
  104. * <code>isReadOnly</code> mode query correctly.
  105. *
  106. * @param newStatus
  107. * new read-only status of the Property
  108. */
  109. public void setReadOnly(boolean newStatus);
  110. /**
  111. * <code>Exception</code> object that signals that a requested Property
  112. * modification failed because it's in read-only mode.
  113. *
  114. * @author Vaadin Ltd.
  115. * @version
  116. * @VERSION@
  117. * @since 3.0
  118. */
  119. @SuppressWarnings("serial")
  120. public class ReadOnlyException extends RuntimeException {
  121. /**
  122. * Constructs a new <code>ReadOnlyException</code> without a detail
  123. * message.
  124. */
  125. public ReadOnlyException() {
  126. }
  127. /**
  128. * Constructs a new <code>ReadOnlyException</code> with the specified
  129. * detail message.
  130. *
  131. * @param msg
  132. * the detail message
  133. */
  134. public ReadOnlyException(String msg) {
  135. super(msg);
  136. }
  137. }
  138. /**
  139. * An exception that signals that the value passed to the
  140. * <code>setValue</code> method couldn't be converted to the native type of
  141. * the Property.
  142. *
  143. * @author Vaadin Ltd
  144. * @version
  145. * @VERSION@
  146. * @since 3.0
  147. */
  148. @SuppressWarnings("serial")
  149. public class ConversionException extends RuntimeException {
  150. /**
  151. * Constructs a new <code>ConversionException</code> without a detail
  152. * message.
  153. */
  154. public ConversionException() {
  155. }
  156. /**
  157. * Constructs a new <code>ConversionException</code> with the specified
  158. * detail message.
  159. *
  160. * @param msg
  161. * the detail message
  162. */
  163. public ConversionException(String msg) {
  164. super(msg);
  165. }
  166. /**
  167. * Constructs a new <code>ConversionException</code> from another
  168. * exception.
  169. *
  170. * @param cause
  171. * The cause of the the conversion failure
  172. */
  173. public ConversionException(Throwable cause) {
  174. super(cause);
  175. }
  176. /**
  177. * Constructs a new <code>ConversionException</code> with the specified
  178. * detail message and cause.
  179. *
  180. * @param message
  181. * the detail message
  182. * @param cause
  183. * The cause of the the conversion failure
  184. */
  185. public ConversionException(String message, Throwable cause) {
  186. super(message, cause);
  187. }
  188. }
  189. /**
  190. * Interface implemented by the viewer classes capable of using a Property
  191. * as a data source.
  192. *
  193. * @author Vaadin Ltd.
  194. * @version
  195. * @VERSION@
  196. * @since 3.0
  197. */
  198. public interface Viewer extends Serializable {
  199. /**
  200. * Sets the Property that serves as the data source of the viewer.
  201. *
  202. * @param newDataSource
  203. * the new data source Property
  204. */
  205. public void setPropertyDataSource(Property newDataSource);
  206. /**
  207. * Gets the Property serving as the data source of the viewer.
  208. *
  209. * @return the Property serving as the viewers data source
  210. */
  211. public Property getPropertyDataSource();
  212. }
  213. /**
  214. * Interface implemented by the editor classes capable of editing the
  215. * Property.
  216. * <p>
  217. * Implementing this interface means that the Property serving as the data
  218. * source of the editor can be modified through the editor. It does not
  219. * restrict the editor from editing the Property internally, though if the
  220. * Property is in a read-only mode, attempts to modify it will result in the
  221. * <code>ReadOnlyException</code> being thrown.
  222. * </p>
  223. *
  224. * @author Vaadin Ltd.
  225. * @version
  226. * @VERSION@
  227. * @since 3.0
  228. */
  229. public interface Editor extends Property.Viewer, Serializable {
  230. }
  231. /* Value change event */
  232. /**
  233. * An <code>Event</code> object specifying the Property whose value has been
  234. * changed.
  235. *
  236. * @author Vaadin Ltd.
  237. * @version
  238. * @VERSION@
  239. * @since 3.0
  240. */
  241. public interface ValueChangeEvent extends Serializable {
  242. /**
  243. * Retrieves the Property that has been modified.
  244. *
  245. * @return source Property of the event
  246. */
  247. public Property getProperty();
  248. }
  249. /**
  250. * The <code>listener</code> interface for receiving
  251. * <code>ValueChangeEvent</code> objects.
  252. *
  253. * @author Vaadin Ltd.
  254. * @version
  255. * @VERSION@
  256. * @since 3.0
  257. */
  258. public interface ValueChangeListener extends Serializable {
  259. /**
  260. * Notifies this listener that the Property's value has changed.
  261. *
  262. * @param event
  263. * value change event object
  264. */
  265. public void valueChange(Property.ValueChangeEvent event);
  266. }
  267. /**
  268. * The interface for adding and removing <code>ValueChangeEvent</code>
  269. * listeners. If a Property wishes to allow other objects to receive
  270. * <code>ValueChangeEvent</code> generated by it, it must implement this
  271. * interface.
  272. * <p>
  273. * Note : The general Java convention is not to explicitly declare that a
  274. * class generates events, but to directly define the
  275. * <code>addListener</code> and <code>removeListener</code> methods. That
  276. * way the caller of these methods has no real way of finding out if the
  277. * class really will send the events, or if it just defines the methods to
  278. * be able to implement an interface.
  279. * </p>
  280. *
  281. * @author Vaadin Ltd.
  282. * @version
  283. * @VERSION@
  284. * @since 3.0
  285. */
  286. public interface ValueChangeNotifier extends Serializable {
  287. /**
  288. * Registers a new value change listener for this Property.
  289. *
  290. * @param listener
  291. * the new Listener to be registered
  292. */
  293. public void addListener(Property.ValueChangeListener listener);
  294. /**
  295. * Removes a previously registered value change listener.
  296. *
  297. * @param listener
  298. * listener to be removed
  299. */
  300. public void removeListener(Property.ValueChangeListener listener);
  301. }
  302. /* ReadOnly Status change event */
  303. /**
  304. * An <code>Event</code> object specifying the Property whose read-only
  305. * status has been changed.
  306. *
  307. * @author Vaadin Ltd.
  308. * @version
  309. * @VERSION@
  310. * @since 3.0
  311. */
  312. public interface ReadOnlyStatusChangeEvent extends Serializable {
  313. /**
  314. * Property whose read-only state has changed.
  315. *
  316. * @return source Property of the event.
  317. */
  318. public Property getProperty();
  319. }
  320. /**
  321. * The listener interface for receiving
  322. * <code>ReadOnlyStatusChangeEvent</code> objects.
  323. *
  324. * @author Vaadin Ltd.
  325. * @version
  326. * @VERSION@
  327. * @since 3.0
  328. */
  329. public interface ReadOnlyStatusChangeListener extends Serializable {
  330. /**
  331. * Notifies this listener that a Property's read-only status has
  332. * changed.
  333. *
  334. * @param event
  335. * Read-only status change event object
  336. */
  337. public void readOnlyStatusChange(
  338. Property.ReadOnlyStatusChangeEvent event);
  339. }
  340. /**
  341. * The interface for adding and removing
  342. * <code>ReadOnlyStatusChangeEvent</code> listeners. If a Property wishes to
  343. * allow other objects to receive <code>ReadOnlyStatusChangeEvent</code>
  344. * generated by it, it must implement this interface.
  345. * <p>
  346. * Note : The general Java convention is not to explicitly declare that a
  347. * class generates events, but to directly define the
  348. * <code>addListener</code> and <code>removeListener</code> methods. That
  349. * way the caller of these methods has no real way of finding out if the
  350. * class really will send the events, or if it just defines the methods to
  351. * be able to implement an interface.
  352. * </p>
  353. *
  354. * @author Vaadin Ltd.
  355. * @version
  356. * @VERSION@
  357. * @since 3.0
  358. */
  359. public interface ReadOnlyStatusChangeNotifier extends Serializable {
  360. /**
  361. * Registers a new read-only status change listener for this Property.
  362. *
  363. * @param listener
  364. * the new Listener to be registered
  365. */
  366. public void addListener(Property.ReadOnlyStatusChangeListener listener);
  367. /**
  368. * Removes a previously registered read-only status change listener.
  369. *
  370. * @param listener
  371. * listener to be removed
  372. */
  373. public void removeListener(
  374. Property.ReadOnlyStatusChangeListener listener);
  375. }
  376. }