Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 351585

Summary: Make Dialogs usable from threadless life cycle
Product: [RT] RAP Reporter: Rüdiger Herrmann <ruediger.herrmann>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3    
Version: unspecified   
Target Milestone: 1.5 M1   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 341761    

Description Rüdiger Herrmann CLA 2011-07-08 10:56:50 EDT
All subclasses of Dialog that come with RWT run a nested event loop in their open() method. This makes them unusable from applications that use the threadless life cycle (see bug 344091).
A callback should be introduced that notifies the application when the dialog was closed, like the sketch below shows:
  final FontDialog dialog = new FontDialog( parent, SWT.NONE );
  dialog.open( new DialogCallback() {
    public void dialogClosed() {
      applyFont( dialog.getFontList() );
    }
  } );

The challenge here is rather to find a way to provide the extra API that does not (or as least as possible) irritate users of the UI-threaded life cycle but is still as convenient as possible for users of the threadless lifefcyle.
Comment 1 Rüdiger Herrmann CLA 2011-07-14 09:43:25 EDT
Dialog now implements Adaptable. Dialog#getAdapter() returns an IDialogAdapter that can be used to open dialogs in a non-blocking way.

In addition, I created preliminary API for application code to use this feature. org.eclipse.rwt.widgets.DialogUtil#open() can be used to open a given dialog without blocking and a DialogCallback can be supplied to be notified when the dialog was closed.

Alternatively the API could offer an abstract class _NonBlockingDialog_ (or similar) that combines the open() method from DialogUtil with the dialogClosed() callback method from DialogCallback.
abstract class NonBlockingDialog {
  NonBlockingDialog( Dialog dialog ) {
    // ...
  }
  
  void open() {
    // ...
  }
  
  abstract void dialogClosed( int returnCode )
}
application code:
NonBlockingDialog dialog = new NonBlockingDialog( fontDialog ) {
  void dialogClosed( int returnCode ) {
    // ...    
  }
}

What do you think?