*/
public void discard() throws SourceException;
- /**
- * Tests if the object is in write-through mode. If the object is in
- * write-through mode, all modifications to it will result in
- * <code>commit</code> being called after the modification.
- *
- * @return <code>true</code> if the object is in write-through mode,
- * <code>false</code> if it's not.
- * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note
- * that setReadThrough(true), setWriteThrough(true) equals
- * setBuffered(false)
- */
- @Deprecated
- public boolean isWriteThrough();
-
- /**
- * Sets the object's write-through mode to the specified status. When
- * switching the write-through mode on, the <code>commit</code> operation
- * will be performed.
- *
- * @param writeThrough
- * Boolean value to indicate if the object should be in
- * write-through mode after the call.
- * @throws SourceException
- * If the operation fails because of an exception is thrown by
- * the data source.
- * @throws InvalidValueException
- * If the implicit commit operation fails because of a
- * validation error.
- *
- * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note
- * that setReadThrough(true), setWriteThrough(true) equals
- * setBuffered(false)
- */
- @Deprecated
- public void setWriteThrough(boolean writeThrough) throws SourceException,
- InvalidValueException;
-
- /**
- * Tests if the object is in read-through mode. If the object is in
- * read-through mode, retrieving its value will result in the value being
- * first updated from the data source to the object.
- * <p>
- * The only exception to this rule is that when the object is not in
- * write-through mode and it's buffer contains a modified value, the value
- * retrieved from the object will be the locally modified value in the
- * buffer which may differ from the value in the data source.
- * </p>
- *
- * @return <code>true</code> if the object is in read-through mode,
- * <code>false</code> if it's not.
- * @deprecated As of 7.0, use {@link #isBuffered(boolean)} instead. Note
- * that setReadThrough(true), setWriteThrough(true) equals
- * setBuffered(false)
- */
- @Deprecated
- public boolean isReadThrough();
-
- /**
- * Sets the object's read-through mode to the specified status. When
- * switching read-through mode on, the object's value is updated from the
- * data source.
- *
- * @param readThrough
- * Boolean value to indicate if the object should be in
- * read-through mode after the call.
- *
- * @throws SourceException
- * If the operation fails because of an exception is thrown by
- * the data source. The cause is included in the exception.
- * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note
- * that setReadThrough(true), setWriteThrough(true) equals
- * setBuffered(false)
- */
- @Deprecated
- public void setReadThrough(boolean readThrough) throws SourceException;
-
/**
* Sets the object's buffered mode to the specified status.
* <p>
private LinkedList<Validator> validators = null;
/**
- * Auto commit mode.
+ * True if field is in buffered mode, false otherwise
*/
- private boolean writeThroughMode = true;
-
- /**
- * Reads the value from data-source, when it is not modified.
- */
- private boolean readThroughMode = true;
+ private boolean buffered;
/**
* Flag to indicate that the field is currently committing its value to the
*/
private T getFieldValue() {
// Give the value from abstract buffers if the field if possible
- if (dataSource == null || !isReadThrough() || isModified()) {
+ if (dataSource == null || isBuffered() || isModified()) {
return getInternalValue();
}
requestRepaint();
}
- /*
- * Tests if the field is in write-through mode. Don't add a JavaDoc comment
- * here, we use the default documentation from the implemented interface.
- */
- @Override
- public boolean isWriteThrough() {
- return writeThroughMode;
- }
-
- /**
- * Sets the field's write-through mode to the specified status. When
- * switching the write-through mode on, a {@link #commit()} will be
- * performed.
- *
- * @see #setBuffered(boolean) for an easier way to control read through and
- * write through modes
- *
- * @param writeThrough
- * Boolean value to indicate if the object should be in
- * write-through mode after the call.
- * @throws SourceException
- * If the operation fails because of an exception is thrown by
- * the data source.
- * @throws InvalidValueException
- * If the implicit commit operation fails because of a
- * validation error.
- * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note
- * that setReadThrough(true), setWriteThrough(true) equals
- * setBuffered(false)
- */
- @Override
- @Deprecated
- public void setWriteThrough(boolean writeThrough)
- throws Buffered.SourceException, InvalidValueException {
- if (writeThroughMode == writeThrough) {
- return;
- }
- writeThroughMode = writeThrough;
- if (writeThroughMode) {
- commit();
- }
- }
-
- /*
- * Tests if the field is in read-through mode. Don't add a JavaDoc comment
- * here, we use the default documentation from the implemented interface.
- */
- @Override
- public boolean isReadThrough() {
- return readThroughMode;
- }
-
- /**
- * Sets the field's read-through mode to the specified status. When
- * switching read-through mode on, the object's value is updated from the
- * data source.
- *
- * @see #setBuffered(boolean) for an easier way to control read through and
- * write through modes
- *
- * @param readThrough
- * Boolean value to indicate if the object should be in
- * read-through mode after the call.
- *
- * @throws SourceException
- * If the operation fails because of an exception is thrown by
- * the data source. The cause is included in the exception.
- * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note
- * that setReadThrough(true), setWriteThrough(true) equals
- * setBuffered(false)
- */
- @Override
- @Deprecated
- public void setReadThrough(boolean readThrough)
- throws Buffered.SourceException {
- if (readThroughMode == readThrough) {
- return;
- }
- readThroughMode = readThrough;
- if (!isModified() && readThroughMode && getPropertyDataSource() != null) {
- setInternalValue(convertFromDataSource(getDataSourceValue()));
- fireValueChange(false);
- }
- }
-
/**
* Sets the buffered mode of this Field.
* <p>
* property data source until {@link #commit()} is called.
* </p>
* <p>
- * Changing buffered mode will change the read through and write through
- * state for the field.
+ * Setting buffered mode from true to false will commit any pending changes.
* </p>
* <p>
- * Mixing calls to {@link #setBuffered(boolean)} and
- * {@link #setReadThrough(boolean)} or {@link #setWriteThrough(boolean)} is
- * generally a bad idea.
+ *
* </p>
*
+ * @since 7.0.0
* @param buffered
* true if buffered mode should be turned on, false otherwise
*/
@Override
public void setBuffered(boolean buffered) {
- setReadThrough(!buffered);
- setWriteThrough(!buffered);
+ if (this.buffered == buffered) {
+ return;
+ }
+ this.buffered = buffered;
+ if (!buffered) {
+ commit();
+ }
}
/**
* Checks the buffered mode of this Field.
- * <p>
- * This method only returns true if both read and write buffering is used.
*
* @return true if buffered mode is on, false otherwise
*/
@Override
public boolean isBuffered() {
- return !isReadThrough() && !isWriteThrough();
+ return buffered;
}
/* Property interface implementation */
setModified(dataSource != null);
valueWasModifiedByDataSourceDuringCommit = false;
- // In write through mode , try to commit
- if (isWriteThrough() && dataSource != null
+ // In not buffering, try to commit
+ if (!isBuffered() && dataSource != null
&& (isInvalidCommitted() || isValid())) {
try {
*/
@Override
public void valueChange(Property.ValueChangeEvent event) {
- if (isReadThrough()) {
+ if (!isBuffered()) {
if (committingValueToDataSource) {
boolean propertyNotifiesOfTheBufferedValue = equals(event
.getProperty().getValue(), getInternalValue());
if (!isListeningToPropertyEvents) {
addPropertyListeners();
- if (!isModified() && isReadThrough()) {
+ if (!isModified() && !isBuffered()) {
// Update value from data source
discard();
}
private Buffered.SourceException currentBufferedSourceException = null;
/**
- * Is the form in write trough mode.
+ * Is the form in buffered mode.
*/
- private boolean writeThrough = true;
-
- /**
- * Is the form in read trough mode.
- */
- private boolean readThrough = true;
+ private boolean buffered = false;
/**
* Mapping from propertyName to corresponding field.
}
/*
- * Is the editor in a read-through mode? Don't add a JavaDoc comment here,
- * we use the default one from the interface.
- */
- @Override
- @Deprecated
- public boolean isReadThrough() {
- return readThrough;
- }
-
- /*
- * Is the editor in a write-through mode? Don't add a JavaDoc comment here,
- * we use the default one from the interface.
- */
- @Override
- @Deprecated
- public boolean isWriteThrough() {
- return writeThrough;
- }
-
- /*
- * Sets the editor's read-through mode to the specified status. Don't add a
- * JavaDoc comment here, we use the default one from the interface.
- */
- @Override
- public void setReadThrough(boolean readThrough) {
- if (readThrough != this.readThrough) {
- this.readThrough = readThrough;
- for (final Iterator<Object> i = propertyIds.iterator(); i.hasNext();) {
- (fields.get(i.next())).setReadThrough(readThrough);
- }
- }
- }
-
- /*
- * Sets the editor's read-through mode to the specified status. Don't add a
+ * Sets the editor's buffered mode to the specified status. Don't add a
* JavaDoc comment here, we use the default one from the interface.
*/
@Override
- public void setWriteThrough(boolean writeThrough) throws SourceException,
- InvalidValueException {
- if (writeThrough != this.writeThrough) {
- this.writeThrough = writeThrough;
+ public void setBuffered(boolean buffered) {
+ if (buffered != this.buffered) {
+ this.buffered = buffered;
for (final Iterator<Object> i = propertyIds.iterator(); i.hasNext();) {
- (fields.get(i.next())).setWriteThrough(writeThrough);
+ (fields.get(i.next())).setBuffered(buffered);
}
}
}
propertyIds.addLast(propertyId);
}
- // Update the read and write through status and immediate to match the
+ // Update the buffered mode and immediate to match the
// form.
// Should this also include invalidCommitted (#3993)?
- field.setReadThrough(readThrough);
- field.setWriteThrough(writeThrough);
+ field.setBuffered(buffered);
if (isImmediate() && field instanceof AbstractComponent) {
((AbstractComponent) field).setImmediate(true);
}
: new Select();
newField.setCaption(oldField.getCaption());
newField.setReadOnly(oldField.isReadOnly());
- newField.setReadThrough(oldField.isReadThrough());
- newField.setWriteThrough(oldField.isWriteThrough());
+ newField.setBuffered(oldField.isBuffered());
// Creates the options list
newField.addContainerProperty("desc", String.class, "");
*/
public void testRemoveListener() {
getField().setPropertyDataSource(new ObjectProperty<String>(""));
- getField().setWriteThrough(true);
- getField().setReadThrough(true);
+ getField().setBuffered(false);
// Expectations and start test
listener.valueChange(EasyMock.isA(ValueChangeEvent.class));
* Field value change notifications closely mirror value changes of the data
* source behind the field.
*/
- public void testWriteThroughReadThrough() {
+ public void testNonBuffered() {
getField().setPropertyDataSource(new ObjectProperty<String>(""));
- getField().setWriteThrough(true);
- getField().setReadThrough(true);
+ getField().setBuffered(false);
expectValueChangeFromSetValueNotCommit();
}
* Field value change notifications reflect the buffered value in the field,
* not the original data source value changes.
*/
- public void testNoWriteThroughNoReadThrough() {
+ public void testBuffered() {
getField().setPropertyDataSource(new ObjectProperty<String>(""));
- getField().setWriteThrough(false);
- getField().setReadThrough(false);
-
- expectValueChangeFromSetValueNotCommit();
- }
-
- /**
- * Less common partly buffered case: writeThrough (auto-commit) is on and
- * readThrough is off. Calling commit() should not cause notifications.
- *
- * Without readThrough activated, changes to the data source that do not
- * cause notifications are not reflected by the field value.
- *
- * Field value change notifications correspond to changes made to the data
- * source value through the text field or the (notifying) property.
- */
- public void testWriteThroughNoReadThrough() {
- getField().setPropertyDataSource(new ObjectProperty<String>(""));
- getField().setWriteThrough(true);
- getField().setReadThrough(false);
-
- expectValueChangeFromSetValueNotCommit();
- }
-
- /**
- * Partly buffered use where the data source is read but not nor modified
- * during editing, and is updated at commit().
- *
- * When used like this, a field is updated from the data source if necessary
- * when its value is requested and the property value has changed but the
- * field has not been modified in its buffer.
- *
- * Field value change notifications reflect the buffered value in the field,
- * not the original data source value changes.
- */
- public void testNoWriteThroughReadThrough() {
- getField().setPropertyDataSource(new ObjectProperty<String>(""));
- getField().setWriteThrough(false);
- getField().setReadThrough(true);
+ getField().setBuffered(true);
expectValueChangeFromSetValueNotCommit();
}
EasyMock.verify(getListener());
}
- /**
- * If read through is on and value has been modified, but not committed, the
- * value should not propagate similar to
- * {@link #testValueChangeEventPropagationWithReadThrough()}
- *
- * TODO make test field type agnostic (eg. combobox)
- */
- public void testValueChangePropagationWithReadThroughWithModifiedValue() {
- final String initialValue = "initial";
- ObjectProperty<String> property = new ObjectProperty<String>(
- initialValue);
- getField().setPropertyDataSource(property);
-
- // write buffering on, read buffering off
- getField().setWriteThrough(false);
- getField().setReadThrough(true);
-
- // Expect no value changes calls to listener
- EasyMock.replay(getListener());
-
- // first set the value (note, write through false -> not forwarded to
- // property)
- setValue(getField());
-
- Assert.assertTrue(getField().isModified());
-
- // Add listener and set the value -> should end up in listener once
- getField().addListener(getListener());
-
- // modify property value, should not fire value change in field as the
- // field has uncommitted value (aka isModified() == true)
- property.setValue("Foo");
-
- // Ensure listener was called once
- EasyMock.verify(getListener());
-
- // get value should not fire value change again
- Object value = getField().getValue();
- // Ensure listener still has been called only once
- EasyMock.verify(getListener());
-
- // field value should be different from the original value and current
- // proeprty value
- boolean isValueEqualToInitial = value.equals(initialValue);
- Assert.assertFalse(isValueEqualToInitial);
- boolean isValueEqualToPropertyValue = value.equals(property.getValue());
- Assert.assertFalse(isValueEqualToPropertyValue);
-
- // Ensure listener has not been called
- EasyMock.verify(getListener());
-
- }
-
/**
* Value change events from property should not propagate if read through is
* false. Execpt when the property is being set.
tf = new TextField("A field, must contain 1-2 chars",
new ObjectProperty<String>("a"));
tf.addValidator(new StringLengthValidator("Invalid length", 1, 2, false));
- tf.setWriteThrough(false);
+ tf.setBuffered(true);
tf.setRequired(true);
Button b = new Button("Commit", new ClickListener() {
addressForm = new Form();
}
addressForm.setCaption("Address");
- addressForm.setWriteThrough(false);
+ addressForm.setBuffered(true);
// make sure field changes are sent early
addressForm.setImmediate(true);
beanItem = new BeanItem<Person>(person);
setCaption("Update person details");
- setWriteThrough(false);
+ setBuffered(true);
setFormFieldFactory(new PersonFieldFactory());
// set the data source and the visible fields
// Note that if the nested form is the first or last field in the parent
* Create and configure form.
*/
final Form form = new Form();
- form.setWriteThrough(false); // set write buffering on
+ form.setBuffered(true); // set write buffering on
form.setImmediate(true); // make form (and especially its fields
// immediate)
}
private void printState() {
- log.log("Date. Field: " + f((Date) dateField.getValue())
- + " Property: " + f(dateProperty.getValue()));
+ log.log("Date. Field: " + f(dateField.getValue()) + " Property: "
+ + f(dateProperty.getValue()));
log.log("Integer: Field: " + integerField.getValue() + " Property: "
+ integerProperty.getValue());
}
final Form generalForm = new Form();
{
generalForm.setCaption("My form");
- generalForm.setWriteThrough(true);
+ generalForm.setBuffered(false);
generalForm.setFormFieldFactory(fieldFactory);
BeanItem<MyBean> myBeanItem = new BeanItem<MyBean>(myBean);
PopupDateField df = new PopupDateField();
df.setLocale(new Locale("en", "US"));
df.setResolution(Resolution.DAY);
- df.setWriteThrough(true);
- df.setReadThrough(true);
+ df.setBuffered(false);
df.setImmediate(true);
return df;
}
controllerComboBox.setNullSelectionAllowed(false);
controllerComboBox.setNewItemsAllowed(false);
controllerComboBox.setImmediate(true);
- controllerComboBox.setWriteThrough(false);
- controllerComboBox.setReadThrough(false);
+ controllerComboBox.setBuffered(true);
}
slaveComboBox.setNullSelectionAllowed(false);
slaveComboBox.setNewItemsAllowed(false);
slaveComboBox.setImmediate(true);
- slaveComboBox.setWriteThrough(false);
- slaveComboBox.setReadThrough(false);
+ slaveComboBox.setBuffered(true);
}
private void refreshSlaveDropdown(Integer masterId) {
form.setImmediate(true);
// this is critical for the problem to occur
- form.setWriteThrough(false);
+ form.setBuffered(true);
HorizontalLayout footer = new HorizontalLayout();
footer.setSpacing(true);
private TestForm() {
setSizeFull();
- setWriteThrough(false);
+ setBuffered(true);
setInvalidCommitted(false);
save = new Button("Save", this);
addComponent(addComp);
componentEditor = new Form();
- componentEditor.setWriteThrough(false);
+ componentEditor.setBuffered(true);
componentEditor.setCaption("Component properties:");
componentEditor.setFormFieldFactory(MFieldFactory.get());
addComponent(componentEditor);
positionEditor = new Form();
positionEditor.setCaption("Component position");
- positionEditor.setWriteThrough(false);
+ positionEditor.setBuffered(true);
positionEditor.setFormFieldFactory(MFieldFactory.get());
addComponent(positionEditor);
final ObjectProperty<String> prop = new ObjectProperty<String>("");
final TextField tf1 = new TextField(
"Buffered TextField bound to ObjectProperty");
- tf1.setWriteThrough(false);
- tf1.setReadThrough(false);
+ tf1.setBuffered(true);
tf1.setPropertyDataSource(prop);
main.addComponent(tf1);
main.addComponent(new Button(