use of com.haulmont.cuba.core.global.Configuration 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.core.global.Configuration 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;
}
use of com.haulmont.cuba.core.global.Configuration in project cuba by cuba-platform.
the class DesktopAbstractUploadComponent method getFileSizeLimitString.
protected String getFileSizeLimitString() {
String fileSizeLimitString;
if (fileSizeLimit > 0) {
if (fileSizeLimit % BYTES_IN_MEGABYTE == 0) {
fileSizeLimitString = String.valueOf(fileSizeLimit / BYTES_IN_MEGABYTE);
} else {
Datatype<Double> doubleDatatype = Datatypes.getNN(Double.class);
double fileSizeInMb = fileSizeLimit / ((double) BYTES_IN_MEGABYTE);
fileSizeLimitString = doubleDatatype.format(fileSizeInMb);
}
} else {
Configuration configuration = AppBeans.get(Configuration.NAME);
fileSizeLimitString = String.valueOf(configuration.getConfig(ClientConfig.class).getMaxUploadSizeMb());
}
return fileSizeLimitString;
}
use of com.haulmont.cuba.core.global.Configuration in project cuba by cuba-platform.
the class FontDialog method initUI.
private void initUI() {
Configuration configuration = AppBeans.get(Configuration.NAME);
DesktopConfig desktopConfig = configuration.getConfig(DesktopConfig.class);
setIconImage(null);
setIconImages(null);
setPreferredSize(new Dimension(400, 220));
setSize(new Dimension(400, 220));
setMinimumSize(new Dimension(380, 200));
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout(0, 5));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
// font properties panel
JPanel fontPrefsPanel = new JPanel();
fontPrefsPanel.setLayout(new BoxLayout(fontPrefsPanel, BoxLayout.X_AXIS));
fontFamilyBox = new JComboBox();
fontFamilyBox.setPreferredSize(new Dimension(160, -1));
String[] availableFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
fontFamilyBox.setModel(new DefaultComboBoxModel<>(availableFonts));
fontSizeBox = new JComboBox();
fontSizeBox.setPreferredSize(new Dimension(60, -1));
fontSizeBox.setMaximumSize(new Dimension(60, Integer.MAX_VALUE));
fontSizeBox.setMinimumSize(new Dimension(60, 0));
fontSizeBox.setModel(new ListComboBoxModel<>(desktopConfig.getAvailableFontSizes()));
DesktopResources resources = App.getInstance().getResources();
boldToggle = new JToggleButton(resources.getIcon("font/bold.png"));
italicToggle = new JToggleButton(resources.getIcon("font/italic.png"));
underlineToggle = new JToggleButton(resources.getIcon("font/underline.png"));
fontPrefsPanel.add(fontFamilyBox);
fontPrefsPanel.add(fontSizeBox);
fontPrefsPanel.add(boldToggle);
fontPrefsPanel.add(italicToggle);
fontPrefsPanel.add(underlineToggle);
if (editFont != null) {
fontFamilyBox.setSelectedItem(editFont.getFamily());
fontSizeBox.setSelectedItem(editFont.getSize());
// toggle buttons
Map<TextAttribute, ?> attributes = editFont.getAttributes();
boldToggle.setSelected((editFont.getStyle() & Font.BOLD) == Font.BOLD);
italicToggle.setSelected((editFont.getStyle() & Font.ITALIC) == Font.ITALIC);
underlineToggle.setSelected(attributes.get(TextAttribute.UNDERLINE) == TextAttribute.UNDERLINE_ON);
} else {
fontFamilyBox.setSelectedIndex(0);
fontSizeBox.setSelectedIndex(0);
}
initListeners();
contentPane.add(fontPrefsPanel, BorderLayout.NORTH);
// preview panel
JPanel previewPanel = new JPanel();
previewPanel.setLayout(new GridBagLayout());
previewPanel.setPreferredSize(new Dimension(-1, 120));
previewPanel.setMinimumSize(new Dimension(0, 120));
previewPanel.setSize(-1, 120);
previewLabel = new JLabel("ABCDEFG abcdefg");
previewPanel.add(previewLabel);
previewLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
if (editFont != null)
previewLabel.setFont(editFont);
CollapsiblePanel groupBox = new CollapsiblePanel(previewPanel);
groupBox.setCollapsible(false);
groupBox.setCaption(messages.getMessage(getClass(), "FontDialog.preview"));
contentPane.add(groupBox, BorderLayout.CENTER);
// buttons panel
JPanel buttonsPanel = new JPanel();
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
JButton okBtn = new JButton(new AbstractAction(messages.getMessage(getClass(), "actions.Ok"), resources.getIcon("icons/ok.png")) {
@Override
public void actionPerformed(ActionEvent e) {
result = compileFont();
closeDialog();
}
});
okBtn.setPreferredSize(new Dimension(0, DesktopComponentsHelper.BUTTON_HEIGHT));
JButton cancelBtn = new JButton(new AbstractAction(messages.getMessage(getClass(), "actions.Cancel"), resources.getIcon("icons/cancel.png")) {
@Override
public void actionPerformed(ActionEvent e) {
closeDialog();
}
});
cancelBtn.setPreferredSize(new Dimension(0, DesktopComponentsHelper.BUTTON_HEIGHT));
buttonsPanel.add(okBtn);
buttonsPanel.add(cancelBtn);
contentPane.add(buttonsPanel, BorderLayout.SOUTH);
initToolTips();
setContentPane(contentPane);
pack();
applyLocation();
}
use of com.haulmont.cuba.core.global.Configuration in project cuba by cuba-platform.
the class SwingXTableSettings method loadFontPreferences.
protected void loadFontPreferences(Element element) {
// load font preferences
String fontFamily = element.attributeValue("fontFamily");
String fontSize = element.attributeValue("fontSize");
String fontStyle = element.attributeValue("fontStyle");
String fontUnderline = element.attributeValue("fontUnderline");
if (!StringUtils.isBlank(fontFamily) && !StringUtils.isBlank(fontSize) && !StringUtils.isBlank(fontUnderline) && !StringUtils.isBlank(fontStyle)) {
try {
int size = Integer.parseInt(fontSize);
int style = Integer.parseInt(fontStyle);
String[] availableFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
int fontIndex = Arrays.asList(availableFonts).indexOf(fontFamily);
if (fontIndex < 0) {
log.debug("Unsupported font family, font settings not loaded");
return;
}
Configuration configuration = AppBeans.get(Configuration.NAME);
DesktopConfig desktopConfig = configuration.getConfig(DesktopConfig.class);
int sizeIndex = desktopConfig.getAvailableFontSizes().indexOf(size);
if (sizeIndex < 0) {
log.debug("Unsupported font size, font settings not loaded");
return;
}
Boolean underline = BooleanUtils.toBooleanObject(fontUnderline);
@SuppressWarnings("MagicConstant") Font font = new Font(fontFamily, style, size);
if (underline != null && Boolean.TRUE.equals(underline)) {
Map<TextAttribute, Integer> attributes = new HashMap<>();
attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
font = font.deriveFont(attributes);
}
table.setFont(font);
} catch (NumberFormatException ex) {
log.debug("Broken font definition in user setting");
}
}
}
Aggregations