Search in sources :

Example 51 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 52 with Messages

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

the class WebRelatedEntities method refreshNavigationActions.

protected void refreshNavigationActions() {
    ComponentContainer actionContainer = (ComponentContainer) vPopupComponent;
    actionContainer.removeAllComponents();
    actionOrder.clear();
    if (listComponent != null) {
        MetaClass metaClass = getMetaClass(listComponent);
        Pattern excludePattern = null;
        if (excludeRegex != null) {
            excludePattern = Pattern.compile(excludeRegex);
        }
        for (MetaProperty metaProperty : metaClass.getProperties()) {
            if (relatedEntitiesSecurity.isSuitableProperty(metaProperty, metaClass) && (excludePattern == null || !excludePattern.matcher(metaProperty.getName()).matches())) {
                addNavigationAction(metaClass, metaProperty);
            }
        }
        if (actionContainer.getComponentCount() == 0) {
            Messages messages = beanLocator.get(Messages.NAME);
            actionContainer.addComponent(new Label(messages.getMainMessage("actions.Related.Empty")));
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Messages(com.haulmont.cuba.core.global.Messages) MetaClass(com.haulmont.chile.core.model.MetaClass) ComponentContainer(com.vaadin.ui.ComponentContainer) Label(com.vaadin.ui.Label) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 53 with Messages

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

the class LogWindow method initUI.

protected void initUI() {
    ClientConfig clientConfig = AppBeans.<Configuration>get(Configuration.NAME).getConfig(ClientConfig.class);
    String closeShortcut = clientConfig.getCloseShortcut();
    KeyCombination closeCombination = KeyCombination.create(closeShortcut);
    com.vaadin.event.ShortcutAction closeShortcutAction = new com.vaadin.event.ShortcutAction("closeShortcutAction", closeCombination.getKey().getCode(), KeyCombination.Modifier.codes(closeCombination.getModifiers()));
    addActionHandler(new com.vaadin.event.Action.Handler() {

        @Override
        public com.vaadin.event.Action[] getActions(Object target, Object sender) {
            return new com.vaadin.event.Action[] { closeShortcutAction };
        }

        @Override
        public void handleAction(com.vaadin.event.Action action, Object sender, Object target) {
            if (Objects.equals(action, closeShortcutAction)) {
                close();
            }
        }
    });
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setMargin(false);
    layout.setSizeFull();
    setContent(layout);
    Panel scrollablePanel = new Panel();
    scrollablePanel.setSizeFull();
    VerticalLayout scrollContent = new VerticalLayout();
    scrollContent.setMargin(false);
    scrollContent.setSpacing(false);
    scrollContent.setSizeUndefined();
    scrollablePanel.setContent(scrollContent);
    final Label label = new Label();
    label.setContentMode(ContentMode.HTML);
    label.setValue(writeLog());
    label.setSizeUndefined();
    label.setStyleName("c-log-content");
    ((Layout) scrollablePanel.getContent()).addComponent(label);
    HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setMargin(false);
    topLayout.setSpacing(false);
    topLayout.setWidth("100%");
    topLayout.setHeightUndefined();
    Messages messages = AppBeans.get(Messages.NAME);
    Button refreshBtn = new CubaButton(messages.getMessage(getClass(), "logWindow.refreshBtn"), event -> label.setValue(writeLog()));
    topLayout.addComponent(refreshBtn);
    layout.addComponent(topLayout);
    layout.addComponent(scrollablePanel);
    layout.setExpandRatio(scrollablePanel, 1.0f);
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) KeyCombination(com.haulmont.cuba.gui.components.KeyCombination) CubaButton(com.haulmont.cuba.web.widgets.CubaButton) CubaButton(com.haulmont.cuba.web.widgets.CubaButton) ClientConfig(com.haulmont.cuba.client.ClientConfig)

Example 54 with Messages

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

the class PresentationEditor method initLayout.

protected void initLayout() {
    ThemeConstants theme = App.getInstance().getThemeConstants();
    VerticalLayout root = new VerticalLayout();
    root.setWidthUndefined();
    root.setSpacing(true);
    root.setMargin(false);
    setContent(root);
    messages = AppBeans.get(Messages.class);
    nameField = new TextField(messages.getMainMessage("PresentationsEditor.name"));
    nameField.setWidth(theme.get("cuba.web.PresentationEditor.name.width"));
    nameField.setValue(getPresentationCaption());
    root.addComponent(nameField);
    autoSaveField = new CheckBox();
    autoSaveField.setCaption(messages.getMainMessage("PresentationsEditor.autoSave"));
    autoSaveField.setValue(BooleanUtils.isTrue(presentation.getAutoSave()));
    root.addComponent(autoSaveField);
    defaultField = new CheckBox();
    defaultField.setCaption(messages.getMainMessage("PresentationsEditor.default"));
    defaultField.setValue(presentation.getId().equals(component.getDefaultPresentationId()));
    root.addComponent(defaultField);
    if (allowGlobalPresentations) {
        globalField = new CheckBox();
        globalField.setCaption(messages.getMainMessage("PresentationsEditor.global"));
        globalField.setValue(!isNew && presentation.getUser() == null);
        root.addComponent(globalField);
    }
    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setMargin(false);
    buttons.setSpacing(true);
    buttons.setWidthUndefined();
    root.addComponent(buttons);
    root.setComponentAlignment(buttons, Alignment.MIDDLE_LEFT);
    Button commitButton = new CubaButton(messages.getMainMessage("PresentationsEditor.save"));
    commitButton.addClickListener(event -> {
        if (validate()) {
            commit();
            forceClose();
        }
    });
    buttons.addComponent(commitButton);
    Button closeButton = new CubaButton(messages.getMainMessage("PresentationsEditor.close"));
    closeButton.addClickListener(event -> forceClose());
    buttons.addComponent(closeButton);
    nameField.focus();
}
Also used : ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) Messages(com.haulmont.cuba.core.global.Messages) CubaButton(com.haulmont.cuba.web.widgets.CubaButton) CubaButton(com.haulmont.cuba.web.widgets.CubaButton)

Example 55 with Messages

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

the class WebV8AbstractField method validate.

@Override
public void validate() throws ValidationException {
    if (hasValidationError()) {
        setValidationError(null);
    }
    if (!isVisibleRecursive() || !isEditableWithParent() || !isEnabledRecursive()) {
        return;
    }
    try {
        // if we cannot convert current presentation value into model - UI value is invalid
        convertToModel(component.getValue());
    } catch (ConversionException ce) {
        LoggerFactory.getLogger(getClass()).trace("Unable to convert presentation value to model", ce);
        setValidationError(ce.getLocalizedMessage());
        throw new ValidationException(ce.getLocalizedMessage());
    }
    if (isEmpty() && isRequired()) {
        String requiredMessage = getRequiredMessage();
        if (requiredMessage == null) {
            Messages messages = beanLocator.get(Messages.NAME);
            requiredMessage = messages.getMainMessage("validationFail.defaultRequiredMessage");
        }
        throw new RequiredValueMissingException(requiredMessage, this);
    }
    V value = getValue();
    triggerValidators(value);
}
Also used : ConversionException(com.haulmont.cuba.gui.components.data.ConversionException) Messages(com.haulmont.cuba.core.global.Messages)

Aggregations

Messages (com.haulmont.cuba.core.global.Messages)56 ClientConfig (com.haulmont.cuba.client.ClientConfig)7 Configuration (com.haulmont.cuba.core.global.Configuration)7 Notifications (com.haulmont.cuba.gui.Notifications)5 Icons (com.haulmont.cuba.gui.icons.Icons)4 CubaButton (com.haulmont.cuba.web.widgets.CubaButton)4 File (java.io.File)4 MetaClass (com.haulmont.chile.core.model.MetaClass)3 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)3 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)3 WindowManager (com.haulmont.cuba.gui.WindowManager)3 ThemeConstants (com.haulmont.cuba.gui.theme.ThemeConstants)3 FileUploadingAPI (com.haulmont.cuba.gui.upload.FileUploadingAPI)3 UserSession (com.haulmont.cuba.security.global.UserSession)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 Locale (java.util.Locale)3 MetaProperty (com.haulmont.chile.core.annotations.MetaProperty)2 Metadata (com.haulmont.cuba.core.global.Metadata)2 Dialogs (com.haulmont.cuba.gui.Dialogs)2