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

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