Class TextEditorPositioner


  • public final class TextEditorPositioner
    extends Object
    Utility methods to set position of given IEditorPart. Methods will extract ITextEditor from target given IEditorPart.
    Restriction:
    This class is not intended to be sub-classed by clients.
    Restriction:
    This class is not intended to be instantiated by clients.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void positionEditor​(org.eclipse.ui.IEditorPart editor, int lineNumber)
      Positions the given editor to the given line number.
      static void positionEditor​(org.eclipse.ui.IEditorPart editor, int lineNumber, boolean selectLine)
      Positions the given editor to the given line number and, optionally, select a whole line.
      static void positionEditor​(org.eclipse.ui.IEditorPart editor, int offset, int length)
      Positions the given editor to the given offset with the given length.
      static void positionEditor​(org.eclipse.ui.IEditorPart editor, int lineNumber, String substring)
      Positions the given editor to the given line number and select the given substring.
      static void positionEditor​(org.eclipse.ui.IEditorPart editor, int lineNumber, String substring, int occurrenceIndex)
      Positions the given editor to the given line number and select the given substring with the given occurrence index.
    • Method Detail

      • positionEditor

        public static void positionEditor​(org.eclipse.ui.IEditorPart editor,
                                          int lineNumber)
                                   throws org.eclipse.core.runtime.CoreException
        Positions the given editor to the given line number.

        This is convenience method, fully equivalent to:

         positionEditor(editor, lineNumber, true);
         
        Parameters:
        editor - the text editor to set position, cannot be null
        lineNumber - the line number to set position to, must be non-negative
        Throws:
        org.eclipse.core.runtime.CoreException - if positioning fails for some reason
      • positionEditor

        public static void positionEditor​(org.eclipse.ui.IEditorPart editor,
                                          int lineNumber,
                                          boolean selectLine)
                                   throws org.eclipse.core.runtime.CoreException
        Positions the given editor to the given line number and, optionally, select a whole line.
        Parameters:
        editor - the text editor to set position, cannot be null
        lineNumber - the line number to set position to, must be non-negative
        selectLine - whether need to select whole line
        Throws:
        org.eclipse.core.runtime.CoreException - if positioning fails for some reason
      • positionEditor

        public static void positionEditor​(org.eclipse.ui.IEditorPart editor,
                                          int lineNumber,
                                          String substring)
                                   throws org.eclipse.core.runtime.CoreException
        Positions the given editor to the given line number and select the given substring. Does nothing if substring occurrence not found.

        This is convenience method, fully equivalent to:

         positionEditor(editor, lineNumber, substring, 1);
         
        Parameters:
        editor - the text editor to set position, cannot be null
        lineNumber - the line number to set position to
        substring - substring to select, cannot be null
        Throws:
        org.eclipse.core.runtime.CoreException - if positioning fails for some reason
      • positionEditor

        public static void positionEditor​(org.eclipse.ui.IEditorPart editor,
                                          int lineNumber,
                                          String substring,
                                          int occurrenceIndex)
                                   throws org.eclipse.core.runtime.CoreException
        Positions the given editor to the given line number and select the given substring with the given occurrence index. Orrurrence indexes are 1-based.

        Does nothing, if occurrence occurencces not found or occurencces count less than occurrenceIndex.

        Parameters:
        editor - the text editor to set position, cannot be null
        lineNumber - the line number to set position to
        substring - substring to select, cannot be null
        occurrenceIndex - the index of the substring occurrence to select, must be positive
        Throws:
        org.eclipse.core.runtime.CoreException - if positioning fails for some reason
      • positionEditor

        public static void positionEditor​(org.eclipse.ui.IEditorPart editor,
                                          int offset,
                                          int length)
        Positions the given editor to the given offset with the given length.
        Parameters:
        editor - the text editor to set position, cannot be null
        offset - the offset of the selection
        length - the length of the selection