本文整理汇总了Java中com.vaadin.server.FileDownloader类的典型用法代码示例。如果您正苦于以下问题:Java FileDownloader类的具体用法?Java FileDownloader怎么用?Java FileDownloader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileDownloader类属于com.vaadin.server包,在下文中一共展示了FileDownloader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDownloadButton
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
@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;
}
示例2: init
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
@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);
}
示例3: initializeDownload
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
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);
}
示例4: fileLinkComponent
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
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());
}
}
示例5: createDownloader
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
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));
}
示例6: zipProject
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
/**
* 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);
}
}
示例7: getDownloadSdkButtonForSdnController
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
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;
}
示例8: getDownloadSdkButtonForManager
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
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;
}
示例9: getDownloadButton
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
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;
}
示例10: updateDetails
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
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);
}
示例11: download
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
/**
* 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);
}
示例12: buildDownloadButton
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
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);
}
}
示例13: initContent
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
@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);
}
示例14: buildExportButton
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
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;
}
示例15: NamedQueryImportExport
import com.vaadin.server.FileDownloader; //导入依赖的package包/类
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);
}