use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class EventController method selectOrCreateEventForContactList.
public void selectOrCreateEventForContactList(List<ContactReferenceDto> contactRefs) {
if (contactRefs == null || contactRefs.isEmpty()) {
return;
}
List<ContactDto> contactDtos = FacadeProvider.getContactFacade().getByUuids(contactRefs.stream().map(ReferenceDto::getUuid).collect(Collectors.toList()));
EventSelectionField eventSelect = new EventSelectionField(contactDtos.stream().findFirst().get().getDisease(), I18nProperties.getString(Strings.infoPickOrCreateEventForContact), null);
eventSelect.setWidth(1100, Sizeable.Unit.PIXELS);
final CommitDiscardWrapperComponent<EventSelectionField> component = new CommitDiscardWrapperComponent<>(eventSelect);
component.addCommitListener(() -> {
EventIndexDto selectedEvent = eventSelect.getValue();
if (selectedEvent != null) {
EventReferenceDto eventReferenceDto = new EventReferenceDto(selectedEvent.getUuid());
linkContactsToEvent(eventReferenceDto, contactDtos);
} else {
createFromContactList(contactRefs);
SormasUI.refreshView();
}
});
eventSelect.setSelectionChangeCallback(commitAllowed -> component.getCommitButton().setEnabled(commitAllowed));
VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateEvent));
}
use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class EventGroupController method selectOrCreate.
public void selectOrCreate(List<EventReferenceDto> eventReferences, Runnable callback) {
Set<String> excludedEventGroupUuids = FacadeProvider.getEventGroupFacade().getCommonEventGroupsByEvents(eventReferences).stream().map(EventGroupReferenceDto::getUuid).collect(Collectors.toSet());
EventGroupSelectionField selectionField = new EventGroupSelectionField(excludedEventGroupUuids);
selectionField.setWidth(1024, Sizeable.Unit.PIXELS);
final CommitDiscardWrapperComponent<EventGroupSelectionField> component = new CommitDiscardWrapperComponent<>(selectionField);
component.addCommitListener(() -> {
EventGroupIndexDto selectedEventGroup = selectionField.getValue();
if (selectedEventGroup != null) {
FacadeProvider.getEventGroupFacade().linkEventsToGroup(eventReferences, selectedEventGroup.toReference());
FacadeProvider.getEventGroupFacade().notifyEventAddedToEventGroup(selectedEventGroup.toReference(), eventReferences);
Notification.show(I18nProperties.getString(Strings.messageEventLinkedToGroup), Type.TRAY_NOTIFICATION);
if (callback != null) {
callback.run();
} else {
SormasUI.refreshView();
}
} else {
create(eventReferences, callback);
}
});
selectionField.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateEventGroup));
}
use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class EventGroupController method getEventGroupEditComponent.
public CommitDiscardWrapperComponent<?> getEventGroupEditComponent(String uuid) {
EventGroupDto eventGroup = FacadeProvider.getEventGroupFacade().getEventGroupByUuid(uuid);
EventGroupDataForm eventGroupEditForm = new EventGroupDataForm(false);
eventGroupEditForm.setValue(eventGroup);
UserProvider user = UserProvider.getCurrent();
final CommitDiscardWrapperComponent<EventGroupDataForm> editView = new CommitDiscardWrapperComponent<>(eventGroupEditForm, user.hasUserRight(UserRight.EVENTGROUP_EDIT), eventGroupEditForm.getFieldGroup());
List<RegionReferenceDto> regions = FacadeProvider.getEventGroupFacade().getEventGroupRelatedRegions(uuid);
boolean hasRegion = user.hasNationalJurisdictionLevel() || regions.stream().allMatch(user::hasRegion);
editView.setReadOnly(hasRegion);
if (user.hasUserRight(UserRight.EVENTGROUP_EDIT) && hasRegion) {
editView.addCommitListener(() -> {
if (!eventGroupEditForm.getFieldGroup().isModified()) {
EventGroupDto updatedEventGroup = eventGroupEditForm.getValue();
FacadeProvider.getEventGroupFacade().saveEventGroup(updatedEventGroup);
Notification.show(I18nProperties.getString(Strings.messageEventGroupSaved), Notification.Type.WARNING_MESSAGE);
SormasUI.refreshView();
}
});
}
if (user.hasUserRight(UserRight.EVENTGROUP_DELETE) && hasRegion) {
editView.addDeleteListener(() -> {
deleteEventGroup(eventGroup);
UI.getCurrent().getNavigator().navigateTo(EventsView.VIEW_NAME);
}, I18nProperties.getString(Strings.entityEventGroup));
}
// Initialize 'Archive' button
if (user.hasUserRight(UserRight.EVENTGROUP_ARCHIVE) && hasRegion) {
boolean archived = FacadeProvider.getEventGroupFacade().isArchived(uuid);
Button archiveEventButton = ButtonHelper.createButton(archived ? Captions.actionDearchive : Captions.actionArchive, e -> {
archiveOrDearchiveEventGroup(uuid, !archived);
}, ValoTheme.BUTTON_LINK);
editView.getButtonsPanel().addComponentAsFirst(archiveEventButton);
editView.getButtonsPanel().setComponentAlignment(archiveEventButton, Alignment.BOTTOM_LEFT);
}
editView.addDiscardListener(SormasUI::refreshView);
return editView;
}
use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class LabMessageController method pickOrCreateEvent.
private void pickOrCreateEvent(LabMessageDto labMessageDto, PersonDto person) {
EventSelectionField eventSelect = new EventSelectionField(labMessageDto.getTestedDisease(), I18nProperties.getString(Strings.infoPickOrCreateEventForLabMessage), null);
eventSelect.setWidth(1024, Sizeable.Unit.PIXELS);
Window window = VaadinUiUtil.createPopupWindow();
final CommitDiscardWrapperComponent<EventSelectionField> component = new CommitDiscardWrapperComponent<>(eventSelect);
component.addCommitListener(() -> {
EventIndexDto selectedEvent = eventSelect.getValue();
if (selectedEvent != null) {
EventCriteria eventCriteria = new EventCriteria();
eventCriteria.setPerson(person.toReference());
eventCriteria.setUserFilterIncluded(false);
List<EventIndexDto> eventIndexDtos = FacadeProvider.getEventFacade().getIndexList(eventCriteria, null, null, null);
EventReferenceDto eventReferenceDto = new EventReferenceDto(selectedEvent.getUuid());
if (!eventIndexDtos.contains(selectedEvent)) {
createEventParticipant(FacadeProvider.getEventFacade().getEventByUuid(eventReferenceDto.getUuid(), false), labMessageDto, person);
} else {
CommitDiscardWrapperComponent<VerticalLayout> commitDiscardWrapperComponent = new CommitDiscardWrapperComponent<>(new VerticalLayout(new Label(I18nProperties.getString(Strings.infoEventParticipantAlreadyExisting))));
commitDiscardWrapperComponent.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionContinue));
commitDiscardWrapperComponent.getDiscardButton().setCaption(I18nProperties.getCaption(Captions.actionBack));
commitDiscardWrapperComponent.addCommitListener(() -> {
EventParticipantReferenceDto participant = FacadeProvider.getEventParticipantFacade().getReferenceByEventAndPerson(selectedEvent.getUuid(), person.getUuid());
List<SampleDto> samples = FacadeProvider.getSampleFacade().getSimilarSamples(createSampleCriteria(labMessageDto).eventParticipant(participant));
if (samples.isEmpty()) {
createSample(SampleDto.build(UserProvider.getCurrent().getUserReference(), participant), labMessageDto, selectedEvent.getDisease(), false);
} else {
pickOrCreateSample(FacadeProvider.getEventParticipantFacade().getByUuid(participant.getUuid()), labMessageDto, samples);
}
});
commitDiscardWrapperComponent.addDiscardListener(() -> pickOrCreateEvent(labMessageDto, person));
VaadinUiUtil.showModalPopupWindow(commitDiscardWrapperComponent, I18nProperties.getCaption(Captions.info));
}
} else {
createEvent(labMessageDto, person);
}
window.close();
});
component.addDiscardListener(window::close);
eventSelect.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
window.setContent(component);
window.setCaption(I18nProperties.getString(Strings.headingPickOrCreateEvent));
UI.getCurrent().addWindow(window);
}
use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class LabMessageController method confirmContinueProcessing.
private CompletionStage<Boolean> confirmContinueProcessing(LabMessageDto labMessageDto, SampleReferenceDto sample) {
CompletableFuture<Boolean> ret = new CompletableFuture<>();
Window window = VaadinUiUtil.createPopupWindow();
Label label = new Label(I18nProperties.getString(Strings.confirmLabMessageCorrectionThrough));
label.addStyleName(CssStyles.LABEL_WHITE_SPACE_NORMAL);
CommitDiscardWrapperComponent<Label> confirmComponent = new CommitDiscardWrapperComponent<>(label);
confirmComponent.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionYes));
confirmComponent.getDiscardButton().setCaption(I18nProperties.getCaption(Captions.actionNo));
confirmComponent.addCommitListener(() -> {
ret.complete(true);
window.close();
});
confirmComponent.addDiscardListener(window::close);
window.addCloseListener((e) -> {
if (!ret.isDone()) {
ret.complete(false);
}
finishProcessingLabMessage(labMessageDto, sample);
});
showFormWithLabMessage(labMessageDto, confirmComponent, window, I18nProperties.getString(Strings.headingLabMessageCorrectionThrough), false);
return ret;
}
Aggregations