title: What is the recommended way for SWT Views (ViewPart) which receive a external event to update a GUI element?
body: <p>My View is derived from ViewPart, but I have a listener on it which receives Events from non-GUI threads. </p>
  
  <p>If something is supposed to happen on within the GUI thread, it has to go through <code>asyncExec()</code>.</p>
  
  <p>So far so good.</p>
  
  <p>The thing is, the GUI elements are created in <code>createPartControl()</code>, so they can't be final. At the moment I just put them in a <code>AtomicReference</code> which can be final just fine.</p>
  
  <p>What is your approach?</p>
  
  <p><strong>Update</strong></p>
  
  <p>to clarify the problem using the example from one of the answers below:</p>
  
  <pre><code>public class MyView extends ViewPart implements SomeNetWorkActionListener {
  
      private Text text1;
  
      private final AtomicReference&lt;Text&gt; text3 = new AtomicReference&lt;Text&gt;();
  
      public void createPartControl(Composite parent) {
          text1 = new Text(parent, SWT.None);
          final Text text2 = new Text(parent, SWT.None);
          text3.set(new Text(parent, SWT.None));
  
          parent.getDisplay().asyncExec(new Runnable() {
              public void run() {
                  text1.setText("Hello");
                  text2.setText("World");
              }
          });
      }
  
      public void setFocus() {
          text1.forceFocus();
      }
  
      @Override
      public void someNetworkMessageReceived(MyMessage message) {
          getSite ().getShell ().getDisplay().asyncExec(new Runnable() {
              public void run() {
                  //... how to reference text 1 or text 2?
                  text3.get().setText(message.toString()); // this is what I do at the moment
              }
          });
      }
  }
  </code></pre>