mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-02 19:27:57 +08:00
PL-9608 Ability to override error notification for Window validation
This commit is contained in:
parent
6f38526f8d
commit
c7784745c7
@ -373,4 +373,14 @@ public interface ClientConfig extends Config {
|
||||
@Property("cuba.gui.suggestionField.asyncSearchDelayMs")
|
||||
@DefaultInt(300)
|
||||
int getSuggestionFieldAsyncSearchDelayMs();
|
||||
|
||||
/**
|
||||
* Standard Window validation error notification type.
|
||||
*
|
||||
* @return one of com.haulmont.cuba.gui.components.Frame.NotificationType values
|
||||
*/
|
||||
@SuppressWarnings("JavadocReference")
|
||||
@Property("cuba.gui.validationNotificationType")
|
||||
@Default("TRAY")
|
||||
String getValidationNotificationType();
|
||||
}
|
@ -202,25 +202,16 @@ public class DesktopFrame
|
||||
|
||||
DesktopComponentsHelper.focusProblemComponent(errors);
|
||||
|
||||
showValidationErrors(errors);
|
||||
Window window = ComponentsHelper.getWindow(wrapper);
|
||||
if (window instanceof AbstractFrame) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
((AbstractFrame) window).showValidationErrors(errors);
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void showValidationErrors(final ValidationErrors errors) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (ValidationErrors.Item error : errors.getAll()) {
|
||||
buffer.append(error.description).append("\n");
|
||||
}
|
||||
showNotification(
|
||||
messages.getMainMessage("validationFail.caption"),
|
||||
buffer.toString(),
|
||||
NotificationType.HUMANIZED
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private DesktopWindowManager getWindowManager() {
|
||||
return DesktopComponentsHelper.getTopLevelFrame((Frame) this).getWindowManager();
|
||||
}
|
||||
|
@ -1392,25 +1392,13 @@ public class DesktopWindow implements Window, Component.Disposable,
|
||||
|
||||
DesktopComponentsHelper.focusProblemComponent(errors);
|
||||
|
||||
showValidationErrors(errors);
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
delegate.showValidationErrors(errors);
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void showValidationErrors(final ValidationErrors errors) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (ValidationErrors.Item error : errors.getAll()) {
|
||||
buffer.append(error.description).append("\n");
|
||||
}
|
||||
showNotification(
|
||||
messages.getMainMessage("validationFail.caption"),
|
||||
buffer.toString(),
|
||||
NotificationType.HUMANIZED
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionsPermissions getActionsPermissions() {
|
||||
return actionsPermissions;
|
||||
|
@ -16,7 +16,10 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
import com.haulmont.cuba.client.ClientConfig;
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.Configuration;
|
||||
import com.haulmont.cuba.core.global.DevelopmentException;
|
||||
import com.haulmont.cuba.core.global.Messages;
|
||||
import com.haulmont.cuba.gui.DialogParams;
|
||||
@ -409,6 +412,24 @@ public class AbstractFrame implements Frame, Frame.Wrapper, Component.Wrapper, C
|
||||
return frame.validateAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show validation errors alert. Can be overriden in subclasses.
|
||||
*
|
||||
* @param errors the list of validation errors. Caller fills it by errors found during the default validation.
|
||||
*/
|
||||
public void showValidationErrors(ValidationErrors errors) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (ValidationErrors.Item error : errors.getAll()) {
|
||||
buffer.append(error.description).append("\n");
|
||||
}
|
||||
|
||||
Configuration configuration = AppBeans.get(Configuration.NAME);
|
||||
ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
|
||||
|
||||
NotificationType notificationType = NotificationType.valueOf(clientConfig.getValidationNotificationType());
|
||||
showNotification(messages.getMainMessage("validationFail.caption"), buffer.toString(), notificationType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link WindowManager.OpenType} or {@link Window#getDialogOptions()} from screen controller
|
||||
*/
|
||||
|
@ -202,6 +202,12 @@ public class WindowDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
public void showValidationErrors(ValidationErrors errors) {
|
||||
if (wrapper instanceof AbstractWindow) {
|
||||
((AbstractWindow) wrapper).showValidationErrors(errors);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean preClose(String actionId) {
|
||||
if (wrapper instanceof AbstractWindow) {
|
||||
return ((AbstractWindow) wrapper).preClose(actionId);
|
||||
|
@ -390,23 +390,13 @@ public class WebWindow implements Window, Component.Wrapper,
|
||||
if (errors.isEmpty())
|
||||
return true;
|
||||
|
||||
showValidationErrors(errors);
|
||||
delegate.showValidationErrors(errors);
|
||||
|
||||
WebComponentsHelper.focusProblemComponent(errors);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void showValidationErrors(ValidationErrors errors) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (ValidationErrors.Item error : errors.getAll()) {
|
||||
buffer.append(error.description).append("\n");
|
||||
}
|
||||
|
||||
showNotification(messages.getMessage(WebWindow.class, "validationFail.caption"),
|
||||
buffer.toString(), NotificationType.TRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebWindowManager getWindowManager() {
|
||||
return windowManager;
|
||||
|
@ -18,7 +18,6 @@ package com.haulmont.cuba.web.gui.components;
|
||||
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.Messages;
|
||||
import com.haulmont.cuba.gui.ComponentsHelper;
|
||||
import com.haulmont.cuba.gui.DialogParams;
|
||||
import com.haulmont.cuba.gui.FrameContext;
|
||||
@ -240,24 +239,16 @@ public class WebFrame extends WebVBoxLayout implements Frame, WrappedFrame {
|
||||
if (errors.isEmpty())
|
||||
return true;
|
||||
|
||||
showValidationErrors(errors);
|
||||
Window window = ComponentsHelper.getWindow(wrapper);
|
||||
if (window instanceof AbstractFrame) {
|
||||
((AbstractFrame) window).showValidationErrors(errors);
|
||||
}
|
||||
|
||||
WebComponentsHelper.focusProblemComponent(errors);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void showValidationErrors(ValidationErrors errors) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (ValidationErrors.Item error : errors.getAll()) {
|
||||
buffer.append(error.description).append("\n");
|
||||
}
|
||||
|
||||
Messages messages = AppBeans.get(Messages.NAME);
|
||||
showNotification(messages.getMainMessage("validationFail.caption"),
|
||||
buffer.toString(), NotificationType.TRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window openWindow(String windowAlias, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
|
||||
|
Loading…
Reference in New Issue
Block a user