-
Notifications
You must be signed in to change notification settings - Fork 5
/
RadioButtonWithValue.java
53 lines (46 loc) · 2.04 KB
/
RadioButtonWithValue.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
package org.genericsystem.ir.app.gui.utils;
import org.genericsystem.common.Generic;
import org.genericsystem.cv.model.DocClass.DocClassInstance;
import org.genericsystem.ir.app.gui.pages.HomePageTable;
import org.genericsystem.reactor.ReactorStatics;
import org.genericsystem.reactor.annotations.TagName;
import org.genericsystem.reactor.contextproperties.ConvertedValueDefaults;
import org.genericsystem.reactor.contextproperties.SelectionDefaults;
import org.genericsystem.reactor.gscomponents.TagImpl;
@TagName(value = TagName.INPUT, type = TagName.RADIO)
public class RadioButtonWithValue extends TagImpl implements ConvertedValueDefaults {
public RadioButtonWithValue() {
createConvertedValueProperty();
bindOptionalBiDirectionalAttribute(VALUE, ReactorStatics.CHECKED, ReactorStatics.CHECKED);
}
public static class RadioButtonEditor extends RadioButtonWithValue implements SelectionDefaults {
@Override
public void init() {
initValueProperty(context -> {
// Get the current item (from DOC_CLASS_SELECTOR)
Generic currentItem = context.getGeneric();
// Get the docClass from the document
Generic currentDocClass = context.getGenerics()[2];
// If there is a match, that means the current item is also the current docClass
return currentItem == currentDocClass;
});
addConvertedValueChangeListener((context, nva) -> {
// NB: nva will always return true, since it represents the selected element
DocClassInstance currentItem = (DocClassInstance) context.getGeneric();
// Store the current item in the context property
getContextProperty(HomePageTable.DOCCLASS_CONTEXT_PROPERTY, context).setValue(currentItem);
});
// Fix the "name" attribute with the name of the document
addPrefixBinding(context -> {
getDomNodeAttributes(context).put("name", context.getGenerics()[1].getValue().toString());
});
}
}
public static class RadioButtonDisplayer extends RadioButtonEditor {
@Override
public void init() {
super.init();
addAttribute(ReactorStatics.DISABLED, ReactorStatics.DISABLED);
}
}
}