ResetableProperty.java
001 /*
002  * Copyright 2008-2017 the original author or authors.
003  *
004  * Licensed under the Apache License, Version 2.0 (the "License");
005  * you may not use this file except in compliance with the License.
006  * You may obtain a copy of the License at
007  *
008  *     http://www.apache.org/licenses/LICENSE-2.0
009  *
010  * Unless required by applicable law or agreed to in writing, software
011  * distributed under the License is distributed on an "AS IS" BASIS,
012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013  * See the License for the specific language governing permissions and
014  * limitations under the License.
015  */
016 package griffon.javafx.beans.property;
017 
018 import javafx.beans.binding.BooleanBinding;
019 import javafx.beans.property.Property;
020 import javafx.beans.property.ReadOnlyProperty;
021 
022 import javax.annotation.Nonnull;
023 import javax.annotation.Nullable;
024 
025 /**
026  @author Andres Almiray
027  @since 2.10.0
028  */
029 public interface ResetableProperty<T> {
030     /**
031      * A property that tracks the base value of this {@code ResetableProperty}.
032      */
033     @Nonnull
034     ReadOnlyProperty<T> baseValueProperty();
035 
036     /**
037      * A property that tracks the current value of this {@code ResetableProperty}.
038      */
039     @Nonnull
040     Property<T> valueProperty();
041 
042     /**
043      * A property that tracks if the current value differs form the base value.
044      */
045     @Nonnull
046     BooleanBinding dirtyProperty();
047 
048     /**
049      * Returns the base value of this {@code ResetableProperty}.
050      *
051      @return the base value
052      */
053     @Nullable
054     T getBaseValue();
055 
056     /**
057      * Returns the current value of this {@code ResetableProperty}.
058      *
059      @return the current value
060      */
061     @Nullable
062     T getValue();
063 
064     /**
065      * Sets the current value.
066      *
067      @param value the new value
068      */
069     @Nonnull
070     ResetableProperty<T> setValue(@Nullable T value);
071 
072     /**
073      * Query if the current value differs from the base value.
074      *
075      @return {@code true} if values differ, {@code false} otherwise
076      */
077     boolean isDirty();
078 
079     /**
080      * Sets the current value as the base value.
081      *
082      @return this {@code ResetableProperty}
083      */
084     @Nonnull
085     ResetableProperty<T> rebase();
086 
087     /**
088      * Sets the base value as the current value.
089      *
090      @return this {@code ResetableProperty}
091      */
092     @Nonnull
093     ResetableProperty<T> reset();
094 
095     /**
096      * Returns the {@code Object} that contains this property. If this property
097      * is not contained in an {@code Object}, {@code null} is returned.
098      *
099      @return the containing {@code Object} or {@code null}
100      */
101     @Nullable
102     Object getBean();
103 
104     /**
105      * Returns the name of this property. If the property does not have a name,
106      * this method returns an empty {@code String}.
107      *
108      @return the name or an empty {@code String}
109      */
110     @Nonnull
111     String getName();
112 }