Class ProjectionViewer

    • Field Detail

      • EXPAND

        public static final int EXPAND
        Operation constant for the expand operation.
        See Also:
        Constant Field Values
      • COLLAPSE

        public static final int COLLAPSE
        Operation constant for the collapse operation.
        See Also:
        Constant Field Values
      • TOGGLE

        public static final int TOGGLE
        Operation constant for the toggle projection operation.
        See Also:
        Constant Field Values
      • EXPAND_ALL

        public static final int EXPAND_ALL
        Operation constant for the expand all operation.
        See Also:
        Constant Field Values
      • COLLAPSE_ALL

        public static final int COLLAPSE_ALL
        Operation constant for the collapse all operation.
        Since:
        3.2
        See Also:
        Constant Field Values
    • Constructor Detail

      • ProjectionViewer

        public ProjectionViewer​(Composite parent,
                                IVerticalRuler ruler,
                                IOverviewRuler overviewRuler,
                                boolean showsAnnotationOverview,
                                int styles)
        Creates a new projection source viewer.
        Parameters:
        parent - the SWT parent control
        ruler - the vertical ruler
        overviewRuler - the overview ruler
        showsAnnotationOverview - true if the overview ruler should be shown
        styles - the SWT style bits
    • Method Detail

      • setProjectionSummary

        public void setProjectionSummary​(org.eclipse.jface.text.source.projection.ProjectionSummary projectionSummary)
        Sets the projection summary for this viewer.
        Parameters:
        projectionSummary - the projection summary.
      • 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
        Overrides:
        setDocument in class SourceViewer
        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)
      • createVisualAnnotationModel

        protected IAnnotationModel createVisualAnnotationModel​(IAnnotationModel annotationModel)
        Description copied from class: SourceViewer
        Creates the visual annotation model on top of the given annotation model.
        Overrides:
        createVisualAnnotationModel in class SourceViewer
        Parameters:
        annotationModel - the wrapped annotation model
        Returns:
        the visual annotation model on top of the given annotation model
      • getProjectionAnnotationModel

        public ProjectionAnnotationModel getProjectionAnnotationModel()
        Returns the projection annotation model.
        Returns:
        the projection annotation model
      • updateSlaveDocument

        protected boolean updateSlaveDocument​(IDocument slaveDocument,
                                              int modelRangeOffset,
                                              int modelRangeLength)
                                       throws BadLocationException
        Description copied from class: TextViewer
        Updates the given slave document to show the specified range of its master document.
        Overrides:
        updateSlaveDocument in class TextViewer
        Parameters:
        slaveDocument - the slave document
        modelRangeOffset - the offset of the master document range
        modelRangeLength - the length of the master document range
        Returns:
        true if the slave has been adapted successfully
        Throws:
        BadLocationException - in case the specified range is not valid in the master document
      • addProjectionListener

        public void addProjectionListener​(IProjectionListener listener)
        Adds a projection annotation listener to this viewer. The listener may not be null. If the listener is already registered, this method does not have any effect.
        Parameters:
        listener - the listener to add
      • removeProjectionListener

        public void removeProjectionListener​(IProjectionListener listener)
        Removes the given listener from this viewer. The listener may not be null. If the listener is not registered with this viewer, this method is without effect.
        Parameters:
        listener - the listener to remove
      • fireProjectionEnabled

        protected void fireProjectionEnabled()
        Notifies all registered projection listeners that projection mode has been enabled.
      • fireProjectionDisabled

        protected void fireProjectionDisabled()
        Notifies all registered projection listeners that projection mode has been disabled.
      • isProjectionMode

        public final boolean isProjectionMode()
        Returns whether this viewer is in projection mode.
        Returns:
        true if this viewer is in projection mode, false otherwise
      • disableProjection

        public final void disableProjection()
        Disables the projection mode.
      • enableProjection

        public final void enableProjection()
        Enables the projection mode.
      • setVisibleRegion

        public void setVisibleRegion​(int start,
                                     int length)
        Description copied from interface: ITextViewer
        Defines and sets the region of this viewer's document which will be visible in the presentation. Every character inside the specified region is supposed to be visible in the viewer's widget after that call.
        Specified by:
        setVisibleRegion in interface ITextViewer
        Overrides:
        setVisibleRegion in class TextViewer
        Parameters:
        start - the offset of the visible region
        length - the length of the visible region
      • setVisibleDocument

        protected void setVisibleDocument​(IDocument document)
        Description copied from class: TextViewer
        Sets this viewer's visible document. The visible document represents the visible region of the viewer's input document.
        Overrides:
        setVisibleDocument in class TextViewer
        Parameters:
        document - the visible document
      • resetVisibleRegion

        public void resetVisibleRegion()
        Description copied from interface: ITextViewer
        Resets the region of this viewer's document which is visible in the presentation. Afterwards, the whole input document is visible.
        Specified by:
        resetVisibleRegion in interface ITextViewer
        Overrides:
        resetVisibleRegion in class TextViewer
      • getVisibleRegion

        public IRegion getVisibleRegion()
        Description copied from interface: ITextViewer
        Returns the current visible region of this viewer's document. The result may differ from the argument passed to setVisibleRegion if the document has been modified since then. The visible region is supposed to be a consecutive region in viewer's input document and every character inside that region is supposed to visible in the viewer's widget.

        Viewers implementing ITextViewerExtension5 may be forced to change the fractions of the input document that are shown, in order to fulfill this contract.

        Specified by:
        getVisibleRegion in interface ITextViewer
        Overrides:
        getVisibleRegion in class TextViewer
        Returns:
        this viewer's current visible region
      • overlapsWithVisibleRegion

        public boolean overlapsWithVisibleRegion​(int offset,
                                                 int length)
        Description copied from interface: ITextViewer
        Returns whether a given range overlaps with the visible region of this viewer's document.

        Viewers implementing ITextViewerExtension5may be forced to change the fractions of the input document that are shown in order to fulfill this request. This is because the overlap is supposed to be without gaps.

        Specified by:
        overlapsWithVisibleRegion in interface ITextViewer
        Overrides:
        overlapsWithVisibleRegion in class TextViewer
        Parameters:
        offset - the offset
        length - the length
        Returns:
        true if the specified range overlaps with the visible region
      • processCatchupRequest

        protected final void processCatchupRequest​(AnnotationModelEvent event)
        Processes the request for catch up with the annotation model in the UI thread. If the current thread is not the UI thread or there are pending catch up requests, a new request is posted.
        Parameters:
        event - the annotation model event
      • postCatchupRequest

        protected final void postCatchupRequest​(AnnotationModelEvent event)
        Posts the request for catch up with the annotation model into the UI thread.
        Parameters:
        event - the annotation model event
      • computeCollapsedRegion

        public IRegion computeCollapsedRegion​(Position position)
        Computes the region that must be collapsed when the given position is the position of an expanded projection annotation.
        Parameters:
        position - the position
        Returns:
        the range that must be collapsed
      • computeCollapsedRegionAnchor

        public Position computeCollapsedRegionAnchor​(Position position)
        Computes the collapsed region anchor for the given position. Assuming that the position is the position of an expanded projection annotation, the anchor is the region that is still visible after the projection annotation has been collapsed.
        Parameters:
        position - the position
        Returns:
        the collapsed region anchor
      • reinitializeProjection

        public final void reinitializeProjection()
                                          throws BadLocationException
        Forces this viewer to throw away any old state and to initialize its content from its projection annotation model.
        Throws:
        BadLocationException - in case something goes wrong during initialization
      • exposeModelRange

        public boolean exposeModelRange​(IRegion modelRange)
        Description copied from interface: ITextViewerExtension5
        Exposes the given model range. Returns whether this call caused a change of the set of exposed model ranges.
        Specified by:
        exposeModelRange in interface ITextViewerExtension5
        Parameters:
        modelRange - the model range to be exposed
        Returns:
        true if the set of exposed model ranges changed, false otherwise
      • setRangeIndication

        public void setRangeIndication​(int offset,
                                       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
        Overrides:
        setRangeIndication in class SourceViewer
        Parameters:
        offset - the offset of the range
        length - the length of the range
        moveCursor - indicates whether the cursor should be moved to the given offset
      • 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 SourceViewer
      • handleVisibleDocumentChanged

        protected void handleVisibleDocumentChanged​(DocumentEvent event)
        Description copied from class: TextViewer
        Hook method called when the visible document has been changed.

        Subclasses may override.

        Overrides:
        handleVisibleDocumentChanged in class TextViewer
        Parameters:
        event - the document event
      • handleVisibleDocumentAboutToBeChanged

        protected void handleVisibleDocumentAboutToBeChanged​(DocumentEvent event)
        Description copied from class: TextViewer
        Hook method called when the visible document is about to be changed.

        Subclasses may override.

        Overrides:
        handleVisibleDocumentAboutToBeChanged in class TextViewer
        Parameters:
        event - the document event
      • getCoveredModelRanges

        public IRegion[] getCoveredModelRanges​(IRegion modelRange)
        Description copied from interface: ITextViewerExtension5
        Returns the maximal subranges of the given model range thus that there is no offset inside a subrange for which there is no image offset.
        Specified by:
        getCoveredModelRanges in interface ITextViewerExtension5
        Parameters:
        modelRange - the model range
        Returns:
        the list of subranges
      • 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 SourceViewer
        Parameters:
        operation - the operation code
      • 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 SourceViewer
        Parameters:
        operation - the operation code
        Returns:
        true if the specified operation can be performed
      • copyMarkedRegion

        protected void copyMarkedRegion​(boolean delete)
        Description copied from class: TextViewer
        Copies/cuts the marked region.
        Overrides:
        copyMarkedRegion in class TextViewer
        Parameters:
        delete - true if the region should be deleted rather than copied.
      • widgetSelection2ModelSelection

        protected Point widgetSelection2ModelSelection​(Point widgetSelection)
        Adapts the behavior of the super class to respect line based folding.
        Overrides:
        widgetSelection2ModelSelection in class TextViewer
        Parameters:
        widgetSelection - the widget selection
        Returns:
        the model selection while respecting line based folding
      • findAndSelect

        protected int findAndSelect​(int startPosition,
                                    String findString,
                                    boolean forwardSearch,
                                    boolean caseSensitive,
                                    boolean wholeWord,
                                    boolean regExSearch)
        Description copied from class: TextViewer
        Overrides:
        findAndSelect in class TextViewer
        Parameters:
        startPosition - the start position
        findString - the find string specification
        forwardSearch - the search direction
        caseSensitive - true if case sensitive, false otherwise
        wholeWord - true if matches must be whole words, false otherwise
        regExSearch - true if findString is a regular expression, false otherwise
        Returns:
        the model offset of the first match
      • findAndSelectInRange

        protected int findAndSelectInRange​(int startPosition,
                                           String findString,
                                           boolean forwardSearch,
                                           boolean caseSensitive,
                                           boolean wholeWord,
                                           int rangeOffset,
                                           int rangeLength,
                                           boolean regExSearch)
        Description copied from class: TextViewer
        Overrides:
        findAndSelectInRange in class TextViewer
        Parameters:
        startPosition - the start position
        findString - the find string specification
        forwardSearch - the search direction
        caseSensitive - true if case sensitive, false otherwise
        wholeWord - true if matches must be whole words, false otherwise
        rangeOffset - the search scope offset
        rangeLength - the search scope length
        regExSearch - true if findString is a regular expression, false otherwise
        Returns:
        the model offset of the first match