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