Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java')
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java61
1 files changed, 27 insertions, 34 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java
index 16bf1194db..7437bf48b2 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,16 +9,16 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.listeners;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
import org.eclipse.jpt.common.utility.model.event.StateChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
-import org.eclipse.swt.widgets.Display;
/**
* Wrap another state change listener and forward events to it on the SWT
- * UI thread, asynchronously if necessary. If the event arrived on the UI
- * thread that is probably because it was initiated by a UI widget; as a
- * result, we want to loop back synchronously so the events can be
- * short-circuited.
+ * UI thread, asynchronously if necessary.
+ *
+ * @see SWTPropertyChangeListenerWrapper
*/
public class SWTStateChangeListenerWrapper
implements StateChangeListener
@@ -34,46 +34,39 @@ public class SWTStateChangeListenerWrapper
}
public void stateChanged(StateChangeEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.stateChanged_(event);
- } else {
- this.executeOnUIThread(this.buildStateChangedRunnable(event));
- }
+ this.execute(new StateChangedRunnable(event));
}
- private Runnable buildStateChangedRunnable(final StateChangeEvent event) {
- return new Runnable() {
- public void run() {
- SWTStateChangeListenerWrapper.this.stateChanged_(event);
- }
- @Override
- public String toString() {
- return "state changed runnable"; //$NON-NLS-1$
- }
- };
+ /* CU private */ class StateChangedRunnable
+ extends RunnableAdapter
+ {
+ private final StateChangeEvent event;
+ StateChangedRunnable(StateChangeEvent event) {
+ super();
+ this.event = event;
+ }
+ @Override
+ public void run() {
+ SWTStateChangeListenerWrapper.this.stateChanged_(this.event);
+ }
}
- private boolean isExecutingOnUIThread() {
- return Display.getCurrent() != null;
+ void stateChanged_(StateChangeEvent event) {
+ this.listener.stateChanged(event);
}
/**
- * {@link Display#asyncExec(Runnable)} seems to work OK;
- * but using {@link Display#syncExec(Runnable)} can somtimes make things
+ * {@link SWTUtil#execute(Runnable)} seems to work OK;
+ * but using {@link SWTUtil#syncExec(Runnable)} can somtimes make things
* more predictable when debugging, at the risk of deadlocks.
*/
- private void executeOnUIThread(Runnable r) {
- Display.getDefault().asyncExec(r);
-// Display.getDefault().syncExec(r);
- }
-
- void stateChanged_(StateChangeEvent event) {
- this.listener.stateChanged(event);
+ private void execute(Runnable r) {
+ SWTUtil.execute(r);
+// SWTUtil.syncExec(r);
}
@Override
public String toString() {
- return "SWT(" + this.listener.toString() + ')'; //$NON-NLS-1$
+ return "SWT(" + this.listener + ')'; //$NON-NLS-1$
}
-
}

Back to the top