code: private void createContextMenu() {
      // Create menu manager.
      MenuManager menuMgr = new MenuManager();
      menuMgr.setRemoveAllWhenShown(true);
      menuMgr.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager mgr) {
          fillContextMenu(mgr);
        }
      });
  
      // Create menu.
      Menu menu = menuMgr.createContextMenu(viewer.getControl());
      viewer.getControl().setMenu(menu);
  
      // Register menu for extension.
      getSite().registerContextMenu(menuMgr, viewer);
    }
docs: Contextual menu