title: SWT Right click menu item selection listener not getting called.
body: <p>We have a client who complains that the right click functionality suddenly stopped working. So I debugged a little and found that the RCP app is not throwing any exceptions, just that the right click menuItem listeners are not getting called. Here is the outline of the code that we use in our app. </p>
  
  <pre><code>rightClickListener = new Listener(){
          public void handleEvent(Event event) {
              TRACER.trace("Handle event for tree's right click listener");
  
              if(treeComp.tree.getSelectionCount()&gt;0 &amp;&amp; PlatformUI.getPreferenceStore().getBoolean("RightClickEnabled")){
                  TRACER.trace(currSelection + " selected.");
                          rcmenu.selectionMenu(event);
  
              }
          }
  
  
      };
      treeComp.tree.addListener(SWT.MenuDetect,rightClickListener);
  </code></pre>
  
  <p>And the actual menu and menu items are created in the rcmenu class. Listeners are added there. </p>
  
  <pre><code>public void selectionMenu(Event event){
  
      TRACER.trace("Begin selectionMenu()");
  
  
      shell = tree.getShell();
      display = tree.getDisplay();        
       Menu menu = null;
       try{
           menu = new Menu(shell, SWT.POP_UP);
       }catch(Exception e){
           ERROR_REPORTER.report("Error when creating menu ", e);
       }
      menu.addDisposeListener(new DisposeListener(){
  
          @Override
          public void widgetDisposed(DisposeEvent e) {
              TRACER.trace("Menu Disposed");
  
          }
  
      });
      TreeItem[] selectionItems = tree.getSelection();
  
  
  
          if(selectionItems.length=1){
              addMenuItems(menu);
          }
  
          handleSetEnableLogic(); //after adding the menu items in addMenuItems(menu) we enable them here in this method. 
  
  
      menu.setLocation(event.x, event.y);
      menu.setVisible(true);
  
      try{
          while (!menu.isDisposed() &amp;&amp; menu.isVisible()) {
  
              boolean readAndDispatch = display.readAndDispatch();
              if (!readAndDispatch){
                  display.sleep();
              }           
          }
      }catch(Exception e){
          ERROR_REPORTER.report("Error during dispatch event ",e);
      }
      try{
          menu.dispose();
      }catch(Exception e){
          ERROR_REPORTER.report("Error during menu dispose ",e);
      }
      TRACER.trace("End selectionMenu()");
  }
  </code></pre>
  
  <p>And the addMenuItems() method is as shown</p>
  
  <pre><code>item_modify = new MenuItem(menu, SWT.PUSH);
      item_modify.setText("Modify"); //Modify
  
      //"Modify"
      item_modify.addListener(SWT.Selection, new Listener() {
          public void handleEvent(Event e) {
              BusyIndicator.showWhile(Display.getCurrent(), new Runnable(){
                  public void run(){
                      TRACER.trace("Handle event for right click menu-- modify: ");
                      //listener code                         
                  }
              });
          }
      });
      item_modify.setEnabled(false);
  </code></pre>
  
  <p>The right click menu is getting created, the item_modify menu item is enabled. Nothing is disposed. When we select on the item_modify menu item the display.readAndDispatch is returning true hence the display is not going to sleep. But at that point the selection listener for item_modify is not getting fired. Then the menu becomes invisible and comes out of the while loop and gets disposed as expected. But  the point is I am not understanding why the selection listener is not getting fired. Is there is a way to know if an event is fired? Does any group policies on the machine affect how the events are fired? </p>
  
  <p>Every other listener in the application works fine. </p>