title: Java SWT: wrapping syncExec and asyncExec to clean up code
body: <p>I have a Java Application using SWT as the toolkit, and I'm getting tired of all the ugly boiler plate code it takes to update a GUI element.</p>
  
  <p>Just to set a disabled button to be enabled I have to go through something like this:</p>
  
  <pre><code>shell.getDisplay().asyncExec(new Runnable() {
      public void run() {
          buttonOk.setEnabled(true);
      }
  });
  </code></pre>
  
  <p>I prefer keeping my source code as flat as I possibly can, but I need a whopping 3 indentation levels just to do something simple.</p>
  
  <p>Is there some way I can wrap it?  I would like a class like:</p>
  
  <pre><code>public class UIUpdater {
      public static void updateUI(Shell shell, *function_ptr*) {
          shell.getDisplay().asyncExec(new Runnable() {
             public void run() {
                //Execute function_ptr
             }
          });
      }
  }
  </code></pre>
  
  <p>And can be used like so:</p>
  
  <pre><code>UIUpdater.updateUI(shell, buttonOk.setEnabled(true));
  </code></pre>
  
  <p>Something like this would be great for hiding that horrible mess SWT seems to think is necessary to do anything.</p>
  
  <p>As I understand it, Java cannot do functions pointers.  But Java 7 will have something called Closures which should be what I want.  But in the meantime is there anything at all I can do to pass a function pointer or callback to another function to be executed?</p>
  
  <p>As an aside, I'm starting to think it'd be worth the effort to redo this application in Swing, and I don't have to put up with this ugly crap and non-cross-platformyness of SWT.</p>