use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class ActivityAsCaseField method editEntry.
@Override
protected void editEntry(ActivityAsCaseDto entry, boolean create, Consumer<ActivityAsCaseDto> commitCallback) {
if (create) {
entry.setUuid(DataHelper.createUuid());
}
ActivityAsCaseForm activityAsCaseForm = new ActivityAsCaseForm(create, fieldVisibilityCheckers, fieldAccessCheckers);
activityAsCaseForm.setValue(entry);
final CommitDiscardWrapperComponent<ActivityAsCaseForm> component = new CommitDiscardWrapperComponent<>(activityAsCaseForm, UserProvider.getCurrent().hasUserRight(UserRight.CASE_EDIT), activityAsCaseForm.getFieldGroup());
component.getCommitButton().setCaption(I18nProperties.getString(Strings.done));
Window popupWindow = VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.entityActivityAsCase));
popupWindow.setHeight(90, Unit.PERCENTAGE);
component.addCommitListener(() -> {
if (!activityAsCaseForm.getFieldGroup().isModified()) {
commitCallback.accept(activityAsCaseForm.getValue());
}
});
if (!create) {
component.addDeleteListener(() -> {
popupWindow.close();
ActivityAsCaseField.this.removeEntry(entry);
}, I18nProperties.getCaption(ExposureDto.I18N_PREFIX));
}
}
use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class PreviousHospitalizationsField method editEntry.
@Override
protected void editEntry(PreviousHospitalizationDto entry, boolean create, Consumer<PreviousHospitalizationDto> commitCallback) {
if (create && entry.getUuid() == null) {
entry.setUuid(DataHelper.createUuid());
}
PreviousHospitalizationEditForm editForm = new PreviousHospitalizationEditForm(create, fieldVisibilityCheckers, fieldAccessCheckers);
editForm.setValue(entry);
final CommitDiscardWrapperComponent<PreviousHospitalizationEditForm> editView = new CommitDiscardWrapperComponent<PreviousHospitalizationEditForm>(editForm, UserProvider.getCurrent().hasUserRight(UserRight.CASE_EDIT), editForm.getFieldGroup());
editView.getCommitButton().setCaption(I18nProperties.getString(Strings.done));
Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getCaption(PreviousHospitalizationDto.I18N_PREFIX));
editView.addCommitListener(new CommitListener() {
@Override
public void onCommit() {
if (!editForm.getFieldGroup().isModified()) {
commitCallback.accept(editForm.getValue());
}
}
});
if (!isEmpty(entry)) {
editView.addDeleteListener(new DeleteListener() {
@Override
public void onDelete() {
popupWindow.close();
PreviousHospitalizationsField.this.removeEntry(entry);
}
}, I18nProperties.getCaption(PreviousHospitalizationDto.I18N_PREFIX));
}
}
use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationController method getImmunizationCreateComponent.
private CommitDiscardWrapperComponent<ImmunizationCreationForm> getImmunizationCreateComponent() {
UserProvider currentUserProvider = UserProvider.getCurrent();
if (currentUserProvider != null) {
ImmunizationCreationForm createForm = new ImmunizationCreationForm();
ImmunizationDto immunization = ImmunizationDto.build(null);
immunization.setReportingUser(currentUserProvider.getUserReference());
createForm.setValue(immunization);
final CommitDiscardWrapperComponent<ImmunizationCreationForm> viewComponent = new CommitDiscardWrapperComponent<>(createForm, currentUserProvider.hasUserRight(UserRight.IMMUNIZATION_CREATE), createForm.getFieldGroup());
viewComponent.addCommitListener(() -> {
if (!createForm.getFieldGroup().isModified()) {
final ImmunizationDto dto = createForm.getValue();
PersonDto searchedPerson = createForm.getSearchedPerson();
if (searchedPerson != null) {
dto.setPerson(searchedPerson.toReference());
selectOrCreateimmunizationForPerson(dto, searchedPerson.toReference());
} else {
final PersonDto person = createForm.getPerson();
ControllerProvider.getPersonController().selectOrCreatePerson(person, I18nProperties.getString(Strings.infoSelectOrCreatePersonForImmunization), selectedPerson -> {
if (selectedPerson != null) {
selectOrCreateimmunizationForPerson(dto, selectedPerson);
}
}, true);
}
}
});
return viewComponent;
}
return null;
}
use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationController method selectOrCreateImmunization.
private void selectOrCreateImmunization(ImmunizationDto immunizationDto, Consumer<String> selectedImmunizationUuidConsumer) {
ImmunizationSimilarityCriteria criteria = new ImmunizationSimilarityCriteria.Builder().withDisease(immunizationDto.getDisease()).withStartDate(immunizationDto.getStartDate()).withEndDate(immunizationDto.getEndDate()).withPerson(immunizationDto.getPerson().getUuid()).withMeansOfImmunization(immunizationDto.getMeansOfImmunization()).build();
List<ImmunizationDto> similarImmunizations = FacadeProvider.getImmunizationFacade().getSimilarImmunizations(criteria);
if (!similarImmunizations.isEmpty()) {
ImmunizationPickOrCreateField pickOrCreateField = new ImmunizationPickOrCreateField(immunizationDto, similarImmunizations);
pickOrCreateField.setWidth(1280, Sizeable.Unit.PIXELS);
final CommitDiscardWrapperComponent<ImmunizationPickOrCreateField> component = new CommitDiscardWrapperComponent<>(pickOrCreateField);
component.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
component.getCommitButton().setEnabled(false);
component.addCommitListener(() -> selectedImmunizationUuidConsumer.accept(pickOrCreateField.getValue()));
pickOrCreateField.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateImmunization));
} else {
selectedImmunizationUuidConsumer.accept(immunizationDto.getUuid());
}
}
use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationController method getImmunizationDataEditComponent.
public CommitDiscardWrapperComponent<ImmunizationDataForm> getImmunizationDataEditComponent(ImmunizationDto immunizationDto) {
ImmunizationDataForm immunizationDataForm = new ImmunizationDataForm(immunizationDto.isPseudonymized(), immunizationDto.getRelatedCase());
immunizationDataForm.setValue(immunizationDto);
UserProvider currentUserProvider = UserProvider.getCurrent();
CommitDiscardWrapperComponent<ImmunizationDataForm> editComponent = new CommitDiscardWrapperComponent<ImmunizationDataForm>(immunizationDataForm, currentUserProvider != null && currentUserProvider.hasUserRight(UserRight.IMMUNIZATION_EDIT), immunizationDataForm.getFieldGroup()) {
@Override
public void discard() {
immunizationDataForm.discard();
super.discard();
}
};
AutomaticDeletionInfoDto automaticDeletionInfoDto = FacadeProvider.getImmunizationFacade().getAutomaticDeletionInfo(immunizationDto.getUuid());
if (automaticDeletionInfoDto != null) {
editComponent.getButtonsPanel().addComponentAsFirst(new AutomaticDeletionLabel(automaticDeletionInfoDto));
}
editComponent.addCommitListener(() -> {
if (!immunizationDataForm.getFieldGroup().isModified()) {
ImmunizationDto immunizationDtoValue = immunizationDataForm.getValue();
List<ImmunizationDto> similarImmunizations = findSimilarImmunizations(immunizationDtoValue);
if (similarImmunizations.isEmpty()) {
FacadeProvider.getImmunizationFacade().save(immunizationDtoValue);
if (immunizationDtoValue.getImmunizationStatus() == ImmunizationStatus.ACQUIRED) {
NotificationHelper.showNotification(I18nProperties.getString(Strings.messageImmunizationSavedVaccinationStatusUpdated), Notification.Type.WARNING_MESSAGE, -1);
} else {
Notification.show(I18nProperties.getString(Strings.messageImmunizationSaved), Notification.Type.WARNING_MESSAGE);
}
SormasUI.refreshView();
} else {
showSimilarImmunizationPopup(immunizationDtoValue, similarImmunizations.get(0), this::saveImmunization);
}
}
});
// Initialize 'Delete' button
if (UserProvider.getCurrent().hasUserRight(UserRight.IMMUNIZATION_DELETE)) {
editComponent.addDeleteListener(() -> {
FacadeProvider.getImmunizationFacade().deleteImmunization(immunizationDto.getUuid());
UI.getCurrent().getNavigator().navigateTo(ImmunizationsView.VIEW_NAME);
}, I18nProperties.getString(Strings.entityImmunization));
}
// Initialize 'Archive' button
if (UserProvider.getCurrent().hasUserRight(UserRight.IMMUNIZATION_ARCHIVE)) {
boolean archived = FacadeProvider.getImmunizationFacade().isArchived(immunizationDto.getUuid());
Button archiveButton = ButtonHelper.createButton(archived ? Captions.actionDearchive : Captions.actionArchive, e -> {
if (editComponent.isModified()) {
editComponent.commit();
}
if (archived) {
ControllerProvider.getArchiveController().dearchiveEntity(immunizationDto, FacadeProvider.getImmunizationFacade(), Strings.headingDearchiveImmunization, Strings.confirmationDearchiveImmunization, Strings.entityImmunization, Strings.messageImmunizationDearchived, () -> navigateToImmunization(immunizationDto.getUuid()));
} else {
ControllerProvider.getArchiveController().archiveEntity(immunizationDto, FacadeProvider.getImmunizationFacade(), Strings.headingArchiveImmunization, Strings.confirmationArchiveImmunization, Strings.entityImmunization, Strings.messageImmunizationArchived, () -> navigateToImmunization(immunizationDto.getUuid()));
}
}, ValoTheme.BUTTON_LINK);
editComponent.getButtonsPanel().addComponentAsFirst(archiveButton);
editComponent.getButtonsPanel().setComponentAlignment(archiveButton, Alignment.BOTTOM_LEFT);
}
return editComponent;
}
Aggregations