Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] SWT Event Processing

I see how many events are generated by calling methods on controls, displays, ... using either the asyncExec or syncExec.  But, I haven't found an example of creating our own Event and "posting" or "sending" it so listeners registered for this event are invoked.  My UI experience is from Win32 API's.  I'd seen a response discussing notifyListeners() but I haven't found which class has this method.

The code sample below is familiar to me from Win32 for processing events.  I just need help finding the equivalent of post/sendMessage...

  Listener listener = new Listener () {
    public void handleEvent (Event e) {
     switch (e.type) {
       case SWT.Close: {
       int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
       MessageBox messageBox = new MessageBox(shell, style);
       messageBox.setText("Shutdown confirmation");
       messageBox.setMessage("Close this program?");
       if (messageBox.open() == SWT.YES) {
        demo.shutdown();
                e.doit = true;        
       } else {
        e.doit = false;
       }
       break;
       }
       default:
          break;
     }
    }
  };
shell.addListener(SWT.Close, listener);

For example, if I wanted to generate an SWT.Close event and send it, what would I put in the middle of the code below instead of calling a method:

    stopButton.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
       display.asyncExec(new Runnable() {
         public void run() {
           shell.close();} // want my own event added to the message queue
         });
      }
    });

In particular, I'm not trying to solve how to close the application.  I'm trying to understand how I can formulate my own Events so my "monitor" thread can notify the "UI" (e.g., main) thread that something has happened (passing some supporting data in the event) so the UI thread can display something for the user.  Basic thread / UI communications issue.

Also, has anyone written the equivalent of Charles Petzolds' Win32 books for SWT / Draw2d / GEF?  Or is there some white paper I can download that introduces the SWT, etc., concepts for people familiar with the Win32 API's?

Thanks in advance for your help, Nat


Back to the top