List of usage examples for com.vaadin.server FileDownloader FileDownloader
public FileDownloader(Resource resource)
From source file:org.apache.openaz.xacml.admin.components.PolicyEditor.java
License:Apache License
protected void initializeDownload() { ////from www . ja v a2 s . co m // 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); }
From source file:org.dussan.vaadin.dcharts.DCharts.java
License:Apache License
private void addChartContainer() { chartData.put(ID, chartId);/*from w ww . j a v a2 s . co m*/ downloadButton = new Button("Download chart"); downloadButton.setId(chartId + "-button"); downloadButton.addStyleName("small"); downloadButton.setSizeUndefined(); setContent(downloadButton); fileDownloader = new FileDownloader(getChartResource()); fileDownloader.extend(downloadButton); setSizeFull(); markAsDirty(); }
From source file:org.ikasan.dashboard.ui.mappingconfiguration.panel.MappingConfigurationPanel.java
License:BSD License
/** * Helper method to initialise this object. *//*ww w . j a v a 2 s.c o m*/ @SuppressWarnings("serial") protected void init() { layout = new GridLayout(5, 6); layout.setSpacing(true); layout.setMargin(true); layout.setWidth("100%"); this.addStyleName(ValoTheme.PANEL_BORDERLESS); paramQueriesLayout = new VerticalLayout(); toolBarLayout = new HorizontalLayout(); toolBarLayout.setWidth("100%"); Button linkButton = new Button(); linkButton.setIcon(VaadinIcons.REPLY_ALL); linkButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); linkButton.setDescription("Return to search results"); linkButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); linkButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { Navigator navigator = new Navigator(UI.getCurrent(), menuLayout.getContentContainer()); for (IkasanUIView view : topLevelNavigator.getIkasanViews()) { navigator.addView(view.getPath(), view.getView()); } saveRequiredMonitor.manageSaveRequired("mappingView"); navigator = new Navigator(UI.getCurrent(), mappingNavigator.getContainer()); for (IkasanUIView view : mappingNavigator.getIkasanViews()) { navigator.addView(view.getPath(), view.getView()); } } }); toolBarLayout.addComponent(linkButton); toolBarLayout.setExpandRatio(linkButton, 0.865f); this.editButton.setIcon(VaadinIcons.EDIT); this.editButton.setDescription("Edit the mapping configuration"); this.editButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); this.editButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); this.editButton.setVisible(false); this.editButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { setEditable(true); mappingConfigurationFunctionalGroup.editButtonPressed(); } }); toolBarLayout.addComponent(this.editButton); toolBarLayout.setExpandRatio(this.editButton, 0.045f); this.saveButton.setIcon(VaadinIcons.HARDDRIVE); this.saveButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); this.saveButton.setDescription("Save the mapping configuration"); this.saveButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); this.saveButton.setVisible(false); this.saveButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { try { logger.info("Save button clicked!!"); save(); setEditable(false); Notification.show("Changes Saved!", "", Notification.Type.HUMANIZED_MESSAGE); mappingConfigurationFunctionalGroup.saveOrCancelButtonPressed(); } catch (InvalidValueException e) { // We can ignore this one as we have already dealt with the // validation messages using the validation framework. } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); Notification.show("Cauget exception trying to save a Mapping Configuration!", sw.toString(), Notification.Type.ERROR_MESSAGE); } } }); toolBarLayout.addComponent(this.saveButton); toolBarLayout.setExpandRatio(this.saveButton, 0.045f); this.cancelButton.setIcon(VaadinIcons.CLOSE_CIRCLE); this.cancelButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); this.cancelButton.setDescription("Cancel the current edit"); this.cancelButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); this.cancelButton.setVisible(false); this.cancelButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { setEditable(false); mappingConfigurationFunctionalGroup.saveOrCancelButtonPressed(); Navigator navigator = new Navigator(UI.getCurrent(), menuLayout.getContentContainer()); for (IkasanUIView view : topLevelNavigator.getIkasanViews()) { navigator.addView(view.getPath(), view.getView()); } saveRequiredMonitor.manageSaveRequired("mappingView"); navigator = new Navigator(UI.getCurrent(), mappingNavigator.getContainer()); for (IkasanUIView view : mappingNavigator.getIkasanViews()) { navigator.addView(view.getPath(), view.getView()); } } }); toolBarLayout.addComponent(this.cancelButton); toolBarLayout.setExpandRatio(this.cancelButton, 0.045f); FileDownloader fd = new FileDownloader(this.getMappingConfigurationExportStream()); fd.extend(exportMappingConfigurationButton); this.exportMappingConfigurationButton.setIcon(VaadinIcons.DOWNLOAD_ALT); this.exportMappingConfigurationButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); this.exportMappingConfigurationButton.setDescription("Export the current mapping configuration"); this.exportMappingConfigurationButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); toolBarLayout.addComponent(this.exportMappingConfigurationButton); toolBarLayout.setExpandRatio(this.exportMappingConfigurationButton, 0.045f); final GridLayout contentLayout = new GridLayout(1, 2); contentLayout.setWidth("100%"); contentLayout.addComponent(toolBarLayout); contentLayout.addComponent(createMappingConfigurationForm()); VerticalSplitPanel vpanel = new VerticalSplitPanel(contentLayout, createTableLayout(false)); vpanel.setStyleName(ValoTheme.SPLITPANEL_LARGE); paramQueriesLayout.setSpacing(true); Label configValueLabels = new Label("Source Configuration Value Queries:"); layout.addComponent(configValueLabels, 2, 2, 3, 2); Panel queryParamsPanel = new Panel(); queryParamsPanel.addStyleName(ValoTheme.PANEL_BORDERLESS); queryParamsPanel.setHeight(100, Unit.PIXELS); queryParamsPanel.setWidth(100, Unit.PERCENTAGE); queryParamsPanel.setContent(paramQueriesLayout); this.layout.addComponent(queryParamsPanel, 2, 3, 3, 5); vpanel.setSplitPosition(325, Unit.PIXELS); this.setContent(vpanel); this.setSizeFull(); }
From source file:org.ikasan.dashboard.ui.mappingconfiguration.panel.MappingConfigurationPanel.java
License:BSD License
/** * Helper method to create the layout of the table. * //from ww w. j a va 2 s . c o m * @param buttonsVisible are the buttons visible? * * @return the Layout associated with the table. */ protected Layout createTableLayout(boolean buttonsVisible) { VerticalLayout tableLayout = new VerticalLayout(); HorizontalLayout controlsLayout = new HorizontalLayout(); controlsLayout.setWidth("100%"); this.addNewRecordButton.setIcon(VaadinIcons.PLUS); this.addNewRecordButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); this.addNewRecordButton.setDescription("Add a mapping configuration value to the table below"); this.addNewRecordButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); this.addNewRecordButton.setVisible(buttonsVisible); this.addNewRecordButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { saveRequiredMonitor.setSaveRequired(true); try { mappingConfigurationFunctionalGroup.editButtonPressed(); mappingConfigurationConfigurationValuesTable.addNewRecord(); } catch (MappingConfigurationServiceException e) { e.printStackTrace(); } } }); final RemoveAllItemsAction removeAllItemsAction = new RemoveAllItemsAction( this.mappingConfigurationConfigurationValuesTable); this.deleteAllRecordsButton.setIcon(VaadinIcons.TRASH); this.deleteAllRecordsButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); this.deleteAllRecordsButton.setDescription("Delete all values from the table below"); this.deleteAllRecordsButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); this.deleteAllRecordsButton.setVisible(buttonsVisible); this.deleteAllRecordsButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { IkasanMessageDialog dialog = new IkasanMessageDialog("Delete all records!", "This action will delete all source and target mapping configurations " + "from the database. Are you sure you would like to proceed?", removeAllItemsAction); UI.getCurrent().addWindow(dialog); } }); this.importMappingConfigurationButton.setIcon(VaadinIcons.UPLOAD_ALT); this.importMappingConfigurationButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); this.importMappingConfigurationButton.setDescription("Import mapping configuration values"); this.importMappingConfigurationButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); this.importMappingConfigurationButton.setVisible(buttonsVisible); this.importMappingConfigurationButton.addClickListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { MappingConfigurationValuesImportWindow dialog = new MappingConfigurationValuesImportWindow( mappingConfigurationService, mappingConfiguration, mappingConfigurationConfigurationValuesTable, systemEventService); UI.getCurrent().addWindow(dialog); } }); this.exportMappingConfigurationValuesButton.setIcon(VaadinIcons.DOWNLOAD_ALT); this.exportMappingConfigurationValuesButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY); this.exportMappingConfigurationValuesButton.setDescription("Export mapping configuration values"); this.exportMappingConfigurationValuesButton.addStyleName(ValoTheme.BUTTON_BORDERLESS); this.exportMappingConfigurationValuesButton.setVisible(buttonsVisible); FileDownloader fd = new FileDownloader(this.getMappingConfigurationValuesExportStream()); fd.extend(exportMappingConfigurationValuesButton); Label spacer = new Label(" ", ContentMode.HTML); controlsLayout.addComponent(spacer); controlsLayout.setExpandRatio(spacer, 0.84f); controlsLayout.addComponent(this.addNewRecordButton); controlsLayout.setExpandRatio(this.addNewRecordButton, 0.04f); controlsLayout.addComponent(this.deleteAllRecordsButton); controlsLayout.setExpandRatio(this.deleteAllRecordsButton, 0.04f); controlsLayout.addComponent(this.importMappingConfigurationButton); controlsLayout.setExpandRatio(this.importMappingConfigurationButton, 0.04f); controlsLayout.addComponent(this.exportMappingConfigurationValuesButton); controlsLayout.setExpandRatio(this.exportMappingConfigurationValuesButton, 0.04f); tableLayout.addComponent(controlsLayout); tableLayout.addComponent(this.mappingConfigurationConfigurationValuesTable); return tableLayout; }
From source file:org.jumpmind.metl.ui.views.admin.LoggingPanel.java
License:Open Source License
public LoggingPanel(ApplicationContext context, TabbedPanel tabbedPanel) { this.context = context; this.tabbedPanel = tabbedPanel; this.backgroundRefresherService = context.getBackgroundRefresherService(); if (LogUtils.isFileEnabled()) { logFile = new File(LogUtils.getLogFilePath()); }//from ww w.j ava2 s. c o m setSizeFull(); setSpacing(true); setMargin(true); HorizontalLayout topPanelLayout = new HorizontalLayout(); topPanelLayout.setWidth(100, Unit.PERCENTAGE); topPanelLayout.setSpacing(true); Button refreshButton = new Button("Refresh"); refreshButton.addClickListener(new ClickListener() { public void buttonClick(ClickEvent event) { refresh(); } }); topPanelLayout.addComponent(refreshButton); topPanelLayout.setComponentAlignment(refreshButton, Alignment.BOTTOM_LEFT); bufferSize = new TextField(); bufferSize.setImmediate(true); bufferSize.setWidth(5, Unit.EM); bufferSize.setValue("1000"); bufferSize.addValueChangeListener(new ValueChangeListener() { public void valueChange(ValueChangeEvent event) { refresh(); } }); topPanelLayout.addComponent(bufferSize); filter = new TextField(); filter.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON); filter.setInputPrompt("Filter"); filter.setIcon(FontAwesome.SEARCH); filter.setNullRepresentation(""); filter.setImmediate(true); filter.setTextChangeEventMode(TextChangeEventMode.LAZY); filter.setTextChangeTimeout(200); filter.addValueChangeListener(new ValueChangeListener() { public void valueChange(ValueChangeEvent event) { refresh(); } }); topPanelLayout.addComponent(filter); topPanelLayout.setComponentAlignment(filter, Alignment.BOTTOM_LEFT); autoRefreshOn = new CheckBox("Auto Refresh"); autoRefreshOn.setValue(true); autoRefreshOn.setImmediate(true); topPanelLayout.addComponent(autoRefreshOn); topPanelLayout.setComponentAlignment(autoRefreshOn, Alignment.BOTTOM_LEFT); Label spacer = new Label(); topPanelLayout.addComponent(spacer); topPanelLayout.setExpandRatio(spacer, 1); if (logFile != null && logFile.exists()) { Button downloadButton = new Button("Download log file"); downloadButton.addStyleName(ValoTheme.BUTTON_LINK); downloadButton.addStyleName(ValoTheme.BUTTON_SMALL); FileDownloader fileDownloader = new FileDownloader(getLogFileResource()); fileDownloader.extend(downloadButton); topPanelLayout.addComponent(downloadButton); topPanelLayout.setComponentAlignment(downloadButton, Alignment.BOTTOM_RIGHT); } addComponent(topPanelLayout); logPanel = new Panel("Log Output"); logPanel.setSizeFull(); logView = new Label("", ContentMode.HTML); logView.setSizeUndefined(); logPanel.setContent(logView); addComponent(logPanel); setExpandRatio(logPanel, 1); refresh(); backgroundRefresherService.register(this); }
From source file:org.jumpmind.metl.ui.views.ExploreDirectoryView.java
License:Open Source License
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 {// w w w . jav a 2s . c o m return new Label(file.getName()); } } else { return new Label(((DirectoryResource) itemId).getName()); } }
From source file:org.jumpmind.vaadin.ui.common.ReadOnlyTextAreaDialog.java
License:Open Source License
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); }/* ww w .j a v a 2 s . c o m*/ }, 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); } }
From source file:org.jumpmind.vaadin.ui.sqlexplorer.DbExportDialog.java
License:Open Source License
protected void buildFileDownloader() { if (fileDownloader != null) { fileDownloader.remove();//from w w w.ja v a2 s . c o m } fileDownloader = new FileDownloader(createResource()) { private static final long serialVersionUID = 1L; @Override public Resource getFileDownloadResource() { /* recreate the resource so the file name is regenerated */ return createResource(); } }; fileDownloader.extend(exportFileButton); }
From source file:org.lunifera.vaaclipse.ui.preferences.addon.internal.impexp.ExportPreferences.java
License:Open Source License
@SuppressWarnings("restriction") @Override/*from w ww . j a va2s . c om*/ protected void doAction() { // dlg.close(); List<PreferencesPage> selectedPages = getSelectedPages(); if (selectedPages.isEmpty()) { setStatusText("Preferences doesn't selected. Please select preferences above."); return; } IEclipsePreferences root = PreferencesService.getDefault().getRootNode(); ByteArrayOutputStream baos = new ByteArrayOutputStream(200); try { PreferencesService.getDefault().exportPreferences(root, new IPreferenceFilter[] { createFilter(selectedPages) }, baos); } catch (CoreException e) { logger.error("Exception when export preferences", e); return; } preferencesBytes = baos.toByteArray(); StringBuffer exportedPrefNames = toTextWithCatName(selectedPages); setStatusText("Preferences was exported: " + exportedPrefNames.toString()); if (downloadButton == null) { downloadButton = new Button(BaseTheme.BUTTON_LINK); downloadButton.addStyleName("download-button"); downloadButton.setCaption("Download preferences.epf"); layout.addComponent(downloadButton); FileDownloader fileDownloader = new FileDownloader(createResource()); fileDownloader.extend(downloadButton); } }
From source file:org.opennms.features.vaadin.jmxconfiggenerator.ui.ResultView.java
License:Open Source License
public ResultView() { // available content tabContentMap.put(OutputDataKey.JmxDataCollectionConfig, new TabContent(OutputDataKey.JmxDataCollectionConfig)); tabContentMap.put(OutputDataKey.SnmpGraphProperties, new TabContent(OutputDataKey.SnmpGraphProperties)); tabContentMap.put(OutputDataKey.CollectdConfigSnippet, new TabContent(OutputDataKey.CollectdConfigSnippet)); // we have to sort the keys, because map.keySet or map.values do not return a sorted // collection which results in non deterministic ui results. List<OutputDataKey> keyList = new ArrayList<>(tabContentMap.keySet()); Collections.sort(keyList, new Comparator<OutputDataKey>() { @Override/*from w ww.j a va 2 s .c o m*/ public int compare(OutputDataKey o1, OutputDataKey o2) { return o1.name().compareTo(o2.name()); } }); // add all tabs for (OutputDataKey eachKey : keyList) { TabContent eachContent = tabContentMap.get(eachKey); tabSheet.addTab(eachContent, eachContent.getCaption()); } tabSheet.setSizeFull(); tabSheet.setSelectedTab(0); // select first component! tabSheet.addStyleName(Reindeer.TABSHEET_BORDERLESS); buttonPanel.getNext().setCaption("download all"); buttonPanel.getNext().setDescription("Download a zip file containing the JMX datacollection configuration"); buttonPanel.getNext().setIcon(Config.Icons.BUTTON_SAVE); // this is a dummy resource as we are going to set the real // resource when entering the view. fileDownloader = new FileDownloader(new Resource() { @Override public String getMIMEType() { return "application/unknown"; } }); fileDownloader.extend(buttonPanel.getNext()); setSizeFull(); addComponent(tabSheet); addComponent(buttonPanel); setExpandRatio(tabSheet, 1); }