Search in sources :

Example 1 with Notifications

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();
        }
    });
}
Also used : UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) Messages(com.haulmont.cuba.core.global.Messages) ThemeConstantsManager(com.haulmont.cuba.gui.theme.ThemeConstantsManager) WindowManager(com.haulmont.cuba.gui.WindowManager) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) UserSession(com.haulmont.cuba.security.global.UserSession) Notifications(com.haulmont.cuba.gui.Notifications)

Example 2 with Notifications

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;
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) Screens(com.haulmont.cuba.gui.Screens) Notifications(com.haulmont.cuba.gui.Notifications)

Example 3 with Notifications

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);
}
Also used : ClientConfig(com.haulmont.cuba.client.ClientConfig) Notifications(com.haulmont.cuba.gui.Notifications)

Example 4 with Notifications

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();
}
Also used : NotificationFacet(com.haulmont.cuba.gui.components.NotificationFacet) Frame(com.haulmont.cuba.gui.components.Frame) NotificationType(com.haulmont.cuba.gui.Notifications.NotificationType) Button(com.haulmont.cuba.gui.components.Button) ContentMode(com.haulmont.cuba.gui.components.ContentMode) Supplier(java.util.function.Supplier) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) Consumer(java.util.function.Consumer) Subscription(com.haulmont.bali.events.Subscription) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) Notifications(com.haulmont.cuba.gui.Notifications) WebAbstractFacet(com.haulmont.cuba.web.gui.WebAbstractFacet) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) Component(com.haulmont.cuba.gui.components.Component) Action(com.haulmont.cuba.gui.components.Action) Nullable(javax.annotation.Nullable) UiControllerUtils(com.haulmont.cuba.gui.screen.UiControllerUtils) Frame(com.haulmont.cuba.gui.components.Frame) Notifications(com.haulmont.cuba.gui.Notifications)

Example 5 with Notifications

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();
    });
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) Configuration(com.haulmont.cuba.core.global.Configuration) FileUploadingAPI(com.haulmont.cuba.gui.upload.FileUploadingAPI) FileOutputStream(java.io.FileOutputStream) ClientConfig(com.haulmont.cuba.client.ClientConfig) FileStorageException(com.haulmont.cuba.core.global.FileStorageException) File(java.io.File) Notifications(com.haulmont.cuba.gui.Notifications) FileStorageException(com.haulmont.cuba.core.global.FileStorageException)

Aggregations

Notifications (com.haulmont.cuba.gui.Notifications)14 Messages (com.haulmont.cuba.core.global.Messages)6 MetaClass (com.haulmont.chile.core.model.MetaClass)3 Entity (com.haulmont.cuba.core.entity.Entity)3 NotificationType (com.haulmont.cuba.gui.Notifications.NotificationType)3 ClientConfig (com.haulmont.cuba.client.ClientConfig)2 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)2 Dialogs (com.haulmont.cuba.gui.Dialogs)2 WindowManager (com.haulmont.cuba.gui.WindowManager)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)2 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 ExcelExportFormat (com.haulmont.cuba.gui.export.ExcelExportFormat)2 ExcelExporter (com.haulmont.cuba.gui.export.ExcelExporter)2 ExportDisplay (com.haulmont.cuba.gui.export.ExportDisplay)2 CubaIcon (com.haulmont.cuba.gui.icons.CubaIcon)2 Icons (com.haulmont.cuba.gui.icons.Icons)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Subscription (com.haulmont.bali.events.Subscription)1