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"));
}
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")));
}
}
}
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);
}
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();
}
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);
}
Aggregations