Search in sources :

Example 1 with DiscardListener

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.DiscardListener in project SORMAS-Project by hzi-braunschweig.

the class CaseImporter method handleCaseSimilarity.

/**
 * Presents a popup window to the user that allows them to deal with detected potentially duplicate cases.
 * By passing the desired result to the resultConsumer, the importer decided how to proceed with the import process.
 */
protected void handleCaseSimilarity(CaseImportSimilarityInput input, Consumer<CaseImportSimilarityResult> resultConsumer) {
    currentUI.accessSynchronously(() -> {
        CasePickOrImportField pickOrImportField = new CasePickOrImportField(input.getCaze(), input.getPerson(), input.getSimilarCases());
        pickOrImportField.setWidth(1024, Unit.PIXELS);
        final CommitDiscardWrapperComponent<CasePickOrImportField> component = new CommitDiscardWrapperComponent<>(pickOrImportField);
        component.addCommitListener(() -> {
            CaseSelectionDto pickedCase = pickOrImportField.getValue();
            if (pickedCase != null) {
                if (pickOrImportField.isOverrideCase()) {
                    resultConsumer.accept(new CaseImportSimilarityResult(null, pickedCase, ImportSimilarityResultOption.OVERRIDE));
                } else {
                    resultConsumer.accept(new CaseImportSimilarityResult(null, pickedCase, ImportSimilarityResultOption.PICK));
                }
            } else {
                resultConsumer.accept(new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.CREATE));
            }
        });
        DiscardListener discardListener = () -> resultConsumer.accept(new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.CANCEL));
        component.addDiscardListener(discardListener);
        component.getDiscardButton().setCaption(I18nProperties.getCaption(Captions.actionCancel));
        component.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
        component.getCommitButton().setEnabled(false);
        Button skipButton = ButtonHelper.createButton(Captions.actionSkip, e -> {
            component.removeDiscardListener(discardListener);
            component.discard();
            resultConsumer.accept(new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.SKIP));
        });
        component.getButtonsPanel().addComponentAsFirst(skipButton);
        pickOrImportField.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
        VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateCase));
    });
}
Also used : CaseImportSimilarityResult(de.symeda.sormas.ui.importer.CaseImportSimilarityResult) Button(com.vaadin.ui.Button) CaseSelectionDto(de.symeda.sormas.api.caze.CaseSelectionDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) DiscardListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.DiscardListener)

Aggregations

Button (com.vaadin.ui.Button)1 CaseSelectionDto (de.symeda.sormas.api.caze.CaseSelectionDto)1 CaseImportSimilarityResult (de.symeda.sormas.ui.importer.CaseImportSimilarityResult)1 CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)1 DiscardListener (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.DiscardListener)1