use of com.vaadin.server.FileResource in project cuba by cuba-platform.
the class WebComponentsHelper method getResource.
public static Resource getResource(String resURL) {
if (StringUtils.isEmpty(resURL))
return null;
if (resURL.startsWith("file:")) {
return new FileResource(new File(resURL.substring("file:".length())));
} else if (resURL.startsWith("jar:")) {
return new ClassResource(resURL.substring("jar:".length()));
} else if (resURL.startsWith("theme:")) {
String resourceId = resURL.substring("theme:".length());
Configuration configuration = AppBeans.get(Configuration.NAME);
WebConfig webConfig = configuration.getConfig(WebConfig.class);
if (webConfig.getUseFontIcons()) {
String fontIcon;
ThemeConstants themeConstants = App.getInstance().getThemeConstants();
String iconKey = "cuba.web." + StringUtils.replace(resourceId, "/", ".");
fontIcon = themeConstants.get(iconKey);
try {
Resource resource = getFontIconResource(fontIcon);
if (resource != null) {
return resource;
}
} catch (NoSuchFieldException | IllegalAccessException e) {
LoggerFactory.getLogger(WebComponentsHelper.class).warn("Unable to use font icon " + fontIcon);
}
}
return new VersionedThemeResource(resourceId);
} else if (resURL.contains("icon:")) {
try {
return getFontIconResource(resURL);
} catch (NoSuchFieldException | IllegalAccessException e) {
LoggerFactory.getLogger(WebComponentsHelper.class).warn("Unable to use font icon " + resURL);
}
return null;
} else {
return new VersionedThemeResource(resURL);
}
}
use of com.vaadin.server.FileResource in project cuba by cuba-platform.
the class FileIconProvider method getIconResource.
@Override
public Resource getIconResource(String iconPath) {
Preconditions.checkNotEmptyString(iconPath, "Icon path should not be empty");
String icon = iconPath.substring(FILE_PREFIX.length());
File iconFile = new File(icon);
if (!iconFile.exists()) {
throw new IllegalArgumentException("Icon file does not exist: " + icon);
}
return new FileResource(iconFile);
}
use of com.vaadin.server.FileResource in project ANNIS by korpling.
the class ExportPanel method showResult.
public void showResult(File currentTmpFile, Exception exportError) {
btExport.setEnabled(true);
btCancel.setEnabled(false);
progressBar.setVisible(false);
progressLabel.setValue("");
// copy the result to the class member in order to delete if
// when not longer needed
tmpOutputFile = currentTmpFile;
//
if (exportError instanceof CacheException | exportError instanceof IllegalStateException | exportError instanceof ClassCastException) {
Notification.show(exportError.getMessage(), Notification.Type.ERROR_MESSAGE);
} else if (tmpOutputFile == null) {
Notification.show("Could not create the Exporter", "The server logs might contain more information about this " + "so you should contact the provider of this ANNIS installation " + "for help.", Notification.Type.ERROR_MESSAGE);
} else if (exportError instanceof InterruptedException) {
// we were aborted, don't do anything
Notification.show("Export cancelled", Notification.Type.WARNING_MESSAGE);
} else {
if (downloader != null && btDownload.getExtensions().contains(downloader)) {
btDownload.removeExtension(downloader);
}
downloader = new FileDownloader(new FileResource(tmpOutputFile));
downloader.extend(btDownload);
btDownload.setEnabled(true);
Notification.show("Export finished", "Click on the button right to the export button to actually download the file.", Notification.Type.HUMANIZED_MESSAGE);
}
}
Aggregations