Search in sources :

Example 1 with FileResource

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);
    }
}
Also used : Configuration(com.haulmont.cuba.core.global.Configuration) FileResource(com.vaadin.server.FileResource) Resource(com.vaadin.server.Resource) FileResource(com.vaadin.server.FileResource) VersionedThemeResource(com.haulmont.cuba.web.toolkit.VersionedThemeResource) WebConfig(com.haulmont.cuba.web.WebConfig) VersionedThemeResource(com.haulmont.cuba.web.toolkit.VersionedThemeResource) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) File(java.io.File)

Example 2 with FileResource

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);
}
Also used : FileResource(com.vaadin.server.FileResource) File(java.io.File)

Example 3 with FileResource

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);
    }
}
Also used : CacheException(net.sf.ehcache.CacheException) FileResource(com.vaadin.server.FileResource) FileDownloader(com.vaadin.server.FileDownloader)

Aggregations

FileResource (com.vaadin.server.FileResource)3 File (java.io.File)2 Configuration (com.haulmont.cuba.core.global.Configuration)1 ThemeConstants (com.haulmont.cuba.gui.theme.ThemeConstants)1 WebConfig (com.haulmont.cuba.web.WebConfig)1 VersionedThemeResource (com.haulmont.cuba.web.toolkit.VersionedThemeResource)1 FileDownloader (com.vaadin.server.FileDownloader)1 Resource (com.vaadin.server.Resource)1 CacheException (net.sf.ehcache.CacheException)1