-
Notifications
You must be signed in to change notification settings - Fork 5
/
QuestionDiv.java
190 lines (161 loc) · 7.06 KB
/
QuestionDiv.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package ihm;
import org.genericsystem.common.Generic;
import org.genericsystem.quiz.model.Answer;
import org.genericsystem.quiz.model.Question;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.annotations.BindAction;
import org.genericsystem.reactor.annotations.BindText;
import org.genericsystem.reactor.annotations.Children;
import org.genericsystem.reactor.annotations.DirectSelect;
import org.genericsystem.reactor.annotations.ForEach;
import org.genericsystem.reactor.annotations.SetText;
import org.genericsystem.reactor.annotations.Stepper;
import org.genericsystem.reactor.annotations.Style;
import org.genericsystem.reactor.annotations.StyleClass;
import org.genericsystem.reactor.context.ContextAction;
import org.genericsystem.reactor.context.ObservableListExtractor;
import org.genericsystem.reactor.contextproperties.StepperDefaults;
import org.genericsystem.reactor.gscomponents.DivWithTitle.TitleDiv;
import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlButton;
import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlCheckBox;
import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlDiv;
import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlH2;
import org.genericsystem.reactor.gscomponents.HtmlTag.HtmlLabel;
import ihm.QuestionDiv.Empty;
import ihm.QuestionDiv.FooterDiv;
import ihm.QuestionDiv.FooterDiv.FinishBtn;
import ihm.QuestionDiv.FooterDiv.NextBtn;
import ihm.QuestionDiv.FooterDiv.PreviousBtn;
import ihm.QuestionDiv.UnitDiv;
import javafx.collections.ObservableList;
import utils.StepperBis;
@Children({ UnitDiv.class, FooterDiv.class, Empty.class })
//
@Style(name = "display", value = "flex")
@Style(name = "flex", value = "1")
@Style(name = "flex-direction", value = "column")
@Style(name = "padding", value = "10px")
@Style(name = "background-color", value = "#DCDCDC")
@Style(path = { UnitDiv.class, TitleDiv.class }, name = "background-color", value = "#708090")
@Style(path = { UnitDiv.class, TitleDiv.class }, name = "padding", value = "10px")
@Style(path = { UnitDiv.class, TitleDiv.class }, name = "margin", value = "10px")
//
@DirectSelect(Question.class)
@ForEach(path = UnitDiv.class, value = ObservableListExtractor.SUBINSTANCES.class)
@BindText(path = { UnitDiv.class, TitleDiv.class, HtmlH2.class })
@Stepper(switchClass = UnitDiv.class, headerClass = Empty.class)
public class QuestionDiv extends HtmlDiv implements StepperDefaults {
// TODO Remplacer cette classe (temporaire, afin de faire fonctionner le stepper)
// par une autre Div affichant une information non steppable
// Ou faire évoluer le Stepper afin qu'il puisse prendre uniquement la switchClass en paramètre
public static class Empty extends HtmlDiv {
}
@Children({ TitleDiv.class, AnswersDiv.class })
//
@Style(name = "display", value = "flex")
@Style(name = "flex", value = "1")
@Style(name = "min-height", value = "100%")
@Style(name = "flex-direction", value = "column")
@Style(path = HtmlDiv.class, name = "border-radius", value = "10px")
public static class UnitDiv extends HtmlDiv {
}
@Children(AnswerDiv.class)
//
@Style(name = "display", value = "flex")
@Style(name = "flex-wrap", value = "wrap")
@Style(name = "justify-content", value = "space-around")
@Style(name = "margin", value = "10px")
@Style(name = "border", value = "1px solid silver")
@Style(name = "align-items", value = "center")
@StyleClass("fdirection-r-r-c")
public static class AnswersDiv extends HtmlDiv {
}
@Children({ HtmlCheckBox.class, HtmlLabel.class })
//
@Style(name = "min-width", value = "174px")
@Style(name = "display", value = "flex")
@Style(name = "flex-wrap", value = "nowrap")
@Style(name = "flex-direction", value = "row")
@Style(path = HtmlCheckBox.class, name = "margin-right", value = "10px")
@Style(path = HtmlCheckBox.class, name = "min-height", value = "15px")
@Style(path = HtmlCheckBox.class, name = "min-width", value = "15px")
@Style(path = HtmlLabel.class, name = "margin-top", value = "10px")
@Style(path = HtmlLabel.class, name = "margin-bottom", value = "10px")
@Style(path = HtmlLabel.class, name = "word-wrap", value = "break-word")
@Style(path = HtmlLabel.class, name = "hyphens", value = "auto")
@Style(path = HtmlLabel.class, name = "max-width", value = "100%")
@StyleClass("width-35-35-90")
@StyleClass(path = HtmlLabel.class, value = "vertical-align")
@StyleClass(path = HtmlCheckBox.class, value = "vertical-align")
//
@ForEach(ANSWERS_EXTRACTOR.class)
@BindText(path = HtmlLabel.class)
public static class AnswerDiv extends HtmlDiv {
}
@Children({ PreviousBtn.class, NextBtn.class, FinishBtn.class })
//
@Style(name = "display", value = "flex")
@Style(name = "justify-content", value = "space-around")
@Style(name = "align-self", value = "flex-end")
@Style(name = "width", value = "100%")
@StyleClass(path = HtmlButton.class, value = "monitorButton")
public static class FooterDiv extends HtmlDiv {
@SetText("Next >")
//
@Style(name = "text-align", value = "center")
//
@BindAction(NEXT_TAG.class)
public static class NextBtn extends HtmlButton implements StepperBis {
}
@SetText("< Previous")
//
@Style(name = "display", value = "none")
@Style(name = "text-align", value = "center")
//
@BindAction(PREVIOUS_TAG.class)
public static class PreviousBtn extends HtmlButton implements StepperBis {
}
@SetText("Finish")
//
@Style(name = "display", value = "none")
@Style(name = "text-align", value = "center")
public static class FinishBtn extends HtmlButton implements StepperBis {
}
}
public static class NEXT_TAG implements ContextAction {
@Override
public void accept(Context context, Tag tagNext) {
if (StepperBis.class.isAssignableFrom(tagNext.getClass())) {
// Réussir à insérer les tags de navigation (PREVIOUS, NEXT, FINISH)
Tag tag = tagNext.getParent();
Tag tagPrevious = tag.find(PreviousBtn.class);
Tag tagFinish = tag.find(FinishBtn.class);
((StepperBis) tagNext).next(context, tagNext, tagPrevious, tagFinish);
} else
log.warn("The NEXT action is applicable only to a tag implementing StepperDefaults.");
}
}
public static class PREVIOUS_TAG implements ContextAction {
@Override
public void accept(Context context, Tag tagPrevious) {
if (StepperBis.class.isAssignableFrom(tagPrevious.getClass())) {
Tag tag = tagPrevious.getParent();
Tag tagNext = tag.find(NextBtn.class);
Tag tagFinish = tag.find(FinishBtn.class);
((StepperBis) tagPrevious).prev(context, tagNext, tagPrevious, tagFinish);
} else
log.warn("The PREVIOUS action is applicable only to a tag implementing StepperDefaults.");
}
}
public static class ANSWERS_EXTRACTOR implements ObservableListExtractor {
// generics[0] est l'element courant.
// Le getRoot permet d'utiliser la methode find (Le root donne accès à tous les éléments du context)
// TODO Rendre la méthode générique -> lui faire trouver les enfants d'un generic ssi il y a un unique enfant
// OU
@Override
public ObservableList<Generic> apply(Generic[] generics) {
return generics[0].getObservableHolders(generics[0].getRoot().find(Answer.class));
}
}
}