0

ObjectPropertyBase skips value invalidation when newValue == oldValue:

/**
 * {@inheritDoc}
 */
@Override
public void set(T newValue) {
    if (isBound()) {
        throw new java.lang.RuntimeException((getBean() != null && getName() != null ?
                getBean().getClass().getSimpleName() + "." + getName() + " : ": "") + "A bound value cannot be set.");
    }
    if (value != newValue) {
        value = newValue;
        markInvalid();
    }
}

Problem: markInvalid() and value are private, therefore I cannot override set(newValue) properly.

Question: How can I obtain a type, that does not do the (value != newValue) check?

This question is related to this question.

user1803551
  • 12,965
  • 5
  • 47
  • 74
kerner1000
  • 3,382
  • 1
  • 37
  • 57

1 Answers1

1

How can I obtain a type, that does not do the (value != newValue) check?

Extend SimpleObjectProperty (or ObjectPropertyBase) and override its set method and skip the check. While you can't call markInvalid yourself, the method doesn't do much you can't do:

class InvalidatingObjectProperty<T> extends SimpleObjectProperty<T> {

    @Override
    public void set(T newValue) {
        if (isBound()) {
            throw new java.lang.RuntimeException(
                    (getBean() != null && getName() != null ? getBean().getClass().getSimpleName() + "." + getName() + " : " : "")
                            + "A bound value cannot be set.");
        }
        invalidated();
        fireValueChangedEvent();
    }
}

What we're missing is setting valid to false. However, the only place where that matters is in its toString method, which you can override as well.

user1803551
  • 12,965
  • 5
  • 47
  • 74
  • Did you mean `SimpleObjectProperty` or `ObjectPropertyBase`? (You wrote the same thing twice - `ObjectPropertyBase`). – Itai Aug 15 '17 at 08:59