Eclipse Platform
2.0

org.eclipse.jface.text.rules
Class DefaultPartitioner

java.lang.Object
  |
  +--org.eclipse.jface.text.rules.DefaultPartitioner
All Implemented Interfaces:
IDocumentPartitioner, IDocumentPartitionerExtension

public class DefaultPartitioner
extends Object
implements IDocumentPartitioner, IDocumentPartitionerExtension

A standard implementation of a document partitioner. It uses a partition token scanner to scan the document and to determine the document's partitioning. The tokens returned by the scanner are supposed to return the partition type as their data. The partitoner remembers the document's partitions in the document itself rather than maintaining its own data structure.

Since:
2.0
See Also:
IPartitionTokenScanner

Field Summary
static String CONTENT_TYPES_CATEGORY
          The position category this partitioner uses to store the document's partitioning information
protected  int fDeleteOffset
          The offset at which a partition has been deleted
protected  IDocument fDocument
          The partitioner's document
protected  int fEndOffset
          The offset at which the last changed partition ends
protected  String[] fLegalContentTypes
          The legal content types of this partitioner
protected  DefaultPositionUpdater fPositionUpdater
          The position updater used to for the default updating of partitions
protected  int fPreviousDocumentLength
          The document length before a document change occured
protected  IPartitionTokenScanner fScanner
          The partitioner's scanner
protected  int fStartOffset
          The offset at which the first changed partition starts
 
Constructor Summary
DefaultPartitioner(IPartitionTokenScanner scanner, String[] legalContentTypes)
          Creates a new partitioner that uses the given scanner and may return partitions of the given legal content types.
 
Method Summary
 ITypedRegion[] computePartitioning(int offset, int length)
          Returns the partitioning of the given range of the connected document.
 void connect(IDocument document)
          Connects the partitioner to a document.
 void disconnect()
          Disconnects the partitioner from the document it is connected to.
 void documentAboutToBeChanged(DocumentEvent e)
          Informs about a forthcoming document change.
 boolean documentChanged(DocumentEvent e)
          The document has been changed.
 IRegion documentChanged2(DocumentEvent e)
          The document has been changed.
protected  TypedPosition findClosestPosition(int offset)
          Returns the position in the partitoner's position category which is close to the given offset.
 String getContentType(int offset)
          Returns the content type of the partition containing the given offset in the connected document.
 String[] getLegalContentTypes()
          Returns the set of all legal content types of this partitioner.
 ITypedRegion getPartition(int offset)
          Returns the partition containing the given offset of the connected document.
protected  String getTokenContentType(IToken token)
          Returns a content type encoded in the given token.
protected  void initialize()
          Performs the initial partitioning of the partitioner's document.
protected  boolean isSupportedContentType(String contentType)
          Returns whether the given type is one of the legal content types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPES_CATEGORY

public static final String CONTENT_TYPES_CATEGORY
The position category this partitioner uses to store the document's partitioning information

See Also:
Constant Field Values

fScanner

protected IPartitionTokenScanner fScanner
The partitioner's scanner


fLegalContentTypes

protected String[] fLegalContentTypes
The legal content types of this partitioner


fDocument

protected IDocument fDocument
The partitioner's document


fPreviousDocumentLength

protected int fPreviousDocumentLength
The document length before a document change occured


fPositionUpdater

protected DefaultPositionUpdater fPositionUpdater
The position updater used to for the default updating of partitions


fStartOffset

protected int fStartOffset
The offset at which the first changed partition starts


fEndOffset

protected int fEndOffset
The offset at which the last changed partition ends


fDeleteOffset

protected int fDeleteOffset
The offset at which a partition has been deleted

Constructor Detail

DefaultPartitioner

public DefaultPartitioner(IPartitionTokenScanner scanner,
                          String[] legalContentTypes)
Creates a new partitioner that uses the given scanner and may return partitions of the given legal content types.

Parameters:
scanner - the scanner this partitioner is supposed to use
legalContentTypes - the legal content types of this partitioner
Method Detail

connect

public void connect(IDocument document)
Description copied from interface: IDocumentPartitioner
Connects the partitioner to a document. Connect indicates the begin of the usage of the receiver as partitioner of the given document. Thus, resources the partitioner needs to be operational for this document should be allocated.

The caller of this method must ensure that this partitioner is also set as the document's document partitioner.

Specified by:
connect in interface IDocumentPartitioner
Parameters:
document - the document to be connected to

initialize

protected void initialize()
Performs the initial partitioning of the partitioner's document.


disconnect

public void disconnect()
Description copied from interface: IDocumentPartitioner
Disconnects the partitioner from the document it is connected to. Disconnect indicates the end of the usage of the receiver as partitioner of the connected document. Thus, resources the partitioner needed to be operation for its connected document should be deallocated.

The caller of this method should also must ensure that this partitioner is no longer the document's partitioner.

Specified by:
disconnect in interface IDocumentPartitioner

documentAboutToBeChanged

public void documentAboutToBeChanged(DocumentEvent e)
Description copied from interface: IDocumentPartitioner
Informs about a forthcoming document change. Will be called by the connected document and is not intended to be used by clients other than the connected document.

Specified by:
documentAboutToBeChanged in interface IDocumentPartitioner
Parameters:
e - the event describing the forthcoming change

documentChanged

public boolean documentChanged(DocumentEvent e)
Description copied from interface: IDocumentPartitioner
The document has been changed. The partitioner updates the document's partitioning and returns whether the structure of the document partitioning has been changed, i.e. whether partitions have been added or removed. Will be called by the connected document and is not intended to be used by clients other than the connected document.

Specified by:
documentChanged in interface IDocumentPartitioner
Parameters:
e - the event describing the document change
Returns:
true if partitioning changed

documentChanged2

public IRegion documentChanged2(DocumentEvent e)
Description copied from interface: IDocumentPartitionerExtension
The document has been changed. The partitioner updates the document's partitioning and returns in which region the partition types have changed. This method always returns the surrounding region. Will be called by the connected document and is not intended to be used by clients other than the connected document.

Specified by:
documentChanged2 in interface IDocumentPartitionerExtension
Parameters:
e - the event describing the document change
Returns:
the region of the document in which the partition type changed

findClosestPosition

protected TypedPosition findClosestPosition(int offset)
Returns the position in the partitoner's position category which is close to the given offset. This is, the position has either an offset which is the same as the given offset or an offset which is smaller than the given offset. This method profits from the knowledge that a partitioning is a ordered set of disjoint position.

Parameters:
offset - the offset for which to search the closest position
Returns:
the closest position in the partitioner's category

getContentType

public String getContentType(int offset)
Description copied from interface: IDocumentPartitioner
Returns the content type of the partition containing the given offset in the connected document. There must be a document connected to this partitioner.

Specified by:
getContentType in interface IDocumentPartitioner
Parameters:
offset - the offset in the connected document
Returns:
the content type of the offset's partition

getPartition

public ITypedRegion getPartition(int offset)
Description copied from interface: IDocumentPartitioner
Returns the partition containing the given offset of the connected document. There must be a document connected to this partitioner.

Specified by:
getPartition in interface IDocumentPartitioner
Parameters:
offset - the offset for which to determine the partition
Returns:
the partition containing the offset

computePartitioning

public ITypedRegion[] computePartitioning(int offset,
                                          int length)
Description copied from interface: IDocumentPartitioner
Returns the partitioning of the given range of the connected document. There must be a document connected to this partitioner.

Specified by:
computePartitioning in interface IDocumentPartitioner
Parameters:
offset - the offset of the range of interest
length - the length of the range of interest
Returns:
the partitioning of the range

getLegalContentTypes

public String[] getLegalContentTypes()
Description copied from interface: IDocumentPartitioner
Returns the set of all legal content types of this partitioner. I.e. any result delivered by this partitioner may not contain a content type which would not be included in this method's result.

Specified by:
getLegalContentTypes in interface IDocumentPartitioner
Returns:
the set of legal content types

isSupportedContentType

protected boolean isSupportedContentType(String contentType)
Returns whether the given type is one of the legal content types.

Parameters:
contentType - the content type to check
Returns:
true if the content type is a legal content type

getTokenContentType

protected String getTokenContentType(IToken token)
Returns a content type encoded in the given token. If the token's data is not null and a string it is assumed that it is the encoded content type.

Parameters:
token - the token whose content type is to be determined
Returns:
the token's content type

Eclipse Platform
2.0

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