Class ProjectionDocument

  • All Implemented Interfaces:
    IDocument, IDocumentExtension, IDocumentExtension2, IDocumentExtension3, IDocumentExtension4, IRepairableDocument, IRepairableDocumentExtension
    Direct Known Subclasses:
    ChildDocument

    public class ProjectionDocument
    extends AbstractDocument
    A ProjectionDocument represents a projection of its master document. The contents of a projection document is a sequence of fragments of the master document, i.e. the projection document can be thought as being constructed from the master document by not copying the whole master document but omitting several ranges of the master document.

    The projection document indirectly utilizes its master document as ITextStore by means of a ProjectionTextStore.

    The content of a projection document can be changed in two ways. Either by a text replace applied to the master document or the projection document. Or by changing the projection between the master document and the projection document. For the latter the two methods addMasterDocumentRange and removeMasterDocumentRange are provided. For any manipulation, the projection document sends out a ProjectionDocumentEvent describing the change.

    Clients are not supposed to directly instantiate this class. In order to obtain a projection document, a ProjectionDocumentManagershould be used. This class is not intended to be subclassed outside of its origin package.

    Since:
    3.0
    Restriction:
    This class is not intended to be subclassed by clients.
    Restriction:
    This class is not intended to be instantiated by clients.
    • Constructor Detail

      • ProjectionDocument

        public ProjectionDocument​(IDocument masterDocument)
        Creates a projection document for the given master document.
        Parameters:
        masterDocument - the master document
    • Method Detail

      • dispose

        public void dispose()
        Disposes this projection document.
      • getFragments

        protected final Position[] getFragments()
        Returns the fragments of the master documents.
        Returns:
        the fragment of the master document
      • getSegments

        protected final Position[] getSegments()
        Returns the segments of this projection document.
        Returns:
        the segments of this projection document
      • getDocumentInformationMapping

        public IDocumentInformationMapping getDocumentInformationMapping()
        Returns the projection mapping used by this document.
        Returns:
        the projection mapping used by this document
        Since:
        3.4
      • getMasterDocument

        public IDocument getMasterDocument()
        Returns the master document of this projection document.
        Returns:
        the master document of this projection document
      • computeUnprojectedMasterRegions

        public final IRegion[] computeUnprojectedMasterRegions​(int offsetInMaster,
                                                               int lengthInMaster)
                                                        throws BadLocationException
        Returns the sequence of all master document regions which are contained in the given master document range and which are not yet part of this projection document.
        Parameters:
        offsetInMaster - the range offset in the master document
        lengthInMaster - the range length in the master document
        Returns:
        the sequence of regions which are not yet part of the projection document
        Throws:
        BadLocationException - in case the given range is invalid in the master document
      • addMasterDocumentRange

        public void addMasterDocumentRange​(int offsetInMaster,
                                           int lengthInMaster)
                                    throws BadLocationException
        Ensures that the given range of the master document is part of this projection document.
        Parameters:
        offsetInMaster - the offset of the master document range
        lengthInMaster - the length of the master document range
        Throws:
        BadLocationException - in case the master event is not valid
      • removeMasterDocumentRange

        public void removeMasterDocumentRange​(int offsetInMaster,
                                              int lengthInMaster)
                                       throws BadLocationException
        Ensures that the given range of the master document is not part of this projection document.
        Parameters:
        offsetInMaster - the offset of the master document range
        lengthInMaster - the length of the master document range
        Throws:
        BadLocationException - in case the master event is not valid
      • computeProjectedMasterRegions

        public final IRegion[] computeProjectedMasterRegions​(int offsetInMaster,
                                                             int lengthInMaster)
                                                      throws BadLocationException
        Returns the sequence of all master document regions with are contained in the given master document range and which are part of this projection document. May return null if no such regions exist.
        Parameters:
        offsetInMaster - the range offset in the master document
        lengthInMaster - the range length in the master document
        Returns:
        the sequence of regions which are part of the projection document or null
        Throws:
        BadLocationException - in case the given range is invalid in the master document
      • isUpdating

        protected boolean isUpdating()
        Returns whether this projection is being updated.
        Returns:
        true if the document is updating
      • set

        public void set​(String text)
        Description copied from interface: IDocument
        Replaces the content of the document with the given text. Sends a DocumentEvent to all registered IDocumentListener. This method is a convenience method for replace(0, getLength(), text).
        Specified by:
        set in interface IDocument
        Overrides:
        set in class AbstractDocument
        Parameters:
        text - the new content of the document
        See Also:
        DocumentEvent, IDocumentListener
      • adaptProjectionToMasterChange

        protected final boolean adaptProjectionToMasterChange​(DocumentEvent masterEvent)
                                                       throws BadLocationException
        Ensures that when the master event affects this projection document, that the whole region described by the event is part of this projection document.
        Parameters:
        masterEvent - the master document event
        Returns:
        true if masterEvent affects this projection document
        Throws:
        BadLocationException - in case the master event is not valid
      • masterDocumentAboutToBeChanged

        public void masterDocumentAboutToBeChanged​(DocumentEvent masterEvent)
        When called, this projection document is informed about a forthcoming change of its master document. This projection document checks whether the master document change affects it and if so informs all document listeners.
        Parameters:
        masterEvent - the master document event
      • masterDocumentChanged

        public void masterDocumentChanged​(DocumentEvent masterEvent)
        When called, this projection document is informed about a change of its master document. If this projection document is affected it informs all of its document listeners.
        Parameters:
        masterEvent - the master document event
      • fireDocumentAboutToBeChanged

        protected void fireDocumentAboutToBeChanged​(DocumentEvent event)
        Description copied from class: AbstractDocument
        Fires the given document event to all registers document listeners informing them about the forthcoming document manipulation. Uses a robust iterator.
        Overrides:
        fireDocumentAboutToBeChanged in class AbstractDocument
        Parameters:
        event - the event to be sent out
      • fireDocumentChanged

        protected void fireDocumentChanged​(DocumentEvent event)
        Ignores the given event and sends the semantically equal slave document event instead.
        Overrides:
        fireDocumentChanged in class AbstractDocument
        Parameters:
        event - the event to be ignored
      • updateDocumentStructures

        protected void updateDocumentStructures​(DocumentEvent event)
        Description copied from class: AbstractDocument
        Updates document partitioning and document positions according to the specification given by the document event.
        Overrides:
        updateDocumentStructures in class AbstractDocument
        Parameters:
        event - the document event describing the change to which structures must be adapted
      • setAutoExpandMode

        public void setAutoExpandMode​(boolean autoExpandMode)
        Sets the auto expand mode for this document.
        Parameters:
        autoExpandMode - true if auto-expanding
      • replaceMasterDocumentRanges

        public void replaceMasterDocumentRanges​(int offsetInMaster,
                                                int lengthInMaster)
                                         throws BadLocationException
        Replaces all master document ranges with the given master document range.
        Parameters:
        offsetInMaster - the offset in the master document
        lengthInMaster - the length in the master document
        Throws:
        BadLocationException - if the given range of the master document is not valid