Search in sources :

Example 6 with WebConfig

use of com.haulmont.cuba.web.WebConfig 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 7 with WebConfig

use of com.haulmont.cuba.web.WebConfig in project cuba by cuba-platform.

the class WebFileMultiUploadField method initOldComponent.

protected void initOldComponent() {
    CubaMultiUpload impl = createOldComponent();
    ThemeConstants theme = App.getInstance().getThemeConstants();
    String width = theme.get("cuba.web.WebFileMultiUploadField.upload.width");
    String height = theme.get("cuba.web.WebFileMultiUploadField.upload.height");
    impl.setWidth(width);
    impl.setHeight(height);
    int buttonTextLeft = theme.getInt("cuba.web.WebFileMultiUploadField.buttonText.left");
    int buttonTextTop = theme.getInt("cuba.web.WebFileMultiUploadField.buttonText.top");
    impl.setButtonTextLeft(buttonTextLeft);
    impl.setButtonTextTop(buttonTextTop);
    impl.setButtonWidth(Integer.parseInt(width.replace("px", "")));
    impl.setButtonHeight(Integer.parseInt(height.replace("px", "")));
    Messages messages = AppBeans.get(Messages.NAME);
    impl.setCaption(messages.getMessage(AppConfig.getMessagesPack(), "multiupload.submit"));
    Configuration configuration = AppBeans.get(Configuration.NAME);
    impl.setFileSizeLimitMB(configuration.getConfig(ClientConfig.class).getMaxUploadSizeMb());
    WebConfig webConfig = configuration.getConfig(WebConfig.class);
    if (!webConfig.getUseFontIcons()) {
        impl.setButtonImage(new VersionedThemeResource("components/multiupload/images/multiupload-button.png"));
    } else {
        impl.setButtonImage(new VersionedThemeResource("components/multiupload/images/multiupload-button-font-icon.png"));
    }
    impl.setButtonStyles(theme.get("cuba.web.WebFileMultiUploadField.button.style"));
    impl.setButtonDisabledStyles(theme.get("cuba.web.WebFileMultiUploadField.button.disabled.style"));
    impl.setBootstrapFailureHandler(new CubaMultiUpload.BootstrapFailureHandler() {

        @Override
        public void loadWebResourcesFailed() {
            Messages messages = AppBeans.get(Messages.NAME);
            String resourcesLoadFailed = messages.getMessage(WebFileMultiUploadField.class, "multiupload.resources.notLoaded");
            WebWindowManager wm = App.getInstance().getWindowManager();
            wm.showNotification(resourcesLoadFailed, Frame.NotificationType.ERROR);
        }

        @Override
        public void flashNotInstalled() {
            Messages messages = AppBeans.get(Messages.NAME);
            String swfNotSupported = messages.getMessage(WebFileMultiUploadField.class, "multiupload.resources.swfNotSupported");
            WebWindowManager wm = App.getInstance().getWindowManager();
            wm.showNotification(swfNotSupported, Frame.NotificationType.ERROR);
        }
    });
    impl.setReceiver((filename, mimeType) -> {
        FileOutputStream outputStream;
        try {
            FileUploadingAPI.FileInfo fileInfo = fileUploading.createFile();
            tempFileId = fileInfo.getId();
            File tmpFile = fileInfo.getFile();
            outputStream = new FileOutputStream(tmpFile);
        } catch (Exception e) {
            throw new RuntimeException("Unable to open stream for file uploading", e);
        }
        return outputStream;
    });
    impl.addUploadListener(new CubaMultiUpload.UploadListener() {

        @Override
        public void fileUploadStart(String fileName, long contentLength) {
            fireFileUploadStart(fileName, contentLength);
        }

        @Override
        public void fileUploaded(String fileName, long contentLength) {
            files.put(tempFileId, fileName);
            fireFileUploadFinish(fileName, contentLength);
        }

        @Override
        public void queueUploadComplete() {
            fireQueueUploadComplete();
        }

        @Override
        public void errorNotify(String fileName, String message, CubaMultiUpload.UploadErrorType errorCode, long contentLength) {
            LoggerFactory.getLogger(WebFileMultiUploadField.class).warn("Error while uploading file '{}' with code '{}': {}", fileName, errorCode.getId(), message);
            Messages messages = AppBeans.get(Messages.NAME);
            WebWindowManager wm = App.getInstance().getWindowManager();
            switch(errorCode) {
                case QUEUE_LIMIT_EXCEEDED:
                    wm.showNotification(messages.getMessage(WebFileMultiUploadField.class, "multiupload.queueLimitExceed"), Frame.NotificationType.WARNING);
                    break;
                case INVALID_FILETYPE:
                    String invalidFiletypeMsg = messages.formatMainMessage("upload.fileIncorrectExtension.message", fileName);
                    wm.showNotification(invalidFiletypeMsg, Frame.NotificationType.WARNING);
                    break;
                case FILE_EXCEEDS_SIZE_LIMIT:
                    String warningMsg = messages.formatMessage(WebFileMultiUploadField.class, "multiupload.filesizeLimitExceed", fileName, getFileSizeLimitString());
                    wm.showNotification(warningMsg, Frame.NotificationType.WARNING);
                    break;
                case SECURITY_ERROR:
                    wm.showNotification(messages.getMessage(WebFileMultiUploadField.class, "multiupload.securityError"), Frame.NotificationType.WARNING);
                    break;
                case ZERO_BYTE_FILE:
                    wm.showNotification(messages.formatMessage(WebFileMultiUploadField.class, "multiupload.zerobyteFile", fileName), Frame.NotificationType.WARNING);
                    break;
                default:
                    String uploadError = messages.formatMessage(WebFileMultiUploadField.class, "multiupload.uploadError", fileName);
                    wm.showNotification(uploadError, Frame.NotificationType.ERROR);
                    fireFileUploadError(fileName, contentLength, new IOException("Upload error " + errorCode.name()));
                    break;
            }
        }
    });
    impl.setDescription(null);
    component = impl;
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) Configuration(com.haulmont.cuba.core.global.Configuration) WebConfig(com.haulmont.cuba.web.WebConfig) IOException(java.io.IOException) VersionedThemeResource(com.haulmont.cuba.web.toolkit.VersionedThemeResource) FileStorageException(com.haulmont.cuba.core.global.FileStorageException) IOException(java.io.IOException) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) CubaMultiUpload(com.haulmont.cuba.web.toolkit.ui.CubaMultiUpload) WebWindowManager(com.haulmont.cuba.web.WebWindowManager) FileUploadingAPI(com.haulmont.cuba.gui.upload.FileUploadingAPI) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 8 with WebConfig

use of com.haulmont.cuba.web.WebConfig in project cuba by cuba-platform.

the class WebAppWorkArea method createTabbedModeContainer.

protected HasTabSheetBehaviour createTabbedModeContainer() {
    Configuration configuration = AppBeans.get(Configuration.NAME);
    WebConfig webConfig = configuration.getConfig(WebConfig.class);
    if (webConfig.getMainTabSheetMode() == MainTabSheetMode.DEFAULT) {
        CubaTabSheet cubaTabSheet = new CubaTabSheet();
        tabbedContainer = cubaTabSheet;
        cubaTabSheet.setDragMode(LayoutDragMode.CLONE);
        cubaTabSheet.setDropHandler(new TabSheetReorderingDropHandler());
        Action.Handler actionHandler = createTabSheetActionHandler(cubaTabSheet);
        cubaTabSheet.addActionHandler(actionHandler);
    } else {
        CubaManagedTabSheet cubaManagedTabSheet = new CubaManagedTabSheet();
        tabbedContainer = cubaManagedTabSheet;
        cubaManagedTabSheet.setDragMode(LayoutDragMode.CLONE);
        cubaManagedTabSheet.setDropHandler(new TabSheetReorderingDropHandler());
        Action.Handler actionHandler = createTabSheetActionHandler(cubaManagedTabSheet);
        cubaManagedTabSheet.addActionHandler(actionHandler);
    }
    tabbedContainer.setHeight("100%");
    tabbedContainer.setStyleName(TABBED_CONTAINER_STYLENAME);
    tabbedContainer.addStyleName(ValoTheme.TABSHEET_FRAMED);
    tabbedContainer.addStyleName(ValoTheme.TABSHEET_PADDED_TABBAR);
    return tabbedContainer;
}
Also used : Action(com.vaadin.event.Action) Configuration(com.haulmont.cuba.core.global.Configuration) WebConfig(com.haulmont.cuba.web.WebConfig)

Example 9 with WebConfig

use of com.haulmont.cuba.web.WebConfig in project cuba by cuba-platform.

the class WebTasksWatchDog method getExecutionStatus.

@Override
protected ExecutionStatus getExecutionStatus(long actualTimeMs, TaskHandlerImpl taskHandler) {
    WebConfig webConfig = configuration.getConfig(WebConfig.class);
    long timeout = taskHandler.getTimeoutMs();
    if (timeout > 0 && (actualTimeMs - taskHandler.getStartTimeStamp()) > timeout) {
        return ExecutionStatus.TIMEOUT_EXCEEDED;
    }
    // kill tasks, which do not update status for latency milliseconds
    long latencyMs = TimeUnit.SECONDS.toMillis(webConfig.getClientBackgroundTasksLatencySeconds());
    if (timeout > 0 && (actualTimeMs - taskHandler.getStartTimeStamp()) > timeout + latencyMs) {
        return ExecutionStatus.SHOULD_BE_KILLED;
    }
    return ExecutionStatus.NORMAL;
}
Also used : WebConfig(com.haulmont.cuba.web.WebConfig)

Example 10 with WebConfig

use of com.haulmont.cuba.web.WebConfig in project cuba by cuba-platform.

the class CubaUIProvider method getTheme.

@Override
public String getTheme(UICreateEvent event) {
    // get theme from cookies before app ui initialized for smooth theme enabling
    WebConfig webConfig = configuration.getConfig(WebConfig.class);
    GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class);
    String appWindowTheme = webConfig.getAppWindowTheme();
    String userAppTheme = getCookieValue(event.getRequest().getCookies(), App.APP_THEME_COOKIE_PREFIX + globalConfig.getWebContextName());
    if (userAppTheme != null) {
        if (!Objects.equals(userAppTheme, appWindowTheme)) {
            // check theme support
            ThemeConstantsRepository themeRepository = AppBeans.get(ThemeConstantsRepository.NAME);
            Set<String> supportedThemes = themeRepository.getAvailableThemes();
            if (supportedThemes.contains(userAppTheme)) {
                return userAppTheme;
            }
        }
    }
    return super.getTheme(event);
}
Also used : GlobalConfig(com.haulmont.cuba.core.global.GlobalConfig) ThemeConstantsRepository(com.haulmont.cuba.gui.theme.ThemeConstantsRepository) WebConfig(com.haulmont.cuba.web.WebConfig)

Aggregations

WebConfig (com.haulmont.cuba.web.WebConfig)12 Configuration (com.haulmont.cuba.core.global.Configuration)6 ThemeConstants (com.haulmont.cuba.gui.theme.ThemeConstants)3 VersionedThemeResource (com.haulmont.cuba.web.toolkit.VersionedThemeResource)3 FileResource (com.vaadin.server.FileResource)2 Resource (com.vaadin.server.Resource)2 File (java.io.File)2 IOException (java.io.IOException)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)1 GlobalConfig (com.haulmont.cuba.core.global.GlobalConfig)1 Messages (com.haulmont.cuba.core.global.Messages)1 ThemeConstantsRepository (com.haulmont.cuba.gui.theme.ThemeConstantsRepository)1 FileUploadingAPI (com.haulmont.cuba.gui.upload.FileUploadingAPI)1 WebWindowManager (com.haulmont.cuba.web.WebWindowManager)1 CubaAuthProvider (com.haulmont.cuba.web.auth.CubaAuthProvider)1 WebAuthConfig (com.haulmont.cuba.web.auth.WebAuthConfig)1 HttpRequestFilter (com.haulmont.cuba.web.security.HttpRequestFilter)1 CubaFileDownloader (com.haulmont.cuba.web.toolkit.ui.CubaFileDownloader)1 CubaMultiUpload (com.haulmont.cuba.web.toolkit.ui.CubaMultiUpload)1