PL-9717 Field Group should support Container interface

This commit is contained in:
Andrey Subbotin 2017-10-26 16:41:41 +04:00
parent e54242135c
commit bfff19ca7c
7 changed files with 77 additions and 39 deletions

View File

@ -197,7 +197,8 @@ public class DesktopFrame
Collection<Component> components = ComponentsHelper.getComponents(this);
for (Component component : components) {
if (component instanceof Validatable) {
if (!((Validatable) component).isValid())
Component.Validatable validatable = (Component.Validatable) component;
if (validatable.isValidateOnCommit() && !validatable.isValid())
return false;
}
}
@ -209,7 +210,10 @@ public class DesktopFrame
Collection<Component> components = ComponentsHelper.getComponents(this);
for (Component component : components) {
if (component instanceof Validatable) {
((Validatable) component).validate();
Component.Validatable validatable = (Component.Validatable) component;
if (validatable.isValidateOnCommit()) {
validatable.validate();
}
}
}
}
@ -242,15 +246,17 @@ public class DesktopFrame
for (Component component : components) {
if (component instanceof Validatable) {
Validatable validatable = (Validatable) component;
try {
validatable.validate();
} catch (ValidationException e) {
if (log.isTraceEnabled())
log.trace("Validation failed", e);
else if (log.isDebugEnabled())
log.debug("Validation failed: " + e);
if (validatable.isValidateOnCommit()) {
try {
validatable.validate();
} catch (ValidationException e) {
if (log.isTraceEnabled())
log.trace("Validation failed", e);
else if (log.isDebugEnabled())
log.debug("Validation failed: " + e);
ComponentsHelper.fillErrorMessages(validatable, e, errors);
ComponentsHelper.fillErrorMessages(validatable, e, errors);
}
}
}
}

View File

@ -1457,15 +1457,18 @@ public class DesktopWindow implements Window, Component.Disposable,
Collection<Component> components = ComponentsHelper.getComponents(this);
for (Component component : components) {
if (component instanceof Validatable) {
try {
((Validatable) component).validate();
} catch (ValidationException e) {
if (log.isTraceEnabled())
log.trace("Validation failed", e);
else if (log.isDebugEnabled())
log.debug("Validation failed: " + e);
Validatable validatable = (Validatable) component;
if (validatable.isValidateOnCommit()) {
try {
validatable.validate();
} catch (ValidationException e) {
if (log.isTraceEnabled())
log.trace("Validation failed", e);
else if (log.isDebugEnabled())
log.debug("Validation failed: " + e);
ComponentsHelper.fillErrorMessages((Validatable) component, e, errors);
ComponentsHelper.fillErrorMessages(validatable, e, errors);
}
}
}
}

View File

@ -833,6 +833,17 @@ public interface Component {
interface Validatable {
boolean isValid();
void validate() throws ValidationException;
/**
* Enable/disable component validation on window commit for methods
* {@link Window#validateAll}, {@link Frame#validate},
* {@link Frame#validateAll}, {@link Frame#isValid}
* By default is true and component is validated on window commit.
* For FieldGroup is false.
*/
default boolean isValidateOnCommit() {
return true;
}
}
/**

View File

@ -28,7 +28,7 @@ import java.util.Map;
* Multi-column form component.
*/
public interface FieldGroup extends Component, Component.BelongToFrame, Component.HasCaption, Component.HasIcon,
Component.HasBorder, Component.Editable,
Component.HasBorder, Component.Editable, Component.Validatable,
Component.EditableChangeNotifier, Component.ChildEditableController,
Component.Container {
String NAME = "fieldGroup";
@ -485,6 +485,11 @@ public interface FieldGroup extends Component, Component.BelongToFrame, Componen
*/
void setFieldFactory(FieldGroupFieldFactory fieldFactory);
@Override
default boolean isValidateOnCommit() {
return false;
}
/*
* Deprecated API
*/

View File

@ -181,7 +181,8 @@ public class WindowDelegate {
Collection<Component> components = ComponentsHelper.getComponents(window);
for (Component component : components) {
if (component instanceof Component.Validatable) {
if (!((Component.Validatable) component).isValid())
Component.Validatable validatable = (Component.Validatable) component;
if (validatable.isValidateOnCommit() && !validatable.isValid())
return false;
}
}
@ -192,7 +193,10 @@ public class WindowDelegate {
Collection<Component> components = ComponentsHelper.getComponents(window);
for (Component component : components) {
if (component instanceof Component.Validatable) {
((Component.Validatable) component).validate();
Component.Validatable validatable = (Component.Validatable) component;
if (validatable.isValidateOnCommit()) {
validatable.validate();
}
}
}
}

View File

@ -393,15 +393,18 @@ public class WebWindow implements Window, Component.Wrapper,
Collection<Component> components = ComponentsHelper.getComponents(this);
for (Component component : components) {
if (component instanceof Validatable) {
try {
((Validatable) component).validate();
} catch (ValidationException e) {
if (log.isTraceEnabled())
log.trace("Validation failed", e);
else if (log.isDebugEnabled())
log.debug("Validation failed: " + e);
Validatable validatable = (Validatable) component;
if (validatable.isValidateOnCommit()) {
try {
validatable.validate();
} catch (ValidationException e) {
if (log.isTraceEnabled())
log.trace("Validation failed", e);
else if (log.isDebugEnabled())
log.debug("Validation failed: " + e);
ComponentsHelper.fillErrorMessages((Validatable) component, e, errors);
ComponentsHelper.fillErrorMessages(validatable, e, errors);
}
}
}
}

View File

@ -209,7 +209,8 @@ public class WebFrame extends WebVBoxLayout implements Frame, WrappedFrame {
Collection<Component> components = ComponentsHelper.getComponents(this);
for (Component component : components) {
if (component instanceof Validatable) {
if (!((Validatable) component).isValid())
Component.Validatable validatable = (Component.Validatable) component;
if (validatable.isValidateOnCommit() && !validatable.isValid())
return false;
}
}
@ -221,7 +222,10 @@ public class WebFrame extends WebVBoxLayout implements Frame, WrappedFrame {
Collection<Component> components = ComponentsHelper.getComponents(this);
for (Component component : components) {
if (component instanceof Validatable) {
((Validatable) component).validate();
Component.Validatable validatable = (Component.Validatable) component;
if (validatable.isValidateOnCommit()) {
validatable.validate();
}
}
}
}
@ -254,15 +258,17 @@ public class WebFrame extends WebVBoxLayout implements Frame, WrappedFrame {
for (Component component : components) {
if (component instanceof Validatable) {
Validatable validatable = (Validatable) component;
try {
validatable.validate();
} catch (ValidationException e) {
if (log.isTraceEnabled())
log.trace("Validation failed", e);
else if (log.isDebugEnabled())
log.debug("Validation failed: " + e);
if (validatable.isValidateOnCommit()) {
try {
validatable.validate();
} catch (ValidationException e) {
if (log.isTraceEnabled())
log.trace("Validation failed", e);
else if (log.isDebugEnabled())
log.debug("Validation failed: " + e);
ComponentsHelper.fillErrorMessages(validatable, e, errors);
ComponentsHelper.fillErrorMessages(validatable, e, errors);
}
}
}
}