-
Notifications
You must be signed in to change notification settings - Fork 5
/
GSSingleLinkComponentEditor.java
72 lines (57 loc) · 2.5 KB
/
GSSingleLinkComponentEditor.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
package org.genericsystem.reactor.gscomponents;
import java.util.List;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.gscomponents.GSSelect.CompositeSelectWithEmptyEntry;
import org.genericsystem.reactor.gscomponents.GSSelect.InstanceCompositeSelect;
import org.genericsystem.reactor.model.ObservableListExtractor;
import org.genericsystem.reactor.htmltag.HtmlLabel.GSLabelDisplayer;
import javafx.beans.property.Property;
public class GSSingleLinkComponentEditor extends GSDiv {
protected GSSelect select;
public GSSingleLinkComponentEditor(Tag parent) {
this(parent, InstanceCompositeSelect::new);
}
public GSSingleLinkComponentEditor(Tag parent, GSSelectConstructor constructor) {
super(parent, FlexDirection.ROW);
addStyle("flex", "1");
addStyle("justify-content", "center");
addStyle("align-items", "center");
select = constructor.build(this);
select.select(gs -> gs[1].isReferentialIntegrityEnabled(gs[1].getComponents().indexOf(gs[0])) ? gs[0] : null);
select.addStyle("width", "100%");
select.addStyle("height", "100%");
select.addPostfixBinding(model -> {
Property<List<Property<Context>>> selectedComponents = select.getComponentsProperty(model);
if (selectedComponents != null)
selectedComponents.getValue().add(select.getSelectionProperty(model));
});
new GSLabelDisplayer(this) {
{
select(gs -> !gs[1].isReferentialIntegrityEnabled(gs[1].getComponents().indexOf(gs[0])) && !gs[0].getLinks(gs[2]).isEmpty() ? gs[0] : null);
}
};
}
@FunctionalInterface
public interface GSSelectConstructor {
GSSelect build(Tag parent);
}
public static class GSLinkComponentEditor extends GSSingleLinkComponentEditor {
public GSLinkComponentEditor(Tag parent) {
super(parent);
forEach((ObservableListExtractor) gs -> ObservableListExtractor.COMPONENTS.apply(gs).filtered(g -> !g.equals(gs[2])));
}
}
public static class GSLinkComponentAdder extends GSSingleLinkComponentEditor {
public GSLinkComponentAdder(Tag parent) {
super(parent, CompositeSelectWithEmptyEntry::new);
forEach((ObservableListExtractor) gs -> ObservableListExtractor.COMPONENTS.apply(gs).filtered(g -> !g.equals(gs[2])));
}
}
public static class GSLinkComponentBuilder extends GSSingleLinkComponentEditor {
public GSLinkComponentBuilder(Tag parent) {
super(parent, CompositeSelectWithEmptyEntry::new);
forEach((ObservableListExtractor) gs -> ObservableListExtractor.COMPONENTS.apply(gs).filtered(g -> !g.equals(gs[1])));
}
}
}