List of usage examples for com.vaadin.server Page getCurrent
public static Page getCurrent()
From source file:de.metas.procurement.webui.util.JavascriptUtils.java
License:Open Source License
public static void setBeforePageUnloadMessage(final String message) { final JavaScript javaScript = Page.getCurrent().getJavaScript(); if (message == null || message.trim().isEmpty()) { javaScript.execute("$(window).off('beforeunload');"); } else {/*from www . j ava 2s. c o m*/ // TODO: escape the message javaScript.execute("$(window).on('beforeunload', function() { return \"" + message + "\"; });"); } }
From source file:de.metas.ui.web.service.impl.VaadinWebProcessCtl.java
License:Open Source License
@Override public void reportAsync(final ProcessInfo pi, final ActionEvent event) { final ASyncProcess asyncCtrl = new ASyncProcess() { private boolean locked = false; @Override//from w ww . ja v a 2s.co m public void lockUI(final ProcessInfo pi) { locked = true; final Notification notification = new Notification("Executing " + event.getAction().getCaption(), Notification.Type.TRAY_NOTIFICATION); notification.setIcon(Theme.getVaadinResource(event.getAction().getIcon())); notification.show(Page.getCurrent()); } @Override public void unlockUI(final ProcessInfo pi) { locked = false; } @Override public boolean isUILocked() { return locked; } @Override public void executeASync(final ProcessInfo pi) { logger.debug("executeASync: {}", pi); } }; ProcessCtl.process(asyncCtrl, pi.getWindowNo(), pi, ITrx.TRX_None); // calls lockUI, unlockUI }
From source file:de.symeda.sormas.ui.caze.CaseController.java
License:Open Source License
private void saveCase(CaseDataDto cazeDto) { // Compare old and new case CaseDataDto existingDto = FacadeProvider.getCaseFacade().getCaseDataByUuid(cazeDto.getUuid()); onCaseChanged(existingDto, cazeDto); CaseDataDto resultDto = FacadeProvider.getCaseFacade().saveCase(cazeDto); if (resultDto.getPlagueType() != cazeDto.getPlagueType()) { // TODO would be much better to have a notification for this triggered in the backend Window window = VaadinUiUtil.showSimplePopupWindow( I18nProperties.getString(Strings.headingSaveNotification), String.format(I18nProperties.getString(Strings.messagePlagueTypeChange), resultDto.getPlagueType().toString(), resultDto.getPlagueType().toString())); window.addCloseListener(new CloseListener() { private static final long serialVersionUID = 1L; @Override//from w w w . ja va 2s. c o m public void windowClose(CloseEvent e) { if (existingDto.getCaseClassification() != resultDto.getCaseClassification() && resultDto.getClassificationUser() == null) { Notification notification = new Notification(String.format( I18nProperties.getString(Strings.messageCaseSavedClassificationChanged), resultDto.getCaseClassification().toString()), Type.WARNING_MESSAGE); notification.setDelayMsec(-1); notification.show(Page.getCurrent()); } else { Notification.show(I18nProperties.getString(Strings.messageCaseSaved), Type.WARNING_MESSAGE); } SormasUI.refreshView(); } }); } else { // Notify user about an automatic case classification change if (existingDto != null && existingDto.getCaseClassification() != resultDto.getCaseClassification() && resultDto.getClassificationUser() == null) { Notification notification = new Notification( String.format(I18nProperties.getString(Strings.messageCaseSavedClassificationChanged), resultDto.getCaseClassification().toString()), Type.WARNING_MESSAGE); notification.setDelayMsec(-1); notification.show(Page.getCurrent()); } else { Notification.show(I18nProperties.getString(Strings.messageCaseSaved), Type.WARNING_MESSAGE); } SormasUI.refreshView(); } }
From source file:de.symeda.sormas.ui.caze.CaseController.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) public void showBulkCaseDataEditComponent(Collection<CaseIndexDto> selectedCases) { if (selectedCases.size() == 0) { new Notification(I18nProperties.getString(Strings.headingNoCasesSelected), I18nProperties.getString(Strings.messageNoCasesSelected), Type.WARNING_MESSAGE, false) .show(Page.getCurrent()); return;// w ww . j av a 2 s. c o m } // Check if cases with multiple districts have been selected String districtUuid = null; for (CaseIndexDto selectedCase : selectedCases) { if (districtUuid == null) { districtUuid = selectedCase.getDistrictUuid(); } else if (!districtUuid.equals(selectedCase.getDistrictUuid())) { districtUuid = null; break; } } DistrictReferenceDto district = FacadeProvider.getDistrictFacade().getDistrictReferenceByUuid(districtUuid); // Create a temporary case in order to use the CommitDiscardWrapperComponent CaseDataDto tempCase = new CaseDataDto(); BulkCaseDataForm form = new BulkCaseDataForm(district); form.setValue(tempCase); final CommitDiscardWrapperComponent<BulkCaseDataForm> editView = new CommitDiscardWrapperComponent<BulkCaseDataForm>( form, form.getFieldGroup()); Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getString(Strings.headingEditCases)); editView.addCommitListener(new CommitListener() { @Override public void onCommit() { CaseDataDto updatedTempCase = form.getValue(); for (CaseIndexDto indexDto : selectedCases) { CaseDataDto caseDto = FacadeProvider.getCaseFacade().getCaseDataByUuid(indexDto.getUuid()); if (form.getClassificationCheckBox().getValue() == true) { caseDto.setCaseClassification(updatedTempCase.getCaseClassification()); } if (form.getInvestigationStatusCheckBox().getValue() == true) { caseDto.setInvestigationStatus(updatedTempCase.getInvestigationStatus()); } if (form.getOutcomeCheckBox().getValue() == true) { caseDto.setOutcome(updatedTempCase.getOutcome()); } // Setting the surveillance officer is only allowed if all selected cases are in the same district if (district != null && form.getSurveillanceOfficerCheckBox().getValue() == true) { caseDto.setSurveillanceOfficer(updatedTempCase.getSurveillanceOfficer()); } FacadeProvider.getCaseFacade().saveCase(caseDto); } popupWindow.close(); navigateToIndex(); Notification.show(I18nProperties.getString(Strings.messageCasesEdited), Type.HUMANIZED_MESSAGE); } }); editView.addDiscardListener(new DiscardListener() { @Override public void onDiscard() { popupWindow.close(); } }); }
From source file:de.symeda.sormas.ui.caze.CaseController.java
License:Open Source License
public void deleteAllSelectedItems(Collection<CaseIndexDto> selectedRows, Runnable callback) { if (selectedRows.size() == 0) { new Notification(I18nProperties.getString(Strings.headingNoCasesSelected), I18nProperties.getString(Strings.messageNoCasesSelected), Type.WARNING_MESSAGE, false) .show(Page.getCurrent()); } else {//from w w w . j a v a 2 s . co m VaadinUiUtil.showDeleteConfirmationWindow( String.format(I18nProperties.getString(Strings.confirmationDeleteCases), selectedRows.size()), new Runnable() { public void run() { for (CaseIndexDto selectedRow : selectedRows) { FacadeProvider.getCaseFacade().deleteCase( new CaseReferenceDto(selectedRow.getUuid()), UserProvider.getCurrent().getUuid()); } callback.run(); new Notification(I18nProperties.getString(Strings.headingCasesDeleted), I18nProperties.getString(Strings.messageCasesDeleted), Type.HUMANIZED_MESSAGE, false).show(Page.getCurrent()); } }); } }
From source file:de.symeda.sormas.ui.caze.CaseController.java
License:Open Source License
public void archiveAllSelectedItems(Collection<CaseIndexDto> selectedRows, Runnable callback) { if (selectedRows.size() == 0) { new Notification(I18nProperties.getString(Strings.headingNoCasesSelected), I18nProperties.getString(Strings.messageNoCasesSelected), Type.WARNING_MESSAGE, false) .show(Page.getCurrent()); } else {/*from w w w.ja v a2 s. c om*/ VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingConfirmArchiving), new Label(String.format(I18nProperties.getString(Strings.confirmationArchiveCases), selectedRows.size())), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), null, e -> { if (e.booleanValue() == true) { for (CaseIndexDto selectedRow : selectedRows) { FacadeProvider.getCaseFacade().archiveOrDearchiveCase(selectedRow.getUuid(), true); } callback.run(); new Notification(I18nProperties.getString(Strings.headingCasesArchived), I18nProperties.getString(Strings.messageCasesArchived), Type.HUMANIZED_MESSAGE, false).show(Page.getCurrent()); } }); } }
From source file:de.symeda.sormas.ui.caze.CaseController.java
License:Open Source License
public void dearchiveAllSelectedItems(Collection<CaseIndexDto> selectedRows, Runnable callback) { if (selectedRows.size() == 0) { new Notification(I18nProperties.getString(Strings.headingNoCasesSelected), I18nProperties.getString(Strings.messageNoCasesSelected), Type.WARNING_MESSAGE, false) .show(Page.getCurrent()); } else {//from w w w . j a v a 2 s . c o m VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingConfirmDearchiving), new Label(String.format(I18nProperties.getString(Strings.confirmationDearchiveCases), selectedRows.size())), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), null, e -> { if (e.booleanValue() == true) { for (CaseIndexDto selectedRow : selectedRows) { FacadeProvider.getCaseFacade().archiveOrDearchiveCase(selectedRow.getUuid(), false); } callback.run(); new Notification(I18nProperties.getString(Strings.headingCasesDearchived), I18nProperties.getString(Strings.messageCasesDearchived), Type.HUMANIZED_MESSAGE, false).show(Page.getCurrent()); } }); } }
From source file:de.symeda.sormas.ui.caze.CaseImportLayout.java
License:Open Source License
public CaseImportLayout() { super();//from ww w . j a v a 2 s .co m addDownloadResourcesComponent(1, new ClassResource("/SORMAS_Import_Guide.pdf"), new ClassResource("/doc/SORMAS_Data_Dictionary.xlsx")); addDownloadImportTemplateComponent(2, FacadeProvider.getImportFacade().getCaseImportTemplateFilePath().toString(), "sormas_import_case_template.csv"); addImportCsvComponent(3, new ImportReceiver("_case_import_", new Consumer<File>() { @Override public void accept(File file) { resetDownloadErrorReportButton(); try { CaseImporter importer = new CaseImporter(file, currentUser, currentUI); importer.startImport(new Consumer<StreamResource>() { @Override public void accept(StreamResource resource) { extendDownloadErrorReportButton(resource); } }); } catch (IOException e) { new Notification(I18nProperties.getString(Strings.headingImportFailed), I18nProperties.getString(Strings.messageImportFailed), Type.ERROR_MESSAGE, false) .show(Page.getCurrent()); } } })); addDownloadErrorReportComponent(4); }
From source file:de.symeda.sormas.ui.caze.CasesView.java
License:Open Source License
public VerticalLayout createFilterBar() { VerticalLayout filterLayout = new VerticalLayout(); filterLayout.setSpacing(false);//from w w w.ja v a 2 s.c o m filterLayout.setMargin(false); filterLayout.setWidth(100, Unit.PERCENTAGE); firstFilterRowLayout = new HorizontalLayout(); firstFilterRowLayout.setMargin(false); firstFilterRowLayout.setSpacing(true); firstFilterRowLayout.setSizeUndefined(); { if (!UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) { caseOriginFilter = new ComboBox(); caseOriginFilter.setId(CaseDataDto.CASE_ORIGIN); caseOriginFilter.setWidth(140, Unit.PIXELS); caseOriginFilter.setInputPrompt( I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.CASE_ORIGIN)); caseOriginFilter.addItems((Object[]) CaseOrigin.values()); caseOriginFilter.addValueChangeListener(e -> { criteria.caseOrigin(((CaseOrigin) e.getProperty().getValue())); if (UserProvider.getCurrent().hasUserRight(UserRight.PORT_HEALTH_INFO_VIEW)) { pointOfEntryFilter.setEnabled(e.getProperty().getValue() != CaseOrigin.IN_COUNTRY); portHealthCasesWithoutFacilityFilter .setEnabled(e.getProperty().getValue() != CaseOrigin.IN_COUNTRY); } navigateTo(criteria); }); firstFilterRowLayout.addComponent(caseOriginFilter); } outcomeFilter = new ComboBox(); outcomeFilter.setId(CaseDataDto.OUTCOME); outcomeFilter.setWidth(140, Unit.PIXELS); outcomeFilter .setInputPrompt(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.OUTCOME)); outcomeFilter.addItems((Object[]) CaseOutcome.values()); outcomeFilter.addValueChangeListener(e -> { criteria.outcome(((CaseOutcome) e.getProperty().getValue())); navigateTo(criteria); }); firstFilterRowLayout.addComponent(outcomeFilter); diseaseFilter = new ComboBox(); diseaseFilter.setId(CaseDataDto.DISEASE); diseaseFilter.setWidth(140, Unit.PIXELS); diseaseFilter .setInputPrompt(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.DISEASE)); diseaseFilter.addItems( FacadeProvider.getDiseaseConfigurationFacade().getAllActivePrimaryDiseases().toArray()); diseaseFilter.addValueChangeListener(e -> { criteria.disease(((Disease) e.getProperty().getValue())); navigateTo(criteria); }); firstFilterRowLayout.addComponent(diseaseFilter); classificationFilter = new ComboBox(); classificationFilter.setId(CaseDataDto.CASE_CLASSIFICATION); classificationFilter.setWidth(140, Unit.PIXELS); classificationFilter.setInputPrompt( I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.CASE_CLASSIFICATION)); classificationFilter.addItems((Object[]) CaseClassification.values()); classificationFilter.addValueChangeListener(e -> { criteria.caseClassification(((CaseClassification) e.getProperty().getValue())); navigateTo(criteria); }); firstFilterRowLayout.addComponent(classificationFilter); searchField = new TextField(); searchField.setId("search"); searchField.setWidth(200, Unit.PIXELS); searchField.setNullRepresentation(""); searchField.setInputPrompt(I18nProperties.getString(Strings.promptCasesSearchField)); searchField.addTextChangeListener(e -> { criteria.nameUuidEpidNumberLike(e.getText()); grid.reload(); }); firstFilterRowLayout.addComponent(searchField); addShowMoreOrLessFiltersButtons(firstFilterRowLayout); resetButton = new Button(I18nProperties.getCaption(Captions.actionResetFilters)); resetButton.setId("reset"); resetButton.setVisible(false); resetButton.addClickListener(event -> { ViewModelProviders.of(CasesView.class).remove(CaseCriteria.class); navigateTo(null); }); firstFilterRowLayout.addComponent(resetButton); } filterLayout.addComponent(firstFilterRowLayout); secondFilterRowLayout = new HorizontalLayout(); secondFilterRowLayout.setMargin(false); secondFilterRowLayout.setSpacing(true); secondFilterRowLayout.setSizeUndefined(); { presentConditionFilter = new ComboBox(); presentConditionFilter.setWidth(140, Unit.PIXELS); presentConditionFilter.setInputPrompt( I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.PRESENT_CONDITION)); presentConditionFilter.addItems((Object[]) PresentCondition.values()); presentConditionFilter.addValueChangeListener(e -> { criteria.presentCondition(((PresentCondition) e.getProperty().getValue())); navigateTo(criteria); }); secondFilterRowLayout.addComponent(presentConditionFilter); UserDto user = UserProvider.getCurrent().getUser(); regionFilter = new ComboBox(); if (user.getRegion() == null) { regionFilter.setWidth(140, Unit.PIXELS); regionFilter.setInputPrompt( I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.REGION)); regionFilter.addItems(FacadeProvider.getRegionFacade().getAllAsReference()); regionFilter.addValueChangeListener(e -> { RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue(); criteria.region(region); navigateTo(criteria); }); secondFilterRowLayout.addComponent(regionFilter); } districtFilter = new ComboBox(); districtFilter.setWidth(140, Unit.PIXELS); districtFilter .setInputPrompt(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.DISTRICT)); districtFilter.setDescription(I18nProperties.getDescription(Descriptions.descDistrictFilter)); districtFilter.addValueChangeListener(e -> { DistrictReferenceDto district = (DistrictReferenceDto) e.getProperty().getValue(); criteria.district(district); navigateTo(criteria); }); if (user.getRegion() != null && user.getDistrict() == null) { districtFilter .addItems(FacadeProvider.getDistrictFacade().getAllByRegion(user.getRegion().getUuid())); districtFilter.setEnabled(true); } else { regionFilter.addValueChangeListener(e -> { RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue(); districtFilter.removeAllItems(); if (region != null) { districtFilter .addItems(FacadeProvider.getDistrictFacade().getAllByRegion(region.getUuid())); districtFilter.setEnabled(true); } else { districtFilter.setEnabled(false); } }); districtFilter.setEnabled(false); } secondFilterRowLayout.addComponent(districtFilter); if (!UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) { facilityFilter = new ComboBox(); facilityFilter.setWidth(140, Unit.PIXELS); facilityFilter.setInputPrompt( I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.HEALTH_FACILITY)); facilityFilter.setDescription(I18nProperties.getDescription(Descriptions.descFacilityFilter)); facilityFilter.addValueChangeListener(e -> { criteria.healthFacility(((FacilityReferenceDto) e.getProperty().getValue())); navigateTo(criteria); }); facilityFilter.setEnabled(false); secondFilterRowLayout.addComponent(facilityFilter); } if (UserProvider.getCurrent().hasUserRight(UserRight.PORT_HEALTH_INFO_VIEW)) { pointOfEntryFilter = new ComboBox(); pointOfEntryFilter.setWidth(140, Unit.PIXELS); pointOfEntryFilter.setInputPrompt( I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.POINT_OF_ENTRY)); pointOfEntryFilter .setDescription(I18nProperties.getDescription(Descriptions.descPointOfEntryFilter)); pointOfEntryFilter.addValueChangeListener(e -> { criteria.pointOfEntry(((PointOfEntryReferenceDto) e.getProperty().getValue())); navigateTo(criteria); }); secondFilterRowLayout.addComponent(pointOfEntryFilter); } districtFilter.addValueChangeListener(e -> { if (facilityFilter != null) { facilityFilter.removeAllItems(); DistrictReferenceDto district = (DistrictReferenceDto) e.getProperty().getValue(); if (district != null) { facilityFilter.addItems( FacadeProvider.getFacilityFacade().getHealthFacilitiesByDistrict(district, true)); facilityFilter.setEnabled(true); } else { facilityFilter.setEnabled(false); } } if (pointOfEntryFilter != null) { pointOfEntryFilter.removeAllItems(); DistrictReferenceDto district = (DistrictReferenceDto) e.getProperty().getValue(); if (district != null) { pointOfEntryFilter.addItems( FacadeProvider.getPointOfEntryFacade().getAllByDistrict(district.getUuid(), true)); pointOfEntryFilter.setEnabled( caseOriginFilter == null || caseOriginFilter.getValue() != CaseOrigin.IN_COUNTRY); } else { pointOfEntryFilter.setEnabled(false); } } }); officerFilter = new ComboBox(); officerFilter.setWidth(140, Unit.PIXELS); officerFilter.setInputPrompt( I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.SURVEILLANCE_OFFICER)); if (user.getRegion() != null) { officerFilter.addItems(FacadeProvider.getUserFacade().getUsersByRegionAndRoles(user.getRegion(), UserRole.SURVEILLANCE_OFFICER)); } officerFilter.addValueChangeListener(e -> { criteria.surveillanceOfficer(((UserReferenceDto) e.getProperty().getValue())); navigateTo(criteria); }); secondFilterRowLayout.addComponent(officerFilter); reportedByFilter = new ComboBox(); reportedByFilter.setWidth(140, Unit.PIXELS); reportedByFilter.setInputPrompt(I18nProperties.getString(Strings.reportedBy)); reportedByFilter.addItems((Object[]) UserRole.values()); reportedByFilter.addValueChangeListener(e -> { criteria.reportingUserRole((UserRole) e.getProperty().getValue()); navigateTo(criteria); }); secondFilterRowLayout.addComponent(reportedByFilter); reportingUserFilter = new TextField(); reportingUserFilter.setWidth(200, Unit.PIXELS); reportingUserFilter.setInputPrompt( I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.REPORTING_USER)); reportingUserFilter.setNullRepresentation(""); reportingUserFilter.addTextChangeListener(e -> { criteria.reportingUserLike(e.getText()); grid.reload(); }); secondFilterRowLayout.addComponent(reportingUserFilter); } filterLayout.addComponent(secondFilterRowLayout); secondFilterRowLayout.setVisible(false); thirdFilterRowLayout = new HorizontalLayout(); thirdFilterRowLayout.setMargin(false); thirdFilterRowLayout.setSpacing(true); thirdFilterRowLayout.setSizeUndefined(); CssStyles.style(thirdFilterRowLayout, CssStyles.VSPACE_3); { casesWithoutGeoCoordsFilter = new CheckBox(); CssStyles.style(casesWithoutGeoCoordsFilter, CssStyles.CHECKBOX_FILTER_INLINE); casesWithoutGeoCoordsFilter.setCaption(I18nProperties.getCaption(Captions.caseFilterWithoutGeo)); casesWithoutGeoCoordsFilter .setDescription(I18nProperties.getDescription(Descriptions.descCaseFilterWithoutGeo)); casesWithoutGeoCoordsFilter.addValueChangeListener(e -> { criteria.mustHaveNoGeoCoordinates((Boolean) e.getProperty().getValue()); navigateTo(criteria); }); thirdFilterRowLayout.addComponent(casesWithoutGeoCoordsFilter); if (UserProvider.getCurrent().hasUserRight(UserRight.PORT_HEALTH_INFO_VIEW)) { portHealthCasesWithoutFacilityFilter = new CheckBox(); CssStyles.style(portHealthCasesWithoutFacilityFilter, CssStyles.CHECKBOX_FILTER_INLINE); portHealthCasesWithoutFacilityFilter .setCaption(I18nProperties.getCaption(Captions.caseFilterPortHealthWithoutFacility)); portHealthCasesWithoutFacilityFilter.setDescription( I18nProperties.getDescription(Descriptions.descCaseFilterPortHealthWithoutFacility)); portHealthCasesWithoutFacilityFilter.addValueChangeListener(e -> { criteria.mustBePortHealthCaseWithoutFacility((Boolean) e.getProperty().getValue()); navigateTo(criteria); }); thirdFilterRowLayout.addComponent(portHealthCasesWithoutFacilityFilter); } } filterLayout.addComponent(thirdFilterRowLayout); thirdFilterRowLayout.setVisible(false); dateFilterRowLayout = new HorizontalLayout(); dateFilterRowLayout.setSpacing(true); dateFilterRowLayout.setSizeUndefined(); { Button applyButton = new Button(I18nProperties.getCaption(Captions.actionApplyDateFilter)); weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(applyButton, false, false, I18nProperties.getString(Strings.infoCaseDate), NewCaseDateType.class, I18nProperties.getString(Strings.promptNewCaseDateType), NewCaseDateType.MOST_RELEVANT); weekAndDateFilter.getWeekFromFilter() .setInputPrompt(I18nProperties.getString(Strings.promptCasesEpiWeekFrom)); weekAndDateFilter.getWeekToFilter() .setInputPrompt(I18nProperties.getString(Strings.promptCasesEpiWeekTo)); weekAndDateFilter.getDateFromFilter() .setInputPrompt(I18nProperties.getString(Strings.promptCasesDateFrom)); weekAndDateFilter.getDateToFilter().setInputPrompt(I18nProperties.getString(Strings.promptDateTo)); dateFilterRowLayout.addComponent(weekAndDateFilter); dateFilterRowLayout.addComponent(applyButton); applyButton.addClickListener(e -> { DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter() .getValue(); Date fromDate, toDate; if (dateFilterOption == DateFilterOption.DATE) { fromDate = DateHelper.getStartOfDay(weekAndDateFilter.getDateFromFilter().getValue()); toDate = DateHelper.getEndOfDay(weekAndDateFilter.getDateToFilter().getValue()); } else { fromDate = DateHelper .getEpiWeekStart((EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue()); toDate = DateHelper.getEpiWeekEnd((EpiWeek) weekAndDateFilter.getWeekToFilter().getValue()); } if ((fromDate != null && toDate != null) || (fromDate == null && toDate == null)) { applyButton.removeStyleName(ValoTheme.BUTTON_PRIMARY); NewCaseDateType newCaseDateType = (NewCaseDateType) weekAndDateFilter.getDateTypeSelector() .getValue(); criteria.newCaseDateBetween(fromDate, toDate, newCaseDateType != null ? newCaseDateType : NewCaseDateType.MOST_RELEVANT); navigateTo(criteria); } else { if (dateFilterOption == DateFilterOption.DATE) { Notification notification = new Notification( I18nProperties.getString(Strings.headingMissingDateFilter), I18nProperties.getString(Strings.messageMissingDateFilter), Type.WARNING_MESSAGE, false); notification.setDelayMsec(-1); notification.show(Page.getCurrent()); } else { Notification notification = new Notification( I18nProperties.getString(Strings.headingMissingEpiWeekFilter), I18nProperties.getString(Strings.messageMissingEpiWeekFilter), Type.WARNING_MESSAGE, false); notification.setDelayMsec(-1); notification.show(Page.getCurrent()); } } }); } filterLayout.addComponent(dateFilterRowLayout); dateFilterRowLayout.setVisible(false); return filterLayout; }
From source file:de.symeda.sormas.ui.contact.ContactController.java
License:Open Source License
public void showBulkContactDataEditComponent(Collection<ContactIndexDto> selectedContacts, String caseUuid) { if (selectedContacts.size() == 0) { new Notification(I18nProperties.getString(Strings.headingNoContactsSelected), I18nProperties.getString(Strings.messageNoContactsSelected), Type.WARNING_MESSAGE, false) .show(Page.getCurrent()); return;// ww w.j ava 2s . com } // Check if cases with multiple districts have been selected String districtUuid = null; for (ContactIndexDto selectedContact : selectedContacts) { if (districtUuid == null) { districtUuid = selectedContact.getCaseDistrictUuid(); } else if (!districtUuid.equals(selectedContact.getCaseDistrictUuid())) { districtUuid = null; break; } } DistrictReferenceDto district = FacadeProvider.getDistrictFacade().getDistrictReferenceByUuid(districtUuid); // Create a temporary contact in order to use the CommitDiscardWrapperComponent ContactDto tempContact = new ContactDto(); BulkContactDataForm form = new BulkContactDataForm(district); form.setValue(tempContact); final CommitDiscardWrapperComponent<BulkContactDataForm> editView = new CommitDiscardWrapperComponent<BulkContactDataForm>( form, form.getFieldGroup()); Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getString(Strings.headingEditContacts)); editView.addCommitListener(new CommitListener() { @Override public void onCommit() { ContactDto updatedTempContact = form.getValue(); for (ContactIndexDto indexDto : selectedContacts) { ContactDto contactDto = FacadeProvider.getContactFacade().getContactByUuid(indexDto.getUuid()); if (form.getClassificationCheckBox().getValue() == true) { contactDto.setContactClassification(updatedTempContact.getContactClassification()); } // Setting the contact officer is only allowed if all selected contacts are in the same district if (district != null && form.getContactOfficerCheckBox().getValue() == true) { contactDto.setContactOfficer(updatedTempContact.getContactOfficer()); } FacadeProvider.getContactFacade().saveContact(contactDto); } popupWindow.close(); if (caseUuid == null) { overview(); } else { caseContactsOverview(caseUuid); } Notification.show(I18nProperties.getString(Strings.messageContactsEdited), Type.HUMANIZED_MESSAGE); } }); editView.addDiscardListener(new DiscardListener() { @Override public void onDiscard() { popupWindow.close(); } }); }