Class SourceViewer

    • Field Detail

      • GAP_SIZE

        protected static final int GAP_SIZE
        The size of the gap between the vertical ruler and the text widget (value 2).

        Note: As of 3.2, the text editor framework is no longer using 2 as gap but 1, see {GAP_SIZE_1.

        See Also:
        Constant Field Values
      • GAP_SIZE_1

        protected static final int GAP_SIZE_1
        The size of the gap between the vertical ruler and the text widget (value 1).
        Since:
        3.2
        See Also:
        Constant Field Values
      • _SELECTION_POSITION_CATEGORY

        protected static final String _SELECTION_POSITION_CATEGORY
        Partial name of the position category to manage remembered selections.
        Since:
        3.0
        See Also:
        Constant Field Values
      • MODEL_ANNOTATION_MODEL

        protected static final Object MODEL_ANNOTATION_MODEL
        Key of the model annotation model inside the visual annotation model.
        Since:
        3.0
      • fContentAssistant

        protected IContentAssistant fContentAssistant
        The viewer's content assistant
      • fContentAssistantInstalled

        protected boolean fContentAssistantInstalled
        Flag indicating whether the viewer's content assistant is installed.
        Since:
        2.0
      • fQuickAssistAssistant

        protected IQuickAssistAssistant fQuickAssistAssistant
        This viewer's quick assist assistant.
        Since:
        3.2
      • fQuickAssistAssistantInstalled

        protected boolean fQuickAssistAssistantInstalled
        Flag indicating whether this viewer's quick assist assistant is installed.
        Since:
        3.2
      • fContentFormatter

        protected IContentFormatter fContentFormatter
        The viewer's content formatter
      • fReconciler

        protected IReconciler fReconciler
        The viewer's model reconciler
      • fPresentationReconciler

        protected IPresentationReconciler fPresentationReconciler
        The viewer's presentation reconciler
      • fAnnotationHover

        protected IAnnotationHover fAnnotationHover
        The viewer's annotation hover
      • fSelections

        protected final Stack<Position> fSelections
        Stack of saved selections in the underlying document
        Since:
        3.0
      • fSelectionUpdater

        protected IPositionUpdater fSelectionUpdater
        Position updater for saved selections
        Since:
        3.0
      • fSelectionCategory

        protected String fSelectionCategory
        Position category used by the selection updater
        Since:
        3.0
      • fOverviewRulerAnnotationHover

        protected IAnnotationHover fOverviewRulerAnnotationHover
        The viewer's overview ruler annotation hover
        Since:
        3.0
      • fInformationPresenter

        protected IInformationPresenter fInformationPresenter
        The viewer's information presenter
        Since:
        2.0
    • Constructor Detail

      • SourceViewer

        public SourceViewer​(Composite parent,
                            IVerticalRuler ruler,
                            int styles)
        Constructs a new source viewer. The vertical ruler is initially visible. The viewer has not yet been initialized with a source viewer configuration.
        Parameters:
        parent - the parent of the viewer's control
        ruler - the vertical ruler used by this source viewer
        styles - the SWT style bits for the viewer's control, if SWT.WRAP is set then a custom document adapter needs to be provided, see TextViewer.createDocumentAdapter()
      • SourceViewer

        public SourceViewer​(Composite parent,
                            IVerticalRuler verticalRuler,
                            IOverviewRuler overviewRuler,
                            boolean showAnnotationsOverview,
                            int styles)
        Constructs a new source viewer. The vertical ruler is initially visible. The overview ruler visibility is controlled by the value of showAnnotationsOverview. The viewer has not yet been initialized with a source viewer configuration.
        Parameters:
        parent - the parent of the viewer's control
        verticalRuler - the vertical ruler used by this source viewer
        overviewRuler - the overview ruler
        showAnnotationsOverview - true if the overview ruler should be visible, false otherwise
        styles - the SWT style bits for the viewer's control, if SWT.WRAP is set then a custom document adapter needs to be provided, see TextViewer.createDocumentAdapter()
        Since:
        2.1
    • Method Detail

      • createControl

        protected void createControl​(Composite parent,
                                     int styles)
        Description copied from class: TextViewer
        Creates the viewer's SWT control. The viewer's text widget either is the control or is a child of the control.
        Overrides:
        createControl in class TextViewer
        Parameters:
        parent - the parent of the viewer's control
        styles - the SWT style bits for the viewer's control
      • createLayout

        protected Layout createLayout()
        Creates the layout used for this viewer. Subclasses may override this method.
        Returns:
        the layout used for this viewer
        Since:
        3.0
      • setAnnotationHover

        public void setAnnotationHover​(IAnnotationHover annotationHover)
        Description copied from interface: ISourceViewer
        Sets the annotation hover of this source viewer. The annotation hover provides the information to be displayed in a hover popup window if requested over the annotation presentation area. The annotation hover is assumed to be line oriented.
        Specified by:
        setAnnotationHover in interface ISourceViewer
        Parameters:
        annotationHover - the hover to be used, null is a valid argument
      • setOverviewRulerAnnotationHover

        public void setOverviewRulerAnnotationHover​(IAnnotationHover annotationHover)
        Sets the overview ruler's annotation hover of this source viewer. The annotation hover provides the information to be displayed in a hover popup window if requested over the overview rulers area. The annotation hover is assumed to be line oriented.
        Parameters:
        annotationHover - the hover to be used, null is a valid argument
        Since:
        3.0
      • ensureAnnotationHoverManagerInstalled

        protected void ensureAnnotationHoverManagerInstalled()
        After this method has been executed the caller knows that any installed annotation hover has been installed.
      • ensureOverviewHoverManagerInstalled

        protected void ensureOverviewHoverManagerInstalled()
        After this method has been executed the caller knows that any installed overview hover has been installed.
      • setDocument

        public void setDocument​(IDocument document)
        Description copied from interface: ITextViewer
        Sets the given document as the text viewer's model and updates the presentation accordingly. An appropriate TextEvent is issued. This text event does not carry a related document event.
        Specified by:
        setDocument in interface ITextViewer
        Overrides:
        setDocument in class TextViewer
        Parameters:
        document - the viewer's new input document null if none
      • setDocument

        public void setDocument​(IDocument document,
                                int visibleRegionOffset,
                                int visibleRegionLength)
        Description copied from interface: ITextViewer
        Sets the given document as this viewer's model and exposes the specified region. An appropriate TextEvent is issued. The text event does not carry a related document event. This method is a convenience method for setDocument(document);setVisibleRegion(offset, length).
        Specified by:
        setDocument in interface ITextViewer
        Overrides:
        setDocument in class TextViewer
        Parameters:
        document - the new input document or null if none
        visibleRegionOffset - the offset of the model range
        visibleRegionLength - the length of the model range
      • setDocument

        public void setDocument​(IDocument document,
                                IAnnotationModel annotationModel)
        Description copied from interface: ISourceViewer
        Sets the given document as this viewer's text model and the given annotation model as the model for this viewer's visual annotations. The presentation is accordingly updated. An appropriate TextEvent is issued. This text event does not carry a related document event.
        Specified by:
        setDocument in interface ISourceViewer
        Parameters:
        document - the viewer's new input document
        annotationModel - the model for the viewer's visual annotations
        See Also:
        ITextViewer.setDocument(IDocument)
      • createVisualAnnotationModel

        protected IAnnotationModel createVisualAnnotationModel​(IAnnotationModel annotationModel)
        Creates the visual annotation model on top of the given annotation model.
        Parameters:
        annotationModel - the wrapped annotation model
        Returns:
        the visual annotation model on top of the given annotation model
        Since:
        3.0
      • disposeVisualAnnotationModel

        protected void disposeVisualAnnotationModel()
        Disposes the visual annotation model.
        Since:
        3.1
      • setDocument

        public void setDocument​(IDocument document,
                                IAnnotationModel annotationModel,
                                int modelRangeOffset,
                                int modelRangeLength)
        Description copied from interface: ISourceViewer
        Sets the given document as this viewer's text model and the given annotation model as the model for this viewer's visual annotations. The presentation is accordingly updated whereby only the specified region is exposed. An appropriate TextEvent is issued. The text event does not carry a related document event. This method is a convenience method for setDocument(document, annotationModel);setVisibleRegion(offset, length).
        Specified by:
        setDocument in interface ISourceViewer
        Parameters:
        document - the new input document
        annotationModel - the model of the viewer's visual annotations
        modelRangeOffset - the offset of the model range
        modelRangeLength - the length of the model range
        See Also:
        ITextViewer.setDocument(IDocument, int, int)
      • handleDispose

        protected void handleDispose()
        Description copied from class: TextViewer
        Frees all resources allocated by this viewer. Internally called when the viewer's control has been disposed.
        Overrides:
        handleDispose in class TextViewer
      • canDoOperation

        public boolean canDoOperation​(int operation)
        Description copied from interface: ITextOperationTarget
        Returns whether the operation specified by the given operation code can be performed.
        Specified by:
        canDoOperation in interface ITextOperationTarget
        Overrides:
        canDoOperation in class TextViewer
        Parameters:
        operation - the operation code
        Returns:
        true if the specified operation can be performed
      • createFormattingContext

        protected IFormattingContext createFormattingContext()
        Creates a new formatting context for a format operation.

        After the use of the context, clients are required to call its dispose method.

        Returns:
        The new formatting context
        Since:
        3.0
      • createFormattingContext

        protected IFormattingContext createFormattingContext​(int selectionOffset,
                                                             int selectionLength)
        Creates a new formatting context for a format operation. If the returned context has the FormattingContextProperties.CONTEXT_REGION property set to an IRegion, the section of the document defined by that region is formatted, otherwise the whole document is formatted.

        The default implementation calls createFormattingContext() and sets the FormattingContextProperties.CONTEXT_REGION property if the selection is not empty. Overriding methods may implement a different logic, or return null to indicate that the formatting operation should not proceed.

        Returning null may be used, for example, when the user clicks on the Cancel button in a dialog that, in case of an empty selection, asks the user whether formatting should be applied to the whole document or to the current statement. Please notice that returning null from this method cancels the already initiated formatting operation unlike canDoOperation(int), which is used for enabling and disabling formatting actions.

        After the use of the context, clients are required to call its dispose method.

        Parameters:
        selectionOffset - the character offset of the selection in the document
        selectionLength - the length of the selection
        Returns:
        The new formatting context, or null to cancel the formatting
        Since:
        3.10
      • rememberSelection

        protected Point rememberSelection()
        Remembers and returns the current selection. The saved selection can be restored by calling restoreSelection().
        Returns:
        the current selection
        Since:
        3.0
        See Also:
        ITextViewer.getSelectedRange()
      • restoreSelection

        protected void restoreSelection()
        Restores a previously saved selection in the document.

        If no selection was previously saved, nothing happens.

        Since:
        3.0
      • clearRememberedSelection

        protected void clearRememberedSelection()
      • doOperation

        public void doOperation​(int operation)
        Description copied from interface: ITextOperationTarget
        Performs the operation specified by the operation code on the target. doOperation must only be called if canDoOperation returns true.
        Specified by:
        doOperation in interface ITextOperationTarget
        Overrides:
        doOperation in class TextViewer
        Parameters:
        operation - the operation code
      • updateSlaveDocuments

        protected void updateSlaveDocuments​(IDocument masterDocument)
        Updates all slave documents of the given document. This default implementation calls updateSlaveDocument for their current visible range. Subclasses may reimplement.
        Parameters:
        masterDocument - the master document
        Since:
        3.0
      • setRangeIndicator

        public void setRangeIndicator​(Annotation rangeIndicator)
        Description copied from interface: ISourceViewer
        Sets the annotation used by this viewer as range indicator. The range covered by this annotation is referred to as range indication.
        Specified by:
        setRangeIndicator in interface ISourceViewer
        Parameters:
        rangeIndicator - the annotation to be used as this viewer's range indicator
      • setRangeIndication

        public void setRangeIndication​(int start,
                                       int length,
                                       boolean moveCursor)
        Description copied from interface: ISourceViewer
        Sets the viewers's range indication to the specified range. It is indicated whether the cursor should also be moved to the beginning of the specified range.
        Specified by:
        setRangeIndication in interface ISourceViewer
        Parameters:
        start - the offset of the range
        length - the length of the range
        moveCursor - indicates whether the cursor should be moved to the given offset
      • removeRangeIndication

        public void removeRangeIndication()
        Description copied from interface: ISourceViewer
        Removes the viewer's range indication. There is no visible range indication after this method completed.
        Specified by:
        removeRangeIndication in interface ISourceViewer
      • showAnnotations

        public void showAnnotations​(boolean show)
        Description copied from interface: ISourceViewer
        Controls the visibility of annotations and in the case of separate presentation areas of text and annotations, the visibility of the annotation's presentation area.

        By default, annotations and their presentation area are visible.

        Specified by:
        showAnnotations in interface ISourceViewer
        Parameters:
        show - indicates the visibility of annotations
      • getVerticalRuler

        protected final IVerticalRuler getVerticalRuler()
        Returns the vertical ruler of this viewer.
        Returns:
        the vertical ruler of this viewer
        Since:
        3.0
      • addVerticalRulerColumn

        public void addVerticalRulerColumn​(IVerticalRulerColumn column)
        Adds the give column as last column to this viewer's vertical ruler.
        Parameters:
        column - the column to be added
        Since:
        3.8
      • removeVerticalRulerColumn

        public void removeVerticalRulerColumn​(IVerticalRulerColumn column)
        Removes the give column from this viewer's vertical ruler.
        Parameters:
        column - the column to be removed
        Since:
        3.8
      • showAnnotationsOverview

        public void showAnnotationsOverview​(boolean show)
        Description copied from interface: ISourceViewerExtension
        Shows/hides an overview representation of the annotations of the whole document of this viewer.
        Specified by:
        showAnnotationsOverview in interface ISourceViewerExtension
        Parameters:
        show - true if annotation overview should be visible, false otherwise
      • setCodeMiningProviders

        public void setCodeMiningProviders​(org.eclipse.jface.text.codemining.ICodeMiningProvider[] codeMiningProviders)
        Description copied from interface: ISourceViewerExtension5
        Register the code mining providers.
        Specified by:
        setCodeMiningProviders in interface ISourceViewerExtension5
        Parameters:
        codeMiningProviders - the code mining providers to register.
      • hasCodeMiningProviders

        public boolean hasCodeMiningProviders()
        Description copied from interface: ISourceViewerExtension5
        Returns true if there are code mining providers and false otherwise.
        Specified by:
        hasCodeMiningProviders in interface ISourceViewerExtension5
        Returns:
        true if there are code mining providers and false otherwise.
      • updateCodeMinings

        public void updateCodeMinings()
        Description copied from interface: ISourceViewerExtension5
        Update the code minings. Clients and implementors are responsible of calling this method when needed. A typical use-case can be to run it upon completion of a reconcilier and after a job that would compute all the necessary pre-requisites to insert code mining annotations.
        Specified by:
        updateCodeMinings in interface ISourceViewerExtension5