use of com.haulmont.cuba.gui.Notifications in project cuba by cuba-platform.
the class BulkEditAction method actionPerform.
@Override
public void actionPerform(Component component) {
if (beforeActionPerformedHandler != null && !beforeActionPerformedHandler.beforeActionPerformed()) {
return;
}
UserSession userSession = AppBeans.get(UserSessionSource.class).getUserSession();
if (!userSession.isSpecificPermitted(BulkEditor.PERMISSION)) {
Messages messages = AppBeans.get(Messages.NAME);
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.ERROR).withCaption(messages.getMainMessage("accessDenied.message")).show();
return;
}
if (target.getSelected().isEmpty()) {
Messages messages = AppBeans.get(Messages.NAME);
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.HUMANIZED).withCaption(messages.getMainMessage("actions.BulkEdit.emptySelection")).show();
return;
}
OpenType openType = this.openType;
if (openType.getOpenMode() == OpenMode.DIALOG) {
ThemeConstantsManager themeManager = AppBeans.get(ThemeConstantsManager.NAME);
ThemeConstants theme = themeManager.getConstants();
openType = openType.copy().width(theme.get("cuba.gui.BulkEditAction.editorDialog.width")).height(theme.get("cuba.gui.BulkEditAction.editorDialog.height")).resizable(true);
}
Map<String, Object> params = ParamsMap.of().pair("metaClass", target.getDatasource().getMetaClass()).pair("selected", target.getSelected()).pair("exclude", exclude).pair("includeProperties", includeProperties != null ? includeProperties : Collections.EMPTY_LIST).pair("fieldValidators", fieldValidators).pair("modelValidators", modelValidators).pair("loadDynamicAttributes", loadDynamicAttributes).pair("useConfirmDialog", useConfirmDialog).pair("columnsMode", columnsMode).create();
WindowManager wm = ((WindowManager) getScreenContext(target.getFrame()).getScreens());
WindowInfo windowInfo = AppBeans.get(WindowConfig.class).getWindowInfo("bulkEditor");
Window bulkEditor = wm.openWindow(windowInfo, openType, params);
bulkEditor.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
target.getDatasource().refresh();
}
if (target instanceof Component.Focusable) {
((Component.Focusable) target).focus();
}
});
}
use of com.haulmont.cuba.gui.Notifications in project cuba by cuba-platform.
the class LocalizedTaskWrapper method handleTimeoutException.
@Override
public boolean handleTimeoutException() {
boolean handled = wrappedTask.handleTimeoutException();
if (handled || wrappedTask.getOwnerScreen() == null) {
Screens screens = getScreenContext().getScreens();
screens.remove(screen);
} else {
Screens screens = getScreenContext().getScreens();
screens.remove(screen);
Notifications notifications = getScreenContext().getNotifications();
Messages messages = AppBeans.get(Messages.NAME);
notifications.create(Notifications.NotificationType.WARNING).withCaption(messages.getMessage(LocalizedTaskWrapper.class, "backgroundWorkProgress.timeout")).withDescription(messages.getMessage(LocalizedTaskWrapper.class, "backgroundWorkProgress.timeoutMessage")).show();
handled = true;
}
return handled;
}
use of com.haulmont.cuba.gui.Notifications in project cuba by cuba-platform.
the class ScreenValidation method showValidationErrors.
/**
* Show validation alert with passed errors and first problem UI component.
*
* @param origin screen controller
* @param errors validation error
*/
public void showValidationErrors(FrameOwner origin, ValidationErrors errors) {
checkNotNullArgument(origin);
checkNotNullArgument(errors);
if (errors.isEmpty()) {
return;
}
StringBuilder buffer = new StringBuilder();
for (ValidationErrors.Item error : errors.getAll()) {
buffer.append(error.description).append("\n");
}
ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
String validationNotificationType = clientConfig.getValidationNotificationType();
if (validationNotificationType.endsWith("_HTML")) {
// HTML validation notification types are not supported
validationNotificationType = validationNotificationType.replace("_HTML", "");
}
Notifications notifications = getScreenContext(origin).getNotifications();
notifications.create(NotificationType.valueOf(validationNotificationType)).withCaption(messages.getMainMessage("validationFail.caption")).withDescription(buffer.toString()).show();
focusProblemComponent(errors);
}
use of com.haulmont.cuba.gui.Notifications in project cuba by cuba-platform.
the class WebNotificationFacet method show.
@Override
public void show() {
Frame owner = getOwner();
if (owner == null) {
throw new IllegalStateException("Notification is not attached to Frame");
}
Notifications notifications = UiControllerUtils.getScreenContext(owner.getFrameOwner()).getNotifications();
String caption = this.caption;
if (captionProvider != null) {
caption = captionProvider.get();
}
String description = this.description;
if (descriptionProvider != null) {
description = descriptionProvider.get();
}
notifications.create(type).withCaption(caption).withDescription(description).withHideDelayMs(delayMs).withContentMode(contentMode).withHtmlSanitizer(htmlSanitizerEnabled).withStyleName(styleName).withPosition(position).withCloseListener(e -> publish(CloseEvent.class, new CloseEvent(this))).show();
}
use of com.haulmont.cuba.gui.Notifications in project cuba by cuba-platform.
the class WebFileMultiUploadField method initComponent.
protected void initComponent(CubaFileUpload impl) {
impl.setMultiSelect(true);
Messages messages = beanLocator.get(Messages.NAME);
impl.setProgressWindowCaption(messages.getMainMessage("upload.uploadingProgressTitle"));
impl.setUnableToUploadFileMessage(messages.getMainMessage("upload.unableToUploadFile"));
impl.setCancelButtonCaption(messages.getMainMessage("upload.cancel"));
impl.setCaption(messages.getMainMessage("upload.submit"));
impl.setDropZonePrompt(messages.getMainMessage("upload.dropZonePrompt"));
impl.setDescription(null);
Configuration configuration = beanLocator.get(Configuration.NAME);
int maxUploadSizeMb = configuration.getConfig(ClientConfig.class).getMaxUploadSizeMb();
int maxSizeBytes = maxUploadSizeMb * BYTES_IN_MEGABYTE;
impl.setFileSizeLimit(maxSizeBytes);
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 receive file", e);
}
return outputStream;
});
impl.addStartedListener(event -> fireFileUploadStart(event.getFileName(), event.getContentLength()));
impl.addQueueUploadFinishedListener(event -> fireQueueUploadComplete());
impl.addSucceededListener(event -> {
files.put(tempFileId, event.getFileName());
fireFileUploadFinish(event.getFileName(), event.getContentLength());
});
impl.addFailedListener(event -> {
try {
// close and remove temp file
fileUploading.deleteFile(tempFileId);
tempFileId = null;
} catch (Exception e) {
if (e instanceof FileStorageException) {
FileStorageException fse = (FileStorageException) e;
if (fse.getType() != FileStorageException.Type.FILE_NOT_FOUND) {
LoggerFactory.getLogger(WebFileMultiUploadField.class).warn("Could not remove temp file {} after broken uploading", tempFileId);
}
}
LoggerFactory.getLogger(WebFileMultiUploadField.class).warn("Error while delete temp file {}", tempFileId);
}
fireFileUploadError(event.getFileName(), event.getContentLength(), event.getReason());
});
impl.addFileSizeLimitExceededListener(e -> {
Notifications notifications = getScreenContext(this).getNotifications();
notifications.create(NotificationType.WARNING).withCaption(messages.formatMainMessage("multiupload.filesizeLimitExceed", e.getFileName(), getFileSizeLimitString())).show();
});
impl.addFileExtensionNotAllowedListener(e -> {
Notifications notifications = getScreenContext(this).getNotifications();
notifications.create(NotificationType.WARNING).withCaption(messages.formatMainMessage("upload.fileIncorrectExtension.message", e.getFileName())).show();
});
}
Aggregations