-
Notifications
You must be signed in to change notification settings - Fork 5
/
MapStringDefaults.java
26 lines (21 loc) · 1.01 KB
/
MapStringDefaults.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
package org.genericsystem.reactor.modelproperties;
import java.util.function.Function;
import javafx.collections.FXCollections;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableMap;
import javafx.collections.WeakMapChangeListener;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.HtmlDomNode;
import org.genericsystem.reactor.Tag;
public interface MapStringDefaults extends ContextProperty {
default ObservableMap<String, String> getDomNodeMap(Context model, String propertyName, Function<HtmlDomNode, MapChangeListener<String, String>> getListener) {
if (!model.containsProperty((Tag) this, propertyName)) {
createNewInitializedProperty(propertyName, model, m -> {
ObservableMap<String, String> map = FXCollections.observableHashMap();
map.addListener(new WeakMapChangeListener<>(getListener.apply(model.getHtmlDomNode((Tag) this))));
return map;
});
}
return (ObservableMap<String, String>) getProperty(propertyName, model).getValue();
}
}