Eclipse Platform
Release 3.0

org.eclipse.jface.text.projection
Class ProjectionDocument

java.lang.Object
  extended byorg.eclipse.jface.text.AbstractDocument
      extended byorg.eclipse.jface.text.projection.ProjectionDocument
All Implemented Interfaces:
IDocument, IDocumentExtension, IDocumentExtension2, IDocumentExtension3, IRepairableDocument
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

Nested Class Summary
 
Nested classes inherited from class org.eclipse.jface.text.IDocumentExtension
IDocumentExtension.IReplace
 
Field Summary
 
Fields inherited from interface org.eclipse.jface.text.IDocument
DEFAULT_CATEGORY, DEFAULT_CONTENT_TYPE
 
Fields inherited from interface org.eclipse.jface.text.IDocumentExtension3
DEFAULT_PARTITIONING
 
Constructor Summary
ProjectionDocument(IDocument masterDocument)
          Creates a projection document for the given master document.
 
Method Summary
protected  boolean adaptProjectionToMasterChange(DocumentEvent masterEvent)
          Ensures that when the master event effects this projection document, that the whole region described by the event is part of this projection document.
 void addMasterDocumentRange(int offsetInMaster, int lengthInMaster)
          Ensures that the given range of the master document is part of this projection document.
 IRegion[] computeProjectedMasterRegions(int offsetInMaster, int lengthInMaster)
          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.
 IRegion[] computeUnprojectedMasterRegions(int offsetInMaster, int lengthInMaster)
          Returns the sequence of all master document regions with are contained in the given master document range and which are not yet part of this projection document.
 void dispose()
          Disposes this projection document.
protected  void fireDocumentAboutToBeChanged(DocumentEvent event)
          Fires the given document event to all registers document listeners informing them about the forthcoming document manipulation.
protected  void fireDocumentChanged(DocumentEvent event)
          Ignores the given event and sends the semantically equal slave document event instead.
protected  Position[] getFragments()
          Returns the fragments of the master documents.
 IDocument getMasterDocument()
          Returns the master document of this projection document.
 ProjectionMapping getProjectionMapping()
          Returns the projection mapping used by this document.
protected  Position[] getSegments()
          Returns the segments of this projection document.
protected  boolean isUpdating()
          Returns whether this project is being updated.
 void masterDocumentAboutToBeChanged(DocumentEvent masterEvent)
          When called, this projection document is informed about a forthcoming change of its master document.
 void masterDocumentChanged(DocumentEvent masterEvent)
          When called, this projection document is informed about a change of its master document.
 void registerPostNotificationReplace(IDocumentListener owner, IDocumentExtension.IReplace replace)
          Callback for document listeners to be used inside documentChanged to register a post notification replace operation on the document notifying them.
 void removeMasterDocumentRange(int offsetInMaster, int lengthInMaster)
          Ensures that the given range of the master document is not part of this projection document.
 void replace(int offset, int length, String text)
          Substitutes the given text for the specified document range.
 void replaceMasterDocumentRanges(int offsetInMaster, int lengthInMaster)
          Replaces all master document ranges with the given master document range.
 void set(String text)
          Replaces the content of the document with the given text.
 void setAutoExpandMode(boolean autoExpandMode)
          Sets the auto expand mode for this document.
protected  void updateDocumentStructures(DocumentEvent event)
          Updates document partitioning and document positions according to the specification given by the document event.
 
Methods inherited from class org.eclipse.jface.text.AbstractDocument
acceptPostNotificationReplaces, addDocumentListener, addDocumentPartitioningListener, addPosition, addPosition, addPositionCategory, addPositionUpdater, addPrenotifiedDocumentListener, completeInitialization, computeIndexInCategory, computeIndexInPositionList, computeNumberOfLines, computePartitioning, computePartitioning, containsPosition, containsPositionCategory, doFireDocumentChanged, doFireDocumentChanged, doFireDocumentChanged2, fireDocumentPartitioningChanged, fireDocumentPartitioningChanged, fireDocumentPartitioningChanged, get, get, getChar, getContentType, getContentType, getDocumentListeners, getDocumentManagedPositions, getDocumentPartitioner, getDocumentPartitioner, getDocumentPartitioningListeners, getLegalContentTypes, getLegalContentTypes, getLegalLineDelimiters, getLength, getLineDelimiter, getLineInformation, getLineInformationOfOffset, getLineLength, getLineOffset, getLineOfOffset, getNumberOfLines, getNumberOfLines, getPartition, getPartition, getPartitionings, getPositionCategories, getPositions, getPositionUpdaters, getStore, getTracker, ignorePostNotificationReplaces, insertPositionUpdater, removeDocumentListener, removeDocumentPartitioningListener, removePosition, removePosition, removePositionCategory, removePositionUpdater, removePrenotifiedDocumentListener, repairLineInformation, resumeListenerNotification, resumePostNotificationProcessing, search, setDocumentPartitioner, setDocumentPartitioner, setLineTracker, setTextStore, startSequentialRewrite, stopListenerNotification, stopPostNotificationProcessing, stopSequentialRewrite, updatePositions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

getProjectionMapping

public ProjectionMapping getProjectionMapping()
Returns the projection mapping used by this document.

Returns:
the projection mapping used by this document

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 with 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 project is being updated.

Returns:
true if the document is updating

replace

public void replace(int offset,
                    int length,
                    String text)
             throws BadLocationException
Description copied from interface: IDocument
Substitutes the given text for the specified document range. Sends a DocumentEvent to all registered IDocumentListener.

Specified by:
replace in interface IDocument
Overrides:
replace in class AbstractDocument
Throws:
BadLocationException

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

adaptProjectionToMasterChange

protected final boolean adaptProjectionToMasterChange(DocumentEvent masterEvent)
                                               throws BadLocationException
Ensures that when the master event effects 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

registerPostNotificationReplace

public void registerPostNotificationReplace(IDocumentListener owner,
                                            IDocumentExtension.IReplace replace)
Description copied from interface: IDocumentExtension
Callback for document listeners to be used inside documentChanged to register a post notification replace operation on the document notifying them.

Specified by:
registerPostNotificationReplace in interface IDocumentExtension
Overrides:
registerPostNotificationReplace in class AbstractDocument

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

Eclipse Platform
Release 3.0

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2004. All rights reserved.