-
Notifications
You must be signed in to change notification settings - Fork 5
/
GenericStringDefaults.java
40 lines (32 loc) · 1.53 KB
/
GenericStringDefaults.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
package org.genericsystem.reactor.modelproperties;
import javafx.beans.property.Property;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.beans.value.ObservableValue;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.model.StringExtractor;
public interface GenericStringDefaults extends TextPropertyDefaults {
public static final String GENERIC_STRING = "genericString";
public static final String EXTRACTOR = "extractor";
default ObservableValue<String> getGenericStringProperty(Context model) {
if (!model.containsProperty((Tag) this, GENERIC_STRING))
storeProperty(GENERIC_STRING, model, m -> new ReadOnlyStringWrapper(getStringExtractor(m).apply(m.getGeneric())));
return getProperty(GENERIC_STRING, model);
}
default void bindText() {
addPrefixBinding(model -> getDomNodeTextProperty(model).bind(getGenericStringProperty(model)));
}
default StringExtractor getStringExtractor(Context model) {
Property<StringExtractor> stringExtractorProperty = getProperty(EXTRACTOR, model);
return stringExtractorProperty != null ? stringExtractorProperty.getValue() : StringExtractor.SIMPLE_CLASS_EXTRACTOR;
}
default void setStringExtractor(StringExtractor extractor) {
addPrefixBinding(model -> {
if (!model.containsProperty((Tag) this, EXTRACTOR))
storeProperty(EXTRACTOR, model, m -> new ReadOnlyObjectWrapper<>(extractor));
else
getProperty(EXTRACTOR, model).setValue(extractor);
});
}
}