@SuppressWarnings("serial") private Button createDownloadButton() { this.download = new Button(VmidcMessages.getString(VmidcMessages_.SUMMARY_DOWNLOAD_LOG)) { @Override public void setEnabled(boolean enabled) { if (enabled) { // because setEnabled(false) calls are ignored and button is disabled // on client because of setDisableOnClick(true), by doing this we // make sure that the button is actually disabled so that setEnabled(true) // has effect getUI().getConnectorTracker().getDiffState(this).put("enabled", false); super.setEnabled(enabled); } } }; SummaryLayout.this.download.setDisableOnClick(true); if (this.checkbox != null && this.checkbox.getValue()) { this.download.setCaption(VmidcMessages.getString(VmidcMessages_.SUMMARY_DOWNLOAD_BUNDLE)); } StreamResource zipStream = getZipStream(); FileDownloader fileDownloader = new FileDownloader(zipStream); fileDownloader.extend(this.download); return this.download; }
@PostConstruct public void init() { VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true); layout.setWidthUndefined(); layout.addComponent(attendeeExportBtn); FileDownloader attendeeDownloader = new FileDownloader(handler.createAttendeeExport(this)); attendeeDownloader.extend(attendeeExportBtn); layout.addComponent(tillExportBtn); FileDownloader tillDownloader = new FileDownloader(handler.createTillExport(this)); tillDownloader.extend(tillExportBtn); layout.setComponentAlignment(attendeeExportBtn, Alignment.TOP_CENTER); layout.setComponentAlignment(tillExportBtn, Alignment.TOP_CENTER); addComponent(layout); }
protected void initializeDownload() { // // Create a stream resource pointing to the file // StreamResource r = new StreamResource(new StreamResource.StreamSource() { private static final long serialVersionUID = 1L; @Override public InputStream getStream() { try { return new FileInputStream(self.file); } catch (Exception e) { logger.error("Failed to open input stream " + self.file); } return null; } }, self.file.getName()); r.setCacheTime(-1); r.setMIMEType("application/xml"); // // Extend a downloader to attach to the Export Button // FileDownloader downloader = new FileDownloader(r); downloader.extend(this.buttonExport); }
protected Component fileLinkComponent(Table source, Object itemId, Object propertyId) { if (itemId instanceof FileInfo) { final FileInfo file = (FileInfo) itemId; if (!file.isDirectory()) { final Button button = new Button(file.getName()); button.addStyleName(ValoTheme.BUTTON_LINK); button.addStyleName(ValoTheme.BUTTON_SMALL); button.setIcon(FontAwesome.FILE); StreamResource resource = new StreamResource(() -> stream(file), file.getName()); FileDownloader fileDownloader = new FileDownloader(resource); fileDownloader.extend(button); return button; } else { return new Label(file.getName()); } } else { return new Label(((DirectoryResource) itemId).getName()); } }
private FileDownloader createDownloader(final byte[] file, final String fileName) { // Подготовить имя файла final String webFileName = encodeWebFileName(fileName); return new OnDemandFileDownloader(new OnDemandFileDownloader.OnDemandStreamResource() { @Override public String getFilename() { return webFileName; } @Override public InputStream getStream() { return new ByteArrayInputStream(file); } }); // return new FileDownloader( // new StreamResource(new StreamResource.StreamSource() { // @Override // public InputStream getStream() { // return new ByteArrayInputStream(file); // } // // }, webFileName)); }
/** * Zips project. * * @param projectName the name of the project to be zipped */ protected void zipProject() { try { File zipFile = File.createTempFile("mideaas-"+project.getName(), ".zip"); zipProjectToFile(zipFile, settings); FileResource zip = new FileResource(zipFile); FileDownloader fd = new FileDownloader(zip); Button downloadButton = new Button("Download project"); fd.extend(downloadButton); //filedonwnloader can not be connected to menuitem :( So I connected it to popupwindow :) Window zipButtonWindow = new Window(); zipButtonWindow.setCaption("Zip and download project"); zipButtonWindow.setWidth(200, Unit.PIXELS); zipButtonWindow.setContent(downloadButton); UI.getCurrent().addWindow(zipButtonWindow); } catch (IOException e) { e.printStackTrace(); Notification.show("Error: " + e.getMessage(), Notification.Type.ERROR_MESSAGE); } }
private Button getDownloadSdkButtonForSdnController() throws URISyntaxException, MalformedURLException { SdkUtil sdkUtil = new SdkUtil(); Button downloadSdk = new Button(VmidcMessages.getString(VmidcMessages_.MAINTENANCE_SDNPLUGIN_DOWNLOAD_SDK)); URI currentLocation = UI.getCurrent().getPage().getLocation(); URI downloadLocation = new URI(currentLocation.getScheme(), null, currentLocation.getHost(), currentLocation.getPort(), sdkUtil.getSdk(SdkUtil.sdkType.SDN_CONTROLLER), null, null); FileDownloader downloader = new FileDownloader(new ExternalResource(downloadLocation.toURL().toString())); downloader.extend(downloadSdk); return downloadSdk; }
private Button getDownloadSdkButtonForManager() throws URISyntaxException, MalformedURLException { SdkUtil sdkUtil = new SdkUtil(); Button downloadSdk = new Button(VmidcMessages.getString(VmidcMessages_.MAINTENANCE_MANAGERPLUGIN_DOWNLOAD_SDK)); URI currentLocation = UI.getCurrent().getPage().getLocation(); URI downloadLocation = new URI(currentLocation.getScheme(), null, currentLocation.getHost(), currentLocation.getPort(), sdkUtil.getSdk(SdkUtil.sdkType.MANAGER), null, null); FileDownloader downloader = new FileDownloader(new ExternalResource(downloadLocation.toURL().toString())); downloader.extend(downloadSdk); return downloadSdk; }
private Button getDownloadButton(Application app) { // Download logs button : download file StreamResource resource = getLogsStream(app); // Download logs button Button downloadButton = new Button("Download full logfile"); FileDownloader fileDownloader = new FileDownloader(resource); fileDownloader.setOverrideContentType(false); fileDownloader.extend(downloadButton); // Download logs button : on click downloadButton.addClickListener(e -> fileDownloader.setFileDownloadResource(getLogsStream(app))); return downloadButton; }
private void updateDetails(ListEntry item) { LOG.info("Display details for {}", item); ObjectMetadata objectMetadata = s3Client.getObjectMetadata(item.getBucket(), item.getKey()); VerticalLayout detailsContent = new VerticalLayout(); detailsContent.setSpacing(true); detailsContent.setMargin(true); Label caption = new Label(item.getKey()); caption.addStyleName(ValoTheme.LABEL_H3); detailsContent.addComponent(caption); if (objectMetadata.getLastModified() != null) { detailsContent.addComponent(buildDetailsTextField("LastModified", objectMetadata.getLastModified().toString())); } detailsContent.addComponent(buildDetailsTextField("ContentLength", Long.toString(objectMetadata.getContentLength()))); if (objectMetadata.getContentType() != null) { detailsContent.addComponent(buildDetailsTextField("ContentType", objectMetadata.getContentType())); } if (objectMetadata.getETag() != null) { detailsContent.addComponent(buildDetailsTextField("ETag", objectMetadata.getETag())); } Button downloadButton = new Button("Download"); FileDownloader fileDownloader = new FileDownloader(new StreamResource(() -> { LOG.info("Download {}/{}", item.getBucket(), item.getKey()); return s3Client.getObject(item.getBucket(), item.getKey()).getObjectContent(); }, item.getKey())); fileDownloader.extend(downloadButton); detailsContent.addComponent(downloadButton); details.setContent(detailsContent); }
/** * Download actual file */ 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); }
private void buildDownloadButton(String title) { downloadButton = new Button("Download"); final byte[] lobData = getLobData(title); if (lobData != null) { Resource resource = new StreamResource(new StreamSource() { private static final long serialVersionUID = 1L; public InputStream getStream() { return new ByteArrayInputStream(lobData); } }, title); FileDownloader fileDownloader = new FileDownloader(resource); fileDownloader.extend(downloadButton); buttonLayout.addComponent(downloadButton); buttonLayout.setComponentAlignment(downloadButton, Alignment.BOTTOM_CENTER); long fileSize = lobData.length; String sizeText = fileSize + " Bytes"; if (fileSize / 1024 > 0) { sizeText = Math.round(fileSize / 1024.0) + " kB"; fileSize /= 1024; } if (fileSize / 1024 > 0) { sizeText = Math.round(fileSize / 1024.0) + " MB"; fileSize /= 1024; } if (fileSize / 1024 > 0) { sizeText = Math.round(fileSize / 1024.0) + " GB"; } Label sizeLabel = new Label(sizeText); buttonLayout.addComponent(sizeLabel); buttonLayout.setExpandRatio(sizeLabel, 1.0f); buttonLayout.setComponentAlignment(sizeLabel, Alignment.BOTTOM_CENTER); } }
@Override public void initContent() { removeAllComponents(); MHorizontalLayout header = new MHorizontalLayout().withFullWidth(); ELabel layoutHeader = ELabel.h2(String.format("%s %s", 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); }
private Component buildExportButton() { Button exportButton = new Button(Messages.getString("Caption.Button.Export")); Resource exportResource = getExportResource(); FileDownloader fileDownloader = new FileDownloader(exportResource); fileDownloader.extend(exportButton); return exportButton; }
public NamedQueryImportExport() { setSizeFull(); setSpacing(true); setMargin(true); Panel importPanel = new Panel("Import"); importPanel.setSizeFull(); Panel exportPanel = new Panel("Export"); exportPanel.setSizeFull(); VerticalLayout exportLayout = new VerticalLayout(); exportLayout.setSizeFull(); exportLayout.setMargin(true); exportLayout.setSpacing(true); Button exportButton = new Button("Export Named Queries"); exportLayout.addComponent(exportButton); StreamResource streamResource = getNamedQueriesExportStream(); FileDownloader fileDownloader = new FileDownloader(streamResource); fileDownloader.extend(exportButton); exportPanel.setContent(exportLayout); addComponent(exportPanel); FormLayout importLayout = new FormLayout(); importLayout.setSizeFull(); importLayout.setMargin(true); importLayout.setSpacing(true); importLayout.addComponent(cleanBeforeImportCheckbox); CSVReceiver uploadReceiver = new CSVReceiver(); Upload upload = new Upload("", uploadReceiver); upload.setButtonCaption("Import Named Queries"); upload.addStyleName(ValoTheme.BUTTON_LARGE); upload.addStyleName(ValoTheme.BUTTON_FRIENDLY); upload.addSucceededListener(uploadReceiver); upload.addFailedListener(uploadReceiver); importLayout.addComponent(upload); importPanel.setContent(importLayout); addComponent(importPanel); }
public HttpSourceImportExport() { setSizeFull(); setSpacing(true); setMargin(true); Panel importPanel = new Panel("Import"); importPanel.setSizeFull(); Panel exportPanel = new Panel("Export"); exportPanel.setSizeFull(); VerticalLayout exportLayout = new VerticalLayout(); exportLayout.setSizeFull(); exportLayout.setMargin(true); exportLayout.setSpacing(true); Button exportButton = new Button("Export HTTP Sources"); exportLayout.addComponent(exportButton); StreamResource streamResource = getHttpSourcesExportStream(); FileDownloader fileDownloader = new FileDownloader(streamResource); fileDownloader.extend(exportButton); exportPanel.setContent(exportLayout); addComponent(exportPanel); FormLayout importLayout = new FormLayout(); importLayout.setSizeFull(); importLayout.setMargin(true); importLayout.setSpacing(true); importLayout.addComponent(cleanBeforeImportCheckbox); CSVReceiver uploadReceiver = new CSVReceiver(); Upload upload = new Upload("", uploadReceiver); upload.setButtonCaption("Import HTTP Sources"); upload.addStyleName(ValoTheme.BUTTON_LARGE); upload.addStyleName(ValoTheme.BUTTON_FRIENDLY); upload.addSucceededListener(uploadReceiver); upload.addFailedListener(uploadReceiver); importLayout.addComponent(upload); importPanel.setContent(importLayout); addComponent(importPanel); }
public HttpSourceTestImportExport() { setSizeFull(); setSpacing(true); setMargin(true); Panel importPanel = new Panel("Import"); importPanel.setSizeFull(); Panel exportPanel = new Panel("Export"); exportPanel.setSizeFull(); VerticalLayout exportLayout = new VerticalLayout(); exportLayout.setSizeFull(); exportLayout.setMargin(true); exportLayout.setSpacing(true); Button exportButton = new Button("Export HTTP Source Tests"); exportLayout.addComponent(exportButton); StreamResource streamResource = getHttpSourcesExportStream(); FileDownloader fileDownloader = new FileDownloader(streamResource); fileDownloader.extend(exportButton); exportPanel.setContent(exportLayout); addComponent(exportPanel); FormLayout importLayout = new FormLayout(); importLayout.setSizeFull(); importLayout.setMargin(true); importLayout.setSpacing(true); importLayout.addComponent(cleanBeforeImportCheckbox); CSVReceiver uploadReceiver = new CSVReceiver(); Upload upload = new Upload("", uploadReceiver); upload.setButtonCaption("Import HTTP Source Tests"); upload.addStyleName(ValoTheme.BUTTON_LARGE); upload.addStyleName(ValoTheme.BUTTON_FRIENDLY); upload.addSucceededListener(uploadReceiver); upload.addFailedListener(uploadReceiver); importLayout.addComponent(upload); importPanel.setContent(importLayout); addComponent(importPanel); }
public ReportWindow(String title, String report) { super(title); this.title = title; buildWindowLayout(); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setMargin(true); verticalLayout.setSpacing(true); verticalLayout.addComponent(buildButtonBar()); verticalLayout.addComponent(buildReportPanel(report)); setContent(verticalLayout); FileDownloader downloader = new FileDownloader(getDownloadStream()); downloader.extend(btnDownload); }
protected void setLink(File file) { downloadButton.setEnabled(false); fileDownloader = new FileDownloader(new FileResource(file)); fileDownloader.extend(downloadButton); downloadButton.setEnabled(true); }
/** * Setup UI. */ private void initComponents() { Label info = new Label( Messages.getString("PaperSelectionPanel.hintMsg"), //$NON-NLS-1$ ContentMode.HTML); languages = new ComboBox(Messages.getString("PaperSelectionPanel.language"), //$NON-NLS-1$ Arrays.asList(SubmissionLanguage.values())); languages.setNullSelectionAllowed(false); languages.setValue(SubmissionLanguage.valueOf(PropertyKey.defaultSubmissionLanguage.getValue(SubmissionLanguage.ENGLISH.name()))); paperTable = new Table(Messages.getString("PaperSelectionPanel.tableTitle")); //$NON-NLS-1$ paperTable.setSelectable(true); paperTable.setMultiSelect(true); paperTable.setPageLength(4); paperTable.addContainerProperty("title", String.class, null); //$NON-NLS-1$ paperTable.setColumnHeader( "title", Messages.getString("PaperSelectionPanel.titleColumnTitle")); //$NON-NLS-1$ //$NON-NLS-2$ paperTable.setWidth("100%"); //$NON-NLS-1$ paperTable.setImmediate(true); btGenerate = new Button( Messages.getString( "PaperSelectionPanel.generateButtonCaption")); //$NON-NLS-1$ StreamResource templateStreamResource = new StreamResource( new StreamSource() { @Override public InputStream getStream() { return createTemplates(); } }, "your_personal_dh_templates.zip" ); //$NON-NLS-1$ templateStreamResource.setCacheTime(0); new FileDownloader(templateStreamResource).extend(btGenerate); addCenteredComponent(info); addCenteredComponent(languages); addCenteredComponent(paperTable); addCenteredComponent(btGenerate); postDownloadLabel = new Label( Messages.getString("PaperSelectionPanel.postDownloadInfo", inputConverter.getTextEditorDescription(), PropertyKey.base_url.getValue()+"popup/DHConvalidatorServices#!converter"), ContentMode.HTML); postDownloadLabel.addStyleName("postDownloadInfoRedAndBold"); postDownloadLabel.setVisible(false); addCenteredComponent(postDownloadLabel); }
@Override protected void init(VaadinRequest request) { try { Messages.setLocaleProvider(VaadinSessionLocaleProvider.INSTANCE); VerticalLayout content = new VerticalLayout(); content.setMargin(true); content.setSpacing(true); setContent(content); HeaderPanel headerPanel = new HeaderPanel(null); headerPanel.getBackLink().setVisible(false); content.addComponent(headerPanel); // prepare downloader for input file Button btGetInputfile = new Button( Messages.getString("DHConvalidatorExample.btInputCaption")); //$NON-NLS-1$ content.addComponent(btGetInputfile); FileDownloader inputFileDownloader = new FileDownloader(new StreamResource( new StreamSource() { @Override public InputStream getStream() { return Thread.currentThread().getContextClassLoader().getResourceAsStream( "/org/adho/dhconvalidator/conversion/example/1_Digital_Humanities.odt"); //$NON-NLS-1$ } }, "1_Digital_Humanities.odt")); //$NON-NLS-1$ inputFileDownloader.extend(btGetInputfile); // prepare downloader for output file Button btGetOutputfile = new Button( Messages.getString( "DHConvalidatorExample.btConversionResultCaption")); //$NON-NLS-1$ content.addComponent(btGetOutputfile); FileDownloader outputFileDownloader = new FileDownloader(new StreamResource( new StreamSource() { @Override public InputStream getStream() { return Thread.currentThread().getContextClassLoader().getResourceAsStream( "/org/adho/dhconvalidator/conversion/example/1_Digital_Humanities.dhc"); //$NON-NLS-1$ } }, "1_Digital_Humanities.dhc")); //$NON-NLS-1$ outputFileDownloader.extend(btGetOutputfile); // setup visual feedback Label preview = new Label("", ContentMode.HTML); //$NON-NLS-1$ preview.addStyleName("tei-preview"); //$NON-NLS-1$ preview.setWidth("800px"); //$NON-NLS-1$ content.addComponent(preview); content.setComponentAlignment(preview, Alignment.MIDDLE_CENTER); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); IOUtils.copy( Thread.currentThread().getContextClassLoader().getResourceAsStream( "/org/adho/dhconvalidator/conversion/example/1_Digital_Humanities.html"), //$NON-NLS-1$ buffer); preview.setValue(buffer.toString("UTF-8")); //$NON-NLS-1$ Page.getCurrent().setTitle(Messages.getString("DHConvalidatorExample.title")); //$NON-NLS-1$ } catch(Exception e) { e.printStackTrace(); } }
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 infoLayout = GridFormLayoutHelper.defaultFormLayoutHelper(1, 4); if (content.getDescription() != null) { final Label descLbl = new Label(); if (!content.getDescription().equals("")) { descLbl.setData(content.getDescription()); } else { descLbl.setValue(" "); descLbl.setContentMode(ContentMode.HTML); } infoLayout.addComponent(descLbl, UserUIContext.getMessage(GenericI18Enum.FORM_DESCRIPTION), 0, 0); } UserService userService = AppContextUtil.getSpringBean(UserService.class); SimpleUser user = userService.findUserByUserNameInAccount(content.getCreatedUser(), AppUI.getAccountId()); if (user == null) { infoLayout.addComponent(new UserLink(UserUIContext.getUsername(), UserUIContext.getUserAvatarId(), UserUIContext.getUserDisplayName()), UserUIContext.getMessage(GenericI18Enum.OPT_CREATED_BY), 0, 1); } else { infoLayout.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())); infoLayout.addComponent(size, UserUIContext.getMessage(FileI18nEnum.OPT_SIZE), 0, 2); ELabel dateCreate = new ELabel().prettyDateTime(content.getCreated().getTime()); infoLayout.addComponent(dateCreate, UserUIContext.getMessage(GenericI18Enum.FORM_CREATED_TIME), 0, 3); layout.addComponent(infoLayout.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); }
private void addAttachmentRow(final Content attachment) { String docName = attachment.getPath(); int lastIndex = docName.lastIndexOf("/"); if (lastIndex != -1) { docName = docName.substring(lastIndex + 1, docName.length()); } 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, AppUI.getSiteName()), UserUIContext.getMessage(GenericI18Enum.CONFIRM_DELETE_ATTACHMENT), UserUIContext.getMessage(GenericI18Enum.ACTION_YES), UserUIContext.getMessage(GenericI18Enum.ACTION_NO), confirmDialog -> { if (confirmDialog.isConfirmed()) { ResourceService attachmentService = AppContextUtil.getSpringBean(ResourceService.class); attachmentService.removeResource(attachment.getPath(), UserUIContext.getUsername(), true, AppUI.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); }
public Exporter() { fileDownloader = new FileDownloader(new StreamResource(this, getDownloadFileName())); fileDownloader.extend(this); }
/** * Constructs a new Download button without ContentWriter. Be sure to set * the ContentWriter or override its getter, before instance is actually * used. */ public DownloadButton() { new FileDownloader(streamResource).extend(this); }