View | Details | Raw Unified | Return to bug 198904 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/internal/databinding/internal/swt/ButtonObservableValue.java (+15 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brad Reynolds - bug 164653
10
 *     Brad Reynolds - bug 164653
11
 *     Ashley Cambrell - bug 198904
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jface.internal.databinding.internal.swt;
13
package org.eclipse.jface.internal.databinding.internal.swt;
13
14
Lines 64-67 Link Here
64
		return Boolean.class;
65
		return Boolean.class;
65
	}
66
	}
66
67
68
	/*
69
	 * (non-Javadoc)
70
	 *
71
	 * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose()
72
	 */
73
	public synchronized void dispose() {
74
		super.dispose();
75
76
		if (!button.isDisposed()) {
77
			button.removeListener(SWT.Selection, updateListener);
78
			button.removeListener(SWT.DefaultSelection, updateListener);
79
		}
80
	}
81
67
}
82
}
(-)src/org/eclipse/jface/internal/databinding/internal/swt/ComboObservableValue.java (-2 / +18 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brad Reynolds - bug 164653
10
 *     Brad Reynolds - bug 164653
11
 *     Ashley Cambrell - bug 198904
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jface.internal.databinding.internal.swt;
13
package org.eclipse.jface.internal.databinding.internal.swt;
13
14
Lines 28-33 Link Here
28
	private final String attribute;
29
	private final String attribute;
29
	private boolean updating = false;
30
	private boolean updating = false;
30
	private String currentValue;
31
	private String currentValue;
32
	private ModifyListener modifyListener;
31
33
32
	/**
34
	/**
33
	 * @param combo
35
	 * @param combo
Lines 41-47 Link Here
41
		if (attribute.equals(SWTProperties.SELECTION)
43
		if (attribute.equals(SWTProperties.SELECTION)
42
				|| attribute.equals(SWTProperties.TEXT)) {
44
				|| attribute.equals(SWTProperties.TEXT)) {
43
			this.currentValue = combo.getText();
45
			this.currentValue = combo.getText();
44
			combo.addModifyListener(new ModifyListener() {
46
			modifyListener = new ModifyListener() {
45
47
46
				public void modifyText(ModifyEvent e) {
48
				public void modifyText(ModifyEvent e) {
47
					if (!updating) {
49
					if (!updating) {
Lines 52-58 Link Here
52
								currentValue));
54
								currentValue));
53
					}
55
					}
54
				}
56
				}
55
			});
57
			};
58
			combo.addModifyListener(modifyListener);
56
		} else
59
		} else
57
			throw new IllegalArgumentException();
60
			throw new IllegalArgumentException();
58
	}
61
	}
Lines 111-114 Link Here
111
	public String getAttribute() {
114
	public String getAttribute() {
112
		return attribute;
115
		return attribute;
113
	}
116
	}
117
118
	/*
119
	 * (non-Javadoc)
120
	 *
121
	 * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose()
122
	 */
123
	public synchronized void dispose() {
124
		super.dispose();
125
126
		if (modifyListener != null && !combo.isDisposed()) {
127
			combo.removeModifyListener(modifyListener);
128
		}
129
	}
114
}
130
}
(-)src/org/eclipse/jface/internal/databinding/internal/swt/ComboSingleSelectionObservableValue.java (-5 / +21 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brad Reynolds - bug 164653
10
 *     Brad Reynolds - bug 164653
11
 *     Ashley Cambrell - bug 198904
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jface.internal.databinding.internal.swt;
13
package org.eclipse.jface.internal.databinding.internal.swt;
13
14
Lines 17-25 Link Here
17
18
18
/**
19
/**
19
 * @since 1.0
20
 * @since 1.0
20
 * 
21
 *
21
 */
22
 */
22
public class ComboSingleSelectionObservableValue extends SingleSelectionObservableValue {
23
public class ComboSingleSelectionObservableValue extends
24
		SingleSelectionObservableValue {
25
26
	private SelectionListener selectionListener;
23
27
24
	/**
28
	/**
25
	 * @param combo
29
	 * @param combo
Lines 33-39 Link Here
33
	}
37
	}
34
38
35
	protected void doAddSelectionListener(final Runnable runnable) {
39
	protected void doAddSelectionListener(final Runnable runnable) {
36
		getCombo().addSelectionListener(new SelectionListener() {
40
		selectionListener = new SelectionListener() {
37
			public void widgetDefaultSelected(SelectionEvent e) {
41
			public void widgetDefaultSelected(SelectionEvent e) {
38
				runnable.run();
42
				runnable.run();
39
			}
43
			}
Lines 41-47 Link Here
41
			public void widgetSelected(SelectionEvent e) {
45
			public void widgetSelected(SelectionEvent e) {
42
				runnable.run();
46
				runnable.run();
43
			}
47
			}
44
		});
48
		};
49
		getCombo().addSelectionListener(selectionListener);
45
	}
50
	}
46
51
47
	protected int doGetSelectionIndex() {
52
	protected int doGetSelectionIndex() {
Lines 49-55 Link Here
49
	}
54
	}
50
55
51
	protected void doSetSelectionIndex(int index) {
56
	protected void doSetSelectionIndex(int index) {
52
		getCombo().setText(getCombo().getItem(index));
57
		getCombo().select(index);
53
	}
58
	}
54
59
60
	/*
61
	 * (non-Javadoc)
62
	 *
63
	 * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose()
64
	 */
65
	public synchronized void dispose() {
66
		super.dispose();
67
		if (selectionListener != null && !getCombo().isDisposed()) {
68
			getCombo().removeSelectionListener(selectionListener);
69
		}
70
	}
55
}
71
}
(-)src/org/eclipse/jface/internal/databinding/internal/swt/ListObservableValue.java (-2 / +17 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brad Reynolds - bug 164653
10
 *     Brad Reynolds - bug 164653
11
 *     Ashley Cambrell - bug 198904
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jface.internal.databinding.internal.swt;
13
package org.eclipse.jface.internal.databinding.internal.swt;
13
14
Lines 30-35 Link Here
30
31
31
	private String currentValue;
32
	private String currentValue;
32
33
34
	private Listener listener;
35
33
	/**
36
	/**
34
	 * @param list
37
	 * @param list
35
	 */
38
	 */
Lines 42-48 Link Here
42
			throw new IllegalArgumentException(
45
			throw new IllegalArgumentException(
43
					"SWT.SINGLE support only for a List selection"); //$NON-NLS-1$
46
					"SWT.SINGLE support only for a List selection"); //$NON-NLS-1$
44
47
45
		list.addListener(SWT.Selection, new Listener() {
48
		listener = new Listener() {
46
49
47
			public void handleEvent(Event event) {
50
			public void handleEvent(Event event) {
48
				if (!updating) {
51
				if (!updating) {
Lines 53-59 Link Here
53
				}
56
				}
54
			}
57
			}
55
58
56
		});
59
		};
60
		list.addListener(SWT.Selection, listener);
57
	}
61
	}
58
62
59
	public void doSetValue(Object value) {
63
	public void doSetValue(Object value) {
Lines 91-94 Link Here
91
		return String.class;
95
		return String.class;
92
	}
96
	}
93
97
98
	/*
99
	 * (non-Javadoc)
100
	 *
101
	 * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose()
102
	 */
103
	public synchronized void dispose() {
104
		super.dispose();
105
		if (listener != null && !list.isDisposed()) {
106
			list.removeListener(SWT.Selection, listener);
107
		}
108
	}
94
}
109
}
(-)src/org/eclipse/jface/internal/databinding/internal/swt/ListSingleSelectionObservableValue.java (-2 / +17 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brad Reynolds - bug 164653
10
 *     Brad Reynolds - bug 164653
11
 *     Ashley Cambrell - bug 198904
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jface.internal.databinding.internal.swt;
13
package org.eclipse.jface.internal.databinding.internal.swt;
13
14
Lines 22-27 Link Here
22
public class ListSingleSelectionObservableValue extends
23
public class ListSingleSelectionObservableValue extends
23
		SingleSelectionObservableValue {
24
		SingleSelectionObservableValue {
24
25
26
	private SelectionListener selectionListener;
27
25
	/**
28
	/**
26
	 * @param combo
29
	 * @param combo
27
	 */
30
	 */
Lines 34-40 Link Here
34
	}
37
	}
35
38
36
	protected void doAddSelectionListener(final Runnable runnable) {
39
	protected void doAddSelectionListener(final Runnable runnable) {
37
		getList().addSelectionListener(new SelectionListener() {
40
		selectionListener = new SelectionListener() {
38
			public void widgetDefaultSelected(SelectionEvent e) {
41
			public void widgetDefaultSelected(SelectionEvent e) {
39
				runnable.run();
42
				runnable.run();
40
			}
43
			}
Lines 42-48 Link Here
42
			public void widgetSelected(SelectionEvent e) {
45
			public void widgetSelected(SelectionEvent e) {
43
				runnable.run();
46
				runnable.run();
44
			}
47
			}
45
		});
48
		};
49
		getList().addSelectionListener(selectionListener);
46
	}
50
	}
47
51
48
	protected int doGetSelectionIndex() {
52
	protected int doGetSelectionIndex() {
Lines 53-56 Link Here
53
		getList().setSelection(index);
57
		getList().setSelection(index);
54
	}
58
	}
55
59
60
	/*
61
	 * (non-Javadoc)
62
	 *
63
	 * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose()
64
	 */
65
	public synchronized void dispose() {
66
		super.dispose();
67
		if (selectionListener != null && !getList().isDisposed()) {
68
			getList().removeSelectionListener(selectionListener);
69
		}
70
	}
56
}
71
}
(-)src/org/eclipse/jface/internal/databinding/internal/swt/TableSingleSelectionObservableValue.java (-3 / +19 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brad Reynolds - bug 164653
10
 *     Brad Reynolds - bug 164653
11
 *     Ashley Cambrell - bug 198904
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jface.internal.databinding.internal.swt;
13
package org.eclipse.jface.internal.databinding.internal.swt;
13
14
Lines 19-25 Link Here
19
 * @since 1.0
20
 * @since 1.0
20
 * 
21
 * 
21
 */
22
 */
22
public class TableSingleSelectionObservableValue extends SingleSelectionObservableValue {
23
public class TableSingleSelectionObservableValue extends
24
		SingleSelectionObservableValue {
25
26
	private SelectionListener selectionListener;
23
27
24
	/**
28
	/**
25
	 * @param table
29
	 * @param table
Lines 33-39 Link Here
33
	}
37
	}
34
38
35
	protected void doAddSelectionListener(final Runnable runnable) {
39
	protected void doAddSelectionListener(final Runnable runnable) {
36
		getTable().addSelectionListener(new SelectionListener() {
40
		selectionListener = new SelectionListener() {
37
			public void widgetDefaultSelected(SelectionEvent e) {
41
			public void widgetDefaultSelected(SelectionEvent e) {
38
				runnable.run();
42
				runnable.run();
39
			}
43
			}
Lines 41-47 Link Here
41
			public void widgetSelected(SelectionEvent e) {
45
			public void widgetSelected(SelectionEvent e) {
42
				runnable.run();
46
				runnable.run();
43
			}
47
			}
44
		});
48
		};
49
		getTable().addSelectionListener(selectionListener);
45
	}
50
	}
46
51
47
	protected int doGetSelectionIndex() {
52
	protected int doGetSelectionIndex() {
Lines 52-55 Link Here
52
		getTable().setSelection(index);
57
		getTable().setSelection(index);
53
	}
58
	}
54
59
60
	/*
61
	 * (non-Javadoc)
62
	 *
63
	 * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose()
64
	 */
65
	public synchronized void dispose() {
66
		super.dispose();
67
		if (selectionListener != null && !getTable().isDisposed()) {
68
			getTable().removeSelectionListener(selectionListener);
69
		}
70
	}
55
}
71
}
(-)src/org/eclipse/jface/internal/databinding/internal/swt/CComboObservableValue.java (-2 / +19 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brad Reynolds - bug 164653
10
 *     Brad Reynolds - bug 164653
11
 *     Ashley Cambrell - bug 198904
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jface.internal.databinding.internal.swt;
13
package org.eclipse.jface.internal.databinding.internal.swt;
13
14
Lines 36-41 Link Here
36
37
37
	private String currentValue;
38
	private String currentValue;
38
39
40
	private ModifyListener modifyListener;
41
39
	/**
42
	/**
40
	 * @param ccombo
43
	 * @param ccombo
41
	 * @param attribute
44
	 * @param attribute
Lines 48-54 Link Here
48
		if (attribute.equals(SWTProperties.SELECTION)
51
		if (attribute.equals(SWTProperties.SELECTION)
49
				|| attribute.equals(SWTProperties.TEXT)) {
52
				|| attribute.equals(SWTProperties.TEXT)) {
50
			this.currentValue = ccombo.getText();
53
			this.currentValue = ccombo.getText();
51
			ccombo.addModifyListener(new ModifyListener() {
54
			modifyListener = new ModifyListener() {
52
55
53
				public void modifyText(ModifyEvent e) {
56
				public void modifyText(ModifyEvent e) {
54
					if (!updating) {
57
					if (!updating) {
Lines 59-65 Link Here
59
								currentValue));
62
								currentValue));
60
					}
63
					}
61
				}
64
				}
62
			});
65
			};
66
			ccombo.addModifyListener(modifyListener);
63
		} else
67
		} else
64
			throw new IllegalArgumentException();
68
			throw new IllegalArgumentException();
65
	}
69
	}
Lines 118-121 Link Here
118
	public String getAttribute() {
122
	public String getAttribute() {
119
		return attribute;
123
		return attribute;
120
	}
124
	}
125
126
	/*
127
	 * (non-Javadoc)
128
	 *
129
	 * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose()
130
	 */
131
	public synchronized void dispose() {
132
		super.dispose();
133
134
		if (modifyListener != null && !ccombo.isDisposed()) {
135
			ccombo.removeModifyListener(modifyListener);
136
		}
137
	}
121
}
138
}
(-)src/org/eclipse/jface/internal/databinding/internal/swt/CComboSingleSelectionObservableValue.java (-4 / +21 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brad Reynolds - bug 164653
10
 *     Brad Reynolds - bug 164653
11
 *     Ashley Cambrell - bug 198904
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jface.internal.databinding.internal.swt;
13
package org.eclipse.jface.internal.databinding.internal.swt;
13
14
Lines 17-25 Link Here
17
18
18
/**
19
/**
19
 * @since 1.0
20
 * @since 1.0
20
 * 
21
 *
21
 */
22
 */
22
public class CComboSingleSelectionObservableValue extends SingleSelectionObservableValue {
23
public class CComboSingleSelectionObservableValue extends
24
		SingleSelectionObservableValue {
25
26
	private SelectionListener selectionListener;
23
27
24
	/**
28
	/**
25
	 * @param combo
29
	 * @param combo
Lines 33-39 Link Here
33
	}
37
	}
34
38
35
	protected void doAddSelectionListener(final Runnable runnable) {
39
	protected void doAddSelectionListener(final Runnable runnable) {
36
		getCCombo().addSelectionListener(new SelectionListener() {
40
		selectionListener = new SelectionListener() {
37
			public void widgetDefaultSelected(SelectionEvent e) {
41
			public void widgetDefaultSelected(SelectionEvent e) {
38
				runnable.run();
42
				runnable.run();
39
			}
43
			}
Lines 41-47 Link Here
41
			public void widgetSelected(SelectionEvent e) {
45
			public void widgetSelected(SelectionEvent e) {
42
				runnable.run();
46
				runnable.run();
43
			}
47
			}
44
		});
48
		};
49
		getCCombo().addSelectionListener(selectionListener);
45
	}
50
	}
46
51
47
	protected int doGetSelectionIndex() {
52
	protected int doGetSelectionIndex() {
Lines 52-55 Link Here
52
		getCCombo().setText(getCCombo().getItem(index));
57
		getCCombo().setText(getCCombo().getItem(index));
53
	}
58
	}
54
59
60
	/*
61
	 * (non-Javadoc)
62
	 *
63
	 * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose()
64
	 */
65
	public synchronized void dispose() {
66
		super.dispose();
67
		if (selectionListener != null && !getCCombo().isDisposed()) {
68
			getCCombo().removeSelectionListener(selectionListener);
69
		}
70
71
	}
55
}
72
}
(-)src/org/eclipse/jface/internal/databinding/internal/swt/SpinnerObservableValue.java (-2 / +18 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brad Reynolds - bug 164653
10
 *     Brad Reynolds - bug 164653
11
 *     Ashley Cambrell - bug 198904
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jface.internal.databinding.internal.swt;
13
package org.eclipse.jface.internal.databinding.internal.swt;
13
14
Lines 32-37 Link Here
32
33
33
	private int currentSelection;
34
	private int currentSelection;
34
35
36
	private ModifyListener modifyListener;
37
35
	/**
38
	/**
36
	 * @param spinner
39
	 * @param spinner
37
	 * @param attribute
40
	 * @param attribute
Lines 42-48 Link Here
42
		this.attribute = attribute;
45
		this.attribute = attribute;
43
		if (attribute.equals(SWTProperties.SELECTION)) {
46
		if (attribute.equals(SWTProperties.SELECTION)) {
44
			currentSelection = spinner.getSelection();
47
			currentSelection = spinner.getSelection();
45
			spinner.addModifyListener(new ModifyListener() {
48
			modifyListener = new ModifyListener() {
46
				public void modifyText(ModifyEvent e) {
49
				public void modifyText(ModifyEvent e) {
47
					if (!updating) {
50
					if (!updating) {
48
						int newSelection = SpinnerObservableValue.this.spinner
51
						int newSelection = SpinnerObservableValue.this.spinner
Lines 52-58 Link Here
52
						currentSelection = newSelection;
55
						currentSelection = newSelection;
53
					}
56
					}
54
				}
57
				}
55
			});
58
			};
59
			spinner.addModifyListener(modifyListener);
56
		} else if (!attribute.equals(SWTProperties.MIN)
60
		} else if (!attribute.equals(SWTProperties.MIN)
57
				&& !attribute.equals(SWTProperties.MAX)) {
61
				&& !attribute.equals(SWTProperties.MAX)) {
58
			throw new IllegalArgumentException(
62
			throw new IllegalArgumentException(
Lines 109-112 Link Here
109
	public String getAttribute() {
113
	public String getAttribute() {
110
		return attribute;
114
		return attribute;
111
	}
115
	}
116
117
	/*
118
	 * (non-Javadoc)
119
	 *
120
	 * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose()
121
	 */
122
	public synchronized void dispose() {
123
		super.dispose();
124
		if (modifyListener != null && !spinner.isDisposed()) {
125
			spinner.removeModifyListener(modifyListener);
126
		}
127
	}
112
}
128
}
(-)src/org/eclipse/jface/tests/databinding/AbstractSWTTestCase.java (-9 / +25 lines)
Lines 7-54 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Ashley Cambrell - bug 198904
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.jface.tests.databinding;
13
package org.eclipse.jface.tests.databinding;
13
14
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.widgets.Event;
14
import org.eclipse.swt.widgets.Shell;
17
import org.eclipse.swt.widgets.Shell;
18
import org.eclipse.swt.widgets.Widget;
15
19
16
/**
20
/**
17
 * Abstract test case that handles disposing of the Shell after each test.
21
 * Abstract test case that handles disposing of the Shell after each test.
18
 * 
22
 *
19
 * @since 1.1
23
 * @since 1.1
20
 */
24
 */
21
public abstract class AbstractSWTTestCase extends AbstractDefaultRealmTestCase {
25
public abstract class AbstractSWTTestCase extends AbstractDefaultRealmTestCase {
22
	private Shell shell;
26
	private Shell shell;
23
	
27
24
	/* (non-Javadoc)
28
	/*
29
	 * (non-Javadoc)
30
	 *
25
	 * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#setUp()
31
	 * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#setUp()
26
	 */
32
	 */
27
	protected void setUp() throws Exception {
33
	protected void setUp() throws Exception {
28
		super.setUp();
34
		super.setUp();
29
	}
35
	}
30
	
36
31
	/* (non-Javadoc)
37
	/*
38
	 * (non-Javadoc)
39
	 *
32
	 * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#tearDown()
40
	 * @see org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase#tearDown()
33
	 */
41
	 */
34
	protected void tearDown() throws Exception {
42
	protected void tearDown() throws Exception {
35
		super.tearDown();
43
		super.tearDown();
36
		
44
37
		if (shell != null && !shell.isDisposed()) {
45
		if (shell != null && !shell.isDisposed()) {
38
			shell.dispose();
46
			shell.dispose();
39
		}
47
		}
40
	}
48
	}
41
	
49
42
	/**
50
	/**
43
	 * Returns a Shell to be used in a test.
51
	 * Returns a Shell to be used in a test.
44
	 * 
52
	 *
45
	 * @return shell
53
	 * @return shell
46
	 */
54
	 */
47
	protected Shell getShell() {
55
	protected Shell getShell() {
48
		if (shell == null || shell.isDisposed()) {
56
		if (shell == null || shell.isDisposed()) {
49
			shell = new Shell();
57
			shell = new Shell();
50
		}
58
		}
51
		
59
52
		return shell;
60
		return shell;
53
	}
61
	}
62
63
	public static void notifySelection(Widget widget) {
64
		Event event = new Event();
65
		event.type = SWT.Selection;
66
		event.display = widget.getDisplay();
67
		event.widget = widget;
68
		widget.notifyListeners(SWT.Selection, event);
69
	}
54
}
70
}
(-)src/org/eclipse/jface/tests/databinding/BindingTestSuite.java (-8 / +15 lines)
Lines 11-16 Link Here
11
 *     Brad Reynolds - bug 116920
11
 *     Brad Reynolds - bug 116920
12
 *     Brad Reynolds - bug 164247
12
 *     Brad Reynolds - bug 164247
13
 *     Brad Reynolds - bug 164653, 159768, 170848, 147515
13
 *     Brad Reynolds - bug 164653, 159768, 170848, 147515
14
 *     Ashley Cambrell - bug 198904
14
 *******************************************************************************/
15
 *******************************************************************************/
15
package org.eclipse.jface.tests.databinding;
16
package org.eclipse.jface.tests.databinding;
16
17
Lines 109-118 Link Here
109
import org.eclipse.jface.tests.examples.databinding.mask.internal.EditMaskParserTest;
110
import org.eclipse.jface.tests.examples.databinding.mask.internal.EditMaskParserTest;
110
import org.eclipse.jface.tests.internal.databinding.internal.swt.ButtonObservableValueTest;
111
import org.eclipse.jface.tests.internal.databinding.internal.swt.ButtonObservableValueTest;
111
import org.eclipse.jface.tests.internal.databinding.internal.swt.CComboObservableValueTest;
112
import org.eclipse.jface.tests.internal.databinding.internal.swt.CComboObservableValueTest;
113
import org.eclipse.jface.tests.internal.databinding.internal.swt.CComboSingleSelectionObservableValueTest;
112
import org.eclipse.jface.tests.internal.databinding.internal.swt.CLabelObservableValueTest;
114
import org.eclipse.jface.tests.internal.databinding.internal.swt.CLabelObservableValueTest;
113
import org.eclipse.jface.tests.internal.databinding.internal.swt.ComboObservableValueTest;
115
import org.eclipse.jface.tests.internal.databinding.internal.swt.ComboObservableValueTest;
116
import org.eclipse.jface.tests.internal.databinding.internal.swt.ComboSingleSelectionObservableValueTest;
114
import org.eclipse.jface.tests.internal.databinding.internal.swt.ControlObservableValueTest;
117
import org.eclipse.jface.tests.internal.databinding.internal.swt.ControlObservableValueTest;
115
import org.eclipse.jface.tests.internal.databinding.internal.swt.LabelObservableValueTest;
118
import org.eclipse.jface.tests.internal.databinding.internal.swt.LabelObservableValueTest;
119
import org.eclipse.jface.tests.internal.databinding.internal.swt.ListSingleSelectionObservableValueTest;
116
import org.eclipse.jface.tests.internal.databinding.internal.swt.ScaleObservableValueTest;
120
import org.eclipse.jface.tests.internal.databinding.internal.swt.ScaleObservableValueTest;
117
import org.eclipse.jface.tests.internal.databinding.internal.swt.SpinnerObservableValueTest;
121
import org.eclipse.jface.tests.internal.databinding.internal.swt.SpinnerObservableValueTest;
118
import org.eclipse.jface.tests.internal.databinding.internal.swt.TableObservableValueTest;
122
import org.eclipse.jface.tests.internal.databinding.internal.swt.TableObservableValueTest;
Lines 169-184 Link Here
169
		addTestSuite(UnionSetRealmTest.class);
173
		addTestSuite(UnionSetRealmTest.class);
170
		addTestSuite(WritableSetRealmTest.class);
174
		addTestSuite(WritableSetRealmTest.class);
171
		addTestSuite(WritableSetTest.class);
175
		addTestSuite(WritableSetTest.class);
172
		
176
173
		//org.eclipse.core.tests.databinding.observable.value
177
		//org.eclipse.core.tests.databinding.observable.value
174
		addTestSuite(AbstractObservableValueTest.class);
178
		addTestSuite(AbstractObservableValueTest.class);
175
		addTestSuite(AbstractVetoableValueTest.class);
179
		addTestSuite(AbstractVetoableValueTest.class);
176
		addTestSuite(ComputedValueTest.class);
180
		addTestSuite(ComputedValueTest.class);
177
		addTestSuite(WritableValueTest.class);
181
		addTestSuite(WritableValueTest.class);
178
		
182
179
		//org.eclipse.core.tests.databinding.validation
183
		//org.eclipse.core.tests.databinding.validation
180
		addTestSuite(ValidationStatusTest.class);
184
		addTestSuite(ValidationStatusTest.class);
181
		
185
182
		// org.eclipse.core.tests.internal.databinding
186
		// org.eclipse.core.tests.internal.databinding
183
		addTestSuite(BindingMessagesTest.class);
187
		addTestSuite(BindingMessagesTest.class);
184
		addTestSuite(BindingStatusTest.class);
188
		addTestSuite(BindingStatusTest.class);
Lines 220-229 Link Here
220
		addTestSuite(JavaBeanObservableSetTest.class);
224
		addTestSuite(JavaBeanObservableSetTest.class);
221
		addTestSuite(JavaBeanObservableValueTest.class);
225
		addTestSuite(JavaBeanObservableValueTest.class);
222
		addTestSuite(ListenerSupportTest.class);
226
		addTestSuite(ListenerSupportTest.class);
223
		
227
224
		//org.eclipse.core.tests.internal.databinding.observable
228
		//org.eclipse.core.tests.internal.databinding.observable
225
		addTestSuite(UnmodifiableObservableListTest.class);
229
		addTestSuite(UnmodifiableObservableListTest.class);
226
		
230
227
		// org.eclipse.core.tests.internal.databinding.observable.masterdetail
231
		// org.eclipse.core.tests.internal.databinding.observable.masterdetail
228
		addTestSuite(DetailObservableListTest.class);
232
		addTestSuite(DetailObservableListTest.class);
229
		addTestSuite(DetailObservableSetTest.class);
233
		addTestSuite(DetailObservableSetTest.class);
Lines 251-261 Link Here
251
255
252
		//org.eclipse.jface.tests.databinding.swt
256
		//org.eclipse.jface.tests.databinding.swt
253
		addTestSuite(SWTObservablesTest.class);
257
		addTestSuite(SWTObservablesTest.class);
254
		
258
255
		// org.eclipse.jface.tests.databinding.viewers
259
		// org.eclipse.jface.tests.databinding.viewers
256
		addTestSuite(ObservableMapLabelProviderTest.class);
260
		addTestSuite(ObservableMapLabelProviderTest.class);
257
		addTestSuite(ObservableSetContentProviderTest.class);
261
		addTestSuite(ObservableSetContentProviderTest.class);
258
		
262
259
		//org.eclipse.jface.tests.example.databinding.mask.internal
263
		//org.eclipse.jface.tests.example.databinding.mask.internal
260
		addTestSuite(EditMaskLexerAndTokenTest.class);
264
		addTestSuite(EditMaskLexerAndTokenTest.class);
261
		addTestSuite(EditMaskParserTest.class);
265
		addTestSuite(EditMaskParserTest.class);
Lines 263-278 Link Here
263
		//org.eclipse.jface.tests.internal.databinding.internal.swt
267
		//org.eclipse.jface.tests.internal.databinding.internal.swt
264
		addTestSuite(ButtonObservableValueTest.class);
268
		addTestSuite(ButtonObservableValueTest.class);
265
		addTestSuite(CComboObservableValueTest.class);
269
		addTestSuite(CComboObservableValueTest.class);
270
		addTestSuite(CComboSingleSelectionObservableValueTest.class);
266
		addTestSuite(CLabelObservableValueTest.class);
271
		addTestSuite(CLabelObservableValueTest.class);
267
		addTestSuite(ComboObservableValueTest.class);
272
		addTestSuite(ComboObservableValueTest.class);
273
		addTestSuite(ComboSingleSelectionObservableValueTest.class);
268
		addTestSuite(ControlObservableValueTest.class);
274
		addTestSuite(ControlObservableValueTest.class);
269
		addTestSuite(LabelObservableValueTest.class);
275
		addTestSuite(LabelObservableValueTest.class);
276
		addTestSuite(ListSingleSelectionObservableValueTest.class);
270
		addTestSuite(ScaleObservableValueTest.class);
277
		addTestSuite(ScaleObservableValueTest.class);
271
		addTestSuite(SpinnerObservableValueTest.class);
278
		addTestSuite(SpinnerObservableValueTest.class);
272
		addTestSuite(TableObservableValueTest.class);
279
		addTestSuite(TableObservableValueTest.class);
273
		addTestSuite(TextEditableObservableValueTest.class);
280
		addTestSuite(TextEditableObservableValueTest.class);
274
		addTestSuite(TextObservableValueTest.class);
281
		addTestSuite(TextObservableValueTest.class);
275
		
282
276
		//org.eclipse.jface.tests.internal.databinding.internal.viewers
283
		//org.eclipse.jface.tests.internal.databinding.internal.viewers
277
		addTestSuite(SelectionProviderSingleSelectionObservableValueTest.class);
284
		addTestSuite(SelectionProviderSingleSelectionObservableValueTest.class);
278
	}
285
	}
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/ButtonObservableValueTest.java (-17 / +42 lines)
Lines 7-39 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
9
 *     Brad Reynolds - initial API and implementation
10
 *     Ashley Cambrell - bug 198904
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
14
14
import junit.framework.TestCase;
15
16
import org.eclipse.jface.internal.databinding.internal.swt.ButtonObservableValue;
15
import org.eclipse.jface.internal.databinding.internal.swt.ButtonObservableValue;
16
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
17
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.widgets.Button;
18
import org.eclipse.swt.widgets.Button;
19
import org.eclipse.swt.widgets.Shell;
20
19
21
/**
20
/**
22
 * @since 3.2
21
 * @since 3.2
23
 *
22
 *
24
 */
23
 */
25
public class ButtonObservableValueTest extends TestCase {
24
public class ButtonObservableValueTest extends AbstractSWTTestCase {
26
    public void testSetValue() throws Exception {
25
27
        Shell shell = new Shell();
26
	public void testSetValue() throws Exception {
28
        Button button = new Button(shell, SWT.CHECK);
27
		Button button = new Button(getShell(), SWT.CHECK);
29
        ButtonObservableValue observableValue = new ButtonObservableValue(button);
28
		ButtonObservableValue observableValue = new ButtonObservableValue(
30
        assertEquals(Boolean.FALSE, observableValue.getValue());
29
				button);
31
        assertFalse(button.getSelection());
30
		assertEquals(Boolean.FALSE, observableValue.getValue());
32
        
31
		assertFalse(button.getSelection());
33
        Boolean value = Boolean.TRUE;
32
34
        observableValue.setValue(value);
33
		Boolean value = Boolean.TRUE;
35
        assertTrue("button value", button.getSelection());
34
		observableValue.setValue(value);
36
        assertEquals("observable value", value, observableValue.getValue());
35
		assertTrue("button value", button.getSelection());
37
        shell.dispose();
36
		assertEquals("observable value", value, observableValue.getValue());
38
    }
37
	}
38
39
	public void testDispose() throws Exception {
40
		Button button = new Button(getShell(), SWT.CHECK);
41
		ButtonObservableValue observableValue = new ButtonObservableValue(
42
				button);
43
		TestCounterValueChangeListener testCounterValueChangeListener = new TestCounterValueChangeListener();
44
		observableValue.addValueChangeListener(testCounterValueChangeListener);
45
46
		assertEquals(Boolean.FALSE, observableValue.getValue());
47
		assertFalse(button.getSelection());
48
49
		button.setSelection(true);
50
		notifySelection(button);
51
52
		assertEquals(1, testCounterValueChangeListener.counter);
53
		assertEquals(Boolean.TRUE, observableValue.getValue());
54
		assertTrue(button.getSelection());
55
56
		observableValue.dispose();
57
58
		button.setSelection(false);
59
		notifySelection(button);
60
61
		assertEquals(1, testCounterValueChangeListener.counter);
62
63
	}
39
}
64
}
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/ComboObservableValueTest.java (-18 / +42 lines)
Lines 7-40 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
9
 *     Brad Reynolds - initial API and implementation
10
 *     Ashley Cambrell - bug 198904
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
14
14
import junit.framework.TestCase;
15
16
import org.eclipse.jface.internal.databinding.internal.swt.ComboObservableValue;
15
import org.eclipse.jface.internal.databinding.internal.swt.ComboObservableValue;
17
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
16
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
17
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
18
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.widgets.Combo;
19
import org.eclipse.swt.widgets.Combo;
20
import org.eclipse.swt.widgets.Shell;
21
20
22
/**
21
/**
23
 * @since 3.2
22
 * @since 3.2
24
 * 
23
 *
25
 */
24
 */
26
public class ComboObservableValueTest extends TestCase {
25
public class ComboObservableValueTest extends AbstractSWTTestCase {
27
    public void testSetValueText() throws Exception {
26
	public void testSetValueText() throws Exception {
28
        Shell shell = new Shell();
27
		Combo combo = new Combo(getShell(), SWT.NONE);
29
        Combo combo = new Combo(shell, SWT.NONE);
28
		ComboObservableValue observableValue = new ComboObservableValue(combo,
30
        ComboObservableValue observableValue = new ComboObservableValue(combo, SWTProperties.TEXT);
29
				SWTProperties.TEXT);
31
        assertEquals("", combo.getText());
30
		assertEquals("", combo.getText());
32
        assertEquals("", observableValue.getValue());
31
		assertEquals("", observableValue.getValue());
33
32
34
        String value = "value";
33
		String value = "value";
35
        observableValue.setValue(value);
34
		observableValue.setValue(value);
36
        assertEquals("combo text", value, combo.getText());
35
		assertEquals("combo text", value, combo.getText());
37
        assertEquals("observable value", value, observableValue.getValue());
36
		assertEquals("observable value", value, observableValue.getValue());
38
        shell.dispose();
37
	}
39
    }
38
39
	public void testDispose() throws Exception {
40
		Combo combo = new Combo(getShell(), SWT.NONE);
41
		ComboObservableValue observableValue = new ComboObservableValue(combo,
42
				SWTProperties.TEXT);
43
		TestCounterValueChangeListener testCounterValueChangeListener = new TestCounterValueChangeListener();
44
		observableValue.addValueChangeListener(testCounterValueChangeListener);
45
46
		assertEquals("", combo.getText());
47
		assertEquals("", observableValue.getValue());
48
49
		String expected1 = "Test123";
50
		combo.setText(expected1);
51
52
		assertEquals(1, testCounterValueChangeListener.counter);
53
		assertEquals(expected1, combo.getText());
54
		assertEquals(expected1, observableValue.getValue());
55
56
		observableValue.dispose();
57
58
		String expected2 = "NewValue123";
59
		combo.setText(expected2);
60
61
		assertEquals(1, testCounterValueChangeListener.counter);
62
		assertEquals(expected2, combo.getText());
63
	}
40
}
64
}
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/TableObservableValueTest.java (-19 / +43 lines)
Lines 7-41 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
9
 *     Brad Reynolds - initial API and implementation
10
 *     Ashley Cambrell - bug 198904
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
14
14
import junit.framework.TestCase;
15
16
import org.eclipse.jface.internal.databinding.internal.swt.TableSingleSelectionObservableValue;
15
import org.eclipse.jface.internal.databinding.internal.swt.TableSingleSelectionObservableValue;
16
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
17
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.widgets.Shell;
19
import org.eclipse.swt.widgets.Table;
18
import org.eclipse.swt.widgets.Table;
20
import org.eclipse.swt.widgets.TableItem;
19
import org.eclipse.swt.widgets.TableItem;
21
20
22
/**
21
/**
23
 * @since 3.2
22
 * @since 3.2
24
 */
23
 */
25
public class TableObservableValueTest extends TestCase {
24
public class TableObservableValueTest extends AbstractSWTTestCase {
26
    public void testSetValue() throws Exception {
25
	public void testSetValue() throws Exception {
27
        Shell shell = new Shell();
26
		Table table = new Table(getShell(), SWT.NONE);
28
        Table table = new Table(shell, SWT.NONE);
27
		TableSingleSelectionObservableValue observableValue = new TableSingleSelectionObservableValue(
29
        TableSingleSelectionObservableValue observableValue = new TableSingleSelectionObservableValue(table);
28
				table);
30
        new TableItem(table, SWT.NONE);
29
		new TableItem(table, SWT.NONE);
31
        
30
32
        assertEquals(-1, table.getSelectionIndex());
31
		assertEquals(-1, table.getSelectionIndex());
33
        assertEquals(-1, ((Integer) observableValue.getValue()).intValue());
32
		assertEquals(-1, ((Integer) observableValue.getValue()).intValue());
34
        
33
35
        Integer value = new Integer(0);
34
		Integer value = new Integer(0);
36
        observableValue.setValue(value);
35
		observableValue.setValue(value);
37
        assertEquals("table selection index", value.intValue(), table.getSelectionIndex());
36
		assertEquals("table selection index", value.intValue(), table
38
        assertEquals("observable value", value, observableValue.getValue());
37
				.getSelectionIndex());
39
        shell.dispose();
38
		assertEquals("observable value", value, observableValue.getValue());
40
    }
39
	}
40
41
	public void testDispose() throws Exception {
42
		Table table = new Table(getShell(), SWT.NONE);
43
		TableSingleSelectionObservableValue observableValue = new TableSingleSelectionObservableValue(
44
				table);
45
46
		TableItem item1 = new TableItem(table, SWT.NONE);
47
		item1.setText("Item1");
48
		TableItem item2 = new TableItem(table, SWT.NONE);
49
		item2.setText("Item2");
50
51
		assertEquals(-1, table.getSelectionIndex());
52
		assertEquals(-1, ((Integer) observableValue.getValue()).intValue());
53
54
		table.select(0);
55
		notifySelection(table);
56
		assertEquals(0, table.getSelectionIndex());
57
		assertEquals(new Integer(0), observableValue.getValue());
58
59
		observableValue.dispose();
60
61
		table.select(1);
62
		notifySelection(table);
63
		assertEquals(1, table.getSelectionIndex());
64
	}
41
}
65
}
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/TextObservableValueTest.java (-22 / +45 lines)
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brad Reynolds - bug 116920
10
 *     Brad Reynolds - bug 116920
11
 *     Brad Reynolds - bug 164653
11
 *     Brad Reynolds - bug 164653
12
 *     Ashley Cambrell - bug 198904
12
 *******************************************************************************/
13
 *******************************************************************************/
13
14
14
package org.eclipse.jface.tests.internal.databinding.internal.swt;
15
package org.eclipse.jface.tests.internal.databinding.internal.swt;
Lines 22-28 Link Here
22
23
23
/**
24
/**
24
 * Tests to assert the inputs of the TextObservableValue constructor.
25
 * Tests to assert the inputs of the TextObservableValue constructor.
25
 * 
26
 *
26
 * @since 3.2
27
 * @since 3.2
27
 */
28
 */
28
public class TextObservableValueTest extends AbstractDefaultRealmTestCase {
29
public class TextObservableValueTest extends AbstractDefaultRealmTestCase {
Lines 34-40 Link Here
34
35
35
		Shell shell = new Shell();
36
		Shell shell = new Shell();
36
		text = new Text(shell, SWT.NONE);
37
		text = new Text(shell, SWT.NONE);
37
		
38
38
		listener = new ValueChangeEventTracker();
39
		listener = new ValueChangeEventTracker();
39
	}
40
	}
40
41
Lines 69-86 Link Here
69
		observableValue.setValue(value);
70
		observableValue.setValue(value);
70
		assertEquals("observable value", value, observableValue.getValue());
71
		assertEquals("observable value", value, observableValue.getValue());
71
	}
72
	}
72
	
73
73
	public void testSetValueValueChangeEvent() throws Exception {
74
	public void testSetValueValueChangeEvent() throws Exception {
74
		String a = "a";
75
		String a = "a";
75
		String b = "b";
76
		String b = "b";
76
		
77
77
		TextObservableValue observableValue = new TextObservableValue(text, SWT.NONE);
78
		TextObservableValue observableValue = new TextObservableValue(text, SWT.NONE);
78
		observableValue.addValueChangeListener(listener);
79
		observableValue.addValueChangeListener(listener);
79
		
80
80
		observableValue.setValue(a);
81
		observableValue.setValue(a);
81
		assertEquals("", listener.event.diff.getOldValue());
82
		assertEquals("", listener.event.diff.getOldValue());
82
		assertEquals(a, listener.event.diff.getNewValue());
83
		assertEquals(a, listener.event.diff.getNewValue());
83
		
84
84
		observableValue.setValue(b);
85
		observableValue.setValue(b);
85
		assertEquals(a, listener.event.diff.getOldValue());
86
		assertEquals(a, listener.event.diff.getOldValue());
86
		assertEquals(b, listener.event.diff.getNewValue());
87
		assertEquals(b, listener.event.diff.getNewValue());
Lines 94-100 Link Here
94
		String b = "b";
95
		String b = "b";
95
96
96
		text.setText(a);
97
		text.setText(a);
97
		
98
98
		observableValue.addValueChangeListener(listener);
99
		observableValue.addValueChangeListener(listener);
99
100
100
		assertEquals(0, listener.count);
101
		assertEquals(0, listener.count);
Lines 108-164 Link Here
108
	public void testOnFocusOutValueChangeEvent() throws Exception {
109
	public void testOnFocusOutValueChangeEvent() throws Exception {
109
		String a = "a";
110
		String a = "a";
110
		String b = "b";
111
		String b = "b";
111
		
112
112
		text.setText(a);
113
		text.setText(a);
113
114
114
		TextObservableValue observableValue = new TextObservableValue(text,
115
		TextObservableValue observableValue = new TextObservableValue(text,
115
				SWT.FocusOut);
116
				SWT.FocusOut);
116
		
117
117
		observableValue.addValueChangeListener(listener);
118
		observableValue.addValueChangeListener(listener);
118
		
119
119
		text.setText(b);
120
		text.setText(b);
120
		assertEquals(0, listener.count);
121
		assertEquals(0, listener.count);
121
		
122
122
		text.notifyListeners(SWT.FocusOut, null);
123
		text.notifyListeners(SWT.FocusOut, null);
123
		assertEquals(1, listener.count);
124
		assertEquals(1, listener.count);
124
		
125
125
		assertEquals(a, listener.event.diff.getOldValue());
126
		assertEquals(a, listener.event.diff.getOldValue());
126
		assertEquals(b, listener.event.diff.getNewValue());
127
		assertEquals(b, listener.event.diff.getNewValue());
127
	}
128
	}
128
	
129
129
	public void testChangeEventsSuppressedWhenValueDoesNotChange() throws Exception {
130
	public void testChangeEventsSuppressedWhenValueDoesNotChange() throws Exception {
130
		TextObservableValue observableValue = new TextObservableValue(text, SWT.Modify);
131
		TextObservableValue observableValue = new TextObservableValue(text, SWT.Modify);
131
		
132
132
		observableValue.addValueChangeListener(listener);
133
		observableValue.addValueChangeListener(listener);
133
		
134
134
		String value = "value";
135
		String value = "value";
135
		text.setText(value);
136
		text.setText(value);
136
		assertEquals(1, listener.count);
137
		assertEquals(1, listener.count);
137
		
138
138
		text.setText(value);
139
		text.setText(value);
139
		assertEquals("listener not notified", 1, listener.count);
140
		assertEquals("listener not notified", 1, listener.count);
140
	}
141
	}
141
	
142
142
	/**
143
	/**
143
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=171132
144
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=171132
144
	 * 
145
	 *
145
	 * @throws Exception
146
	 * @throws Exception
146
	 */
147
	 */
147
	public void testGetValueBeforeFocusOutChangeEventsFire() throws Exception {
148
	public void testGetValueBeforeFocusOutChangeEventsFire() throws Exception {
148
		TextObservableValue observableValue = new TextObservableValue(text, SWT.FocusOut);
149
		TextObservableValue observableValue = new TextObservableValue(text, SWT.FocusOut);
149
		observableValue.addValueChangeListener(listener);
150
		observableValue.addValueChangeListener(listener);
150
		
151
151
		String a = "a";
152
		String a = "a";
152
		String b = "b";
153
		String b = "b";
153
		
154
154
		text.setText(a);
155
		text.setText(a);
155
		assertEquals(a, observableValue.getValue()); //fetch the value updating the buffered value
156
		assertEquals(a, observableValue.getValue()); //fetch the value updating the buffered value
156
		
157
157
		text.setText(b);
158
		text.setText(b);
158
		text.notifyListeners(SWT.FocusOut, null);
159
		text.notifyListeners(SWT.FocusOut, null);
159
		
160
160
		assertEquals(1, listener.count);
161
		assertEquals(1, listener.count);
161
		assertEquals(a, listener.event.diff.getOldValue());
162
		assertEquals(a, listener.event.diff.getOldValue());
162
		assertEquals(b, listener.event.diff.getNewValue());
163
		assertEquals(b, listener.event.diff.getNewValue());
163
	}
164
	}
165
166
	public void testDispose() throws Exception {
167
		TextObservableValue observableValue = new TextObservableValue(text,
168
				SWT.Modify);
169
		TestCounterValueChangeListener testCounterValueChangeListener = new TestCounterValueChangeListener();
170
		observableValue.addValueChangeListener(testCounterValueChangeListener);
171
172
		String expected1 = "Test123";
173
		text.setText(expected1);
174
175
		assertEquals(1, testCounterValueChangeListener.counter);
176
		assertEquals(expected1, text.getText());
177
		assertEquals(expected1, observableValue.getValue());
178
179
		observableValue.dispose();
180
181
		String expected2 = "NewValue123";
182
		text.setText(expected2);
183
184
		assertEquals(1, testCounterValueChangeListener.counter);
185
		assertEquals(expected2, text.getText());
186
	}
164
}
187
}
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/SpinnerObservableValueTest.java (-18 / +43 lines)
Lines 7-41 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
9
 *     Brad Reynolds - initial API and implementation
10
 *     Ashley Cambrell - bug 198904
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
14
14
import junit.framework.TestCase;
15
16
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
15
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
17
import org.eclipse.jface.internal.databinding.internal.swt.SpinnerObservableValue;
16
import org.eclipse.jface.internal.databinding.internal.swt.SpinnerObservableValue;
17
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
18
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.widgets.Shell;
20
import org.eclipse.swt.widgets.Spinner;
19
import org.eclipse.swt.widgets.Spinner;
21
20
22
/**
21
/**
23
 * @since 3.2
22
 * @since 3.2
24
 *
23
 *
25
 */
24
 */
26
public class SpinnerObservableValueTest extends TestCase {
25
public class SpinnerObservableValueTest extends AbstractSWTTestCase {
27
    public void testSetValueSelection() throws Exception {
26
	public void testSetValueSelection() throws Exception {
28
        Shell shell = new Shell();
27
		Spinner spinner = new Spinner(getShell(), SWT.NONE);
29
        Spinner spinner = new Spinner(shell, SWT.NONE);
28
		SpinnerObservableValue observableValue = new SpinnerObservableValue(
30
        SpinnerObservableValue observableValue = new SpinnerObservableValue(spinner, SWTProperties.SELECTION);
29
				spinner, SWTProperties.SELECTION);
31
        
30
32
        assertEquals(0, spinner.getSelection());
31
		assertEquals(0, spinner.getSelection());
33
        assertEquals(0, ((Integer) observableValue.getValue()).intValue());
32
		assertEquals(0, ((Integer) observableValue.getValue()).intValue());
34
        
33
35
        Integer value = new Integer(1);
34
		Integer value = new Integer(1);
36
        observableValue.setValue(value);
35
		observableValue.setValue(value);
37
        assertEquals("spinner selection", value.intValue(), spinner.getSelection());
36
		assertEquals("spinner selection", value.intValue(), spinner
38
        assertEquals("observable value", value, observableValue.getValue());
37
				.getSelection());
39
        shell.dispose();
38
		assertEquals("observable value", value, observableValue.getValue());
40
    }
39
	}
40
41
	public void testDispose() throws Exception {
42
		Spinner spinner = new Spinner(getShell(), SWT.NONE);
43
		SpinnerObservableValue observableValue = new SpinnerObservableValue(
44
				spinner, SWTProperties.SELECTION);
45
		TestCounterValueChangeListener testCounterValueChangeListener = new TestCounterValueChangeListener();
46
		observableValue.addValueChangeListener(testCounterValueChangeListener);
47
48
		assertEquals(0, spinner.getSelection());
49
		assertEquals(0, ((Integer) observableValue.getValue()).intValue());
50
51
		Integer expected1 = new Integer(1);
52
		spinner.setSelection(expected1.intValue());
53
54
		assertEquals(1, testCounterValueChangeListener.counter);
55
		assertEquals(expected1.intValue(), spinner.getSelection());
56
		assertEquals(expected1, observableValue.getValue());
57
58
		observableValue.dispose();
59
60
		Integer expected2 = new Integer(2);
61
		spinner.setSelection(expected2.intValue());
62
63
		assertEquals(1, testCounterValueChangeListener.counter);
64
		assertEquals(expected2.intValue(), spinner.getSelection());
65
	}
41
}
66
}
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/CComboObservableValueTest.java (-17 / +43 lines)
Lines 7-39 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
9
 *     Brad Reynolds - initial API and implementation
10
 *     Ashley Cambrell - bug 198904
10
 ******************************************************************************/
11
 ******************************************************************************/
11
12
12
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
14
14
import junit.framework.TestCase;
15
16
import org.eclipse.jface.internal.databinding.internal.swt.CComboObservableValue;
15
import org.eclipse.jface.internal.databinding.internal.swt.CComboObservableValue;
17
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
16
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
17
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
18
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.custom.CCombo;
19
import org.eclipse.swt.custom.CCombo;
20
import org.eclipse.swt.widgets.Shell;
21
20
22
/**
21
/**
23
 * @since 3.2
22
 * @since 3.2
24
 */
23
 */
25
public class CComboObservableValueTest extends TestCase {
24
public class CComboObservableValueTest extends AbstractSWTTestCase {
26
    public void testSetValueText() throws Exception {
25
	public void testSetValueText() throws Exception {
27
        Shell shell = new Shell();
26
		CCombo combo = new CCombo(getShell(), SWT.NONE);
28
        CCombo combo = new CCombo(shell, SWT.NONE);
27
		CComboObservableValue observableValue = new CComboObservableValue(
29
        CComboObservableValue observableValue = new CComboObservableValue(combo, SWTProperties.TEXT);
28
				combo, SWTProperties.TEXT);
30
        assertEquals("", combo.getText());
29
		assertEquals("", combo.getText());
31
        assertEquals("", observableValue.getValue());
30
		assertEquals("", observableValue.getValue());
32
        
31
33
        String value = "value";
32
		String value = "value";
34
        observableValue.setValue(value);
33
		observableValue.setValue(value);
35
        assertEquals("combo value", value, combo.getText());
34
		assertEquals("combo value", value, combo.getText());
36
        assertEquals("observable value value is incorrect", value, observableValue.getValue());
35
		assertEquals("observable value value is incorrect", value,
37
        shell.dispose();
36
				observableValue.getValue());
38
    }
37
	}
38
39
	public void testDispose() throws Exception {
40
		CCombo combo = new CCombo(getShell(), SWT.NONE);
41
		CComboObservableValue observableValue = new CComboObservableValue(
42
				combo, SWTProperties.TEXT);
43
44
		TestCounterValueChangeListener testCounterValueChangeListener = new TestCounterValueChangeListener();
45
		observableValue.addValueChangeListener(testCounterValueChangeListener);
46
47
		assertEquals("", combo.getText());
48
		assertEquals("", observableValue.getValue());
49
50
		String expected1 = "Test123";
51
		combo.setText(expected1);
52
53
		assertEquals(1, testCounterValueChangeListener.counter);
54
		assertEquals(expected1, combo.getText());
55
		assertEquals(expected1, observableValue.getValue());
56
57
		observableValue.dispose();
58
59
		String expected2 = "NewValue123";
60
		combo.setText(expected2);
61
62
		assertEquals(1, testCounterValueChangeListener.counter);
63
		assertEquals(expected2, combo.getText());
64
	}
39
}
65
}
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/ListSingleSelectionObservableValueTest.java (+61 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Ashley Cambrell and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Ashley Cambrell - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
14
import org.eclipse.jface.internal.databinding.internal.swt.ListSingleSelectionObservableValue;
15
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.widgets.List;
18
19
/**
20
 * @since 3.2
21
 *
22
 */
23
public class ListSingleSelectionObservableValueTest extends AbstractSWTTestCase {
24
	public void testSetValue() throws Exception {
25
		List list = new List(getShell(), SWT.NONE);
26
		ListSingleSelectionObservableValue observableValue = new ListSingleSelectionObservableValue(
27
				list);
28
		list.add("Item1");
29
30
		assertEquals(-1, list.getSelectionIndex());
31
		assertEquals(-1, ((Integer) observableValue.getValue()).intValue());
32
33
		Integer value = new Integer(0);
34
		observableValue.setValue(value);
35
		assertEquals("list selection index", value.intValue(), list
36
				.getSelectionIndex());
37
		assertEquals("observable value", value, observableValue.getValue());
38
	}
39
40
	public void testDispose() throws Exception {
41
		List list = new List(getShell(), SWT.NONE);
42
		ListSingleSelectionObservableValue observableValue = new ListSingleSelectionObservableValue(
43
				list);
44
		list.add("Item1");
45
		list.add("Item2");
46
47
		assertEquals(-1, list.getSelectionIndex());
48
		assertEquals(-1, ((Integer) observableValue.getValue()).intValue());
49
50
		list.select(0);
51
		notifySelection(list);
52
		assertEquals(0, list.getSelectionIndex());
53
		assertEquals(new Integer(0), observableValue.getValue());
54
55
		observableValue.dispose();
56
57
		list.select(1);
58
		notifySelection(list);
59
		assertEquals(1, list.getSelectionIndex());
60
	}
61
}
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/TestCounterValueChangeListener.java (+24 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Ashley Cambrell and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Ashley Cambrell - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
14
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
15
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
16
17
class TestCounterValueChangeListener implements
18
		IValueChangeListener {
19
	public int counter = 0;
20
21
	public void handleValueChange(ValueChangeEvent event) {
22
		++counter;
23
	}
24
}
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/ComboSingleSelectionObservableValueTest.java (+65 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Ashley Cambrell and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Ashley Cambrell - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
14
import org.eclipse.jface.internal.databinding.internal.swt.ComboSingleSelectionObservableValue;
15
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.widgets.Combo;
18
19
/**
20
 * @since 3.2
21
 *
22
 */
23
public class ComboSingleSelectionObservableValueTest extends
24
		AbstractSWTTestCase {
25
	public void testSetValue() throws Exception {
26
		Combo combo = new Combo(getShell(), SWT.NONE);
27
		ComboSingleSelectionObservableValue observableValue = new ComboSingleSelectionObservableValue(
28
				combo);
29
		combo.add("Item1");
30
		combo.add("Item2");
31
32
		assertEquals(-1, combo.getSelectionIndex());
33
		assertEquals(-1, ((Integer) observableValue.getValue()).intValue());
34
35
		Integer value = new Integer(1);
36
		observableValue.setValue(value);
37
		assertEquals("combo selection index", value.intValue(), combo
38
				.getSelectionIndex());
39
		assertEquals("observable value", value, observableValue.getValue());
40
41
		assertEquals("Item2", combo.getText());
42
	}
43
44
	public void testDispose() throws Exception {
45
		Combo combo = new Combo(getShell(), SWT.NONE);
46
		ComboSingleSelectionObservableValue observableValue = new ComboSingleSelectionObservableValue(
47
				combo);
48
		combo.add("Item1");
49
		combo.add("Item2");
50
51
		assertEquals(-1, combo.getSelectionIndex());
52
		assertEquals(-1, ((Integer) observableValue.getValue()).intValue());
53
54
		combo.select(0);
55
		notifySelection(combo);
56
		assertEquals(0, combo.getSelectionIndex());
57
		assertEquals(new Integer(0), observableValue.getValue());
58
59
		observableValue.dispose();
60
61
		combo.select(1);
62
		notifySelection(combo);
63
		assertEquals(1, combo.getSelectionIndex());
64
	}
65
}
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/CComboSingleSelectionObservableValueTest.java (+66 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Ashley Cambrell and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Ashley Cambrell - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
14
import org.eclipse.jface.internal.databinding.internal.swt.CComboSingleSelectionObservableValue;
15
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.custom.CCombo;
18
19
/**
20
 * @since 3.2
21
 *
22
 */
23
public class CComboSingleSelectionObservableValueTest extends
24
		AbstractSWTTestCase {
25
	public void testSetValue() throws Exception {
26
		CCombo combo = new CCombo(getShell(), SWT.NONE);
27
		CComboSingleSelectionObservableValue observableValue = new CComboSingleSelectionObservableValue(
28
				combo);
29
		combo.add("Item1");
30
		combo.add("Item2");
31
32
		assertEquals(-1, combo.getSelectionIndex());
33
		assertEquals(-1, ((Integer) observableValue.getValue()).intValue());
34
35
		Integer value = new Integer(1);
36
		observableValue.setValue(value);
37
		assertEquals("combo selection index", value.intValue(), combo
38
				.getSelectionIndex());
39
		assertEquals("observable value", value, observableValue.getValue());
40
41
		assertEquals("Item2", combo.getText());
42
	}
43
44
45
	public void testDispose() throws Exception {
46
		CCombo combo = new CCombo(getShell(), SWT.NONE);
47
		CComboSingleSelectionObservableValue observableValue = new CComboSingleSelectionObservableValue(
48
				combo);
49
		combo.add("Item1");
50
		combo.add("Item2");
51
52
		assertEquals(-1, combo.getSelectionIndex());
53
		assertEquals(-1, ((Integer) observableValue.getValue()).intValue());
54
55
		combo.select(0);
56
		notifySelection(combo);
57
		assertEquals(0, combo.getSelectionIndex());
58
		assertEquals(new Integer(0), observableValue.getValue());
59
60
		observableValue.dispose();
61
62
		combo.select(1);
63
		notifySelection(combo);
64
		assertEquals(1, combo.getSelectionIndex());
65
	}
66
}

Return to bug 198904