为活页夹中的一个组件关闭 setReadOnly 操作

Turn off setReadOnly action for one component inside binder

我在活页夹中有一些组件:

binder.bind(cbClientRating, Client::getRating, Client::setRating);
binder.bind(tfFirstName, Client::getFirstName, Client::setFirstName);
binder.bind(tfLastName, Client::getLastName, Client::setLastName);
binder.bind(dfBirthDate, Client::getBirthDate, Client::setBirthDate);

根据我的业务逻辑,我不需要更改 binder 中一个组件的 readonly 状态,例如 Combobox - cbClientRating 当我调用 binder.setReadOnly(false) 时。它应该保持只读模式等于 true。

现在我打电话 cbClientRating.setReadOnly(true) 在调用 binder.setReadOnly(false)

之后

binder.setReadOnly(false); cbClientRating.setReadoOnly(true);

还有其他解决办法吗?

Binder#setReadOnly(boolean)的源代码:

/**
 * Sets the read only state to the given value for all currently bound
 * fields.
 * <p>
 * This is just a shorthand for calling setReadOnly for all currently bound
 * fields. It means that fields bound after this method call won't be set
 * read-only.
 *
 * @param fieldsReadOnly
 *            true to set the fields to read only, false to set them to read
 *            write
 */
public void setReadOnly(boolean fieldsReadOnly) {
    getBindings().stream().map(BindingImpl::getField)
            .forEach(field -> field.setReadOnly(fieldsReadOnly));
}

所以这只是一个方便的方法。我建议您根据自己的业务逻辑,完全自行处理字段只读状态。