title: SWT Browser Widget: How to listen to JavaScript events?
body: <p>so we are currently working on a RCP application, which integrates a SWT Browser. We would like to implement some sort of a communication between the browser and the RCP Application. Mainly we want that if the user presses a button in the Webinterface an event gets triggered, so the RCP Application can listen to it and handle it accordingly (an example would be opening a specific view inside the RCP Application).</p>
  
  <p>How would you tackle this problem? I already tried to addMouseListener() on the browser. But the mouseevents are not helping much, since they dont carry any information on which element inside the webinterface got pressed...</p>
  
  <p>I hope you could help me out/inspire me with possible solutions!</p>
  
  <p>EDIT:
  Here are some Examples on how to the browser gets instantiated:</p>
  
  <pre><code>public class BrowserView extends ViewPart {
      Browser browser;
  
      private static final Log LOG = LogFactory.getLog(BrowserView.class);
  
      @Override
      public void createPartControl(Composite parent) {
          this.browser = new Browser(parent, SWT.NONE);
  
          browser.addMouseListener(new MouseListener() {
  
              @Override
              public void mouseUp(MouseEvent e) {         
              }
  
              @Override
              public void mouseDown(MouseEvent e) {
                  // do something with the event
  
              }
  
              @Override
              public void mouseDoubleClick(MouseEvent e) {
  
              }
          });
  
      }
  
      @Override
      public void setFocus() {
          // Do nothing
      }
  
      public void setUrl(String url) {
          this.browser.setUrl(url);
      }
  
  
  }
  </code></pre>
  
  <p>So mainly we create a browser in a specific composite. We tried to add a handler to a mouseDown Event, but it doesnt help much, since the event doesnt contain any information on which button got triggered inside the browser.
  How can we get extended information from events regarding the browser?
  Lets say the content inside the Browser has Button1, Button2 and Button3. We want to have something like </p>
  
  <pre><code>        public void mouseDown(MouseEvent e) {
              switch (e.getType.getName()) {
              case "Button1": handleButton1();
              break;
              case "Button2": handleButton2(); 
              break;
              case "Button3": handleButton3();
              break;
              }
  
          }
  </code></pre>
  
  <p>I am well aware that here are other possible solutions. This was just my naive approach</p>