-
Notifications
You must be signed in to change notification settings - Fork 5
/
GeoSearchPerso.java
86 lines (75 loc) · 3.37 KB
/
GeoSearchPerso.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package org.genericsystem.geography.app;
import org.genericsystem.common.Generic;
import org.genericsystem.geography.app.GeoSearchPerso.Input1;
import org.genericsystem.geography.app.GeoSearchPerso.Input2;
import org.genericsystem.geography.app.GeoSearchPerso.Test1;
import org.genericsystem.geography.app.GeoSearchPerso.Test2;
import org.genericsystem.geography.model.AdministrativeTerritory;
import org.genericsystem.geography.model.Building;
import org.genericsystem.geography.model.City;
import org.genericsystem.geography.model.Country;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.annotations.BindText;
import org.genericsystem.reactor.annotations.Children;
import org.genericsystem.reactor.annotations.DependsOnModel;
import org.genericsystem.reactor.annotations.DirectSelect;
import org.genericsystem.reactor.appserver.ApplicationServer;
import org.genericsystem.reactor.context.StringExtractor;
import org.genericsystem.reactor.context.TextBinding;
import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlP;
import org.genericsystem.reactor.gscomponents.RootTagImpl;
import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.value.ObservableValue;
import javafx.collections.transformation.SortedList;
@DependsOnModel({ AdministrativeTerritory.class, Country.class, City.class, Building.class })
@Children({ Input1.class, Input2.class, Test1.class, Test2.class })
public class GeoSearchPerso extends RootTagImpl {
public static void main(String[] mainArgs) {
ApplicationServer.startSimpleGenericApp(mainArgs, GeoSearchPerso.class, "/GeoApp");
}
@DirectSelect(City.class)
public static class Input1 extends InputSelectInstance {
@Override
public String displayInstance(Generic g) {
String str = StringExtractor.SIMPLE_CLASS_EXTRACTOR.apply(g);
while (g.getBaseComponent() != null) {
g = g.getBaseComponent();
str += ", " + g.getValue();
}
return str;
}
}
@DirectSelect(City.class)
public static class Input2 extends InputSelectInstance {
@Override
public SortedList<Generic> filterInstances(Context c, Property<String> t) {
return c.getGeneric().getSubInstances().toObservableList().filtered(res -> (t.getValue() != null && t.getValue().length() > 1) ? ((String) res.getValue()).toLowerCase().contains(t.getValue().toLowerCase()) : false).sorted();
}
}
@BindText(GENERIC_TEXT.class)
public static class Test1 extends HtmlP {
}
@BindText(GENERIC_TEXT2.class)
public static class Test2 extends HtmlP {
}
public static class GENERIC_TEXT implements TextBinding {
@Override
public ObservableValue<String> apply(Context context, Tag tag) {
Tag inputTag = tag.getParent().find(Input1.class);
Context ctx = context.getSubContexts(inputTag).get(0);
Property<?> prop = inputTag.getContextProperty("selected", ctx);
return Bindings.createStringBinding(() -> prop.getValue() != null ? prop.getValue().toString() : "", prop);
}
}
public static class GENERIC_TEXT2 implements TextBinding {
@Override
public ObservableValue<String> apply(Context context, Tag tag) {
Tag inputTag = tag.getParent().find(Input2.class);
Context ctx = context.getSubContexts(inputTag).get(0);
Property<?> prop = inputTag.getContextProperty("selected", ctx);
return Bindings.createStringBinding(() -> prop.getValue() != null ? prop.getValue().toString() : "", prop);
}
}
}