public class ContentFormatter extends Object implements IContentFormatter
IContentFormatter
.
The formatter supports two operation modes: partition aware and
partition unaware. In the partition aware mode, the formatter determines the partitioning of the document region to be formatted. For each partition it determines all document positions which are affected when text changes are applied to the partition. Those which overlap with the partition are remembered as character positions. These character positions are passed over to the formatting strategy registered for the partition's content type. The formatting strategy returns a string containing the formatted document partition as well as the adapted character positions. The formatted partition replaces the old content of the partition. The remembered document positions are updated with the adapted character positions. In addition, all other document positions are accordingly adapted to the formatting changes.
In the partition unaware mode, the document's partitioning is ignored
and the document is considered consisting of only one partition of
the content type IDocument.DEFAULT_CONTENT_TYPE
. The
formatting process is similar to the partition aware mode, with the
exception of having only one partition.
Usually, clients instantiate this class and configure it before using it.
IContentFormatter
,
IDocument
,
ITypedRegion
,
Position
Constructor and Description |
---|
ContentFormatter()
Creates a new content formatter.
|
Modifier and Type | Method and Description |
---|---|
void |
enablePartitionAwareFormatting(boolean enable)
Sets the formatter's operation mode.
|
void |
format(IDocument document,
IRegion region)
Formats the given region of the specified document.The formatter may safely
assume that it is the only subject that modifies the document at this point in time.
|
IFormattingStrategy |
getFormattingStrategy(String contentType)
Returns the formatting strategy registered for the given content type.
|
protected boolean |
positionAboutToBeAdded(IDocument document,
String category,
Position position)
The given position is about to be added to the given position category of the given document.
|
void |
setDocumentPartitioning(String partitioning)
Sets the document partitioning to be used by this formatter.
|
void |
setFormattingStrategy(IFormattingStrategy strategy,
String contentType)
Registers a strategy for a particular content type.
|
void |
setPartitionManagingPositionCategories(String[] categories)
Deprecated.
incompatible with an open set of document partitionings. The provided information is only used
if this formatter can not compute the partition managing position categories.
|
protected void |
updateAffectedPositions(IDocument document,
int[] positions,
int offset)
Updates all the overlapping positions.
|
public ContentFormatter()
public void setFormattingStrategy(IFormattingStrategy strategy, String contentType)
null
the given strategy is registered for
all content types as is called only once per formatting session.strategy
- the formatting strategy to register, or null
to remove an existing onecontentType
- the content type under which to registerpublic void setPartitionManagingPositionCategories(String[] categories)
categories
- the categories to be ignoredpublic void setDocumentPartitioning(String partitioning)
partitioning
- the document partitioningpublic void enablePartitionAwareFormatting(boolean enable)
enable
- indicates whether the formatting process should be partition warepublic IFormattingStrategy getFormattingStrategy(String contentType)
IContentFormatter
getFormattingStrategy
in interface IContentFormatter
contentType
- the content type for which to look up the formatting strategynull
if there is no such strategypublic void format(IDocument document, IRegion region)
IContentFormatter
format
in interface IContentFormatter
document
- the document to be formattedregion
- the region within the document to be formattedprotected void updateAffectedPositions(IDocument document, int[] positions, int offset)
document
- the document to has been formattedpositions
- the adapted character positions to be used to update the document positionsoffset
- the offset of the document region that has been formattedprotected boolean positionAboutToBeAdded(IDocument document, String category, Position position)
This default implementation return true
.
document
- the documentcategory
- the position categoryposition
- the position that will be addedtrue
if the position can be added, false
if it should be ignored
Copyright (c) 2000, 2013 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.