Example usage for com.vaadin.server FileDownloader FileDownloader

List of usage examples for com.vaadin.server FileDownloader FileDownloader

Introduction

In this page you can find the example usage for com.vaadin.server FileDownloader FileDownloader.

Prototype

public FileDownloader(Resource resource) 

Source Link

Document

Creates a new file downloader for the given resource.

Usage

From source file:com.salsaw.msalsa.PhylogeneticTreeView.java

License:Apache License

public PhylogeneticTreeView(ClustalFileMapper clustalFileMapper) throws IOException {
    initializeUiComponents();/*from   w w  w.ja  va  2 s  .  co m*/

    // Download alignment file
    Button aligmentButton = new Button("Download alignment");
    Resource resAlignment = new FileResource(new File(clustalFileMapper.getAlignmentFilePath()));
    FileDownloader fdAln = new FileDownloader(resAlignment);
    fdAln.extend(aligmentButton);
    mainLayout.addComponent(aligmentButton);
    mainLayout.setComponentAlignment(aligmentButton, Alignment.MIDDLE_CENTER);

    // Download tree file
    Button downloadTreeButton = new Button("Download phylogentic tree");
    Resource resTree = new FileResource(new File(clustalFileMapper.getTreeFilePath()));
    FileDownloader fdTree = new FileDownloader(resTree);
    fdTree.extend(downloadTreeButton);
    mainLayout.addComponent(downloadTreeButton);
    mainLayout.setComponentAlignment(downloadTreeButton, Alignment.MIDDLE_CENTER);

    // Add and center with HTML div
    svgHTMLPhylogenticTree = new Label("<div id='svgCanvas'></div>", ContentMode.HTML);
    svgHTMLPhylogenticTree.setWidth("-1px");
    svgHTMLPhylogenticTree.setHeight("-1px");
    mainLayout.addComponent(svgHTMLPhylogenticTree);
    mainLayout.setComponentAlignment(svgHTMLPhylogenticTree, Alignment.MIDDLE_CENTER);

    // Add tab with aligment content
    String aligmentFileContent = new String(
            Files.readAllBytes(Paths.get(clustalFileMapper.getAlignmentFilePath())));
    TextArea aligmentFileTextArea = new TextArea("M-SALSA Aligment");
    aligmentFileTextArea.setWordwrap(false);
    aligmentFileTextArea.setValue(aligmentFileContent);
    aligmentFileTextArea.setWidth("100%");
    aligmentFileTextArea.setHeight("100%");
    mainLayout.addComponent(aligmentFileTextArea);
    mainLayout.setComponentAlignment(aligmentFileTextArea, Alignment.MIDDLE_CENTER);

    // Add JavaScript component to generate phylogentic tree
    JsPhyloSVG jsPhyloSVG = new JsPhyloSVG(getPhylogeneticTreeFileContent(clustalFileMapper));
    mainLayout.addComponent(jsPhyloSVG);

    setCompositionRoot(mainLayout);
}

From source file:control.WizardController.java

License:Open Source License

protected void armDownloadButtons(Button tsv) {
    StreamResource tsvStream = getTSVStream(dataAggregator.getTSVContent(), dataAggregator.getTSVName());
    if (tsvDL == null) {
        tsvDL = new FileDownloader(tsvStream);
        tsvDL.extend(tsv);//from   www. j a v  a 2 s .  co  m
    } else
        tsvDL.setFileDownloadResource(tsvStream);
}

From source file:de.fatalix.bookery.view.common.BookDetailLayout.java

License:Open Source License

private HorizontalLayout createImageLayout() {
    image = new Image();
    image.setImmediate(true);//  ww  w.jav a2  s  .c om
    image.setHeight("200px");
    image.setWidth("130px");

    downloadButton = new Button("download", FontAwesome.DOWNLOAD);
    downloadButton.addStyleName(ValoTheme.BUTTON_FRIENDLY);
    downloadButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                loadData(presenter.updateShared(bookEntry,
                        SecurityUtils.getSubject().getPrincipal().toString()));
            } catch (SolrServerException | IOException ex) {
                Notification.show("Unexpected Error!\n" + ex.getMessage(), Notification.Type.ERROR_MESSAGE);
                logger.error(ex, ex);
            }
        }
    });

    fileDownloader = new FileDownloader(new StreamResource(new BookStreamSource(null), "blbla.epub"));
    fileDownloader.extend(downloadButton);

    sendToKindleButton = new Button("Kindle", FontAwesome.BOOK);
    sendToKindleButton.addStyleName(ValoTheme.BUTTON_FRIENDLY);
    sendToKindleButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                presenter.shareBookWithKindle(bookEntry, SecurityUtils.getSubject().getPrincipal().toString());
                Notification.show("Book is sent to kindle", Notification.Type.HUMANIZED_MESSAGE);
                loadData(presenter.updateShared(bookEntry,
                        SecurityUtils.getSubject().getPrincipal().toString()));
            } catch (SolrServerException | IOException | MessagingException ex) {
                Notification.show("Unexpected Error!\n" + ex.getMessage(), Notification.Type.ERROR_MESSAGE);
                logger.error(ex, ex);
            }
        }
    });

    likeButton = new Button("0 likes", FontAwesome.THUMBS_O_UP);
    likeButton.addStyleName(ValoTheme.BUTTON_LINK);
    likeButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                BookEntry updatedEntry = presenter.updateLike(bookEntry,
                        SecurityUtils.getSubject().getPrincipal().toString());
                loadData(updatedEntry);
            } catch (SolrServerException | IOException ex) {
                Notification.show("Unexpected Error!\n" + ex.getMessage(), Notification.Type.ERROR_MESSAGE);
                logger.error(ex, ex);
            }
        }
    });

    watchListButton = new Button("merken", FontAwesome.STAR_O);
    watchListButton.addStyleName(ValoTheme.BUTTON_LINK);
    watchListButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            presenter.addRemoveFromWatchList(bookEntry, SecurityUtils.getSubject().getPrincipal().toString());
            loadData(bookEntry);
        }
    });
    downloadCount = new Label("0 downloads");

    VerticalLayout rightLayout = new VerticalLayout(sendToKindleButton, downloadButton, watchListButton,
            likeButton, downloadCount);
    rightLayout.setComponentAlignment(downloadCount, Alignment.MIDDLE_CENTER);
    rightLayout.setSpacing(true);

    HorizontalLayout layout = new HorizontalLayout(image, rightLayout);
    layout.setSpacing(true);
    return layout;
}

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);//from   w ww.j a v a 2  s  . c  o  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 ww.ja  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);//ww w .  j a  va  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 ww  .j a  va  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_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 a  va  2s .  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_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);
    }// w w w  .j  a  v  a  2 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);
    }//w ww.  j a  v a  2s . com

    if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_CREATE)) {
        createButton.setCaption(I18nProperties.getCaption(Captions.actionNewEntry));
        createButton.addClickListener(
                e -> ControllerProvider.getInfrastructureController().createHealthFacility(true));
    }
}