Search in sources :

Example 6 with Notifications

use of io.jmix.ui.Notifications in project jmix by jmix-framework.

the class EntityOpenAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() {
    if (!checkFieldValue())
        return;
    Object entity = entityPicker.getValue();
    if (entity != null && EntityValues.isSoftDeleted(entity)) {
        ScreenContext screenContext = ComponentsHelper.getScreenContext(entityPicker);
        Notifications notifications = screenContext.getNotifications();
        notifications.create(Notifications.NotificationType.HUMANIZED).withDescription(messages.getMessage("OpenAction.objectIsDeleted")).show();
        return;
    }
    MetaClass metaClass = entityPicker.getMetaClass();
    if (metaClass == null) {
        throw new DevelopmentException("Neither metaClass nor dataContainer/property is specified " + "for the EntityPicker", "action ID", getId());
    }
    EditorBuilder builder = screenBuilders.editor(entityPicker);
    builder = screenInitializer.initBuilder(builder);
    if (transformation != null) {
        builder.withTransformation(transformation);
    }
    Screen editor = builder.build();
    if (afterCommitHandler != null) {
        editor.addAfterCloseListener(afterCloseEvent -> {
            CloseAction closeAction = afterCloseEvent.getCloseAction();
            if (closeAction.equals(WINDOW_COMMIT_AND_CLOSE_ACTION)) {
                Object committedEntity = ((EditorScreen) editor).getEditedEntity();
                afterCommitHandler.accept((E) committedEntity);
            }
        });
    }
    screenInitializer.initScreen(editor);
    editor.show();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) EditorBuilder(io.jmix.ui.builder.EditorBuilder) Notifications(io.jmix.ui.Notifications) DevelopmentException(io.jmix.core.DevelopmentException)

Example 7 with Notifications

use of io.jmix.ui.Notifications in project jmix by jmix-framework.

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");
    }
    String validationNotificationType = screenProperties.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.getMessage("validationFail.caption")).withDescription(buffer.toString()).show();
    focusProblemComponent(errors);
}
Also used : Notifications(io.jmix.ui.Notifications)

Example 8 with Notifications

use of io.jmix.ui.Notifications in project jmix by jmix-framework.

the class AbstractSingleFileUploadField method onFileExtensionNotAllowed.

protected void onFileExtensionNotAllowed(JmixFileUpload.FileExtensionNotAllowedEvent e) {
    Notifications notifications = getScreenContext(this).getNotifications();
    notifications.create(Notifications.NotificationType.WARNING).withCaption(messages.formatMessage("", "upload.fileIncorrectExtension.message", e.getFileName())).show();
}
Also used : Notifications(io.jmix.ui.Notifications)

Example 9 with Notifications

use of io.jmix.ui.Notifications in project jmix by jmix-framework.

the class LayoutAnalyzerContextMenuProvider method initContextMenu.

public void initContextMenu(Screen screen, io.jmix.ui.component.Component contextMenuTarget) {
    if (screenProperties.isLayoutAnalyzerEnabled()) {
        ContextMenu contextMenu = new ContextMenu(contextMenuTarget.unwrap(AbstractComponent.class), true);
        MenuBar.MenuItem menuItem = contextMenu.addItem(messages.getMessage("actions.analyzeLayout"), c -> {
            LayoutAnalyzer analyzer = new LayoutAnalyzer();
            List<LayoutTip> tipsList = analyzer.analyze(screen);
            if (tipsList.isEmpty()) {
                Notifications notifications = UiControllerUtils.getScreenContext(screen).getNotifications();
                notifications.create(Notifications.NotificationType.HUMANIZED).withCaption("No layout problems found").show();
            } else {
                Screens screens = UiControllerUtils.getScreenContext(screen).getScreens();
                LayoutAnalyzerScreen layoutAnalyzerScreen = screens.create(LayoutAnalyzerScreen.class, OpenMode.DIALOG);
                layoutAnalyzerScreen.setLayoutTips(tipsList);
                layoutAnalyzerScreen.show();
            }
        });
        menuItem.setStyleName("jmix-cm-item");
    }
}
Also used : AbstractComponent(com.vaadin.ui.AbstractComponent) LayoutAnalyzerScreen(io.jmix.ui.app.core.dev.LayoutAnalyzerScreen) LayoutTip(io.jmix.ui.app.core.dev.LayoutTip) MenuBar(com.vaadin.ui.MenuBar) ContextMenu(io.jmix.ui.widget.addon.contextmenu.ContextMenu) LayoutAnalyzer(io.jmix.ui.app.core.dev.LayoutAnalyzer) Notifications(io.jmix.ui.Notifications) Screens(io.jmix.ui.Screens)

Example 10 with Notifications

use of io.jmix.ui.Notifications in project jmix by jmix-framework.

the class BulkEditAction method actionPerform.

@Override
public void actionPerform(Component component) {
    if (beforeActionPerformedHandler != null && !beforeActionPerformedHandler.beforeActionPerformed()) {
        return;
    }
    Security security = AppBeans.get(Security.class);
    if (!security.isSpecificPermitted(BulkEditor.PERMISSION)) {
        Messages messages = AppBeans.get(Messages.class);
        Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
        notifications.create(NotificationType.ERROR).withCaption(messages.getMessage("accessDenied.message")).show();
        return;
    }
    if (target.getSelected().isEmpty()) {
        Messages messages = AppBeans.get(Messages.class);
        Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
        notifications.create(NotificationType.HUMANIZED).withCaption(messages.getMessage("actions.BulkEdit.emptySelection")).show();
        return;
    }
    OpenType openType = this.openType;
    if (openType.getOpenMode() == OpenMode.DIALOG) {
        ThemeConstantsManager themeManager = AppBeans.get(ThemeConstantsManager.class);
        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 : Window(com.haulmont.cuba.gui.components.Window) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) Messages(io.jmix.core.Messages) ThemeConstantsManager(io.jmix.ui.theme.ThemeConstantsManager) Security(com.haulmont.cuba.core.global.Security) WindowManager(com.haulmont.cuba.gui.WindowManager) WindowInfo(io.jmix.ui.WindowInfo) WindowConfig(io.jmix.ui.WindowConfig) ThemeConstants(io.jmix.ui.theme.ThemeConstants) Notifications(io.jmix.ui.Notifications)

Aggregations

Notifications (io.jmix.ui.Notifications)24 MetaClass (io.jmix.core.metamodel.model.MetaClass)5 Screens (io.jmix.ui.Screens)4 Folder (com.haulmont.cuba.core.entity.Folder)2 Messages (io.jmix.core.Messages)2 ReportingException (io.jmix.reports.exception.ReportingException)2 AppUI (io.jmix.ui.AppUI)2 ScreenContext (io.jmix.ui.screen.ScreenContext)2 Nullable (javax.annotation.Nullable)2 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)1 AppFolder (com.haulmont.cuba.core.entity.AppFolder)1 Security (com.haulmont.cuba.core.global.Security)1 WindowManager (com.haulmont.cuba.gui.WindowManager)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1 Filter (com.haulmont.cuba.gui.components.Filter)1 Window (com.haulmont.cuba.gui.components.Window)1 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)1 SearchFolder (com.haulmont.cuba.security.entity.SearchFolder)1 ReportOutputDocument (com.haulmont.yarg.reporting.ReportOutputDocument)1