use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class EventController method selectOrCreateEvent.
public void selectOrCreateEvent(CaseReferenceDto caseRef) {
CaseDataDto caseDataDto = FacadeProvider.getCaseFacade().getCaseDataByUuid(caseRef.getUuid());
EventSelectionField eventSelect = new EventSelectionField(caseDataDto.getDisease(), I18nProperties.getString(Strings.infoPickOrCreateEventForCase), null);
eventSelect.setWidth(1100, Sizeable.Unit.PIXELS);
final CommitDiscardWrapperComponent<EventSelectionField> component = new CommitDiscardWrapperComponent<>(eventSelect);
component.addCommitListener(() -> {
EventIndexDto selectedEvent = eventSelect.getValue();
if (selectedEvent != null) {
EventCriteria eventCriteria = new EventCriteria();
eventCriteria.caze(caseRef);
eventCriteria.setUserFilterIncluded(false);
List<EventIndexDto> eventIndexDto = FacadeProvider.getEventFacade().getIndexList(eventCriteria, null, null, null);
EventReferenceDto eventReferenceDto = new EventReferenceDto(selectedEvent.getUuid());
if (!eventIndexDto.contains(selectedEvent)) {
linkCaseToEvent(eventReferenceDto, caseDataDto, caseRef);
SormasUI.refreshView();
} else {
SormasUI.refreshView();
Notification notification = new Notification(I18nProperties.getString(Strings.messagePersonAlreadyCaseInEvent), "", Type.HUMANIZED_MESSAGE);
notification.setDelayMsec(10000);
notification.show(Page.getCurrent());
}
} else {
create(caseRef);
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 EventController method selectOrCreateSuperordinateEvent.
public void selectOrCreateSuperordinateEvent(EventReferenceDto subordinateEventRef) {
Set<String> excludedUuids = new HashSet<>();
excludedUuids.add(subordinateEventRef.getUuid());
excludedUuids.addAll(FacadeProvider.getEventFacade().getAllSubordinateEventUuids(subordinateEventRef.getUuid()));
EventDto subordinateEvent = FacadeProvider.getEventFacade().getEventByUuid(subordinateEventRef.getUuid(), false);
EventSelectionField selectionField = EventSelectionField.forSuperordinateEvent(subordinateEvent, excludedUuids);
selectionField.setWidth(1100, Sizeable.Unit.PIXELS);
final CommitDiscardWrapperComponent<EventSelectionField> component = new CommitDiscardWrapperComponent<>(selectionField);
component.addCommitListener(() -> {
EventIndexDto selectedEvent = selectionField.getValue();
if (selectedEvent != null) {
subordinateEvent.setSuperordinateEvent(selectedEvent.toReference());
FacadeProvider.getEventFacade().save(subordinateEvent);
navigateToData(subordinateEventRef.getUuid());
Notification.show(I18nProperties.getString(Strings.messageEventLinkedAsSuperordinate), Type.TRAY_NOTIFICATION);
} else {
createSuperordinateEvent(subordinateEventRef);
}
});
selectionField.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 EventController method selectOrCreateEventForCaseList.
public void selectOrCreateEventForCaseList(List<CaseReferenceDto> caseRefs) {
if (caseRefs == null || caseRefs.isEmpty()) {
return;
}
List<CaseDataDto> caseDataDtos = FacadeProvider.getCaseFacade().getByUuids(caseRefs.stream().map(ReferenceDto::getUuid).collect(Collectors.toList()));
EventSelectionField eventSelect = new EventSelectionField(caseDataDtos.stream().findFirst().get().getDisease(), I18nProperties.getString(Strings.infoPickOrCreateEventForCases), 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());
linkCasesToEvent(eventReferenceDto, caseDataDtos);
} else {
createFromCaseList(caseRefs);
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 EventController method getEventCreateComponentForContactList.
public CommitDiscardWrapperComponent<EventDataForm> getEventCreateComponentForContactList(List<ContactReferenceDto> contactRefs) {
List<ContactDto> contactDtos = FacadeProvider.getContactFacade().getByUuids(contactRefs.stream().map(c -> c.getUuid()).collect(Collectors.toList()));
EventDataForm eventCreateForm = new EventDataForm(true, false);
eventCreateForm.setValue(createNewEvent(contactDtos.stream().findFirst().get().getDisease()));
eventCreateForm.getField(EventDto.DISEASE).setReadOnly(true);
final CommitDiscardWrapperComponent<EventDataForm> editView = new CommitDiscardWrapperComponent<EventDataForm>(eventCreateForm, UserProvider.getCurrent().hasUserRight(UserRight.EVENT_CREATE), eventCreateForm.getFieldGroup());
List<ContactDto> finalContactDtos = contactDtos;
editView.addCommitListener(() -> {
if (!eventCreateForm.getFieldGroup().isModified()) {
EventDto dto = eventCreateForm.getValue();
FacadeProvider.getEventFacade().save(dto);
Notification.show(I18nProperties.getString(Strings.messageEventCreated), Type.WARNING_MESSAGE);
linkContactsToEvent(new EventReferenceDto(dto.getUuid()), finalContactDtos);
}
});
return editView;
}
use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.
the class EventController method getEventDataEditComponent.
public CommitDiscardWrapperComponent<EventDataForm> getEventDataEditComponent(final String eventUuid, Consumer<EventStatus> saveCallback) {
EventDto event = findEvent(eventUuid);
AutomaticDeletionInfoDto automaticDeletionInfoDto = FacadeProvider.getEventFacade().getAutomaticDeletionInfo(eventUuid);
EventDataForm eventEditForm = new EventDataForm(false, event.isPseudonymized());
eventEditForm.setValue(event);
final CommitDiscardWrapperComponent<EventDataForm> editView = new CommitDiscardWrapperComponent<EventDataForm>(eventEditForm, UserProvider.getCurrent().hasUserRight(UserRight.EVENT_EDIT), eventEditForm.getFieldGroup());
if (automaticDeletionInfoDto != null) {
editView.getButtonsPanel().addComponentAsFirst(new AutomaticDeletionLabel(automaticDeletionInfoDto));
}
editView.addCommitListener(() -> {
if (!eventEditForm.getFieldGroup().isModified()) {
EventDto eventDto = eventEditForm.getValue();
final UserDto user = UserProvider.getCurrent().getUser();
final RegionReferenceDto userRegion = user.getRegion();
final DistrictReferenceDto userDistrict = user.getDistrict();
final RegionReferenceDto epEventRegion = eventDto.getEventLocation().getRegion();
final DistrictReferenceDto epEventDistrict = eventDto.getEventLocation().getDistrict();
final Boolean eventOutsideJurisdiction = (userRegion != null && !userRegion.equals(epEventRegion) || userDistrict != null && !userDistrict.equals(epEventDistrict));
if (eventOutsideJurisdiction) {
VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingEventJurisdictionUpdated), new Label(I18nProperties.getString(Strings.messageEventJurisdictionUpdated)), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), 500, confirmed -> {
if (confirmed) {
saveEvent(saveCallback, eventDto);
}
});
} else {
saveEvent(saveCallback, eventDto);
}
}
});
if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_DELETE)) {
editView.addDeleteListener(() -> {
if (!existEventParticipantsLinkedToEvent(event)) {
try {
FacadeProvider.getEventFacade().deleteEvent(event.getUuid());
} catch (ExternalSurveillanceToolException e) {
Notification.show(String.format(I18nProperties.getString(Strings.ExternalSurveillanceToolGateway_notificationEntryNotDeleted), DataHelper.getShortUuid(event.getUuid())), "", Type.ERROR_MESSAGE);
}
} else {
VaadinUiUtil.showSimplePopupWindow(I18nProperties.getString(Strings.headingEventNotDeleted), I18nProperties.getString(Strings.messageEventsNotDeletedReason));
}
UI.getCurrent().getNavigator().navigateTo(EventsView.VIEW_NAME);
}, I18nProperties.getString(Strings.entityEvent));
}
// Initialize 'Archive' button
if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_ARCHIVE)) {
boolean archived = FacadeProvider.getEventFacade().isArchived(eventUuid);
Button archiveEventButton = ButtonHelper.createButton(archived ? Captions.actionDearchive : Captions.actionArchive, e -> {
if (editView.isModified()) {
editView.commit();
}
if (archived) {
ControllerProvider.getArchiveController().dearchiveEntity(event, FacadeProvider.getEventFacade(), Strings.headingDearchiveEvent, Strings.confirmationDearchiveEvent, Strings.entityEvent, Strings.messageEventDearchived, () -> navigateToData(event.getUuid()));
} else {
ControllerProvider.getArchiveController().archiveEntity(event, FacadeProvider.getEventFacade(), Strings.headingArchiveEvent, Strings.confirmationArchiveEvent, Strings.entityEvent, Strings.messageEventArchived, () -> navigateToData(event.getUuid()));
}
}, ValoTheme.BUTTON_LINK);
editView.getButtonsPanel().addComponentAsFirst(archiveEventButton);
editView.getButtonsPanel().setComponentAlignment(archiveEventButton, Alignment.BOTTOM_LEFT);
}
return editView;
}
Aggregations