-
Notifications
You must be signed in to change notification settings - Fork 5
/
TextPropertyDefaults.java
43 lines (33 loc) · 1.47 KB
/
TextPropertyDefaults.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package org.genericsystem.reactor.contextproperties;
import java.util.function.Function;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
public interface TextPropertyDefaults extends ContextProperty {
public static final String TEXT = "text";
public static final String TEXT_BINDING = "binding";
default Property<String> getDomNodeTextProperty(Context model) {
if (!model.containsProperty((Tag) this, TEXT)) {
storeProperty(TEXT, model, m -> new SimpleStringProperty());
Property<String> text = getProperty(TEXT, model);
text.addListener(model.getHtmlDomNode((Tag) this).getTextListener());
}
return getProperty(TEXT, model);
}
default void setText(Context context, String value) {
getDomNodeTextProperty(context).setValue(value);
}
default void setText(String value) {
addPrefixBinding(context -> setText(context, value));
}
default void bindText(Context context, Function<Context, ObservableValue<String>> applyOnModel) {
storeProperty(TEXT_BINDING, context, applyOnModel);
getDomNodeTextProperty(context).bind(getObservableValue(TEXT_BINDING, context));
}
default void bindText(Function<Context, ObservableValue<String>> applyOnModel) {
storeProperty(TEXT_BINDING, applyOnModel);
addPrefixBinding(model -> getDomNodeTextProperty(model).bind(getObservableValue(TEXT_BINDING, model)));
}
}