PL-9960 Required field in a non-editable field group is being validated

This commit is contained in:
Yuriy Artamonov 2017-11-01 18:44:43 +04:00
parent 3c806bf4af
commit b65e517f54
13 changed files with 30 additions and 15 deletions

View File

@ -27,7 +27,9 @@ import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.BeanValidation;
import com.haulmont.cuba.core.global.MessageTools;
import com.haulmont.cuba.core.global.MetadataTools;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.components.Field;
import com.haulmont.cuba.gui.components.RequiredValueMissingException;
import com.haulmont.cuba.gui.components.ValidationException;
import com.haulmont.cuba.gui.components.compatibility.ComponentValueListenerWrapper;
import com.haulmont.cuba.gui.components.validators.BeanValidator;
import com.haulmont.cuba.gui.data.Datasource;
@ -121,7 +123,7 @@ public abstract class DesktopAbstractField<C extends JComponent> extends Desktop
@Override
public void validate() throws ValidationException {
if (!isVisible() || !isEditable() || !isEnabled())
if (!isVisible() || !isEditableWithParent() || !isEnabled())
return;
Object value = getValue();

View File

@ -99,7 +99,7 @@ public abstract class DesktopAbstractTextField<T extends JTextComponent> extends
@Override
public void updateMissingValueState() {
boolean state = required && editable && StringUtils.isBlank(impl.getText());
boolean state = isRequired() && isEditableWithParent() && StringUtils.isBlank(impl.getText());
decorateMissingValue(impl, state);
if (getComposition() instanceof JScrollPane) {
decorateMissingValue(getComposition(), state);

View File

@ -325,6 +325,9 @@ public class DesktopDateField extends DesktopAbstractField<JPanel> implements Da
@Override
public void validate() throws ValidationException {
if (!isVisible() || !isEditableWithParent() || !isEnabled())
return;
try {
constructDate();
super.validate();
@ -632,7 +635,7 @@ public class DesktopDateField extends DesktopAbstractField<JPanel> implements Da
@Override
public void updateMissingValueState() {
boolean value = required && editable && datePicker.getEditor().getValue() == null;
boolean value = required && isEditableWithParent() && datePicker.getEditor().getValue() == null;
decorateMissingValue(datePicker.getEditor(), value);
if (isHourUsed()) {
decorateMissingValue(timeField.getImpl(), value);

View File

@ -893,7 +893,7 @@ public class DesktopFieldGroup extends DesktopAbstractComponent<JPanel>
@Override
public void validate() throws ValidationException {
if (!isVisible() || !isEditable() || !isEnabled()) {
if (!isVisible() || !isEditableWithParent() || !isEnabled()) {
return;
}

View File

@ -523,7 +523,7 @@ public class DesktopLookupField extends DesktopAbstractOptionsField<JComponent>
@Override
public void updateMissingValueState() {
Component editorComponent = comboBox.getEditor().getEditorComponent();
boolean value = required && editable && enabled && editorComponent instanceof JTextComponent
boolean value = required && isEditableWithParent() && isEnabledWithParent() && editorComponent instanceof JTextComponent
&& StringUtils.isEmpty(((JTextComponent) editorComponent).getText());
decorateMissingValue(comboBox, value);
}

View File

@ -562,7 +562,7 @@ public class DesktopPickerField extends DesktopAbstractField<Picker>
return;
}
JTextComponent editor = (JTextComponent) impl.getEditor();
boolean value = required && editable && StringUtils.isBlank(editor.getText());
boolean value = required && isEditableWithParent() && StringUtils.isBlank(editor.getText());
decorateMissingValue(impl.getEditor(), value);
}

View File

@ -253,7 +253,10 @@ public class DesktopSearchField extends DesktopAbstractOptionsField<JComponent>
protected void updateEditState() {
Component editorComponent = comboBox.getEditor().getEditorComponent();
boolean value = required && editable && enabled && editorComponent instanceof JTextComponent
boolean value = required
&& isEditableWithParent()
&& isEnabledWithParent()
&& editorComponent instanceof JTextComponent
&& StringUtils.isEmpty(((JTextComponent) editorComponent).getText());
if (value) {
comboBox.setBackground(requiredBgColor);

View File

@ -389,7 +389,7 @@ public class DesktopSuggestionField extends DesktopAbstractOptionsField<JCompone
protected void updateEditState() {
Component editorComponent = comboBox.getEditor().getEditorComponent();
boolean value = required && editable && enabled && editorComponent instanceof JTextComponent
boolean value = required && isEditableWithParent() && isEnabledWithParent() && editorComponent instanceof JTextComponent
&& StringUtils.isEmpty(((JTextComponent) editorComponent).getText());
if (value) {
comboBox.setBackground(requiredBgColor);

View File

@ -97,7 +97,7 @@ public class DesktopTextField extends DesktopAbstractTextField<JTextComponent> i
protected void refreshInputPrompt() {
if (StringUtils.isNotBlank(inputPrompt)) {
if (isEnabledWithParent() && isEditable()) {
if (isEnabledWithParent() && isEditableWithParent()) {
// Save old tooltipText value to use it later
String toolTipText = this.impl.getToolTipText();
@ -136,7 +136,7 @@ public class DesktopTextField extends DesktopAbstractTextField<JTextComponent> i
public void setInputPrompt(String inputPrompt) {
this.inputPrompt = inputPrompt;
if ((!this.impl.isEditable() || !this.impl.isEnabled()) && StringUtils.isNotBlank(inputPrompt)) {
if ((!isEditableWithParent() || !this.impl.isEnabled()) && StringUtils.isNotBlank(inputPrompt)) {
return;
}

View File

@ -381,7 +381,7 @@ public class DesktopTimeField extends DesktopAbstractField<JFormattedTextField>
@Override
public void updateMissingValueState() {
Object implValue = impl.getValue();
boolean value = required && editable
boolean value = required && isEditableWithParent()
&& (implValue == null || implValue instanceof String && StringUtils.isBlank((String) implValue));
decorateMissingValue(impl, value);
}

View File

@ -365,7 +365,7 @@ public abstract class WebAbstractField<T extends com.vaadin.ui.AbstractField>
setValidationError(null);
}
if (!isVisible() || !isEditable() || !isEnabled()) {
if (!isVisible() || !isEditableWithParent() || !isEnabled()) {
return;
}

View File

@ -173,6 +173,14 @@ public class WebCurrencyField extends WebAbstractField<CubaCurrencyField> implem
@Override
public void validate() throws ValidationException {
if (hasValidationError()) {
setValidationError(null);
}
if (!isVisible() || !isEditableWithParent() || !isEnabled()) {
return;
}
textField.validate();
}

View File

@ -39,7 +39,6 @@ import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.stream.Collectors;
@ -660,7 +659,7 @@ public class WebFieldGroup extends WebAbstractComponent<CubaFieldGroupLayout>
@Override
public void validate() throws ValidationException {
if (!isVisible() || !isEditable() || !isEnabled()) {
if (!isVisible() || !isEditableWithParent() || !isEnabled()) {
return;
}