Example usage for com.vaadin.server FileDownloader extend

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

Introduction

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

Prototype

public void extend(EventTrigger eventTrigger) 

Source Link

Document

Add this extension to the EventTrigger .

Usage

From source file:com.foc.web.modules.photoAlbum.PhotoAlbum_Table.java

License:Apache License

@Override
public ColumnGenerator table_getGeneratedColumn(String tableName, final FVTableColumn tableColumn) {
    ColumnGenerator columnGenerator = null;

    if (tableColumn.getName().equals("DOWNLOAD")) {
        columnGenerator = new ColumnGenerator() {
            public Object generateCell(Table source, Object itemId, Object columnId) {
                long objId = (Long) itemId;
                FVButton button = new FVButton("");
                Resource iconResource = FVIconFactory.getInstance().getFVIcon_24(FVIconFactory.ICON_DOWNLOAD);
                button.setStyleName(Runo.BUTTON_LINK);
                button.setWidth("-1px");
                button.setHeight("-1px");
                button.setIcon(iconResource);
                PhotoAlbumFileResource resource = getPhotoAlbumFileResource(objId);
                FileDownloader downloader = new FileDownloader(resource);
                downloader.extend(button);
                return button;
            }/*w  w w. j  a va2  s .  c om*/
        };
    }
    return columnGenerator;
}

From source file:com.gnts.pem.txn.sbi.SBILand.java

void editPropertyImageDetails() {
    try {/*ww  w  .ja v a 2  s  .  co m*/
        List<TPemCmPropImage> imageList = beanPropImage.getPropImageList(headerid);
        TPemCmPropImage propObj = imageList.get(0);
        if (propObj.getPropimage1() != null) {
            byte[] myimage = (byte[]) propObj.getPropimage1();

            UploadUI test = new UploadUI(hlImageLayout1);
            hlImageLayout1.addComponent(btnImgDownload);
            test.dispayImage(myimage);
        } else {

            try {
                new UploadUI(hlImageLayout1);
            } catch (Exception e) {

            }
        }

        if (propObj.getPropimage2() != null) {
            byte[] myimage1 = (byte[]) propObj.getPropimage2();

            UploadUI2 test = new UploadUI2(hlImageLayout2);
            hlImageLayout2.addComponent(btnImg1Download);
            test.dispayImage(myimage1);
        } else {

            try {
                new UploadUI2(hlImageLayout2);
            } catch (Exception e) {

            }
        }

        StreamResource sr = getImgStream();
        FileDownloader fileDownloader = new FileDownloader(sr);
        fileDownloader.extend(btnImgDownload);

        StreamResource sr1 = getImgStream1();
        FileDownloader fileDownloader1 = new FileDownloader(sr1);
        fileDownloader1.extend(btnImg1Download);

    } catch (Exception e) {

    }
}

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 om
 */
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  w w  w. jav  a2s  .co 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  w ww. j  a va 2s .  c om*/
            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 ww  . j  a v a 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  a  va 2 s .  co  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 .j av a2 s. co  m
 * 
 * @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  w  w .  j a  va 2  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;

}

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

License:Apache License

public PhylogeneticTreeView(ClustalFileMapper clustalFileMapper) throws IOException {
    initializeUiComponents();/*from   ww  w.j  av a2s  .com*/

    // 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);
}