27
28 import com.sun.javafx.property.MethodHelper;
29 import com.sun.javafx.property.adapter.Disposer;
30 import com.sun.javafx.property.adapter.ReadOnlyPropertyDescriptor;
31 import javafx.beans.property.ReadOnlyObjectPropertyBase;
32
33 import java.lang.reflect.InvocationTargetException;
34 import java.lang.reflect.UndeclaredThrowableException;
35
36 import java.security.AccessController;
37 import java.security.AccessControlContext;
38 import java.security.PrivilegedAction;
39
40 /**
41 * A {@code ReadOnlyJavaBeanObjectProperty} provides an adapter between a regular
42 * read only Java Bean property of {@code T} and a JavaFX
43 * {@code ReadOnlyObjectProperty}. It cannot be created directly, but a
44 * {@link ReadOnlyJavaBeanObjectPropertyBuilder} has to be used.
45 * <p>
46 * As a minimum, the Java Bean class must implement a getter for the
47 * property. If the getter of an instance of this class is called, the property of
48 * the Java Bean is returned. If the Java Bean property is bound (i.e. it supports
49 * PropertyChangeListeners), this {@code ReadOnlyJavaBeanObjectProperty} will be
50 * aware of changes in the Java Bean. Otherwise it can be notified about
51 * changes by calling {@link #fireValueChangedEvent()}.
52 * </p>
53 * <p>
54 * The Java Bean class must be declared public. If that class is in a named
55 * module, then the module must {@link Module#isOpen(String,Module) open}
56 * the containing package to at least the {@code javafx.base} module
57 * (or {@link Module#isExported(String) export} the containing package
58 * unconditionally).
59 * </p>
60 *
61 * @see javafx.beans.property.ReadOnlyObjectProperty
62 * @see ReadOnlyJavaBeanObjectPropertyBuilder
63 *
64 * @param T the type of the wrapped {@code Object}
65 * @since JavaFX 2.1
66 */
67 public final class ReadOnlyJavaBeanObjectProperty<T> extends ReadOnlyObjectPropertyBase<T> implements ReadOnlyJavaBeanProperty<T> {
68
69 private final ReadOnlyPropertyDescriptor descriptor;
70 private final ReadOnlyPropertyDescriptor.ReadOnlyListener<T> listener;
71
72 private final AccessControlContext acc = AccessController.getContext();
73
74 ReadOnlyJavaBeanObjectProperty(ReadOnlyPropertyDescriptor descriptor, Object bean) {
75 this.descriptor = descriptor;
76 this.listener = descriptor.new ReadOnlyListener<T>(bean, this);
77 descriptor.addListener(listener);
78 Disposer.addRecord(this, new DescriptorListenerCleaner(descriptor, listener));
|
27
28 import com.sun.javafx.property.MethodHelper;
29 import com.sun.javafx.property.adapter.Disposer;
30 import com.sun.javafx.property.adapter.ReadOnlyPropertyDescriptor;
31 import javafx.beans.property.ReadOnlyObjectPropertyBase;
32
33 import java.lang.reflect.InvocationTargetException;
34 import java.lang.reflect.UndeclaredThrowableException;
35
36 import java.security.AccessController;
37 import java.security.AccessControlContext;
38 import java.security.PrivilegedAction;
39
40 /**
41 * A {@code ReadOnlyJavaBeanObjectProperty} provides an adapter between a regular
42 * read only Java Bean property of {@code T} and a JavaFX
43 * {@code ReadOnlyObjectProperty}. It cannot be created directly, but a
44 * {@link ReadOnlyJavaBeanObjectPropertyBuilder} has to be used.
45 * <p>
46 * As a minimum, the Java Bean class must implement a getter for the
47 * property.
48 * The class, as well as the getter method, must be declared public.
49 * If the getter of an instance of this class is called, the property of
50 * the Java Bean is returned. If the Java Bean property is bound (i.e. it supports
51 * PropertyChangeListeners), this {@code ReadOnlyJavaBeanObjectProperty} will be
52 * aware of changes in the Java Bean. Otherwise it can be notified about
53 * changes by calling {@link #fireValueChangedEvent()}.
54 * </p>
55 * <p><b>Deploying an Application as a Module</b></p>
56 * <p>
57 * If the Java Bean class is in a named module, then it must be reflectively
58 * accessible to the {@code javafx.base} module.
59 * A class is reflectively accessible if the module
60 * {@link Module#isOpen(String,Module) opens} the containing package to at
61 * least the {@code javafx.base} module.
62 * </p>
63 * <p>
64 * For example, if {@code com.foo.MyBeanClass} is in the {@code foo.app} module,
65 * the {@code module-info.java} might
66 * look like this:
67 * </p>
68 *
69 <pre>{@code module foo.app {
70 opens com.foo to javafx.base;
71 }}</pre>
72 *
73 * <p>
74 * Alternatively, a class is reflectively accessible if the module
75 * {@link Module#isExported(String) exports} the containing package
76 * unconditionally.
77 * </p>
78 *
79 * @see javafx.beans.property.ReadOnlyObjectProperty
80 * @see ReadOnlyJavaBeanObjectPropertyBuilder
81 *
82 * @param T the type of the wrapped {@code Object}
83 * @since JavaFX 2.1
84 */
85 public final class ReadOnlyJavaBeanObjectProperty<T> extends ReadOnlyObjectPropertyBase<T> implements ReadOnlyJavaBeanProperty<T> {
86
87 private final ReadOnlyPropertyDescriptor descriptor;
88 private final ReadOnlyPropertyDescriptor.ReadOnlyListener<T> listener;
89
90 private final AccessControlContext acc = AccessController.getContext();
91
92 ReadOnlyJavaBeanObjectProperty(ReadOnlyPropertyDescriptor descriptor, Object bean) {
93 this.descriptor = descriptor;
94 this.listener = descriptor.new ReadOnlyListener<T>(bean, this);
95 descriptor.addListener(listener);
96 Disposer.addRecord(this, new DescriptorListenerCleaner(descriptor, listener));
|