Eclipse Platform
2.1

org.eclipse.jface.text
Class ProjectionDocument

java.lang.Object
  |
  +--org.eclipse.jface.text.AbstractDocument
        |
        +--org.eclipse.jface.text.ProjectionDocument
All Implemented Interfaces:
IDocument, IDocumentExtension, IDocumentExtension2

public final 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 by omitting serveral ranges of the master document.

The projection document utilizes its master document as ITextStore.

This class if for internal use only.

Since:
2.1

Inner classes inherited from class org.eclipse.jface.text.IDocumentExtension
IDocumentExtension.IReplace
 
Field Summary
static String FRAGMENT_CATEGORY
          The position category used by ProjectionDocuments to manage the fragments they consist of.
 
Fields inherited from interface org.eclipse.jface.text.IDocument
DEFAULT_CATEGORY, DEFAULT_CONTENT_TYPE
 
Constructor Summary
ProjectionDocument(IDocument parentDocument, String projectionCategory)
          Creates a projection document for the given parent document.
 
Method Summary
 void addFragment(int offsetInParent, int lengthInParent)
          Add a new fragment of the parent document to this projection document.
 IRegion computeParentDocumentRegion(int offset, int length)
          Computes and returns the region of the parent document that corresponds to the given region of the projection document.
 Position computeProjectionDocumentPosition(int offsetInParent, int lengthInParent)
          Creates a position describing the projection document range corresponding to the given parent document range.
 Fragment createFragment(Position parentPosition)
          Creates a fragment from a postion of the parent 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.
 Position[] getAffectedFragments(int offsetInParent, int lengthInParent)
          Returns the list of fragments whose corresponding ranges in the parent document overlap with the specifed range of the parent document.
 Position[] getFragmentation()
          Returns the list of all fragments of this projection document.
protected  Fragment getFragmentOfOffset(int offset)
          Returns the fragment that contains the given offset.
protected  Fragment[] getFragmentsOfRange(int offset, int length)
          Returns the minimal consecutive list of fragments that completely covers the given range.
 IDocument getParentDocument()
          Returns parent document.
 Position getParentDocumentCoverage()
          Returns the minimal range of the parent document that covers all ranges that correspond to the fragments of this projection document.
 Position[] getProjection()
          Returns the ranges of the parent document that correspond to the fragments of this projection document.
 void hide(int offsetInParent, int lengthInParent)
          Convenience method for removing and adapting the fragments whose corresponding ranges in the parent document are included or overlap with the given range of the parent document.
 void joinFragments()
          Joins all fragments that represent neighboring regions in the parent document.
 void parentDocumentAboutToBeChanged(DocumentEvent event)
          When called, this projection document is informed about a forthcoming change of its parent document.
 void parentDocumentChanged(DocumentEvent event)
          When called, this projection document is informed about a change of its parent 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 removeAllFragments()
          Removes all fragments and thereby clears this projection document.
 void removeFragment(Position parentPosition)
          Removes the fragment that corresponds to the given parent document range.
 void replace(int offset, int length, String text)
          Subsitutes the given text for the specified document range.
 void set(String text)
          Replaces the content of the document with the given text.
 void show(int offsetInParent, int lengthInParent)
          Convenience method for adding fragments or adapting existing fragments so that their corresponding ranges in the parent document include the given range of the parent document.
 int toParentDocumentOffset(int offset)
          Returns the offset in the parent document that corresponds to the given offset in this projection document.
 
Methods inherited from class org.eclipse.jface.text.AbstractDocument
acceptPostNotificationReplaces, addDocumentListener, addDocumentPartitioningListener, addPosition, addPosition, addPositionCategory, addPositionUpdater, addPrenotifiedDocumentListener, completeInitialization, computeIndexInCategory, computeIndexInPositionList, computeNumberOfLines, computePartitioning, containsPosition, containsPositionCategory, doFireDocumentChanged, doFireDocumentChanged, fireDocumentPartitioningChanged, fireDocumentPartitioningChanged, get, get, getChar, getContentType, getDocumentListeners, getDocumentManagedPositions, getDocumentPartitioner, getDocumentPartitioningListeners, getLegalContentTypes, getLegalLineDelimiters, getLength, getLineDelimiter, getLineInformation, getLineInformationOfOffset, getLineLength, getLineOffset, getLineOfOffset, getNumberOfLines, getNumberOfLines, getPartition, getPositionCategories, getPositions, getPositionUpdaters, getStore, getTracker, ignorePostNotificationReplaces, insertPositionUpdater, removeDocumentListener, removeDocumentPartitioningListener, removePosition, removePosition, removePositionCategory, removePositionUpdater, removePrenotifiedDocumentListener, resumeListenerNotification, resumePostNotificationProcessing, search, setDocumentPartitioner, setLineTracker, setTextStore, startSequentialRewrite, stopListenerNotification, stopPostNotificationProcessing, stopSequentialRewrite, updateDocumentStructures, updatePositions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FRAGMENT_CATEGORY

public static final String FRAGMENT_CATEGORY
The position category used by ProjectionDocuments to manage the fragments they consist of.
Constructor Detail

ProjectionDocument

public ProjectionDocument(IDocument parentDocument,
                          String projectionCategory)
Creates a projection document for the given parent document.
Parameters:
parentDocument - the parent Document
projectionCategory - the document position category whose positions define the projection of the parent document
Method Detail

createFragment

public Fragment createFragment(Position parentPosition)
Creates a fragment from a postion of the parent document.
Parameters:
parentPosition - a position of the parent document
Returns:
the fragment representing the range given by the parent position

computeProjectionDocumentPosition

public Position computeProjectionDocumentPosition(int offsetInParent,
                                                  int lengthInParent)
Creates a position describing the projection document range corresponding to the given parent document range.
Parameters:
offsetInParent - the parent document offset
lengthInParent - the parent document lengh
Returns:
position describing the projection document range corresponding to the given parent document range

toParentDocumentOffset

public int toParentDocumentOffset(int offset)
                           throws BadLocationException
Returns the offset in the parent document that corresponds to the given offset in this projection document.
Parameters:
offset - the offset in the projection document
Returns:
the corresponding parent document offset
Throws:
BadLocationException - if offset is not valid in this projection document

computeParentDocumentRegion

public IRegion computeParentDocumentRegion(int offset,
                                           int length)
                                    throws BadLocationException
Computes and returns the region of the parent document that corresponds to the given region of the projection document.
Parameters:
offset - the offset of the projection document region
length - the length of the projection document region
Returns:
the corresponding region of the parent document
Throws:
BadLocationException - if the given projection document region is not valid

removeAllFragments

public void removeAllFragments()
Removes all fragments and thereby clears this projection document.

addFragment

public void addFragment(int offsetInParent,
                        int lengthInParent)
                 throws BadLocationException
Add a new fragment of the parent document to this projection document.
Parameters:
offsetInParent - offset of the parent document range
lengthInParent - length of the parent document range
Returns:
returns the position representing the parent document range in this projection document
Throws:
BadLocationException -  

joinFragments

public void joinFragments()
Joins all fragments that represent neighboring regions in the parent document.

removeFragment

public void removeFragment(Position parentPosition)
                    throws BadLocationException
Removes the fragment that corresponds to the given parent document range.
Parameters:
parentPosition - the position representing the parent document range
Throws:
BadLocationException - if the fragment position category is not defined in this projection document

getAffectedFragments

public Position[] getAffectedFragments(int offsetInParent,
                                       int lengthInParent)
Returns the list of fragments whose corresponding ranges in the parent document overlap with the specifed range of the parent document.
Parameters:
offsetInParent - the offset of the parent document range
lengthInParent - the length of the parent document range
Returns:
the list of affected fragments

getFragmentOfOffset

protected Fragment getFragmentOfOffset(int offset)
                                throws BadLocationException
Returns the fragment that contains the given offset.
Parameters:
offset - the offset
Returns:
the fragment that contains the given offset
Throws:
BadLocationException - if offset is not a valid offset

getFragmentsOfRange

protected Fragment[] getFragmentsOfRange(int offset,
                                         int length)
Returns the minimal consecutive list of fragments that completely covers the given range.
Parameters:
offset - the offset of the range
length - the length of the range
Returns:
the minimal consecutive list of fragments convering the given range

getParentDocumentCoverage

public Position getParentDocumentCoverage()
Returns the minimal range of the parent document that covers all ranges that correspond to the fragments of this projection document.
Returns:
a position describing the minimal parent document range covering all fragments

getParentDocument

public IDocument getParentDocument()
Returns parent document.
Returns:
the parent document

getProjection

public Position[] getProjection()
Returns the ranges of the parent document that correspond to the fragments of this projection document.
Returns:
the ranges of the parent document corresponding to the fragments

getFragmentation

public Position[] getFragmentation()
Returns the list of all fragments of this projection document.
Returns:
the list of all fragments of this projection document

parentDocumentAboutToBeChanged

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

parentDocumentChanged

public void parentDocumentChanged(DocumentEvent event)
When called, this projection document is informed about a change of its parent document. If this projection document is affected it informs all of its document listeners.
Parameters:
event - the parent 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
Following copied from class: org.eclipse.jface.text.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

replace

public void replace(int offset,
                    int length,
                    String text)
             throws BadLocationException
Description copied from interface: IDocument
Subsitutes the given text for the specified document range. Sends a DocumentEvent to all registered IDocumentListener.
Overrides:
replace in class AbstractDocument
Following copied from interface: org.eclipse.jface.text.IDocument
Parameters:
offset - the document offset
length - the length of the specified range
text - 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: 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).
Overrides:
set in class AbstractDocument
Following copied from interface: org.eclipse.jface.text.IDocument
Parameters:
text - the new content of the document
See Also:
DocumentEvent, IDocumentListener

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.
Overrides:
registerPostNotificationReplace in class AbstractDocument
Following copied from interface: org.eclipse.jface.text.IDocumentExtension
Parameters:
owner - the owner of the replace operation
the - replace operation to be executed
Throws:
UnsupportedOperationException - if registerPostNotificationReplace is not supported by this document

hide

public void hide(int offsetInParent,
                 int lengthInParent)
Convenience method for removing and adapting the fragments whose corresponding ranges in the parent document are included or overlap with the given range of the parent document.
Parameters:
offsetInParent - the offset of the parent document range
lengthInParent - the length of the parent document range

show

public void show(int offsetInParent,
                 int lengthInParent)
Convenience method for adding fragments or adapting existing fragments so that their corresponding ranges in the parent document include the given range of the parent document.
Parameters:
offsetInParent - the offset of the parent document range
lengthInParent - the length of the parent document range

Eclipse Platform
2.1

Copyright (c) IBM Corp. and others 2000, 2003. All Rights Reserved.