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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. /*
  2. * Copyright 2000-2018 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.v7.data;
  17. import java.io.Serializable;
  18. import com.vaadin.data.Binder;
  19. import com.vaadin.data.HasValue;
  20. import com.vaadin.data.ValueProvider;
  21. import com.vaadin.server.Setter;
  22. /**
  23. * <p>
  24. * The <code>Property</code> is a simple data object that contains one typed
  25. * value. This interface contains methods to inspect and modify the stored value
  26. * and its type, and the object's read-only state.
  27. * </p>
  28. *
  29. * <p>
  30. * The <code>Property</code> also defines the events
  31. * <code>ReadOnlyStatusChangeEvent</code> and <code>ValueChangeEvent</code>, and
  32. * the associated <code>listener</code> and <code>notifier</code> interfaces.
  33. * </p>
  34. *
  35. * <p>
  36. * The <code>Property.Viewer</code> interface should be used to attach the
  37. * Property to an external data source. This way the value in the data source
  38. * can be inspected using the <code>Property</code> interface.
  39. * </p>
  40. *
  41. * <p>
  42. * The <code>Property.editor</code> interface should be implemented if the value
  43. * needs to be changed through the implementing class.
  44. * </p>
  45. *
  46. * @param <T>
  47. * type of values of the property
  48. *
  49. * @author Vaadin Ltd
  50. * @deprecated As of 8.0, replaced by {@link HasValue}, {@link ValueProvider}, {@link Setter}, see {@link Binder}
  51. * @since 3.0
  52. */
  53. @Deprecated
  54. public interface Property<T> extends Serializable {
  55. /**
  56. * Gets the value stored in the Property. The returned object is compatible
  57. * with the class returned by getType().
  58. *
  59. * @return the value stored in the Property
  60. */
  61. public T getValue();
  62. /**
  63. * Sets the value of the Property.
  64. * <p>
  65. * Implementing this functionality is optional. If the functionality is
  66. * missing, one should declare the Property to be in read-only mode and
  67. * throw <code>Property.ReadOnlyException</code> in this function.
  68. * </p>
  69. *
  70. * Note : Since Vaadin 7.0, setting the value of a non-String property as a
  71. * String is no longer supported.
  72. *
  73. * @param newValue
  74. * New value of the Property. This should be assignable to the
  75. * type returned by getType
  76. *
  77. * @throws Property.ReadOnlyException
  78. * if the object is in read-only mode
  79. */
  80. public void setValue(T newValue) throws Property.ReadOnlyException;
  81. /**
  82. * Returns the type of the Property. The methods <code>getValue</code> and
  83. * <code>setValue</code> must be compatible with this type: one must be able
  84. * to safely cast the value returned from <code>getValue</code> to the given
  85. * type and pass any variable assignable to this type as an argument to
  86. * <code>setValue</code>.
  87. *
  88. * @return type of the Property
  89. */
  90. public Class<? extends T> getType();
  91. /**
  92. * Tests if the Property is in read-only mode. In read-only mode calls to
  93. * the method <code>setValue</code> will throw
  94. * <code>ReadOnlyException</code> and will not modify the value of the
  95. * Property.
  96. *
  97. * @return <code>true</code> if the Property is in read-only mode,
  98. * <code>false</code> if it's not
  99. */
  100. public boolean isReadOnly();
  101. /**
  102. * Sets the Property's read-only mode to the specified status.
  103. *
  104. * This functionality is optional, but all properties must implement the
  105. * <code>isReadOnly</code> mode query correctly.
  106. *
  107. * @param newStatus
  108. * new read-only status of the Property
  109. */
  110. public void setReadOnly(boolean newStatus);
  111. /**
  112. * A Property that is capable of handle a transaction that can end in commit
  113. * or rollback.
  114. *
  115. * Note that this does not refer to e.g. database transactions but rather
  116. * two-phase commit that allows resetting old field values (in e.g. a
  117. * FieldGroup) if the commit of one of the properties fails after other
  118. * properties have already been committed.
  119. *
  120. * @param <T>
  121. * The type of the property
  122. * @author Vaadin Ltd
  123. * @since 7.0
  124. */
  125. @Deprecated
  126. public interface Transactional<T> extends Property<T> {
  127. /**
  128. * Starts a transaction.
  129. *
  130. * <p>
  131. * If the value is set during a transaction the value must not replace
  132. * the original value until {@link #commit()} is called. Still,
  133. * {@link #getValue()} must return the current value set in the
  134. * transaction. Calling {@link #rollback()} while in a transaction must
  135. * rollback the value to what it was before the transaction started.
  136. * </p>
  137. * <p>
  138. * {@link ValueChangeEvent}s must not be emitted for internal value
  139. * changes during a transaction. If the value changes as a result of
  140. * {@link #commit()}, a {@link ValueChangeEvent} should be emitted.
  141. * </p>
  142. */
  143. public void startTransaction();
  144. /**
  145. * Commits and ends the transaction that is in progress.
  146. * <p>
  147. * If the value is changed as a result of this operation, a
  148. * {@link ValueChangeEvent} is emitted if such are supported.
  149. * <p>
  150. * This method has no effect if there is no transaction is in progress.
  151. * <p>
  152. * This method must never throw an exception.
  153. */
  154. public void commit();
  155. /**
  156. * Aborts and rolls back the transaction that is in progress.
  157. * <p>
  158. * The value is reset to the value before the transaction started. No
  159. * {@link ValueChangeEvent} is emitted as a result of this.
  160. * <p>
  161. * This method has no effect if there is no transaction is in progress.
  162. * <p>
  163. * This method must never throw an exception.
  164. */
  165. public void rollback();
  166. }
  167. /**
  168. * <code>Exception</code> object that signals that a requested Property
  169. * modification failed because it's in read-only mode.
  170. *
  171. * @author Vaadin Ltd.
  172. * @since 3.0
  173. */
  174. @SuppressWarnings("serial")
  175. @Deprecated
  176. public class ReadOnlyException extends RuntimeException {
  177. /**
  178. * Constructs a new <code>ReadOnlyException</code> without a detail
  179. * message.
  180. */
  181. public ReadOnlyException() {
  182. }
  183. /**
  184. * Constructs a new <code>ReadOnlyException</code> with the specified
  185. * detail message.
  186. *
  187. * @param msg
  188. * the detail message
  189. */
  190. public ReadOnlyException(String msg) {
  191. super(msg);
  192. }
  193. }
  194. /**
  195. * Interface implemented by the viewer classes capable of using a Property
  196. * as a data source.
  197. *
  198. * @author Vaadin Ltd.
  199. * @since 3.0
  200. */
  201. @Deprecated
  202. public interface Viewer extends Serializable {
  203. /**
  204. * Sets the Property that serves as the data source of the viewer.
  205. *
  206. * @param newDataSource
  207. * the new data source Property
  208. */
  209. public void setPropertyDataSource(Property newDataSource);
  210. /**
  211. * Gets the Property serving as the data source of the viewer.
  212. *
  213. * @return the Property serving as the viewers data source
  214. */
  215. public Property getPropertyDataSource();
  216. }
  217. /**
  218. * Interface implemented by the editor classes capable of editing the
  219. * Property.
  220. * <p>
  221. * Implementing this interface means that the Property serving as the data
  222. * source of the editor can be modified through the editor. It does not
  223. * restrict the editor from editing the Property internally, though if the
  224. * Property is in a read-only mode, attempts to modify it will result in the
  225. * <code>ReadOnlyException</code> being thrown.
  226. * </p>
  227. *
  228. * @author Vaadin Ltd.
  229. * @since 3.0
  230. */
  231. @Deprecated
  232. public interface Editor extends Property.Viewer {
  233. }
  234. /* Value change event */
  235. /**
  236. * An <code>Event</code> object specifying the Property whose value has been
  237. * changed.
  238. *
  239. * @author Vaadin Ltd.
  240. * @since 3.0
  241. */
  242. @Deprecated
  243. public interface ValueChangeEvent extends Serializable {
  244. /**
  245. * Retrieves the Property that has been modified.
  246. *
  247. * @return source Property of the event
  248. */
  249. public Property getProperty();
  250. }
  251. /**
  252. * The <code>listener</code> interface for receiving
  253. * <code>ValueChangeEvent</code> objects.
  254. *
  255. * @author Vaadin Ltd.
  256. * @since 3.0
  257. */
  258. @Deprecated
  259. public interface ValueChangeListener extends Serializable {
  260. /**
  261. * Notifies this listener that the Property's value has changed.
  262. *
  263. * @param event
  264. * value change event object
  265. */
  266. public void valueChange(Property.ValueChangeEvent event);
  267. }
  268. /**
  269. * The interface for adding and removing <code>ValueChangeEvent</code>
  270. * listeners. If a Property wishes to allow other objects to receive
  271. * <code>ValueChangeEvent</code> generated by it, it must implement this
  272. * interface.
  273. * <p>
  274. * Note : The general Java convention is not to explicitly declare that a
  275. * class generates events, but to directly define the
  276. * <code>addListener</code> and <code>removeListener</code> methods. That
  277. * way the caller of these methods has no real way of finding out if the
  278. * class really will send the events, or if it just defines the methods to
  279. * be able to implement an interface.
  280. * </p>
  281. *
  282. * @author Vaadin Ltd.
  283. * @since 3.0
  284. */
  285. @Deprecated
  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 addValueChangeListener(
  294. Property.ValueChangeListener listener);
  295. /**
  296. * @deprecated As of 7.0, replaced by
  297. * {@link #addValueChangeListener(ValueChangeListener)}
  298. */
  299. @Deprecated
  300. public void addListener(Property.ValueChangeListener listener);
  301. /**
  302. * Removes a previously registered value change listener.
  303. *
  304. * @param listener
  305. * listener to be removed
  306. */
  307. public void removeValueChangeListener(
  308. Property.ValueChangeListener listener);
  309. /**
  310. * @deprecated As of 7.0, replaced by
  311. * {@link #removeValueChangeListener(ValueChangeListener)}
  312. */
  313. @Deprecated
  314. public void removeListener(Property.ValueChangeListener listener);
  315. }
  316. /* ReadOnly Status change event */
  317. /**
  318. * An <code>Event</code> object specifying the Property whose read-only
  319. * status has been changed.
  320. *
  321. * @author Vaadin Ltd.
  322. * @since 3.0
  323. */
  324. @Deprecated
  325. public interface ReadOnlyStatusChangeEvent extends Serializable {
  326. /**
  327. * Property whose read-only state has changed.
  328. *
  329. * @return source Property of the event.
  330. */
  331. public Property getProperty();
  332. }
  333. /**
  334. * The listener interface for receiving
  335. * <code>ReadOnlyStatusChangeEvent</code> objects.
  336. *
  337. * @author Vaadin Ltd.
  338. * @since 3.0
  339. */
  340. @Deprecated
  341. public interface ReadOnlyStatusChangeListener extends Serializable {
  342. /**
  343. * Notifies this listener that a Property's read-only status has
  344. * changed.
  345. *
  346. * @param event
  347. * Read-only status change event object
  348. */
  349. public void readOnlyStatusChange(
  350. Property.ReadOnlyStatusChangeEvent event);
  351. }
  352. /**
  353. * The interface for adding and removing
  354. * <code>ReadOnlyStatusChangeEvent</code> listeners. If a Property wishes to
  355. * allow other objects to receive <code>ReadOnlyStatusChangeEvent</code>
  356. * generated by it, it must implement this interface.
  357. * <p>
  358. * Note : The general Java convention is not to explicitly declare that a
  359. * class generates events, but to directly define the
  360. * <code>addListener</code> and <code>removeListener</code> methods. That
  361. * way the caller of these methods has no real way of finding out if the
  362. * class really will send the events, or if it just defines the methods to
  363. * be able to implement an interface.
  364. * </p>
  365. *
  366. * @author Vaadin Ltd.
  367. * @since 3.0
  368. */
  369. @Deprecated
  370. public interface ReadOnlyStatusChangeNotifier extends Serializable {
  371. /**
  372. * Registers a new read-only status change listener for this Property.
  373. *
  374. * @param listener
  375. * the new Listener to be registered
  376. */
  377. public void addReadOnlyStatusChangeListener(
  378. Property.ReadOnlyStatusChangeListener listener);
  379. /**
  380. * @deprecated As of 7.0, replaced by
  381. * {@link #addReadOnlyStatusChangeListener(ReadOnlyStatusChangeListener)}
  382. */
  383. @Deprecated
  384. public void addListener(Property.ReadOnlyStatusChangeListener listener);
  385. /**
  386. * Removes a previously registered read-only status change listener.
  387. *
  388. * @param listener
  389. * listener to be removed
  390. */
  391. public void removeReadOnlyStatusChangeListener(
  392. Property.ReadOnlyStatusChangeListener listener);
  393. /**
  394. * @deprecated As of 7.0, replaced by
  395. * {@link #removeReadOnlyStatusChangeListener(ReadOnlyStatusChangeListener)}
  396. */
  397. @Deprecated
  398. public void removeListener(
  399. Property.ReadOnlyStatusChangeListener listener);
  400. }
  401. }