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