2
2
3
3
import static java .util .Objects .isNull ;
4
4
5
- import com .vaadin .flow .component .ClickEvent ;
6
- import com .vaadin .flow .component .button .Button ;
5
+ import com .vaadin .flow .component .checkbox .Checkbox ;
7
6
import com .vaadin .flow .component .combobox .ComboBox ;
8
7
import com .vaadin .flow .component .customfield .CustomField ;
9
8
import com .vaadin .flow .component .html .Div ;
@@ -32,12 +31,12 @@ public class AutocompleteContactField extends CustomField<Contact> implements
32
31
33
32
34
33
private final ComboBox <Contact > contactSelection ;
35
- private final Button selfSelect ;
34
+ private final Checkbox selfSelect ;
36
35
private final TextField nameField ;
37
36
private final TextField emailField ;
38
37
private final Binder <Contact > binder ;
39
38
40
- public AutocompleteContactField (String label ) {
39
+ public AutocompleteContactField (String label , String shortName ) {
41
40
setLabel (label );
42
41
addClassName ("contact-field" );
43
42
binder = new Binder <>();
@@ -52,9 +51,9 @@ public AutocompleteContactField(String label) {
52
51
contactSelection .setItemLabelGenerator (
53
52
contact -> "%s - %s" .formatted (contact .getFullName (), contact .getEmail ()));
54
53
55
- selfSelect = new Button ( "Myself" );
54
+ selfSelect = new Checkbox ( "Choose myself as %s for this project" . formatted ( shortName ) );
56
55
selfSelect .addClassName ("contact-self-select" );
57
- selfSelect .addClickListener (this ::onSelfSelected );
56
+ selfSelect .addValueChangeListener (this ::onSelfSelected );
58
57
59
58
nameField = new TextField ();
60
59
nameField .setRequired (false );
@@ -98,11 +97,13 @@ public AutocompleteContactField(String label) {
98
97
clear ();
99
98
}
100
99
101
- private void onSelfSelected (ClickEvent <Button > buttonClickEvent ) {
102
- Authentication authentication = SecurityContextHolder .getContext ().getAuthentication ();
103
- QbicUserDetails details = (QbicUserDetails ) authentication .getPrincipal ();
104
- Contact userAsContact = new Contact (details .fullName (), details .getEmailAddress ());
105
- setContact (userAsContact );
100
+ private void onSelfSelected (ComponentValueChangeEvent <Checkbox , Boolean > checkboxvalueChangeEvent ) {
101
+ if (checkboxvalueChangeEvent .getValue ().booleanValue ()) {
102
+ Authentication authentication = SecurityContextHolder .getContext ().getAuthentication ();
103
+ QbicUserDetails details = (QbicUserDetails ) authentication .getPrincipal ();
104
+ Contact userAsContact = new Contact (details .fullName (), details .getEmailAddress ());
105
+ setContact (userAsContact );
106
+ }
106
107
}
107
108
108
109
private void updateValidationProperty () {
@@ -182,4 +183,7 @@ public Binder<Contact> getBinder() {
182
183
return binder ;
183
184
}
184
185
186
+ public void hideContactBox () {
187
+ contactSelection .setVisible (false );
188
+ }
185
189
}
0 commit comments