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();
}
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);
}
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();
}
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");
}
}
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();
}
});
}
Aggregations