Class ProjectionDocument
- java.lang.Object
-
- org.eclipse.jface.text.AbstractDocument
-
- org.eclipse.jface.text.projection.ProjectionDocument
-
- All Implemented Interfaces:
IDocument,IDocumentExtension,IDocumentExtension2,IDocumentExtension3,IDocumentExtension4,IRepairableDocument,IRepairableDocumentExtension
- Direct Known Subclasses:
ChildDocument
public class ProjectionDocument extends AbstractDocument
AProjectionDocumentrepresents 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
ITextStoreby means of aProjectionTextStore.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
addMasterDocumentRangeandremoveMasterDocumentRangeare provided. For any manipulation, the projection document sends out aProjectionDocumentEventdescribing 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface 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
-
Fields inherited from interface org.eclipse.jface.text.IDocumentExtension4
UNKNOWN_MODIFICATION_STAMP
-
-
Constructor Summary
Constructors Constructor Description ProjectionDocument(IDocument masterDocument)Creates a projection document for the given master document.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected booleanadaptProjectionToMasterChange(DocumentEvent masterEvent)Ensures that when the master event affects this projection document, that the whole region described by the event is part of this projection document.voidaddMasterDocumentRange(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 which are contained in the given master document range and which are not yet part of this projection document.voiddispose()Disposes this projection document.protected voidfireDocumentAboutToBeChanged(DocumentEvent event)Fires the given document event to all registers document listeners informing them about the forthcoming document manipulation.protected voidfireDocumentChanged(DocumentEvent event)Ignores the given event and sends the semantically equal slave document event instead.StringgetDefaultLineDelimiter()Returns this document's default line delimiter.IDocumentInformationMappinggetDocumentInformationMapping()Returns the projection mapping used by this document.protected Position[]getFragments()Returns the fragments of the master documents.IDocumentgetMasterDocument()Returns the master document of this projection document.ProjectionMappinggetProjectionMapping()Deprecated.As of 3.4, replaced bygetDocumentInformationMapping()protected Position[]getSegments()Returns the segments of this projection document.protected booleanisUpdating()Returns whether this projection is being updated.voidmasterDocumentAboutToBeChanged(DocumentEvent masterEvent)When called, this projection document is informed about a forthcoming change of its master document.voidmasterDocumentChanged(DocumentEvent masterEvent)When called, this projection document is informed about a change of its master document.voidregisterPostNotificationReplace(IDocumentListener owner, IDocumentExtension.IReplace replace)Callback for document listeners to be used insidedocumentChangedto register a post notification replace operation on the document notifying them.voidremoveMasterDocumentRange(int offsetInMaster, int lengthInMaster)Ensures that the given range of the master document is not part of this projection document.voidreplace(int offset, int length, String text)Substitutes the given text for the specified document range.voidreplaceMasterDocumentRanges(int offsetInMaster, int lengthInMaster)Replaces all master document ranges with the given master document range.voidset(String text)Replaces the content of the document with the given text.voidsetAutoExpandMode(boolean autoExpandMode)Sets the auto expand mode for this document.protected voidupdateDocumentStructures(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, addDocumentRewriteSessionListener, addPosition, addPosition, addPositionCategory, addPositionUpdater, addPrenotifiedDocumentListener, checkStateOfPartitioner, completeInitialization, computeIndexInCategory, computeIndexInPositionList, computeIndexInPositionList, computeNumberOfLines, computePartitioning, computePartitioning, containsPosition, containsPositionCategory, doFireDocumentChanged, doFireDocumentChanged, doFireDocumentChanged2, fireDocumentPartitioningChanged, fireDocumentPartitioningChanged, fireDocumentPartitioningChanged, fireRewriteSessionChanged, get, get, getActiveRewriteSession, getChar, getContentType, getContentType, getDocumentListeners, getDocumentManagedPositions, getDocumentPartitioner, getDocumentPartitioner, getDocumentPartitioningListeners, getLegalContentTypes, getLegalContentTypes, getLegalLineDelimiters, getLength, getLineDelimiter, getLineInformation, getLineInformationOfOffset, getLineLength, getLineOffset, getLineOfOffset, getModificationStamp, getNumberOfLines, getNumberOfLines, getPartition, getPartition, getPartitionings, getPositionCategories, getPositions, getPositions, getPositionUpdaters, getStore, getTracker, ignorePostNotificationReplaces, insertPositionUpdater, isLineInformationRepairNeeded, removeDocumentListener, removeDocumentPartitioningListener, removeDocumentRewriteSessionListener, removePosition, removePosition, removePositionCategory, removePositionUpdater, removePrenotifiedDocumentListener, repairLineInformation, replace, resumeListenerNotification, resumePostNotificationProcessing, search, set, setDocumentPartitioner, setDocumentPartitioner, setInitialLineDelimiter, setLineTracker, setTextStore, startRewriteSession, startRewriteSessionOnPartitioners, startSequentialRewrite, stopListenerNotification, stopPostNotificationProcessing, stopRewriteSession, stopRewriteSessionOnPartitioners, stopSequentialRewrite, updatePositions
-
-
-
-
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
@Deprecated public ProjectionMapping getProjectionMapping()
Deprecated.As of 3.4, replaced bygetDocumentInformationMapping()Returns the projection mapping used by this document.- Returns:
- the projection mapping used by this 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
-
getDefaultLineDelimiter
public String getDefaultLineDelimiter()
Description copied from interface:IDocumentExtension4Returns this document's default line delimiter.This default line delimiter should be used by clients who want unique delimiters (e.g. 'CR's) in the document.
- Specified by:
getDefaultLineDelimiterin interfaceIDocumentExtension4- Overrides:
getDefaultLineDelimiterin classAbstractDocument- Returns:
- the default line delimiter or
nullif none
-
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 documentlengthInMaster- 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 BadLocationExceptionEnsures that the given range of the master document is part of this projection document.- Parameters:
offsetInMaster- the offset of the master document rangelengthInMaster- 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 BadLocationExceptionEnsures that the given range of the master document is not part of this projection document.- Parameters:
offsetInMaster- the offset of the master document rangelengthInMaster- 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 returnnullif no such regions exist.- Parameters:
offsetInMaster- the range offset in the master documentlengthInMaster- 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:
trueif the document is updating
-
replace
public void replace(int offset, int length, String text) throws BadLocationExceptionDescription copied from interface:IDocumentSubstitutes the given text for the specified document range. Sends aDocumentEventto all registeredIDocumentListener.- Specified by:
replacein interfaceIDocument- Overrides:
replacein classAbstractDocument- Parameters:
offset- the document offsetlength- the length of the specified rangetext- the substitution text- Throws:
BadLocationException- if the offset is invalid in this document- See Also:
DocumentEvent,IDocumentListener
-
set
public void set(String text)
Description copied from interface:IDocumentReplaces the content of the document with the given text. Sends aDocumentEventto all registeredIDocumentListener. This method is a convenience method forreplace(0, getLength(), text).- Specified by:
setin interfaceIDocument- Overrides:
setin classAbstractDocument- 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:
trueif 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:AbstractDocumentFires the given document event to all registers document listeners informing them about the forthcoming document manipulation. Uses a robust iterator.- Overrides:
fireDocumentAboutToBeChangedin classAbstractDocument- 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:
fireDocumentChangedin classAbstractDocument- Parameters:
event- the event to be ignored
-
updateDocumentStructures
protected void updateDocumentStructures(DocumentEvent event)
Description copied from class:AbstractDocumentUpdates document partitioning and document positions according to the specification given by the document event.- Overrides:
updateDocumentStructuresin classAbstractDocument- 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:IDocumentExtensionCallback for document listeners to be used insidedocumentChangedto register a post notification replace operation on the document notifying them.- Specified by:
registerPostNotificationReplacein interfaceIDocumentExtension- Overrides:
registerPostNotificationReplacein classAbstractDocument- Parameters:
owner- the owner of the replace operationreplace- the replace operation to be executed
-
setAutoExpandMode
public void setAutoExpandMode(boolean autoExpandMode)
Sets the auto expand mode for this document.- Parameters:
autoExpandMode-trueif auto-expanding
-
replaceMasterDocumentRanges
public void replaceMasterDocumentRanges(int offsetInMaster, int lengthInMaster) throws BadLocationExceptionReplaces all master document ranges with the given master document range.- Parameters:
offsetInMaster- the offset in the master documentlengthInMaster- the length in the master document- Throws:
BadLocationException- if the given range of the master document is not valid
-
-