List of usage examples for com.vaadin.server FileDownloader extend
public void extend(EventTrigger eventTrigger)
From source file:de.symeda.sormas.ui.AboutView.java
License:Open Source License
public AboutView() { CustomLayout aboutContent = new CustomLayout("aboutview"); aboutContent.setStyleName("about-content"); // Info section VerticalLayout infoLayout = new VerticalLayout(); infoLayout.setSpacing(false);// w w w . j a va2 s . co m infoLayout.setMargin(false); aboutContent.addComponent(infoLayout, "info"); Label versionLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml() + " " + I18nProperties.getCaption(Captions.aboutSormasVersion) + ": " + InfoProvider.get().getVersion(), ContentMode.HTML); infoLayout.addComponent(versionLabel); Link whatsNewLink = new Link(I18nProperties.getCaption(Captions.aboutWhatsNew), new ExternalResource( "https://github.com/hzi-braunschweig/SORMAS-Project/releases/tag/releases%2Fversion-" + InfoProvider.get().getBaseVersion())); whatsNewLink.setTargetName("_blank"); infoLayout.addComponent(whatsNewLink); Link sormasWebsiteLink = new Link(I18nProperties.getCaption(Captions.aboutSormasWebsite), new ExternalResource("https://sormasorg.helmholtz-hzi.de/")); sormasWebsiteLink.setTargetName("_blank"); infoLayout.addComponent(sormasWebsiteLink); Link sormasGithubLink = new Link("SORMAS Github", new ExternalResource("https://github.com/hzi-braunschweig/SORMAS-Project")); sormasGithubLink.setTargetName("_blank"); infoLayout.addComponent(sormasGithubLink); Link changelogLink = new Link(I18nProperties.getCaption(Captions.aboutChangelog), new ExternalResource("https://github.com/hzi-braunschweig/SORMAS-Project/releases")); changelogLink.setTargetName("_blank"); infoLayout.addComponent(changelogLink); // Documents section VerticalLayout documentsLayout = new VerticalLayout(); documentsLayout.setSpacing(false); documentsLayout.setMargin(false); aboutContent.addComponent(documentsLayout, "documents"); Button classificationDocumentButton = new Button( I18nProperties.getCaption(Captions.aboutCaseClassificationRules)); CssStyles.style(classificationDocumentButton, ValoTheme.BUTTON_LINK, CssStyles.BUTTON_COMPACT); documentsLayout.addComponent(classificationDocumentButton); try { String serverUrl = new URL(((VaadinServletRequest) VaadinService.getCurrentRequest()) .getHttpServletRequest().getRequestURL().toString()).getAuthority(); StreamResource classificationResource = DownloadUtil.createStringStreamResource( ClassificationHtmlRenderer.createHtmlForDownload(serverUrl, FacadeProvider.getDiseaseConfigurationFacade().getAllActivePrimaryDiseases()), "classification_rules.html", "text/html"); new FileDownloader(classificationResource).extend(classificationDocumentButton); } catch (MalformedURLException e) { } Button dataDictionaryButton = new Button(I18nProperties.getCaption(Captions.aboutDataDictionary)); CssStyles.style(dataDictionaryButton, ValoTheme.BUTTON_LINK, CssStyles.BUTTON_COMPACT); documentsLayout.addComponent(dataDictionaryButton); FileDownloader dataDictionaryDownloader = new FileDownloader( new ClassResource("/doc/SORMAS_Data_Dictionary.xlsx")); dataDictionaryDownloader.extend(dataDictionaryButton); Link technicalManualLink = new Link(I18nProperties.getCaption(Captions.aboutTechnicalManual), new ExternalResource( "https://github.com/hzi-braunschweig/SORMAS-Project/files/2585973/SORMAS_Technical_Manual_Webversion_20180911.pdf")); technicalManualLink.setTargetName("_blank"); documentsLayout.addComponent(technicalManualLink); setSizeFull(); setStyleName("about-view"); addComponent(aboutContent); setComponentAlignment(aboutContent, Alignment.MIDDLE_CENTER); }
From source file:de.symeda.sormas.ui.caze.CaseContactsView.java
License:Open Source License
public HorizontalLayout createStatusFilterBar() { HorizontalLayout statusFilterLayout = new HorizontalLayout(); statusFilterLayout.setSpacing(true); statusFilterLayout.setWidth("100%"); statusFilterLayout.addStyleName(CssStyles.VSPACE_3); statusButtons = new HashMap<>(); Button statusAll = new Button(I18nProperties.getCaption(Captions.all), e -> { criteria.contactStatus(null);/*from w w w. j a v a 2 s.c om*/ navigateTo(criteria); }); CssStyles.style(statusAll, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER); statusAll.setCaptionAsHtml(true); statusFilterLayout.addComponent(statusAll); statusButtons.put(statusAll, I18nProperties.getCaption(Captions.all)); activeStatusButton = statusAll; for (ContactStatus status : ContactStatus.values()) { Button statusButton = new Button(status.toString(), e -> { criteria.contactStatus(status); navigateTo(criteria); }); statusButton.setData(status); CssStyles.style(statusButton, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER, CssStyles.BUTTON_FILTER_LIGHT); statusButton.setCaptionAsHtml(true); statusFilterLayout.addComponent(statusButton); statusButtons.put(statusButton, status.toString()); } statusFilterLayout .setExpandRatio(statusFilterLayout.getComponent(statusFilterLayout.getComponentCount() - 1), 1); // Bulk operation dropdown if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) { statusFilterLayout.setWidth(100, Unit.PERCENTAGE); MenuBar bulkOperationsDropdown = new MenuBar(); MenuItem bulkOperationsItem = bulkOperationsDropdown .addItem(I18nProperties.getCaption(Captions.bulkActions), null); Command changeCommand = selectedItem -> { ControllerProvider.getContactController().showBulkContactDataEditComponent( grid.asMultiSelect().getSelectedItems(), getCaseRef().getUuid()); }; bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkEdit), VaadinIcons.ELLIPSIS_H, changeCommand); Command cancelFollowUpCommand = selectedItem -> { ControllerProvider.getContactController() .cancelFollowUpOfAllSelectedItems(grid.asMultiSelect().getSelectedItems(), new Runnable() { public void run() { grid.deselectAll(); grid.reload(); } }); }; bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkCancelFollowUp), VaadinIcons.CLOSE, cancelFollowUpCommand); Command lostToFollowUpCommand = selectedItem -> { ControllerProvider.getContactController().setAllSelectedItemsToLostToFollowUp( grid.asMultiSelect().getSelectedItems(), new Runnable() { public void run() { grid.deselectAll(); grid.reload(); } }); }; bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkLostToFollowUp), VaadinIcons.UNLINK, lostToFollowUpCommand); Command deleteCommand = selectedItem -> { ControllerProvider.getContactController() .deleteAllSelectedItems(grid.asMultiSelect().getSelectedItems(), new Runnable() { public void run() { grid.deselectAll(); grid.reload(); } }); }; bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkDelete), VaadinIcons.TRASH, deleteCommand); statusFilterLayout.addComponent(bulkOperationsDropdown); statusFilterLayout.setComponentAlignment(bulkOperationsDropdown, Alignment.TOP_RIGHT); statusFilterLayout.setExpandRatio(bulkOperationsDropdown, 1); } if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_EXPORT)) { Button exportButton = new Button(I18nProperties.getCaption(Captions.export)); exportButton.addStyleName(ValoTheme.BUTTON_PRIMARY); exportButton.setIcon(VaadinIcons.DOWNLOAD); StreamResource streamResource = new GridExportStreamResource(grid, "sormas_contacts", "sormas_contacts_" + DateHelper.formatDateForExport(new Date()) + ".csv"); FileDownloader fileDownloader = new FileDownloader(streamResource); fileDownloader.extend(exportButton); statusFilterLayout.addComponent(exportButton); statusFilterLayout.setComponentAlignment(exportButton, Alignment.MIDDLE_RIGHT); if (!UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) { statusFilterLayout.setExpandRatio(exportButton, 1); } } if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_CREATE)) { newButton = new Button( I18nProperties.getPrefixCaption(ContactDto.I18N_PREFIX, Captions.contactNewContact)); newButton.addStyleName(ValoTheme.BUTTON_PRIMARY); newButton.setIcon(VaadinIcons.PLUS_CIRCLE); newButton.addClickListener(e -> ControllerProvider.getContactController().create(this.getCaseRef())); statusFilterLayout.addComponent(newButton); statusFilterLayout.setComponentAlignment(newButton, Alignment.MIDDLE_RIGHT); } statusFilterLayout.addStyleName("top-bar"); activeStatusButton = statusAll; return statusFilterLayout; }
From source file:de.symeda.sormas.ui.caze.CasesView.java
License:Open Source License
public CasesView() { super(VIEW_NAME); originalViewTitle = getViewTitleLabel().getValue(); criteria = ViewModelProviders.of(CasesView.class).get(CaseCriteria.class); if (criteria.getArchived() == null) { criteria.archived(false);// w w w . j a v a 2 s . c o m } grid = new CaseGrid(); grid.setCriteria(criteria); gridLayout = new VerticalLayout(); gridLayout.addComponent(createFilterBar()); gridLayout.addComponent(createStatusFilterBar()); gridLayout.addComponent(grid); gridLayout.setMargin(true); gridLayout.setSpacing(false); gridLayout.setSizeFull(); gridLayout.setExpandRatio(grid, 1); gridLayout.setStyleName("crud-main-layout"); grid.getDataProvider().addDataProviderListener(e -> updateStatusButtons()); if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_IMPORT)) { Button importButton = new Button(I18nProperties.getCaption(Captions.actionImport)); importButton.addStyleName(ValoTheme.BUTTON_PRIMARY); importButton.setIcon(VaadinIcons.UPLOAD); importButton.addClickListener(e -> { Window popupWindow = VaadinUiUtil.showPopupWindow(new CaseImportLayout()); popupWindow.setCaption(I18nProperties.getString(Strings.headingImportCases)); popupWindow.addCloseListener(c -> { grid.reload(); }); }); addHeaderComponent(importButton); } if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_EXPORT)) { PopupButton exportButton = new PopupButton(I18nProperties.getCaption(Captions.export)); exportButton.setId("export"); exportButton.setIcon(VaadinIcons.DOWNLOAD); VerticalLayout exportLayout = new VerticalLayout(); exportLayout.setSpacing(true); exportLayout.setMargin(true); exportLayout.addStyleName(CssStyles.LAYOUT_MINIMAL); exportLayout.setWidth(200, Unit.PIXELS); exportButton.setContent(exportLayout); addHeaderComponent(exportButton); Button basicExportButton = new Button(I18nProperties.getCaption(Captions.exportBasic)); basicExportButton.setId("basicExport"); basicExportButton.setDescription(I18nProperties.getString(Strings.infoBasicExport)); basicExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY); basicExportButton.setIcon(VaadinIcons.TABLE); basicExportButton.setWidth(100, Unit.PERCENTAGE); exportLayout.addComponent(basicExportButton); StreamResource streamResource = new GridExportStreamResource(grid, "sormas_cases", "sormas_cases_" + DateHelper.formatDateForExport(new Date()) + ".csv"); FileDownloader fileDownloader = new FileDownloader(streamResource); fileDownloader.extend(basicExportButton); Button extendedExportButton = new Button(I18nProperties.getCaption(Captions.exportDetailed)); extendedExportButton.setId("extendedExport"); extendedExportButton.setDescription(I18nProperties.getString(Strings.infoDetailedExport)); extendedExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY); extendedExportButton.setIcon(VaadinIcons.FILE_TEXT); extendedExportButton.setWidth(100, Unit.PERCENTAGE); exportLayout.addComponent(extendedExportButton); StreamResource extendedExportStreamResource = DownloadUtil.createCsvExportStreamResource( CaseExportDto.class, (Integer start, Integer max) -> FacadeProvider.getCaseFacade() .getExportList(UserProvider.getCurrent().getUuid(), grid.getCriteria(), start, max), (propertyId, type) -> { String caption = I18nProperties.getPrefixCaption(CaseExportDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption(EpiDataDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption( HospitalizationDto.I18N_PREFIX, propertyId)))))); if (Date.class.isAssignableFrom(type)) { caption += " (" + DateHelper.getLocalShortDatePattern() + ")"; } return caption; }, "sormas_cases_" + DateHelper.formatDateForExport(new Date()) + ".csv"); new FileDownloader(extendedExportStreamResource).extend(extendedExportButton); Button sampleExportButton = new Button(I18nProperties.getCaption(Captions.exportSamples)); sampleExportButton.setId("sampleExport"); sampleExportButton.setDescription(I18nProperties.getString(Strings.infoSampleExport)); sampleExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY); sampleExportButton.setIcon(VaadinIcons.FILE_TEXT); sampleExportButton.setWidth(100, Unit.PERCENTAGE); exportLayout.addComponent(sampleExportButton); StreamResource sampleExportStreamResource = DownloadUtil.createCsvExportStreamResource( SampleExportDto.class, (Integer start, Integer max) -> FacadeProvider.getSampleFacade() .getExportList(UserProvider.getCurrent().getUuid(), grid.getCriteria(), start, max), (propertyId, type) -> { String caption = I18nProperties.getPrefixCaption(SampleExportDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption(SampleDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption( AdditionalTestDto.I18N_PREFIX, propertyId))))); if (Date.class.isAssignableFrom(type)) { caption += " (" + DateHelper.getLocalShortDatePattern() + ")"; } return caption; }, "sormas_samples_" + DateHelper.formatDateForExport(new Date()) + ".csv"); new FileDownloader(sampleExportStreamResource).extend(sampleExportButton); // Warning if no filters have been selected Label warningLabel = new Label(I18nProperties.getString(Strings.infoExportNoFilters), ContentMode.HTML); warningLabel.setWidth(100, Unit.PERCENTAGE); exportLayout.addComponent(warningLabel); warningLabel.setVisible(false); exportButton.addClickListener(e -> { warningLabel.setVisible(!criteria.hasAnyFilterActive()); }); } if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_MERGE)) { Button mergeDuplicatesButton = new Button(I18nProperties.getCaption(Captions.caseMergeDuplicates)); mergeDuplicatesButton.setId("mergeDuplicates"); mergeDuplicatesButton.setIcon(VaadinIcons.COMPRESS_SQUARE); mergeDuplicatesButton .addClickListener(e -> ControllerProvider.getCaseController().navigateToMergeCasesView()); addHeaderComponent(mergeDuplicatesButton); } if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_CREATE)) { createButton = new Button(I18nProperties.getCaption(Captions.caseNewCase)); createButton.setId("create"); createButton.addStyleName(ValoTheme.BUTTON_PRIMARY); createButton.setIcon(VaadinIcons.PLUS_CIRCLE); createButton.addClickListener(e -> ControllerProvider.getCaseController().create()); addHeaderComponent(createButton); } addComponent(gridLayout); }
From source file:de.symeda.sormas.ui.configuration.infrastructure.CommunitiesView.java
License:Open Source License
public CommunitiesView() { super(VIEW_NAME); criteria = ViewModelProviders.of(CommunitiesView.class).get(CommunityCriteria.class); grid = new CommunitiesGrid(); grid.setCriteria(criteria);//from w w w.ja va 2 s . co m gridLayout = new VerticalLayout(); gridLayout.addComponent(createFilterBar()); gridLayout.addComponent(grid); gridLayout.setMargin(true); gridLayout.setSpacing(false); gridLayout.setExpandRatio(grid, 1); gridLayout.setSizeFull(); gridLayout.setStyleName("crud-main-layout"); if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_EXPORT)) { Button exportButton = new Button(I18nProperties.getCaption(Captions.export)); exportButton.setDescription(I18nProperties.getDescription(Descriptions.descExportButton)); exportButton.addStyleName(ValoTheme.BUTTON_PRIMARY); exportButton.setIcon(VaadinIcons.TABLE); addHeaderComponent(exportButton); StreamResource streamResource = new GridExportStreamResource(grid, "sormas_communities", "sormas_communities_" + DateHelper.formatDateForExport(new Date()) + ".csv", CommunitiesGrid.EDIT_BTN_ID); FileDownloader fileDownloader = new FileDownloader(streamResource); fileDownloader.extend(exportButton); } if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_CREATE)) { createButton = new Button(I18nProperties.getCaption(Captions.actionNewEntry)); createButton.addStyleName(ValoTheme.BUTTON_PRIMARY); createButton.setIcon(VaadinIcons.PLUS_CIRCLE); createButton.addClickListener(e -> ControllerProvider.getInfrastructureController().createCommunity()); addHeaderComponent(createButton); } addComponent(gridLayout); }
From source file:de.symeda.sormas.ui.configuration.infrastructure.DistrictsView.java
License:Open Source License
public DistrictsView() { super(VIEW_NAME); criteria = ViewModelProviders.of(DistrictsView.class).get(DistrictCriteria.class); grid = new DistrictsGrid(); grid.setCriteria(criteria);/* w w w . j av a 2 s. c om*/ gridLayout = new VerticalLayout(); gridLayout.addComponent(createFilterBar()); gridLayout.addComponent(grid); gridLayout.setMargin(true); gridLayout.setSpacing(false); gridLayout.setExpandRatio(grid, 1); gridLayout.setSizeFull(); gridLayout.setStyleName("crud-main-layout"); if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_EXPORT)) { Button exportButton = new Button(I18nProperties.getCaption(Captions.export)); exportButton.setDescription(I18nProperties.getDescription(Descriptions.descExportButton)); exportButton.addStyleName(ValoTheme.BUTTON_PRIMARY); exportButton.setIcon(VaadinIcons.TABLE); addHeaderComponent(exportButton); StreamResource streamResource = new GridExportStreamResource(grid, "sormas_districts", "sormas_districts_" + DateHelper.formatDateForExport(new Date()) + ".csv", DistrictsGrid.EDIT_BTN_ID); FileDownloader fileDownloader = new FileDownloader(streamResource); fileDownloader.extend(exportButton); } if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_CREATE)) { createButton = new Button(I18nProperties.getCaption(Captions.actionNewEntry)); createButton.addStyleName(ValoTheme.BUTTON_PRIMARY); createButton.setIcon(VaadinIcons.PLUS_CIRCLE); createButton.addClickListener(e -> ControllerProvider.getInfrastructureController().createDistrict()); addHeaderComponent(createButton); } addComponent(gridLayout); }
From source file:de.symeda.sormas.ui.configuration.infrastructure.HealthFacilitiesView.java
License:Open Source License
public HealthFacilitiesView() { super(VIEW_NAME, false); if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_EXPORT)) { StreamResource streamResource = new GridExportStreamResource(grid, "sormas_health_facilities", "sormas_health_facilities_" + DateHelper.formatDateForExport(new Date()) + ".csv", FacilitiesGrid.EDIT_BTN_ID); FileDownloader fileDownloader = new FileDownloader(streamResource); fileDownloader.extend(exportButton); }/*from ww w . j a v a2 s. c o m*/ if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_CREATE)) { createButton.setCaption(I18nProperties.getCaption(Captions.actionNewEntry)); createButton.addClickListener( e -> ControllerProvider.getInfrastructureController().createHealthFacility(false)); } }
From source file:de.symeda.sormas.ui.configuration.infrastructure.LaboratoriesView.java
License:Open Source License
public LaboratoriesView() { super(VIEW_NAME, true); if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_EXPORT)) { StreamResource streamResource = new GridExportStreamResource(grid, "sormas_laboratories", "sormas_laboratories_" + DateHelper.formatDateForExport(new Date()) + ".csv", FacilitiesGrid.EDIT_BTN_ID); FileDownloader fileDownloader = new FileDownloader(streamResource); fileDownloader.extend(exportButton); }/*from w w w . j a va2s.c o m*/ if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_CREATE)) { createButton.setCaption(I18nProperties.getCaption(Captions.actionNewEntry)); createButton.addClickListener( e -> ControllerProvider.getInfrastructureController().createHealthFacility(true)); } }
From source file:de.symeda.sormas.ui.configuration.infrastructure.RegionsView.java
License:Open Source License
public RegionsView() { super(VIEW_NAME); criteria = ViewModelProviders.of(RegionsView.class).get(RegionCriteria.class); grid = new RegionsGrid(); grid.setCriteria(criteria);/*from w w w . ja v a 2 s. c o m*/ gridLayout = new VerticalLayout(); gridLayout.addComponent(createFilterBar()); gridLayout.addComponent(grid); gridLayout.setMargin(true); gridLayout.setSpacing(false); gridLayout.setExpandRatio(grid, 1); gridLayout.setSizeFull(); gridLayout.setStyleName("crud-main-layout"); if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_EXPORT)) { Button exportButton = new Button(I18nProperties.getCaption(Captions.export)); exportButton.setDescription(I18nProperties.getDescription(Descriptions.descExportButton)); exportButton.addStyleName(ValoTheme.BUTTON_PRIMARY); exportButton.setIcon(VaadinIcons.TABLE); addHeaderComponent(exportButton); StreamResource streamResource = new GridExportStreamResource(grid, "sormas_regions", "sormas_regions_" + DateHelper.formatDateForExport(new Date()) + ".csv", RegionsGrid.EDIT_BTN_ID); FileDownloader fileDownloader = new FileDownloader(streamResource); fileDownloader.extend(exportButton); } if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_CREATE)) { createButton = new Button(I18nProperties.getCaption(Captions.actionNewEntry)); createButton.addStyleName(ValoTheme.BUTTON_PRIMARY); createButton.setIcon(VaadinIcons.PLUS_CIRCLE); createButton.addClickListener(e -> ControllerProvider.getInfrastructureController().createRegion()); addHeaderComponent(createButton); } addComponent(gridLayout); }
From source file:de.symeda.sormas.ui.contact.ContactsView.java
License:Open Source License
public ContactsView() { super(VIEW_NAME); originalViewTitle = getViewTitleLabel().getValue(); criteria = ViewModelProviders.of(ContactsView.class).get(ContactCriteria.class); if (criteria.getArchived() == null) { criteria.archived(false);//from ww w . j a va2 s.c o m } grid = new ContactGrid(); grid.setCriteria(criteria); gridLayout = new VerticalLayout(); gridLayout.addComponent(createFilterBar()); gridLayout.addComponent(createStatusFilterBar()); gridLayout.addComponent(grid); gridLayout.setMargin(true); gridLayout.setSpacing(false); gridLayout.setSizeFull(); gridLayout.setExpandRatio(grid, 1); gridLayout.setStyleName("crud-main-layout"); grid.getDataProvider().addDataProviderListener(e -> updateStatusButtons()); if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_EXPORT)) { PopupButton exportButton = new PopupButton(I18nProperties.getCaption(Captions.export)); exportButton.setIcon(VaadinIcons.DOWNLOAD); VerticalLayout exportLayout = new VerticalLayout(); exportLayout.setSpacing(true); exportLayout.setMargin(true); exportLayout.addStyleName(CssStyles.LAYOUT_MINIMAL); exportLayout.setWidth(200, Unit.PIXELS); exportButton.setContent(exportLayout); addHeaderComponent(exportButton); Button basicExportButton = new Button(I18nProperties.getCaption(Captions.exportBasic)); basicExportButton.setDescription(I18nProperties.getDescription(Descriptions.descExportButton)); basicExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY); basicExportButton.setIcon(VaadinIcons.TABLE); basicExportButton.setWidth(100, Unit.PERCENTAGE); exportLayout.addComponent(basicExportButton); StreamResource streamResource = new GridExportStreamResource(grid, "sormas_contacts", "sormas_contacts_" + DateHelper.formatDateForExport(new Date()) + ".csv"); FileDownloader fileDownloader = new FileDownloader(streamResource); fileDownloader.extend(basicExportButton); Button extendedExportButton = new Button(I18nProperties.getCaption(Captions.exportDetailed)); extendedExportButton .setDescription(I18nProperties.getDescription(Descriptions.descDetailedExportButton)); extendedExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY); extendedExportButton.setIcon(VaadinIcons.FILE_TEXT); extendedExportButton.setWidth(100, Unit.PERCENTAGE); exportLayout.addComponent(extendedExportButton); StreamResource extendedExportStreamResource = DownloadUtil.createCsvExportStreamResource( ContactExportDto.class, (Integer start, Integer max) -> FacadeProvider.getContactFacade() .getExportList(UserProvider.getCurrent().getUuid(), grid.getCriteria(), start, max), (propertyId, type) -> { String caption = I18nProperties.getPrefixCaption(ContactExportDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption(ContactDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, propertyId, I18nProperties.getPrefixCaption( HospitalizationDto.I18N_PREFIX, propertyId)))))); if (Date.class.isAssignableFrom(type)) { caption += " (" + DateHelper.getLocalShortDatePattern() + ")"; } return caption; }, "sormas_contacts_" + DateHelper.formatDateForExport(new Date()) + ".csv"); new FileDownloader(extendedExportStreamResource).extend(extendedExportButton); // Warning if no filters have been selected Label warningLabel = new Label(I18nProperties.getString(Strings.infoExportNoFilters)); warningLabel.setWidth(100, Unit.PERCENTAGE); exportLayout.addComponent(warningLabel); warningLabel.setVisible(false); exportButton.addClickListener(e -> { warningLabel.setVisible(!criteria.hasAnyFilterActive()); }); } addComponent(gridLayout); }
From source file:de.symeda.sormas.ui.events.EventsView.java
License:Open Source License
public EventsView() { super(VIEW_NAME); originalViewTitle = getViewTitleLabel().getValue(); criteria = ViewModelProviders.of(EventsView.class).get(EventCriteria.class); if (criteria.getArchived() == null) { criteria.archived(false);// ww w .jav a2s. com } grid = new EventGrid(); grid.setCriteria(criteria); gridLayout = new VerticalLayout(); gridLayout.addComponent(createFilterBar()); gridLayout.addComponent(createStatusFilterBar()); gridLayout.addComponent(grid); gridLayout.setMargin(true); gridLayout.setSpacing(false); gridLayout.setSizeFull(); gridLayout.setExpandRatio(grid, 1); gridLayout.setStyleName("crud-main-layout"); grid.getDataProvider().addDataProviderListener(e -> updateStatusButtons()); addComponent(gridLayout); if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_EXPORT)) { Button exportButton = new Button(I18nProperties.getCaption(Captions.export)); exportButton.addStyleName(ValoTheme.BUTTON_PRIMARY); exportButton.setIcon(VaadinIcons.DOWNLOAD); StreamResource streamResource = new GridExportStreamResource(grid, "sormas_events", "sormas_events_" + DateHelper.formatDateForExport(new Date()) + ".csv"); FileDownloader fileDownloader = new FileDownloader(streamResource); fileDownloader.extend(exportButton); addHeaderComponent(exportButton); } if (UserProvider.getCurrent().hasUserRight(UserRight.EVENT_CREATE)) { createButton = new Button(I18nProperties.getCaption(Captions.eventNewEvent)); createButton.addStyleName(ValoTheme.BUTTON_PRIMARY); createButton.setIcon(VaadinIcons.PLUS_CIRCLE); createButton.addClickListener(e -> ControllerProvider.getEventController().create()); addHeaderComponent(createButton); } }