ilog.views.util.swt
Class IlvEventThreadUtil

java.lang.Object
  extended by ilog.views.util.swt.IlvEventThreadUtil

public class IlvEventThreadUtil
extends Object

This class contains utility functions for dealing with the SWT and AWT/Swing event threads in an SWT environment. In particular, it allows the "merge" between the SWT event thread and the AWT/Swing event thread, by redirecting all event handling from the AWT/Swing event thread to the SWT event thread.

This redirection has the following advantages:

  1. It is no longer required to use EventQueue.invokeLater or EventQueue.invokeAndWait from within the SWT event thread in order to perform operations on Swing components.
  2. It is no longer required to use Display.asyncExec or Display.syncExec from within the AWT/Swing event thread in order to perform operations on SWT components.
  3. The risk of deadlocks, related to the use of EventQueue.invokeAndWait or Display.syncExec, is eliminated.

Limitations:
This redirection has the following restrictions:

  1. It is incompatible with AWT/Swing Dialogs. If you use this redirection, you cannot use AWT Dialogs, Swing JDialogs, or modal JInternalFrames in your application.
  2. IlvSwingUtil.isDispatchThread() must be used instead of EventQueue.isDispatchThread() or SwingUtilities.isEventDispatchThread().
  3. EventQueue.invokeAndWait() and SwingUtilities.invokeAndWait must not be used (because these invokeAndWait() methods are incompatible with Display.syncExec(), and this class uses Display.syncExec()).
These restrictions affect not only the Eclipse/RCP plugins that make use of this class, but all Eclipse/RCP plugins that use AWT or Swing.

Note: Some particular events, like WINDOW_DEACTIVATED, WINDOW_GAINED_FOCUS, WINDOW_LOST_FOCUS are still handled in the original AWT/Swing event thread. Be careful to use SwingUtilities.invokeLater where necessary in such event handlers.

Since:
JViews 8.1

Method Summary
static void enableAWTThreadRedirect()
          Redirects the SWT event thread to the SWT event thread of the default display.
static void execNowOrAsync(Display display, Runnable task)
          Executes the given task in the display's event thread, if not already executing in this thread.
static IlvAWTEventFilter getAWTEventFilter()
          Returns the currently active AWT event filter.
static Display getAWTThreadRedirectDisplay()
          Returns the SWT display to which the AWT/Swing event thread is currently redirected.
static Thread getAWTThreadRedirectThread()
          Returns the SWT event thread to which the AWT/Swing event thread is currently redirected.
static void invokeLaterUnredirected(Runnable task)
          Causes the given task to be executed later, in the AWT/Swing event thread, ignoring redirections.
static void setAWTEventFilter(IlvAWTEventFilter filter)
          Specifies the AWT event filter.
static void setAWTThreadRedirect(Display display)
          Redirects the SWT event thread to the SWT event thread of the given display.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

execNowOrAsync

public static void execNowOrAsync(Display display,
                                  Runnable task)
Executes the given task in the display's event thread, if not already executing in this thread.

This is like Display.asyncExec(task), except that it may run the task immediately.

Note: Throwables thrown by task will not be displayed. If you want them to be displayed, you need to write a try/catch block with printStackTrace() inside task.

Throws:
SWTException -
  • ERROR_DEVICE_DISPOSED - if the display has been disposed

getAWTThreadRedirectDisplay

public static Display getAWTThreadRedirectDisplay()
Returns the SWT display to which the AWT/Swing event thread is currently redirected. Returns null if the AWT/Swing event thread is not redirected.

Returns:
An SWT Display or null.

getAWTThreadRedirectThread

public static Thread getAWTThreadRedirectThread()
Returns the SWT event thread to which the AWT/Swing event thread is currently redirected. Returns null if the AWT/Swing event thread is not redirected.

Returns:
A thread or null.

setAWTThreadRedirect

public static void setAWTThreadRedirect(Display display)
Redirects the SWT event thread to the SWT event thread of the given display.

See above for a description of the limitations of this redirection.

Parameters:
display - An SWT display.
See Also:
getAWTThreadRedirectDisplay(), getAWTThreadRedirectThread(), IlvSwingUtil.isDispatchThread(), IlvSwingUtil.invokeNowOrLater(java.lang.Runnable)

enableAWTThreadRedirect

public static void enableAWTThreadRedirect()
Redirects the SWT event thread to the SWT event thread of the default display.

See above for a description of the limitations of this redirection.

See Also:
setAWTThreadRedirect(org.eclipse.swt.widgets.Display)

invokeLaterUnredirected

public static void invokeLaterUnredirected(Runnable task)
Causes the given task to be executed later, in the AWT/Swing event thread, ignoring redirections.

See Also:
setAWTThreadRedirect(org.eclipse.swt.widgets.Display), EventQueue.invokeLater(java.lang.Runnable)

getAWTEventFilter

public static IlvAWTEventFilter getAWTEventFilter()
Returns the currently active AWT event filter.

Since:
JViews 8.5
See Also:
setAWTEventFilter(ilog.views.util.swt.IlvAWTEventFilter)

setAWTEventFilter

public static void setAWTEventFilter(IlvAWTEventFilter filter)
Specifies the AWT event filter.

Since:
JViews 8.5
See Also:
getAWTEventFilter()


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.