use of com.haulmont.cuba.gui.theme.ThemeConstants in project cuba by cuba-platform.
the class WebFieldGroup method applyFieldDefaults.
protected void applyFieldDefaults(FieldConfigImpl fci) {
Component fieldComponent = fci.getComponentNN();
if (fieldComponent instanceof Field) {
Field cubaField = (Field) fieldComponent;
if (fci.getTargetCaption() != null) {
cubaField.setCaption(fci.getTargetCaption());
}
if (fci.getTargetDescription() != null) {
// we check empty for description since Vaadin components have "" description by default
cubaField.setDescription(fci.getTargetDescription());
}
if (cubaField instanceof HasInputPrompt && fci.getTargetInputPrompt() != null) {
((HasInputPrompt) cubaField).setInputPrompt(fci.getTargetInputPrompt());
}
if (fci.getTargetRequired() != null) {
cubaField.setRequired(fci.getTargetRequired());
}
if (fci.getTargetRequiredMessage() != null) {
cubaField.setRequiredMessage(fci.getTargetRequiredMessage());
}
if (fci.getTargetContextHelpText() != null) {
cubaField.setContextHelpText(fci.getTargetContextHelpText());
}
if (fci.getTargetContextHelpTextHtmlEnabled() != null) {
cubaField.setContextHelpTextHtmlEnabled(fci.getTargetContextHelpTextHtmlEnabled());
}
if (fci.getTargetContextHelpIconClickHandler() != null) {
cubaField.setContextHelpIconClickHandler(fci.getTargetContextHelpIconClickHandler());
}
if (fci.getTargetEditable() != null) {
cubaField.setEditable(fci.getTargetEditable());
}
if (fci.getTargetVisible() != null) {
cubaField.setVisible(fci.getTargetVisible());
}
if (cubaField instanceof Component.Focusable && fci.getTargetTabIndex() != null) {
((Component.Focusable) cubaField).setTabIndex(fci.getTargetTabIndex());
}
for (Field.Validator validator : fci.getTargetValidators()) {
cubaField.addValidator(validator);
}
if (fci.getTargetWidth() != null) {
fieldComponent.setWidth(fci.getTargetWidth());
} else {
if (App.isBound()) {
ThemeConstants theme = App.getInstance().getThemeConstants();
fieldComponent.setWidth(theme.get("cuba.web.WebFieldGroup.defaultFieldWidth"));
}
}
} else {
com.vaadin.ui.Field composition = fci.getCompositionNN();
if (fci.getTargetCaption() != null) {
composition.setCaption(fci.getTargetCaption());
}
if (fci.getTargetDescription() != null) {
((CubaFieldWrapper) composition).setDescription(fci.getTargetDescription());
}
if (fci.getTargetRequired() != null) {
composition.setRequired(fci.getTargetRequired());
}
if (fci.getTargetRequiredMessage() != null) {
composition.setRequiredError(fci.getTargetRequiredMessage());
}
if (fci.getTargetEditable() != null) {
composition.setReadOnly(!fci.getTargetEditable());
}
if (fci.getTargetVisible() != null) {
composition.setVisible(fci.getTargetVisible());
}
if (fci.getTargetWidth() != null) {
composition.setWidth(fci.getTargetWidth());
} else {
if (App.isBound()) {
ThemeConstants theme = App.getInstance().getThemeConstants();
composition.setWidth(theme.get("cuba.web.WebFieldGroup.defaultFieldWidth"));
}
}
}
if (fieldComponent instanceof Component.HasFormatter && fci.getTargetFormatter() != null) {
((Component.HasFormatter) fieldComponent).setFormatter(fci.getTargetFormatter());
}
if (StringUtils.isNotEmpty(fci.getTargetStylename())) {
fieldComponent.setStyleName(fci.getTargetStylename());
}
}
use of com.haulmont.cuba.gui.theme.ThemeConstants 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;
}
use of com.haulmont.cuba.gui.theme.ThemeConstants in project cuba by cuba-platform.
the class WebTimeField method updateWidth.
protected void updateWidth() {
if (!App.isBound()) {
return;
}
App app = App.getInstance();
ThemeConstants theme = app.getThemeConstants();
int digitWidth = theme.getInt("cuba.web.WebTimeField.digitWidth");
int digitPadding = theme.getInt("cuba.web.WebTimeField.digitPadding");
int separatorWidth = theme.getInt("cuba.web.WebTimeField.separatorWidth");
int partsCount = isAmPmUsed() ? 1 : 0;
int newWidth = isAmPmUsed() ? digitWidth + digitPadding : digitPadding;
if (showSeconds) {
newWidth = newWidth + digitWidth;
partsCount += 1;
}
switch(resolution) {
case HOUR:
partsCount += 1;
newWidth = digitWidth + newWidth;
break;
case MIN:
case SEC:
partsCount += 2;
newWidth = digitWidth * 2 + newWidth;
break;
}
newWidth += (partsCount - 1) * separatorWidth;
component.setWidth(newWidth + "px");
}
use of com.haulmont.cuba.gui.theme.ThemeConstants in project cuba by cuba-platform.
the class WebFtsField method adjustWidth.
protected void adjustWidth() {
if (getWidth() < 0) {
// todo rework - use CSS class
ThemeConstants theme = App.getInstance().getThemeConstants();
searchField.setWidth(theme.get("cuba.web.AppWindow.searchField.width"));
} else {
searchField.setWidth(100, Sizeable.Unit.PERCENTAGE);
}
}
use of com.haulmont.cuba.gui.theme.ThemeConstants in project cuba by cuba-platform.
the class IconResolverImpl method getThemeIcon.
protected String getThemeIcon(String iconName) {
ThemeConstants theme = App.getInstance().getThemeConstants();
String themeIcon = null;
for (String prefix : PROPERTY_PREFIXES) {
themeIcon = theme.get(prefix + iconName);
if (StringUtils.isNotEmpty(themeIcon)) {
break;
}
}
return themeIcon;
}
Aggregations