Search in sources :

Example 1 with PersonSearchField

use of de.symeda.sormas.ui.person.PersonSearchField in project SORMAS-Project by hzi-braunschweig.

the class PersonDependentEditForm method createPersonSearchButton.

protected Button createPersonSearchButton(String personSearchLoc) {
    return ButtonHelper.createIconButtonWithCaption(personSearchLoc, StringUtils.EMPTY, VaadinIcons.SEARCH, clickEvent -> {
        VaadinIcons icon = (VaadinIcons) clickEvent.getButton().getIcon();
        if (icon == VaadinIcons.SEARCH) {
            PersonSearchField personSearchField = new PersonSearchField(null, I18nProperties.getString(Strings.infoSearchPerson));
            personSearchField.setWidth(1280, Unit.PIXELS);
            final CommitDiscardWrapperComponent<PersonSearchField> component = new CommitDiscardWrapperComponent<>(personSearchField);
            component.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
            component.getCommitButton().setEnabled(false);
            component.addCommitListener(() -> {
                SimilarPersonDto pickedPerson = personSearchField.getValue();
                if (pickedPerson != null) {
                    // add consumer
                    searchedPerson = FacadeProvider.getPersonFacade().getPersonByUuid(pickedPerson.getUuid());
                    setPerson(searchedPerson);
                    enablePersonFields(false);
                    clickEvent.getButton().setIcon(VaadinIcons.CLOSE);
                }
            });
            personSearchField.setSelectionChangeCallback((commitAllowed) -> {
                component.getCommitButton().setEnabled(commitAllowed);
            });
            VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingSelectPerson));
        } else {
            searchedPerson = null;
            setPerson(searchedPerson);
            enablePersonFields(true);
            clickEvent.getButton().setIcon(VaadinIcons.SEARCH);
        }
    }, CssStyles.FORCE_CAPTION);
}
Also used : PersonSearchField(de.symeda.sormas.ui.person.PersonSearchField) VaadinIcons(com.vaadin.icons.VaadinIcons) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto)

Aggregations

VaadinIcons (com.vaadin.icons.VaadinIcons)1 SimilarPersonDto (de.symeda.sormas.api.person.SimilarPersonDto)1 PersonSearchField (de.symeda.sormas.ui.person.PersonSearchField)1