int index = tblSongs.getSelectionIndex(); Track track; if (index < 0) return getPlayingTrack(); else return getTrackByTableItem(tblSongs.getItems()[index]);
final Track[] answer = new Track[1]; final Object[] monitor = new Object[1]; Runnable r = new Runnable() { public void run() { try { int index = tblSongs.getSelectionIndex(); Track track; if (index < 0) answer[0] = getPlayingTrack(); else answer[0] = getTrackByTableItem(tblSongs.getItems()[index]); } finally { if (monitor[0] != null) synchronized (monitor[0]) { monitor[0].notify(); } } } }; if (display.isValidThread()) r.run(); else {    monitor[0] = new Object(); synchronized (monitor[0]) { display.asyncExec(r); try {monitor[0].wait();} catch (InterruptedException e) {}; } } return answer[0];
  public Track getSelectedTrack()  {    int index = tblSongs.getSelectionIndex();    Track track;     if (index < 0)      return getPlayingTrack();    else      return getTrackByTableItem(tblSongs.getItems()[index]);  }