Search in sources :

Example 16 with Messages

use of com.haulmont.cuba.core.global.Messages 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 17 with Messages

use of com.haulmont.cuba.core.global.Messages in project cuba by cuba-platform.

the class WebRichTextArea method loadLabels.

protected Map<String, String> loadLabels() {
    Map<String, String> labels = new HashMap<>();
    Collection<String> locales = Arrays.asList(CubaRichTextAreaState.RICH_TEXT_AREA_FOREGROUND_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_BACKGROUND_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_BLACK_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_WHITE_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_RED_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_GREEN_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_YELLOW_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_BLUE_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_FONT_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_NORMAL_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_SIZE_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_BOLD_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_ITALIC_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_UNDERLINE_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_SUBSCRIPT_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_SUPERSCRIPT_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_JUSTIFYCENTER_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_JUSTIFYRIGHT_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_JUSTIFYLEFT_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_STRIKETHROUGH_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_INDENT_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_OUTDENT_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_HR_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_OL_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_UL_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_INSERTIMAGE_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_CREATELINK_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_REMOVELINK_LABEL, CubaRichTextAreaState.RICH_TEXT_AREA_REMOVEFORMAT_LABEL);
    Messages messages = AppBeans.get(Messages.NAME);
    for (String locale : locales) {
        labels.put(locale, messages.getMainMessage(locale));
    }
    return labels;
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) HashMap(java.util.HashMap)

Example 18 with Messages

use of com.haulmont.cuba.core.global.Messages in project cuba by cuba-platform.

the class WebRowsCount method onCollectionChanged.

protected void onCollectionChanged() {
    if (datasource == null) {
        return;
    }
    String msgKey;
    size = datasource.size();
    start = 0;
    boolean refreshSizeButton = false;
    if (datasource instanceof CollectionDatasource.SupportsPaging) {
        CollectionDatasource.SupportsPaging ds = (CollectionDatasource.SupportsPaging) datasource;
        if (samePage) {
            state = lastState == null ? State.FIRST_COMPLETE : lastState;
            start = ds.getFirstResult();
            samePage = false;
            refreshSizeButton = State.LAST.equals(state);
        } else if ((size == 0 || size < ds.getMaxResults()) && ds.getFirstResult() == 0) {
            state = State.FIRST_COMPLETE;
            lastState = state;
        } else if (size == ds.getMaxResults() && ds.getFirstResult() == 0) {
            state = State.FIRST_INCOMPLETE;
            lastState = state;
        } else if (size == ds.getMaxResults() && ds.getFirstResult() > 0) {
            state = State.MIDDLE;
            start = ds.getFirstResult();
            lastState = state;
        } else if (size < ds.getMaxResults() && ds.getFirstResult() > 0) {
            state = State.LAST;
            start = ds.getFirstResult();
            lastState = state;
        } else {
            state = State.FIRST_COMPLETE;
            lastState = state;
        }
    } else {
        state = State.FIRST_COMPLETE;
        lastState = state;
    }
    String countValue;
    switch(state) {
        case FIRST_COMPLETE:
            component.getCountButton().setVisible(false);
            component.getPrevButton().setVisible(false);
            component.getNextButton().setVisible(false);
            component.getFirstButton().setVisible(false);
            component.getLastButton().setVisible(false);
            if (size % 100 > 10 && size % 100 < 20) {
                msgKey = "table.rowsCount.msg2Plural1";
            } else {
                switch(size % 10) {
                    case 1:
                        msgKey = "table.rowsCount.msg2Singular";
                        break;
                    case 2:
                    case 3:
                    case 4:
                        msgKey = "table.rowsCount.msg2Plural2";
                        break;
                    default:
                        msgKey = "table.rowsCount.msg2Plural1";
                }
            }
            countValue = String.valueOf(size);
            break;
        case FIRST_INCOMPLETE:
            component.getCountButton().setVisible(true);
            component.getPrevButton().setVisible(false);
            component.getNextButton().setVisible(true);
            component.getFirstButton().setVisible(false);
            component.getLastButton().setVisible(true);
            msgKey = "table.rowsCount.msg1";
            countValue = countValue(start, size);
            break;
        case MIDDLE:
            component.getCountButton().setVisible(true);
            component.getPrevButton().setVisible(true);
            component.getNextButton().setVisible(true);
            component.getFirstButton().setVisible(true);
            component.getLastButton().setVisible(true);
            msgKey = "table.rowsCount.msg1";
            countValue = countValue(start, size);
            break;
        case LAST:
            component.getCountButton().setVisible(false);
            component.getPrevButton().setVisible(true);
            component.getNextButton().setVisible(false);
            component.getFirstButton().setVisible(true);
            component.getLastButton().setVisible(false);
            msgKey = "table.rowsCount.msg2Plural2";
            countValue = countValue(start, size);
            break;
        default:
            throw new UnsupportedOperationException();
    }
    Messages messages = AppBeans.get(Messages.NAME);
    component.getLabel().setValue(messages.formatMainMessage(msgKey, countValue));
    if (component.getCountButton().isVisible() && !refreshing || refreshSizeButton) {
        component.getCountButton().setCaption(messages.getMainMessage("table.rowsCount.msg3"));
        component.getCountButton().removeStyleName("c-paging-count-number");
        component.getCountButton().setEnabled(true);
    }
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Example 19 with Messages

use of com.haulmont.cuba.core.global.Messages in project cuba by cuba-platform.

the class FileDownloadHelper method formatFileSize.

/**
 * Format file size for displaying in bytes, KB, MB.
 *
 * @param longSize      size in bytes
 * @param decimalPos    maximum fraction digits
 * @return  formatted value
 */
public static String formatFileSize(long longSize, int decimalPos) {
    Messages messages = AppBeans.get(Messages.NAME);
    NumberFormat fmt = NumberFormat.getNumberInstance();
    if (decimalPos >= 0) {
        fmt.setMaximumFractionDigits(decimalPos);
    }
    final double size = longSize;
    double val = size / (1024 * 1024);
    if (val > 1) {
        return fmt.format(val).concat(" " + messages.getMessage(FileDownloadHelper.class, "fmtMb"));
    }
    val = size / 1024;
    if (val > 10) {
        return fmt.format(val).concat(" " + messages.getMessage(FileDownloadHelper.class, "fmtKb"));
    }
    return fmt.format(size).concat(" " + messages.getMessage(FileDownloadHelper.class, "fmtB"));
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) NumberFormat(java.text.NumberFormat)

Example 20 with Messages

use of com.haulmont.cuba.core.global.Messages in project cuba by cuba-platform.

the class CronValidator method validate.

@Override
public void validate(Object value) throws ValidationException {
    if (value != null) {
        ServerInfoService serverInfoService = AppBeans.get(ServerInfoService.NAME);
        Messages messages = AppBeans.get(Messages.NAME);
        try {
            new CronSequenceGenerator(value.toString(), serverInfoService.getTimeZone());
        } catch (Exception e) {
            throw new ValidationException(messages.getMessage(CronValidator.class, "validation.cronInvalid"));
        }
    }
}
Also used : ServerInfoService(com.haulmont.cuba.core.app.ServerInfoService) Messages(com.haulmont.cuba.core.global.Messages) ValidationException(com.haulmont.cuba.gui.components.ValidationException) CronSequenceGenerator(org.springframework.scheduling.support.CronSequenceGenerator) ValidationException(com.haulmont.cuba.gui.components.ValidationException)

Aggregations

Messages (com.haulmont.cuba.core.global.Messages)34 Configuration (com.haulmont.cuba.core.global.Configuration)4 ClientConfig (com.haulmont.cuba.client.ClientConfig)3 File (java.io.File)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2 ThemeConstants (com.haulmont.cuba.gui.theme.ThemeConstants)2 FileUploadingAPI (com.haulmont.cuba.gui.upload.FileUploadingAPI)2 AppUI (com.haulmont.cuba.web.AppUI)2 CubaButton (com.haulmont.cuba.web.toolkit.ui.CubaButton)2 CubaWindow (com.haulmont.cuba.web.toolkit.ui.CubaWindow)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 Pattern (java.util.regex.Pattern)2 MetaProperty (com.haulmont.chile.core.annotations.MetaProperty)1 EnumClass (com.haulmont.chile.core.datatypes.impl.EnumClass)1 Instance (com.haulmont.chile.core.model.Instance)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 AbstractInstance (com.haulmont.chile.core.model.impl.AbstractInstance)1