title: How do I make an Eclipse plugin extension which displays different context menu items when the user clicks a marker?
body: <p>This is a question specifically about plugin development for the Eclipse platform:</p>
  
  <p>I want to add a menu item to the default menu which appears when right clicking a kind of IMarker (all markers would be a good start).</p>
  
  <p>I have had some success with implementing IMarkerResolution and referring to it in my plugin.xml</p>
  
  <pre><code>&lt;extension point="org.eclipse.ui.ide.markerResolution"&gt;
  &lt;markerResolutionGenerator
    markerType="my.stuff.mymarker" 
    class="my.stuff.MyResolutionGenerator"&gt;
  &lt;/markerResolutionGenerator&gt;
  &lt;/extension&gt;
  </code></pre>
  
  <p>but instead of accessing my code through the eclipse quick fix functionality, I want to add my own menu text instead of 'quick fixes' and not have to display the action alongside the quick fix options. Being able to run an action by (double) clicking on a marker would be very useful as well.</p>
  
  <p>I am using eclipse 3.5.2 for my current project.</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>Update</strong> I have resolved this:</p>
  
  <pre><code>&lt;extension point="org.eclipse.ui.menus"&gt;
  &lt;menuContribution
      class="my.stuff.MarkerContributionFactory"
      locationURI="popup:#AbstractTextEditorRulerContext?after=additions"&gt;
    &lt;dynamic
           class="my.stuff.MarkerMenuContribution"
           id="my.stuff.MarkerMenuContribution"&gt;
    &lt;/dynamic&gt;
  &lt;/menuContribution&gt;
  &lt;/extension&gt;
  
  public class MarkerContributionFactory extends ExtensionContributionFactory{
  
  @Override
  public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions){
      ITextEditor editor = (ITextEditor) 
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
  
      additions.addContributionItem(new MarkerMenuContribution(editor), null);
  }
  }
  
  public class MarkerMenuContribution extends ContributionItem{
  
  private ITextEditor editor;
  private IVerticalRulerInfo rulerInfo;
  private List&lt;IMarker&gt; markers;
  
  public MarkerMenuContribution(ITextEditor editor){
      this.editor = editor;
      this.rulerInfo = getRulerInfo();
      this.markers = getMarkers();
  }
  
  private IVerticalRulerInfo getRulerInfo(){
      return (IVerticalRulerInfo) editor.getAdapter(IVerticalRulerInfo.class);
  }
  
  private List&lt;IMarker&gt; getMarkers(){
      List&lt;IMarker&gt; clickedOnMarkers = new ArrayList&lt;IMarker&gt;();
      for (IMarker marker : getAllMarkers()){
          if (markerHasBeenClicked(marker)){
              clickedOnMarkers.add(marker);
          }
      }
  
      return clickedOnMarkers;
  }
  
  //Determine whether the marker has been clicked using the ruler's mouse listener
  private boolean markerHasBeenClicked(IMarker marker){
      return (marker.getAttribute(IMarker.LINE_NUMBER, 0)) == (rulerInfo.getLineOfLastMouseButtonActivity() + 1);
  }
  
  //Get all My Markers for this source file
  private IMarker[] getAllMarkers(){
      return ((FileEditorInput) editor.getEditorInput()).getFile()
          .findMarkers("defined.in.plugin.xml.mymarker", true, IResource.DEPTH_ZERO);
  }
  
  @Override
  //Create a menu item for each marker on the line clicked on
  public void fill(Menu menu, int index){
      for (final IMarker marker : markers){
          MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
          menuItem.setText(marker.getAttribute(IMarker.MESSAGE, ""));
          menuItem.addSelectionListener(createDynamicSelectionListener(marker));
      }
  }
  
  //Action to be performed when clicking on the menu item is defined here
  private SelectionAdapter createDynamicSelectionListener(final IMarker marker){
      return new SelectionAdapter(){
          public void widgetSelected(SelectionEvent e){
              System.out.println(marker.getAttribute(IMarker.MESSAGE, ""));
          }
      };
  }
  }
  </code></pre>