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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  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 IT Mill 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 IT Mill 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 IT Mill 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.toString());
  175. }
  176. }
  177. /**
  178. * Interface implemented by the viewer classes capable of using a Property
  179. * as a data source.
  180. *
  181. * @author IT Mill Ltd.
  182. * @version
  183. * @VERSION@
  184. * @since 3.0
  185. */
  186. public interface Viewer extends Serializable {
  187. /**
  188. * Sets the Property that serves as the data source of the viewer.
  189. *
  190. * @param newDataSource
  191. * the new data source Property
  192. */
  193. public void setPropertyDataSource(Property newDataSource);
  194. /**
  195. * Gets the Property serving as the data source of the viewer.
  196. *
  197. * @return the Property serving as the viewers data source
  198. */
  199. public Property getPropertyDataSource();
  200. }
  201. /**
  202. * Interface implemented by the editor classes capable of editing the
  203. * Property.
  204. * <p>
  205. * Implementing this interface means that the Property serving as the data
  206. * source of the editor can be modified through the editor. It does not
  207. * restrict the editor from editing the Property internally, though if the
  208. * Property is in a read-only mode, attempts to modify it will result in the
  209. * <code>ReadOnlyException</code> being thrown.
  210. * </p>
  211. *
  212. * @author IT Mill Ltd.
  213. * @version
  214. * @VERSION@
  215. * @since 3.0
  216. */
  217. public interface Editor extends Property.Viewer, Serializable {
  218. }
  219. /* Value change event */
  220. /**
  221. * An <code>Event</code> object specifying the Property whose value has been
  222. * changed.
  223. *
  224. * @author IT Mill Ltd.
  225. * @version
  226. * @VERSION@
  227. * @since 3.0
  228. */
  229. public interface ValueChangeEvent extends Serializable {
  230. /**
  231. * Retrieves the Property that has been modified.
  232. *
  233. * @return source Property of the event
  234. */
  235. public Property getProperty();
  236. }
  237. /**
  238. * The <code>listener</code> interface for receiving
  239. * <code>ValueChangeEvent</code> objects.
  240. *
  241. * @author IT Mill Ltd.
  242. * @version
  243. * @VERSION@
  244. * @since 3.0
  245. */
  246. public interface ValueChangeListener extends Serializable {
  247. /**
  248. * Notifies this listener that the Property's value has changed.
  249. *
  250. * @param event
  251. * value change event object
  252. */
  253. public void valueChange(Property.ValueChangeEvent event);
  254. }
  255. /**
  256. * The interface for adding and removing <code>ValueChangeEvent</code>
  257. * listeners. If a Property wishes to allow other objects to receive
  258. * <code>ValueChangeEvent</code> generated by it, it must implement this
  259. * interface.
  260. * <p>
  261. * Note : The general Java convention is not to explicitly declare that a
  262. * class generates events, but to directly define the
  263. * <code>addListener</code> and <code>removeListener</code> methods. That
  264. * way the caller of these methods has no real way of finding out if the
  265. * class really will send the events, or if it just defines the methods to
  266. * be able to implement an interface.
  267. * </p>
  268. *
  269. * @author IT Mill Ltd.
  270. * @version
  271. * @VERSION@
  272. * @since 3.0
  273. */
  274. public interface ValueChangeNotifier extends Serializable {
  275. /**
  276. * Registers a new value change listener for this Property.
  277. *
  278. * @param listener
  279. * the new Listener to be registered
  280. */
  281. public void addListener(Property.ValueChangeListener listener);
  282. /**
  283. * Removes a previously registered value change listener.
  284. *
  285. * @param listener
  286. * listener to be removed
  287. */
  288. public void removeListener(Property.ValueChangeListener listener);
  289. }
  290. /* ReadOnly Status change event */
  291. /**
  292. * An <code>Event</code> object specifying the Property whose read-only
  293. * status has been changed.
  294. *
  295. * @author IT Mill Ltd.
  296. * @version
  297. * @VERSION@
  298. * @since 3.0
  299. */
  300. public interface ReadOnlyStatusChangeEvent extends Serializable {
  301. /**
  302. * Property whose read-only state has changed.
  303. *
  304. * @return source Property of the event.
  305. */
  306. public Property getProperty();
  307. }
  308. /**
  309. * The listener interface for receiving
  310. * <code>ReadOnlyStatusChangeEvent</code> objects.
  311. *
  312. * @author IT Mill Ltd.
  313. * @version
  314. * @VERSION@
  315. * @since 3.0
  316. */
  317. public interface ReadOnlyStatusChangeListener extends Serializable {
  318. /**
  319. * Notifies this listener that a Property's read-only status has
  320. * changed.
  321. *
  322. * @param event
  323. * Read-only status change event object
  324. */
  325. public void readOnlyStatusChange(
  326. Property.ReadOnlyStatusChangeEvent event);
  327. }
  328. /**
  329. * The interface for adding and removing
  330. * <code>ReadOnlyStatusChangeEvent</code> listeners. If a Property wishes to
  331. * allow other objects to receive <code>ReadOnlyStatusChangeEvent</code>
  332. * generated by it, it must implement this interface.
  333. * <p>
  334. * Note : The general Java convention is not to explicitly declare that a
  335. * class generates events, but to directly define the
  336. * <code>addListener</code> and <code>removeListener</code> methods. That
  337. * way the caller of these methods has no real way of finding out if the
  338. * class really will send the events, or if it just defines the methods to
  339. * be able to implement an interface.
  340. * </p>
  341. *
  342. * @author IT Mill Ltd.
  343. * @version
  344. * @VERSION@
  345. * @since 3.0
  346. */
  347. public interface ReadOnlyStatusChangeNotifier extends Serializable {
  348. /**
  349. * Registers a new read-only status change listener for this Property.
  350. *
  351. * @param listener
  352. * the new Listener to be registered
  353. */
  354. public void addListener(Property.ReadOnlyStatusChangeListener listener);
  355. /**
  356. * Removes a previously registered read-only status change listener.
  357. *
  358. * @param listener
  359. * listener to be removed
  360. */
  361. public void removeListener(
  362. Property.ReadOnlyStatusChangeListener listener);
  363. }
  364. }