Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableValueEditingSupport.java27
-rw-r--r--tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java2
-rw-r--r--tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableValueEditingSupportTest.java44
3 files changed, 48 insertions, 25 deletions
diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableValueEditingSupport.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableValueEditingSupport.java
index 23d5a8eb..da69029d 100644
--- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableValueEditingSupport.java
+++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableValueEditingSupport.java
@@ -148,19 +148,25 @@ public abstract class ObservableValueEditingSupport extends EditingSupport {
final protected void initializeCellEditorValue(CellEditor cellEditor,
ViewerCell cell) {
IObservableValue target = doCreateCellEditorObservable(cellEditor);
- Assert
- .isNotNull(target,
- "doCreateCellEditorObservable(...) did not return an observable"); //$NON-NLS-1$
+ Assert.isNotNull(target,
+ "doCreateCellEditorObservable(...) did not return an observable"); //$NON-NLS-1$
IObservableValue model = doCreateElementObservable(cell.getElement(),
cell);
Assert.isNotNull(model,
"doCreateElementObservable(...) did not return an observable"); //$NON-NLS-1$
+ dirty = false;
+
Binding binding = createBinding(target, model);
- Assert
- .isNotNull(binding,
- "createBinding(...) did not return a binding"); //$NON-NLS-1$
+
+ target.addChangeListener(new IChangeListener() {
+ public void handleChange(ChangeEvent event) {
+ dirty = true;
+ }
+ });
+
+ Assert.isNotNull(binding, "createBinding(...) did not return a binding"); //$NON-NLS-1$
editingState = new EditingState(binding, target, model);
@@ -199,15 +205,8 @@ public abstract class ObservableValueEditingSupport extends EditingSupport {
*/
protected Binding createBinding(IObservableValue target,
IObservableValue model) {
- dirty = false;
- Binding binding = dbc.bindValue(target, model, new UpdateValueStrategy(
+ return dbc.bindValue(target, model, new UpdateValueStrategy(
UpdateValueStrategy.POLICY_CONVERT), null);
- target.addChangeListener(new IChangeListener() {
- public void handleChange(ChangeEvent event) {
- dirty = true;
- }
- });
- return binding;
}
boolean dirty = false;
diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java
index d8747cc4..055d8054 100644
--- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java
+++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java
@@ -168,6 +168,7 @@ import org.eclipse.jface.tests.databinding.viewers.ObservableListTreeContentProv
import org.eclipse.jface.tests.databinding.viewers.ObservableMapLabelProviderTest;
import org.eclipse.jface.tests.databinding.viewers.ObservableSetContentProviderTest;
import org.eclipse.jface.tests.databinding.viewers.ObservableSetTreeContentProviderTest;
+import org.eclipse.jface.tests.databinding.viewers.ObservableValueEditingSupportTest;
import org.eclipse.jface.tests.databinding.viewers.ViewerSupportTest;
import org.eclipse.jface.tests.databinding.viewers.ViewersObservablesTest;
import org.eclipse.jface.tests.databinding.wizard.WizardPageSupportTest;
@@ -420,6 +421,7 @@ public class BindingTestSuite extends TestSuite {
addTestSuite(ObservableMapLabelProviderTest.class);
addTestSuite(ObservableSetContentProviderTest.class);
addTestSuite(ObservableSetTreeContentProviderTest.class);
+ addTestSuite(ObservableValueEditingSupportTest.class);
addTestSuite(ViewersObservablesTest.class);
addTestSuite(ViewerSupportTest.class);
diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableValueEditingSupportTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableValueEditingSupportTest.java
index ddf643ab..fc651d6d 100644
--- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableValueEditingSupportTest.java
+++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ObservableValueEditingSupportTest.java
@@ -31,6 +31,7 @@ import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
@@ -83,50 +84,68 @@ public class ObservableValueEditingSupportTest extends AbstractSWTTestCase {
}
public void testSaveCellEditorValue_UpdatesModel() throws Exception {
- Text text = new Text(shell, SWT.NONE);
shell.open();
String newValue = bean.getValue() + "a";
viewer.editElement(bean, 0);
- editingSupport.editor.setValue(newValue);
+ editingSupport.target.setValue(newValue);
// force the focus to leave the editor updating the value
- text.setFocus();
+ closeCellEditor();
+ assertTrue(editingSupport.binding.isDisposed());
assertEquals(newValue, bean.getValue());
}
+ /**
+ *
+ */
+ protected void closeCellEditor() {
+ editingSupport.text.notifyListeners(SWT.DefaultSelection, new Event());
+ }
+
+ public void testSaveCellEditorValue_IgnoreIfNotDirty() throws Exception {
+ String initialValue = bean.getValue();
+
+ shell.open();
+
+ viewer.editElement(bean, 0);
+
+ // force the focus to leave the editor updating the value
+ closeCellEditor();
+
+ assertTrue(editingSupport.binding.isDisposed());
+ assertEquals(initialValue, bean.getValue());
+ }
+
public void testDisposesBinding() throws Exception {
- Text text = new Text(shell, SWT.NONE);
shell.open();
viewer.editElement(bean, 0);
assertFalse("precondition", editingSupport.binding.isDisposed());
- text.setFocus();
+ closeCellEditor();
assertTrue(editingSupport.binding.isDisposed());
}
public void testDisposesTargetObservable() throws Exception {
- Text text = new Text(shell, SWT.NONE);
shell.open();
viewer.editElement(bean, 0);
- assertTrue("precondition", editingSupport.target.isDisposed());
+ assertFalse("precondition", editingSupport.target.isDisposed());
- text.setFocus();
+ closeCellEditor();
assertTrue(editingSupport.target.isDisposed());
}
public void testDisposesModelObservable() throws Exception {
- Text text = new Text(shell, SWT.NONE);
shell.open();
viewer.editElement(bean, 0);
- assertTrue("precondition", editingSupport.model.isDisposed());
+ assertFalse("precondition", editingSupport.model.isDisposed());
- text.setFocus();
+ closeCellEditor();
assertTrue(editingSupport.model.isDisposed());
}
@@ -138,6 +157,8 @@ public class ObservableValueEditingSupportTest extends AbstractSWTTestCase {
ObservableValueEditingSupport {
StringBuffer events = new StringBuffer();
+ Text text;
+
TextCellEditor editor;
Binding binding;
@@ -172,6 +193,7 @@ public class ObservableValueEditingSupportTest extends AbstractSWTTestCase {
CellEditor cellEditor) {
event("createCellEditorObservable");
+ text = (Text) cellEditor.getControl();
return target = SWTObservables.observeText(cellEditor.getControl(),
SWT.NONE);
}

Back to the top