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.gnts.pem.txn.synd.SyndConstruction.java

License:Open Source License

@SuppressWarnings("deprecation")
void populateAndConfig(boolean search) {
    try {//from   www  . j a  v  a2s  . c om
        tblEvalDetails.removeAllItems();
        tblEvalDetails.setImmediate(true);
        List<TPemCmEvalDetails> evalList = null;
        evalList = new ArrayList<TPemCmEvalDetails>();
        if (search) {
            String evalno = tfSearchEvalNumber.getValue();
            String customer = tfSearchCustomer.getValue();
            String bankbranch = (String) tfSearchBankbranch.getValue();
            evalList = beanEvaluation.getSearchEvalDetailnList(null, evalno, null, customer, bankbranch,
                    selectedBankid, selectCompanyid, null);
        } else {

            evalList = beanEvaluation.getSearchEvalDetailnList(SelectedFormName, null, null, null, null,
                    selectedBankid, selectCompanyid, null);
            total = evalList.size();
        }
        if (total == 0) {
            lblNotificationIcon.setIcon(new ThemeResource("img/msg_info.png"));
            lblSaveNotification.setValue("No Records found");
        } else {
            lblNotificationIcon.setIcon(null);
            lblSaveNotification.setValue("");
        }
        lblNoofRecords.setValue(
                "<font size=\"2\" color=\"black\">No.of Records:</font> <font size=\"2\" color=\"#1E90FF\"> "
                        + total + "</font>");
        beans = new BeanItemContainer<TPemCmEvalDetails>(TPemCmEvalDetails.class);
        beans.addAll(evalList);
        btnEdit.setEnabled(false);
        tblEvalDetails.setContainerDataSource(beans);
        tblEvalDetails.setSelectable(true);
        tblEvalDetails.setColumnFooter("lastUpdateDt", "No. of Records:" + total);
        tblEvalDetails.setVisibleColumns(new Object[] { "evalNo", "docDate", "bankBranch", "custName",
                "docStatus", "lastUpdtedBy", "lastUpdateDt" });
        tblEvalDetails.setColumnHeaders(new String[] { "Evaluation Number", "Evaluation Date", "Bank Branch",
                "Customer Name", "Status", "Last Updated By", "Last Updated Date" });
        tblEvalDetails.addValueChangeListener(new Property.ValueChangeListener() {
            /**
            * 
            */
            private static final long serialVersionUID = 3729824796823933688L;

            @Override
            public void valueChange(ValueChangeEvent event) {
                StreamResource sr = getPDFStream();

                if (sr != null) {

                    if (filedownloader == null) {
                        filedownloader = new FileDownloader(getPDFStream());
                        filedownloader.extend(btnView);
                    } else {
                        filedownloader.setFileDownloadResource(sr);
                    }
                } else {
                    lblNotificationIcon.setIcon(new ThemeResource("img/msg_info.png"));
                    lblSaveNotification.setValue("No document is there");
                    //   notif.show(Page.getCurrent());
                    if (filedownloader != null) {
                        filedownloader.setFileDownloadResource(null); // reset
                    }

                }

                TPemCmEvalDetails syncList = (TPemCmEvalDetails) event.getProperty().getValue();
                if (syncList != null) {

                    if (syncList.getDocStatus().equals("Draft") || syncList.getDocStatus().equals("Rejected")) {
                        btnEdit.setEnabled(true);
                        btnView.setEnabled(false);
                    } else {
                        btnEdit.setEnabled(false);
                        btnView.setEnabled(true);

                    }
                    btnAdd.setEnabled(false);
                } else {
                    btnEdit.setEnabled(false);
                    btnAdd.setEnabled(true);
                }
            }

        });
        tblEvalDetails.setImmediate(true);
        tblEvalDetails.addItemClickListener(new ItemClickListener() {

            @Override
            public void itemClick(ItemClickEvent event) {
                // TODO Auto-generated method stub
                if (tblEvalDetails.isSelected(event.getItemId())) {

                    btnView.setEnabled(false);
                } else {

                    btnView.setEnabled(true);
                }
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        logger.info("Error-->" + e);
    }
    getExportTableDetails();
}

From source file:com.gnts.pem.txn.synd.SyndConstructionBuilding.java

@SuppressWarnings("deprecation")
void populateAndConfig(boolean search) {
    try {/*from   w  w w.  j a v  a  2  s.  c o  m*/
        tblEvalDetails.removeAllItems();
        tblEvalDetails.setImmediate(true);
        List<TPemCmEvalDetails> evalList = null;
        evalList = new ArrayList<TPemCmEvalDetails>();
        if (search) {
            String evalno = tfSearchEvalNumber.getValue();
            String customer = tfSearchCustomer.getValue();
            String bankbranch = (String) tfSearchBankbranch.getValue();
            evalList = beanEvaluation.getSearchEvalDetailnList(null, evalno, null, customer, bankbranch,
                    selectedBankid, selectCompanyid, null);
        } else {

            evalList = beanEvaluation.getSearchEvalDetailnList(SelectedFormName, null, null, null, null,
                    selectedBankid, selectCompanyid, null);
            total = evalList.size();
        }
        if (total == 0) {
            lblNotificationIcon.setIcon(new ThemeResource("img/msg_info.png"));
            lblSaveNotification.setValue("No Records found");
        } else {
            lblNotificationIcon.setIcon(null);
            lblSaveNotification.setValue("");
        }
        lblNoofRecords.setValue(
                "<font size=\"2\" color=\"black\">No.of Records:</font> <font size=\"2\" color=\"#1E90FF\"> "
                        + total + "</font>");

        beans = new BeanItemContainer<TPemCmEvalDetails>(TPemCmEvalDetails.class);
        beans.addAll(evalList);
        btnEdit.setEnabled(false);
        tblEvalDetails.setContainerDataSource(beans);
        tblEvalDetails.setSelectable(true);
        tblEvalDetails.setColumnFooter("lastUpdateDt", "No. of Records:" + total);
        tblEvalDetails.setVisibleColumns(new Object[] { "evalNo", "docDate", "bankBranch", "custName",
                "docStatus", "lastUpdtedBy", "lastUpdateDt" });
        tblEvalDetails.setColumnHeaders(new String[] { "Evaluation Number", "Evaluation Date", "Bank Branch",
                "Customer Name", "Status", "Last Updated By", "Last Updated Date" });
        tblEvalDetails.addValueChangeListener(new Property.ValueChangeListener() {
            /**
            * 
            */
            private static final long serialVersionUID = 3729824796823933688L;

            @Override
            public void valueChange(ValueChangeEvent event) {
                StreamResource sr = getPDFStream();

                if (sr != null) {

                    if (filedownloader == null) {
                        filedownloader = new FileDownloader(getPDFStream());
                        filedownloader.extend(btnView);
                    } else {
                        filedownloader.setFileDownloadResource(sr);
                    }
                } else {
                    lblNotificationIcon.setIcon(new ThemeResource("img/msg_info.png"));
                    lblSaveNotification.setValue("No document is there");
                    //   notif.show(Page.getCurrent());
                    if (filedownloader != null) {
                        filedownloader.setFileDownloadResource(null); // reset
                    }

                }

                TPemCmEvalDetails syncList = (TPemCmEvalDetails) event.getProperty().getValue();
                if (syncList != null) {

                    if (syncList.getDocStatus().equals("Draft") || syncList.getDocStatus().equals("Rejected")) {
                        btnEdit.setEnabled(true);
                        btnView.setEnabled(false);
                    } else {
                        btnEdit.setEnabled(false);
                        btnView.setEnabled(true);

                    }
                    btnAdd.setEnabled(false);
                } else {
                    btnEdit.setEnabled(false);
                    btnAdd.setEnabled(true);
                }
            }

        });
        tblEvalDetails.setImmediate(true);
        tblEvalDetails.addItemClickListener(new ItemClickListener() {

            @Override
            public void itemClick(ItemClickEvent event) {
                // TODO Auto-generated method stub
                if (tblEvalDetails.isSelected(event.getItemId())) {

                    btnView.setEnabled(false);
                } else {

                    btnView.setEnabled(true);
                }
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        logger.info("Error-->" + e);
    }
    getExportTableDetails();

}

From source file:com.gnts.pem.txn.synd.SyndFlat.java

License:Open Source License

@SuppressWarnings("deprecation")
void populateAndConfig(boolean search) {
    try {/*from w w  w . j  a v  a 2s.c o  m*/
        tblEvalDetails.removeAllItems();
        tblEvalDetails.setImmediate(true);
        List<TPemCmEvalDetails> evalList = null;
        evalList = new ArrayList<TPemCmEvalDetails>();
        if (search) {
            String evalno = tfSearchEvalNumber.getValue();
            String customer = tfSearchCustomer.getValue();
            String bankbranch = (String) tfSearchBankBranch.getValue();
            evalList = beanEvaluation.getSearchEvalDetailnList(null, evalno, null, customer, bankbranch,
                    selectedBankid, selectCompanyid, null);
        } else {

            evalList = beanEvaluation.getSearchEvalDetailnList(selectedFormName, null, null, null, null,
                    selectedBankid, selectCompanyid, null);
            total = evalList.size();
        }
        if (total == 0) {
            lblNotificationIcon.setIcon(new ThemeResource("img/msg_info.png"));
            lblSaveNotification.setValue("No Records found");
        } else {
            lblNotificationIcon.setIcon(null);
            lblSaveNotification.setValue("");
        }
        lblNoofRecords.setValue(
                "<font size=\"2\" color=\"black\">No.of Records:</font> <font size=\"2\" color=\"#1E90FF\"> "
                        + total + "</font>");

        beans = new BeanItemContainer<TPemCmEvalDetails>(TPemCmEvalDetails.class);
        beans.addAll(evalList);
        btnEdit.setEnabled(false);
        tblEvalDetails.setContainerDataSource(beans);
        tblEvalDetails.setSelectable(true);
        tblEvalDetails.setColumnFooter("lastUpdateDt", "No. of Records:" + total);
        tblEvalDetails.setVisibleColumns(new Object[] { "evalNo", "docDate", "bankBranch", "custName",
                "docStatus", "lastUpdtedBy", "lastUpdateDt" });
        tblEvalDetails.setColumnHeaders(new String[] { "Evaluation Number", "Evaluation Date", "Bank Branch",
                "Customer Name", "Status", "Last Updated By", "Last Updated Date" });
        tblEvalDetails.addValueChangeListener(new Property.ValueChangeListener() {
            /**
            * 
            */
            private static final long serialVersionUID = 3729824796823933688L;

            @Override
            public void valueChange(ValueChangeEvent event) {

                StreamResource sr = getPDFStream();

                if (sr != null) {

                    if (filedownloader == null) {
                        filedownloader = new FileDownloader(getPDFStream());
                        filedownloader.extend(btnView);
                    } else {
                        filedownloader.setFileDownloadResource(sr);
                    }
                } else {
                    lblNotificationIcon.setIcon(new ThemeResource("img/msg_info.png"));
                    lblSaveNotification.setValue("No document is there");
                    //   notif.show(Page.getCurrent());
                    if (filedownloader != null) {
                        filedownloader.setFileDownloadResource(null); // reset
                    }

                }

                TPemCmEvalDetails syncList = (TPemCmEvalDetails) event.getProperty().getValue();
                if (syncList != null) {

                    if (syncList.getDocStatus().equals("Draft") || syncList.getDocStatus().equals("Rejected")) {
                        btnEdit.setEnabled(true);
                        btnView.setEnabled(false);
                    } else {
                        btnEdit.setEnabled(false);
                        btnView.setEnabled(true);

                    }
                    btnAdd.setEnabled(false);
                } else {
                    btnEdit.setEnabled(false);
                    btnAdd.setEnabled(true);
                }
            }

        });
        tblEvalDetails.setImmediate(true);
        tblEvalDetails.addItemClickListener(new ItemClickListener() {

            @Override
            public void itemClick(ItemClickEvent event) {
                // TODO Auto-generated method stub
                if (tblEvalDetails.isSelected(event.getItemId())) {

                    btnView.setEnabled(false);
                } else {

                    btnView.setEnabled(true);
                }
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        logger.info("Error-->" + e);
    }
    getExportTableDetails();
}

From source file:com.jain.addon.component.download.JDownloader.java

License:Apache License

/**
 * Download actual file/*from w w w  .  j a  v  a 2 s . c  o m*/
 */
public void download() {
    StreamResource resource = new StreamResource(source, fileName);
    resource.getStream().setParameter("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
    resource.setMIMEType("application/octet-stream");
    resource.setCacheTime(0);
    FileDownloader downloader = new FileDownloader(resource);
    downloader.extend(ui);
}

From source file:com.mycollab.module.file.view.components.FileDownloadWindow.java

License:Open Source License

private void constructBody() {
    final MVerticalLayout layout = new MVerticalLayout().withFullWidth();
    CssLayout iconWrapper = new CssLayout();
    final ELabel iconEmbed = ELabel.fontIcon(FileAssetsUtil.getFileIconResource(content.getName()));
    iconEmbed.addStyleName("icon-48px");
    iconWrapper.addComponent(iconEmbed);
    layout.with(iconWrapper).withAlign(iconWrapper, Alignment.MIDDLE_CENTER);

    final GridFormLayoutHelper inforLayout = GridFormLayoutHelper.defaultFormLayoutHelper(1, 4);

    if (content.getDescription() != null) {
        final Label descLbl = new Label();
        if (!content.getDescription().equals("")) {
            descLbl.setData(content.getDescription());
        } else {/*from ww w . j a v  a  2 s.c o m*/
            descLbl.setValue("&nbsp;");
            descLbl.setContentMode(ContentMode.HTML);
        }
        inforLayout.addComponent(descLbl, "Description", 0, 0);
    }

    UserService userService = AppContextUtil.getSpringBean(UserService.class);
    SimpleUser user = userService.findUserByUserNameInAccount(content.getCreatedUser(),
            AppContext.getAccountId());
    if (user == null) {
        inforLayout.addComponent(new UserLink(AppContext.getUsername(), AppContext.getUserAvatarId(),
                AppContext.getUserDisplayName()), "Created by", 0, 1);
    } else {
        inforLayout.addComponent(new UserLink(user.getUsername(), user.getAvatarid(), user.getDisplayName()),
                "Created by", 0, 1);
    }

    final Label size = new Label(FileUtils.getVolumeDisplay(content.getSize()));
    inforLayout.addComponent(size, "Size", 0, 2);

    ELabel dateCreate = new ELabel().prettyDateTime(content.getCreated().getTime());
    inforLayout.addComponent(dateCreate, "Created date", 0, 3);

    layout.addComponent(inforLayout.getLayout());

    final MHorizontalLayout buttonControls = new MHorizontalLayout()
            .withMargin(new MarginInfo(true, false, true, false));

    final Button downloadBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_DOWNLOAD));
    List<Resource> resources = new ArrayList<>();
    resources.add(content);

    StreamResource downloadResource = StreamDownloadResourceUtil.getStreamResourceSupportExtDrive(resources);

    FileDownloader fileDownloader = new FileDownloader(downloadResource);
    fileDownloader.extend(downloadBtn);
    downloadBtn.setIcon(FontAwesome.DOWNLOAD);
    downloadBtn.addStyleName(UIConstants.BUTTON_ACTION);

    final Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {
                    close();
                }
            });
    cancelBtn.addStyleName(UIConstants.BUTTON_OPTION);
    buttonControls.with(cancelBtn, downloadBtn).alignAll(Alignment.TOP_RIGHT);
    layout.with(buttonControls).withAlign(buttonControls, Alignment.TOP_RIGHT);
    this.setContent(layout);
}

From source file:com.mycollab.module.file.view.FileDownloadWindow.java

License:Open Source License

private void constructBody() {
    final MVerticalLayout layout = new MVerticalLayout().withFullWidth();
    CssLayout iconWrapper = new CssLayout();
    final ELabel iconEmbed = ELabel.fontIcon(FileAssetsUtil.getFileIconResource(content.getName()));
    iconEmbed.addStyleName("icon-48px");
    iconWrapper.addComponent(iconEmbed);
    layout.with(iconWrapper).withAlign(iconWrapper, Alignment.MIDDLE_CENTER);

    final GridFormLayoutHelper inforLayout = GridFormLayoutHelper.defaultFormLayoutHelper(1, 4);

    if (content.getDescription() != null) {
        final Label descLbl = new Label();
        if (!content.getDescription().equals("")) {
            descLbl.setData(content.getDescription());
        } else {//from  ww  w  .j  a v a2s  . c  o m
            descLbl.setValue("&nbsp;");
            descLbl.setContentMode(ContentMode.HTML);
        }
        inforLayout.addComponent(descLbl, UserUIContext.getMessage(GenericI18Enum.FORM_DESCRIPTION), 0, 0);
    }

    UserService userService = AppContextUtil.getSpringBean(UserService.class);
    SimpleUser user = userService.findUserByUserNameInAccount(content.getCreatedUser(),
            MyCollabUI.getAccountId());
    if (user == null) {
        inforLayout.addComponent(
                new UserLink(UserUIContext.getUsername(), UserUIContext.getUserAvatarId(),
                        UserUIContext.getUserDisplayName()),
                UserUIContext.getMessage(GenericI18Enum.OPT_CREATED_BY), 0, 1);
    } else {
        inforLayout.addComponent(new UserLink(user.getUsername(), user.getAvatarid(), user.getDisplayName()),
                UserUIContext.getMessage(GenericI18Enum.OPT_CREATED_BY), 0, 1);
    }

    final Label size = new Label(FileUtils.getVolumeDisplay(content.getSize()));
    inforLayout.addComponent(size, UserUIContext.getMessage(FileI18nEnum.OPT_SIZE), 0, 2);

    ELabel dateCreate = new ELabel().prettyDateTime(content.getCreated().getTime());
    inforLayout.addComponent(dateCreate, UserUIContext.getMessage(GenericI18Enum.FORM_CREATED_TIME), 0, 3);

    layout.addComponent(inforLayout.getLayout());

    MButton downloadBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_DOWNLOAD))
            .withIcon(FontAwesome.DOWNLOAD).withStyleName(WebThemes.BUTTON_ACTION);
    List<Resource> resources = new ArrayList<>();
    resources.add(content);

    StreamResource downloadResource = StreamDownloadResourceUtil.getStreamResourceSupportExtDrive(resources);

    FileDownloader fileDownloader = new FileDownloader(downloadResource);
    fileDownloader.extend(downloadBtn);

    MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            clickEvent -> close()).withStyleName(WebThemes.BUTTON_OPTION);
    final MHorizontalLayout buttonControls = new MHorizontalLayout(cancelBtn, downloadBtn);
    layout.with(buttonControls).withAlign(buttonControls, Alignment.MIDDLE_RIGHT);
    this.setContent(layout);
}

From source file:com.mycollab.module.project.view.FollowingTicketViewImpl.java

License:Open Source License

@Override
public void initContent() {
    removeAllComponents();/*  w  w  w .  java  2  s.  c o m*/
    MHorizontalLayout header = new MHorizontalLayout().withFullWidth();

    ELabel layoutHeader = ELabel
            .h2(FontAwesome.EYE.getHtml() + " "
                    + UserUIContext.getMessage(FollowerI18nEnum.OPT_MY_FOLLOWING_TICKETS, 0))
            .withWidthUndefined();

    Button exportBtn = new Button(UserUIContext.getMessage(GenericI18Enum.ACTION_EXPORT),
            clickEvent -> exportButtonControl.setPopupVisible(true));
    exportButtonControl = new SplitButton(exportBtn);
    exportButtonControl.addStyleName(WebThemes.BUTTON_OPTION);
    exportButtonControl.setIcon(FontAwesome.EXTERNAL_LINK);

    OptionPopupContent popupButtonsControl = new OptionPopupContent();
    exportButtonControl.setContent(popupButtonsControl);

    Button exportPdfBtn = new Button(UserUIContext.getMessage(FileI18nEnum.PDF));
    FileDownloader pdfDownloader = new FileDownloader(constructStreamResource(ReportExportType.PDF));
    pdfDownloader.extend(exportPdfBtn);
    exportPdfBtn.setIcon(FontAwesome.FILE_PDF_O);
    popupButtonsControl.addOption(exportPdfBtn);

    Button exportExcelBtn = new Button(UserUIContext.getMessage(FileI18nEnum.EXCEL));
    FileDownloader excelDownloader = new FileDownloader(constructStreamResource(ReportExportType.EXCEL));
    excelDownloader.extend(exportExcelBtn);
    exportExcelBtn.setIcon(FontAwesome.FILE_EXCEL_O);
    popupButtonsControl.addOption(exportExcelBtn);

    header.with(layoutHeader, exportButtonControl).withAlign(layoutHeader, Alignment.MIDDLE_LEFT)
            .withAlign(exportButtonControl, Alignment.MIDDLE_RIGHT);
    this.addComponent(layoutHeader);

    searchPanel = new FollowingTicketSearchPanel();
    this.addComponent(searchPanel);

    this.ticketTable = new FollowingTicketTableDisplay();
    this.ticketTable.setMargin(new MarginInfo(true, false, false, false));
    this.addComponent(this.ticketTable);
}

From source file:com.mycollab.vaadin.web.ui.AttachmentDisplayComponent.java

License:Open Source License

private void addAttachmentRow(final Content attachment) {
    String docName = attachment.getPath();
    int lastIndex = docName.lastIndexOf("/");
    if (lastIndex != -1) {
        docName = docName.substring(lastIndex + 1, docName.length());
    }//from ww  w  .j  av a 2  s  .c  o m

    final AbsoluteLayout attachmentLayout = new AbsoluteLayout();
    attachmentLayout.setWidth(WebUIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH);
    attachmentLayout.setHeight(WebUIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_HEIGHT);
    attachmentLayout.setStyleName("attachment-block");

    CssLayout thumbnailWrap = new CssLayout();
    thumbnailWrap.setSizeFull();
    thumbnailWrap.setStyleName("thumbnail-wrap");

    Link thumbnail = new Link();
    if (StringUtils.isBlank(attachment.getThumbnail())) {
        thumbnail.setIcon(FileAssetsUtil.getFileIconResource(attachment.getName()));
    } else {
        thumbnail.setIcon(VaadinResourceFactory.getResource(attachment.getThumbnail()));
    }

    if (MimeTypesUtil.isImageType(docName)) {
        thumbnail.setResource(VaadinResourceFactory.getResource(attachment.getPath()));
        new Fancybox(thumbnail).setPadding(0).setVersion("2.1.5").setEnabled(true).setDebug(true);
    }

    Div contentTooltip = new Div().appendChild(new Span().appendText(docName).setStyle("font-weight:bold"));
    Ul ul = new Ul().appendChild(new Li().appendText(UserUIContext.getMessage(FileI18nEnum.OPT_SIZE_VALUE,
            FileUtils.getVolumeDisplay(attachment.getSize())))).setStyle("line-height:1.5em");
    ul.appendChild(new Li().appendText(UserUIContext.getMessage(GenericI18Enum.OPT_LAST_MODIFIED,
            UserUIContext.formatPrettyTime(attachment.getLastModified().getTime()))));
    contentTooltip.appendChild(ul);
    thumbnail.setDescription(contentTooltip.write());
    thumbnail.setWidth(WebUIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH);
    thumbnailWrap.addComponent(thumbnail);

    attachmentLayout.addComponent(thumbnailWrap, "top: 0px; left: 0px; bottom: 0px; right: 0px; z-index: 0;");

    MCssLayout attachmentNameWrap = new MCssLayout()
            .withWidth(WebUIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH).withStyleName("attachment-name-wrap");

    Label attachmentName = new ELabel(docName).withStyleName(UIConstants.TEXT_ELLIPSIS);
    attachmentNameWrap.addComponent(attachmentName);
    attachmentLayout.addComponent(attachmentNameWrap, "bottom: 0px; left: 0px; right: 0px; z-index: 1;");

    MButton trashBtn = new MButton("", clickEvent -> {
        ConfirmDialogExt.show(UI.getCurrent(),
                UserUIContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE, MyCollabUI.getSiteName()),
                UserUIContext.getMessage(GenericI18Enum.CONFIRM_DELETE_ATTACHMENT),
                UserUIContext.getMessage(GenericI18Enum.BUTTON_YES),
                UserUIContext.getMessage(GenericI18Enum.BUTTON_NO), confirmDialog -> {
                    if (confirmDialog.isConfirmed()) {
                        ResourceService attachmentService = AppContextUtil.getSpringBean(ResourceService.class);
                        attachmentService.removeResource(attachment.getPath(), UserUIContext.getUsername(),
                                true, MyCollabUI.getAccountId());
                        ((ComponentContainer) attachmentLayout.getParent()).removeComponent(attachmentLayout);
                    }
                });
    }).withIcon(FontAwesome.TRASH_O).withStyleName("attachment-control");
    attachmentLayout.addComponent(trashBtn, "top: 9px; left: 9px; z-index: 1;");

    MButton downloadBtn = new MButton().withIcon(FontAwesome.DOWNLOAD).withStyleName("attachment-control");
    FileDownloader fileDownloader = new FileDownloader(
            VaadinResourceFactory.getInstance().getStreamResource(attachment.getPath()));
    fileDownloader.extend(downloadBtn);
    attachmentLayout.addComponent(downloadBtn, "right: 9px; top: 9px; z-index: 1;");
    this.addComponent(attachmentLayout);
}

From source file:com.ocs.dynamo.ui.component.DownloadButton.java

License:Apache License

/**
 * Constructor//from www.  ja  v  a2s .  com
 * 
 * @param caption
 *            the caption of the button
 * @param fileName
 *            the name of the file to download
 */
public DownloadButton(String caption) {
    super(caption);
    resource = new StreamResource(new StreamSource() {

        private static final long serialVersionUID = -4870779918745663459L;

        @Override
        public InputStream getStream() {
            byte[] content = doCreateContent();
            if (content != null) {
                return new ByteArrayInputStream(content);
            }
            return null;
        }

    }, doCreateFileName());

    FileDownloader downloader = new FileDownloader(resource);
    downloader.extend(this);

}

From source file:com.saax.gestorweb.presenter.ChatPresenter.java

/**
 * Cria botao para download de anexo//from  w  ww . j a v  a2 s .  c  om
 */
private Button buildButtonDownload(Anexo anexos) {
    Button exportar = new Button();
    exportar.setIcon(FontAwesome.DOWNLOAD);
    exportar.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
    exportar.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    FileDownloader fd = new FileDownloader(new FileResource(new File(anexos.getCaminhoCompleto())));
    fd.extend(exportar);
    return exportar;

}