List of usage examples for com.vaadin.server FileResource FileResource
public FileResource(File sourceFile)
From source file:uk.q3c.krail.core.view.component.LocaleContainer.java
License:Apache License
/** * Loads the container with text from {@link Locale#getDisplayName(Locale)}, and an icon for the country flag if * there is one. If there is no image flag, the flag property is left as null. The result is that the combo * contains an entry for a country in the language of that country (for example Germany is always Deutsch * (Deutschland), regardless of the current locale). This means the user looking for a language will see it in its * most familiar form.//from w w w .j av a2s . c om */ @SuppressWarnings("unchecked") private void fillContainer() { addContainerProperty(PropertyName.NAME, String.class, null); addContainerProperty(PropertyName.FLAG, Resource.class, null); File webInfDir = ResourceUtils.configurationDirectory(); File iconsDir = new File(webInfDir, "icons"); File flagsDir = new File(iconsDir, "flags_iso"); File flagSizedDir = new File(flagsDir, getOptionFlagSize().toString()); for (Locale supportedLocale : supportedLocales) { String id = supportedLocale.toLanguageTag(); log.debug("Added supported locale with id: '{}'", id); Item item = addItem(id); item.getItemProperty(PropertyName.NAME).setValue(supportedLocale.getDisplayName(supportedLocale)); // if the directory is missing don't bother with file if (flagSizedDir.exists()) { String filename = supportedLocale.getCountry().toLowerCase() + ".png"; File file = new File(flagSizedDir, filename); if (file.exists()) { FileResource resource = new FileResource(file); item.getItemProperty(PropertyName.FLAG).setValue(resource); } else { log.warn("File {} for locale flag does not exist.", file.getAbsolutePath()); } } else { log.warn("{} directory for flags does not exist.", flagSizedDir.getAbsolutePath()); } } sort(new Object[] { PropertyName.NAME }, new boolean[] { true }); }
From source file:views.StandaloneTSVImport.java
License:Open Source License
private Component createTSVDownloadComponent(DesignType type, String info) { VerticalLayout v = new VerticalLayout(); v.setSpacing(true);/*from ww w . j av a 2 s .c o m*/ Label l = new Label(info); l.setWidth("300px"); v.addComponent(l); Button button = new Button("Download Example"); v.addComponent(button); String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); FileDownloader tsvDL = new FileDownloader( new FileResource(new File(basepath + "/WEB-INF/files/" + type.getFileName()))); tsvDL.extend(button); return v; }