Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNigel Westbury2014-01-17 18:25:44 +0000
committerNigel Westbury2014-01-17 20:48:14 +0000
commitdedfb93214133e5dc815e10be940996738651c5d (patch)
tree33dbba12efedfcf51826c39cbb49ea4bda1413fb
parentc3c3f1af068f885b8eff3ff563edce0dbccdc87e (diff)
downloadorg.eclipse.e4.databinding-dedfb93214133e5dc815e10be940996738651c5d.tar.gz
org.eclipse.e4.databinding-dedfb93214133e5dc815e10be940996738651c5d.tar.xz
org.eclipse.e4.databinding-dedfb93214133e5dc815e10be940996738651c5d.zip
-rw-r--r--bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/ControlCreator.java2
-rw-r--r--bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/UpdatingComposite.java36
2 files changed, 29 insertions, 9 deletions
diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/ControlCreator.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/ControlCreator.java
index 6175dc0a..b39c60f4 100644
--- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/ControlCreator.java
+++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/ControlCreator.java
@@ -17,7 +17,7 @@ import org.eclipse.swt.widgets.Control;
*/
public abstract class ControlCreator<T extends Control> {
- UpdatingComposite parent;
+ protected UpdatingComposite parent;
Set<T> controls = new HashSet<T>();
diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/UpdatingComposite.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/UpdatingComposite.java
index 5cc07d4b..57a316da 100644
--- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/UpdatingComposite.java
+++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/UpdatingComposite.java
@@ -10,6 +10,8 @@ import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.ObservableTracker;
import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -29,9 +31,10 @@ import org.eclipse.swt.widgets.Display;
* child controls must not create the controls directly. Instead a control
* creator is instantiated for each 'type' of control. If a control creator is
* called to create a control then it will first search the existing unused
- * controls for a control that was previously created by that control creator. A
- * new control is only created if none exist. If the re-used control needs to be
- * moved in the child control order then that is handled by this class.
+ * controls for a control that was previously created by that control creator
+ * (or a control creator that 'equals' it). A new control is only created if
+ * none exist. If the re-used control needs to be moved in the child control
+ * order then that is handled by this class.
* <P>
* Any change to one of the observable dependencies causes the child controls to
* be re-built.
@@ -43,8 +46,9 @@ import org.eclipse.swt.widgets.Display;
*
* <pre>
* class MyComposite extends UpdatableComposite {
- * LabelCreator labelCreator = new LabelCreator(this);
- * LabelCreator labelCreator = new LabelCreator(this);
+ * ControlCreator labelCreator = new LabelCreator(this);
+ * ControlCreator companyNameControlCreator = new CompanyNameControlCreator(this);
+ * ControlCreator genderComboCreator = new GenderComboCreator(this);
*
* &#064;Override
* protected void createControls() {
@@ -60,9 +64,9 @@ import org.eclipse.swt.widgets.Display;
* companyNameControlCreator.create();
* } else {
* Label label3 = labelCreator.create();
- * label3.setText("Sex:");
+ * label3.setText("Gender:");
*
- * sexComboCreator.create();
+ * genderComboCreator.create();
* }
* }
* </pre>
@@ -215,6 +219,12 @@ public abstract class UpdatingComposite extends Composite {
trackControls();
// }
// });
+
+ addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ stopListening();
+ }
+ });
}
protected final void makeDirty() {
@@ -229,6 +239,16 @@ public abstract class UpdatingComposite extends Composite {
*/
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
+ /*
+ * Although we stop listening to the dependencies when this
+ * composite is disposed, there is a small window in which
+ * the composite may be disposed before we get back onto the
+ * UI thread here.
+ */
+ if (isDisposed()) {
+ return;
+ }
+
trackControls();
computeSizeObservable.fireChange();
}
@@ -289,7 +309,7 @@ public abstract class UpdatingComposite extends Composite {
T matchingControl = null;
for (Control control : remainder) {
- if (control.getData(key) == controlCreator) {
+ if (controlCreator.equals(control.getData(key))) {
matchingControl = controlCreator.typeControl(control);
break;
}

Back to the top