Class AbstractBookmarkHandler

java.lang.Object
org.eclipse.core.commands.common.EventManager
org.eclipse.core.commands.AbstractHandler
com.e1c.g5.v8.dt.internal.bookmarks.ui.commands.AbstractBookmarkHandler
All Implemented Interfaces:
org.eclipse.core.commands.IHandler, org.eclipse.core.commands.IHandler2
Direct Known Subclasses:
AbstractNavigateBookmarksHandler, AbstractToggleBookmarkHandler

public abstract class AbstractBookmarkHandler extends org.eclipse.core.commands.AbstractHandler
Abstract base for handlers working with bookmarks.

Instead of execute(ExecutionEvent), childrens should implement #executeInTextEditor(ITextEditor, IResource, ITextSelection). The method will be called from execute(ExecutionEvent) when active part is a text editor whose input is a resource and there is a text selection (which is also used as caret position in text editors).

The handler ignores invocations when current view part is not a ITextEditor (and cannot be adapted to it), selection is not a ITextSelection or editor's input is not a IResource (and cannot be adapted to it). This should support EDT's granular editors (like ConfigurationEditor and FormEditor) consisting of multiple tabs some of which are not text editors as well as regular Eclipse text editors.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected int
    calculateMultilineBookmarkLine(org.eclipse.jface.text.ITextSelection selection)
    Calculates bookmark's line.
    protected int
    calculateMultilineBookmarkOffset(org.eclipse.jface.text.Position bookmarkPosition)
    Calculates bookmark offset from bookmark's position.
    execute(org.eclipse.core.commands.ExecutionEvent event)
     
    protected abstract void
    executeWithTextEditor(org.eclipse.ui.texteditor.ITextEditor editor, org.eclipse.core.resources.IResource resource)
    Handles command in text editor.
    protected NavigableMap<Integer,List<org.eclipse.core.resources.IMarker>>
    findBookmarksWithLines(org.eclipse.core.resources.IResource resource, org.eclipse.ui.texteditor.ITextEditor editor)
    Finds bookmarks with line information specified.
    protected Optional<org.eclipse.jface.text.IDocument>
    findDocument(org.eclipse.ui.texteditor.ITextEditor editor)
    Finds document being edited in the editor.
    protected Optional<org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel>
    findMarkerModel(org.eclipse.ui.texteditor.ITextEditor editor)
    Gets marker model for the editor.
    protected Optional<org.eclipse.jface.text.ITextSelection>
    findTextSelection(org.eclipse.ui.texteditor.ITextEditor textEditor)
    Extracts text selection from an editor.

    Methods inherited from class org.eclipse.core.commands.AbstractHandler

    addHandlerListener, dispose, fireHandlerChanged, hasListeners, isEnabled, isHandled, removeHandlerListener, setBaseEnabled, setEnabled

    Methods inherited from class org.eclipse.core.commands.common.EventManager

    addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractBookmarkHandler

      public AbstractBookmarkHandler()
  • Method Details

    • execute

      public Object execute(org.eclipse.core.commands.ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException
      Throws:
      org.eclipse.core.commands.ExecutionException
    • executeWithTextEditor

      protected abstract void executeWithTextEditor(org.eclipse.ui.texteditor.ITextEditor editor, org.eclipse.core.resources.IResource resource)
      Handles command in text editor.
      Parameters:
      editor - Text editor being active. Must not be null.
      resource - Resource being edited in active text editor. Must not be null.
    • calculateMultilineBookmarkLine

      protected int calculateMultilineBookmarkLine(org.eclipse.jface.text.ITextSelection selection)
      Calculates bookmark's line. Multiline bookmarks span multiple lines and it's a question which of those lines should be marker placed on. As per class's contract, the first line of multiline bookmark is used as marker's line.
      Parameters:
      selection - Current editor selection. Must not be null.
      Returns:
      0-based caret line.
      See Also:
    • calculateMultilineBookmarkOffset

      protected int calculateMultilineBookmarkOffset(org.eclipse.jface.text.Position bookmarkPosition)
      Calculates bookmark offset from bookmark's position. Multiline bookmarks span multiple lines and it's a question which of those lines should be marker placed on. As per class's contract, the first line of multiline bookmark is used as marker's line.
      Parameters:
      bookmarkPosition - Bookmark's position. Must not be null.
      Returns:
      Offset of bookmark.
      See Also:
    • findBookmarksWithLines

      protected NavigableMap<Integer,List<org.eclipse.core.resources.IMarker>> findBookmarksWithLines(org.eclipse.core.resources.IResource resource, org.eclipse.ui.texteditor.ITextEditor editor) throws org.eclipse.core.runtime.CoreException
      Finds bookmarks with line information specified.

      This method accouts for dirty editor and modifications to the underlaying resource via AbstractMarkerAnnotationModel that is supposed to reflect marker modifications when text in editor changes.

      The method will skip any bookmarks without line information specified or being incorrect.

      Parameters:
      resource - Resource for which to get bookmarks. Must not be null.
      editor - Editor where resource is being edited. Must not be null.
      Returns:
      Map where keys are 0-bazed line numbers where bookmarks are present and values are list of bookmarks on the corresponding line. Or an empty map if the editor has no marker model. Never null.
      Throws:
      org.eclipse.core.runtime.CoreException - If resource does not exist or resource is a project that is not open.
      See Also:
      • findMarkerLine(IMarker, IDocument, AbstractMarkerAnnotationModel)
    • findDocument

      protected Optional<org.eclipse.jface.text.IDocument> findDocument(org.eclipse.ui.texteditor.ITextEditor editor)
      Finds document being edited in the editor.
      Parameters:
      editor - Editor for which to find document. Must not be null.
      Returns:
      Document being edited or an empty value if editor is closed or there is no document. Never null.
    • findMarkerModel

      protected Optional<org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel> findMarkerModel(org.eclipse.ui.texteditor.ITextEditor editor)
      Gets marker model for the editor.
      Parameters:
      editor - Editor to get marler model for. Must not be null.
      Returns:
      Marker model of the editor or an empty value if editor is closed, has no annotation model or it is not a marker model. Never null.
    • findTextSelection

      protected Optional<org.eclipse.jface.text.ITextSelection> findTextSelection(org.eclipse.ui.texteditor.ITextEditor textEditor)
      Extracts text selection from an editor.
      Parameters:
      textEditor - Text editor. Must not be null.
      Returns:
      Text selection in the editor or an empty value if editor has no selection provider, there is no selection or selection is not a text selection. Never null.