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));
});
}
Aggregations