Search in sources :

Example 1 with PersonSelectionField

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

the class EventImporter method handlePersonSimilarity.

/**
 * Presents a popup window to the user that allows them to deal with detected potentially duplicate persons.
 * By passing the desired result to the resultConsumer, the importer decided how to proceed with the import process.
 */
protected void handlePersonSimilarity(PersonDto newPerson, Consumer<PersonImportSimilarityResult> resultConsumer) {
    currentUI.accessSynchronously(() -> {
        PersonSelectionField personSelect = new PersonSelectionField(newPerson, I18nProperties.getString(Strings.infoSelectOrCreatePersonForImport));
        personSelect.setWidth(1024, Unit.PIXELS);
        if (personSelect.hasMatches()) {
            final CommitDiscardWrapperComponent<PersonSelectionField> component = new CommitDiscardWrapperComponent<>(personSelect);
            component.addCommitListener(() -> {
                SimilarPersonDto person = personSelect.getValue();
                if (person == null) {
                    resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.CREATE));
                } else {
                    resultConsumer.accept(new PersonImportSimilarityResult(person, ImportSimilarityResultOption.PICK));
                }
            });
            component.addDiscardListener(() -> resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.SKIP)));
            personSelect.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
            Window window = VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreatePerson));
            window.addCloseListener(event -> resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.SKIP)));
            personSelect.selectBestMatch();
        } else {
            resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.CREATE));
        }
    });
}
Also used : Window(com.vaadin.ui.Window) PersonSelectionField(de.symeda.sormas.ui.person.PersonSelectionField) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) PersonImportSimilarityResult(de.symeda.sormas.ui.importer.PersonImportSimilarityResult) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto)

Example 2 with PersonSelectionField

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

the class DataImporter method handlePersonSimilarity.

/**
 * Presents a popup window to the user that allows them to deal with detected potentially duplicate persons.
 * By passing the desired result to the resultConsumer, the importer decided how to proceed with the import process.
 */
protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
    currentUI.accessSynchronously(() -> {
        PersonSelectionField personSelect = new PersonSelectionField(newPerson, I18nProperties.getString(infoText));
        personSelect.setWidth(1024, Unit.PIXELS);
        if (personSelect.hasMatches()) {
            final CommitDiscardWrapperComponent<PersonSelectionField> component = new CommitDiscardWrapperComponent<>(personSelect);
            component.addCommitListener(() -> {
                SimilarPersonDto person = personSelect.getValue();
                if (person == null) {
                    resultConsumer.accept(createSimilarityResult.apply(null, ImportSimilarityResultOption.CREATE));
                } else {
                    resultConsumer.accept(createSimilarityResult.apply(person, ImportSimilarityResultOption.PICK));
                }
            });
            component.addDiscardListener(() -> resultConsumer.accept(createSimilarityResult.apply(null, ImportSimilarityResultOption.SKIP)));
            personSelect.setSelectionChangeCallback((commitAllowed) -> {
                component.getCommitButton().setEnabled(commitAllowed);
            });
            VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreatePerson));
            personSelect.selectBestMatch();
        } else {
            resultConsumer.accept(createSimilarityResult.apply(null, ImportSimilarityResultOption.CREATE));
        }
    });
}
Also used : PersonSelectionField(de.symeda.sormas.ui.person.PersonSelectionField) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto)

Aggregations

SimilarPersonDto (de.symeda.sormas.api.person.SimilarPersonDto)2 PersonSelectionField (de.symeda.sormas.ui.person.PersonSelectionField)2 CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)2 Window (com.vaadin.ui.Window)1 PersonImportSimilarityResult (de.symeda.sormas.ui.importer.PersonImportSimilarityResult)1