ResetableObjectProperty.java
01 /*
02  * SPDX-License-Identifier: Apache-2.0
03  *
04  * Copyright 2008-2017 the original author or authors.
05  *
06  * Licensed under the Apache License, Version 2.0 (the "License");
07  * you may not use this file except in compliance with the License.
08  * You may obtain a copy of the License at
09  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package griffon.javafx.beans.property;
19 
20 import javafx.beans.property.ObjectProperty;
21 import javafx.beans.property.Property;
22 import javafx.beans.property.ReadOnlyObjectProperty;
23 import javafx.beans.property.ReadOnlyProperty;
24 import javafx.beans.property.SimpleObjectProperty;
25 
26 import javax.annotation.Nonnull;
27 import javax.annotation.Nullable;
28 
29 /**
30  @author Andres Almiray
31  @since 2.10.0
32  */
33 public class ResetableObjectProperty<E> extends AbstractResetableProperty<E> {
34     private ObjectProperty<E> baseValue;
35     private ObjectProperty<E> value;
36 
37     public ResetableObjectProperty() {
38         super(null);
39     }
40 
41     public ResetableObjectProperty(@Nullable E value) {
42         super(value);
43     }
44 
45     public ResetableObjectProperty(@Nullable Object bean, @Nonnull String name) {
46         super(bean, name);
47     }
48 
49     public ResetableObjectProperty(@Nullable Object bean, @Nonnull String name, @Nullable E baseValue) {
50         super(bean, name, baseValue);
51     }
52 
53     @Nonnull
54     @Override
55     protected Property<E> writableBaseValueProperty() {
56         return writableBaseValueObjectProperty();
57     }
58 
59     @Nonnull
60     protected ObjectProperty writableBaseValueObjectProperty() {
61         if (baseValue == null) {
62             baseValue = new SimpleObjectProperty<>(this, "baseValue");
63         }
64         return baseValue;
65     }
66 
67     @Nonnull
68     @Override
69     public ReadOnlyProperty<E> baseValueProperty() {
70         return writableBaseValueProperty();
71     }
72 
73     @Nonnull
74     public ReadOnlyObjectProperty baseValueObjectProperty() {
75         return writableBaseValueObjectProperty();
76     }
77 
78     @Nonnull
79     @Override
80     public Property<E> valueProperty() {
81         return valueObjectProperty();
82     }
83 
84     @Nonnull
85     public ObjectProperty<E> valueObjectProperty() {
86         if (value == null) {
87             value = new SimpleObjectProperty<>(this, "value");
88         }
89         return value;
90     }
91 }