Class InvokeSWTLater

java.lang.Object
com.iizigo.swt.InvokeSWTLater

public class InvokeSWTLater extends Object
Helper class to invoke a Runnable in the SWT thread after a while, once. This is typically used when many events should react to a single action a little later (or that it must run in the SWT thread), and on top of that just once. There is no point in firing the event in SWT thread for every event, otherwise Display.syncExec should be used.
Author:
Christopher Mindus
  • Constructor Details

    • InvokeSWTLater

      public InvokeSWTLater()
      Constructs an instance that fires the event immediately.
    • InvokeSWTLater

      public InvokeSWTLater(int wait)
      Constructs an instance that fires the event after a while.
      Parameters:
      wait - How long to wait in milliseconds, (0=no wait).
    • InvokeSWTLater

      public InvokeSWTLater(int wait, Runnable callback)
      Constructs an instance that fires the event after a while.
      Parameters:
      wait - How long to wait in milliseconds, (0=no wait).
      callback - The callback to use for all events in SWT.
    • InvokeSWTLater

      public InvokeSWTLater(int wait, boolean triggerCancelPending, Runnable callback)
      Constructs an instance that fires the event after a while.
      Parameters:
      wait - How long to wait in milliseconds, (0=no wait).
      triggerCancelPending - Flag indicating trigger will cancel pending triggered event.
      callback - The callback to use for all events in SWT.
  • Method Details

    • getDisplay

      public static Display getDisplay()
      Gets the display.

      Never Display.getDefault() alone: once the workbench has ended and its Display is disposed, getDefault() CREATES a new Display on the calling thread, and on GTK that blocks forever in gdk_threads_enter (the GDK lock the first Display's thread holds). The stress run of r21335 hung the Designer test runtime that way on lx64 for 4.5 hours: SyncState.setState on a Building worker, after the harness' Display was gone (CC-FIX-STRESS-R21335-REDS). The workbench running is the test that no Display need be created; public since then, for every caller that may run after the workbench ended.

      Returns:
      The display instance, or null if Eclipse is shutting down!
    • isDisposed

      public boolean isDisposed()
      Checks if disposed of.
    • dispose

      public void dispose()
      Disposes of the instance.
    • setCallback

      public void setCallback(Runnable callback)
      Sets the callback, when it is the same one to use all the time.
      Parameters:
      callback - The callback to use for all events in SWT.
      Throws:
      NullPointerException - If the callback is null.
    • trigger

      public void trigger()
      Calls the trigger function, the Runnable is the one registered using setCallback(Runnable).
      Throws:
      NullPointerException - If the callback is null.
    • trigger

      public void trigger(Runnable callback)
      Calls the trigger function, the Runnable is the one registered using setCallback(Runnable).
      Parameters:
      callback - The callback to notify upon event.
      Throws:
      NullPointerException - If the callback is null.
    • isTriggered

      public boolean isTriggered()
      Flag indicating the async call has been done and that it will run.
    • cancel

      public boolean cancel()
      Cancels a pending run-later task.
      Returns:
      true if successfully canceled, false if disposed of or no pending task was set to run.