BindingDecorator.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.binding;
19 
20 import javafx.beans.InvalidationListener;
21 import javafx.beans.binding.Binding;
22 import javafx.beans.value.ChangeListener;
23 import javafx.collections.ObservableList;
24 
25 import javax.annotation.Nonnull;
26 
27 import static java.util.Objects.requireNonNull;
28 
29 /**
30  @author Andres Almiray
31  @since 2.13.0
32  */
33 public class BindingDecorator<T> implements Binding<T> {
34     private final Binding<T> delegate;
35 
36     public BindingDecorator(@Nonnull Binding<T> delegate) {
37         this.delegate = requireNonNull(delegate, "Argument 'delegate' must not be null");
38     }
39 
40     @Nonnull
41     protected final Binding<T> getDelegate() {
42         return delegate;
43     }
44 
45     @Override
46     public boolean isValid() {
47         return getDelegate().isValid();
48     }
49 
50     @Override
51     public void invalidate() {
52         getDelegate().invalidate();
53     }
54 
55     @Override
56     public ObservableList<?> getDependencies() {
57         return getDelegate().getDependencies();
58     }
59 
60     @Override
61     public void dispose() {
62         getDelegate().dispose();
63     }
64 
65     @Override
66     public void addListener(ChangeListener<? super T> listener) {
67         getDelegate().addListener(listener);
68     }
69 
70     @Override
71     public void removeListener(ChangeListener<? super T> listener) {
72         getDelegate().removeListener(listener);
73     }
74 
75     @Override
76     public T getValue() {
77         return getDelegate().getValue();
78     }
79 
80     @Override
81     public void addListener(InvalidationListener listener) {
82         getDelegate().addListener(listener);
83     }
84 
85     @Override
86     public void removeListener(InvalidationListener listener) {
87         getDelegate().removeListener(listener);
88     }
89 }