Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.port80.eclipse.editors.util
Class RegionContentFormatter  view RegionContentFormatter download RegionContentFormatter.java

java.lang.Object
  extended bycom.port80.eclipse.editors.util.RegionContentFormatter
All Implemented Interfaces:
org.eclipse.jface.text.formatter.IContentFormatter

public class RegionContentFormatter
extends java.lang.Object
implements org.eclipse.jface.text.formatter.IContentFormatter

Standard implementation of IContentFormatter. The formatter supports two operation modi: 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 postions 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.


Nested Class Summary
(package private)  class RegionContentFormatter.NonDeletingPositionUpdater
          The position updater used to adapt all to update the remembered partitions.
(package private) static class RegionContentFormatter.PositionReference
          Defines a reference to either the offset or the end offset of a particular position.
(package private)  class RegionContentFormatter.RemoveAffectedPositions
          The position updater which runs as first updater on the document's positions.
(package private)  class RegionContentFormatter.UpdateAffectedPositions
          The position updater which runs as last updater on the document's positions.
 
Field Summary
private  boolean fIsPartitionAware
          The indicator of whether the formatter operates in partition aware mode or not
private  java.util.List fOverlappingPositionReferences
          The list of references to offset and end offset of all overlapping positions
private  org.eclipse.jface.text.IPositionUpdater fPartitioningUpdater
          Position updater used for partitioning positions
private  java.lang.String[] fPartitionManagingCategories
          The partition information managing document position categories
private  java.util.Map fStrategies
          The map of IFormattingStrategy objects
private static java.lang.String PARTITIONING
          Internal position category used for the formatter partitioning
 
Constructor Summary
RegionContentFormatter()
          Creates a new content formatter.
 
Method Summary
private  void addPartitioningUpdater(org.eclipse.jface.text.IDocument document)
          Installs those updaters which the formatter needs to keep track of the partitions.
private  void determinePositionsToUpdate(org.eclipse.jface.text.IDocument document, int offset, int length)
          Determines all embracing, overlapping, and follow up positions for the given region of the document.
 void enablePartitionAwareFormatting(boolean enable)
          Sets the formatter's operation mode.
private  void format(org.eclipse.jface.text.IDocument document, org.eclipse.jface.text.formatter.IFormattingStrategy strategy, org.eclipse.jface.text.TypedPosition region)
          Formats the given region of the document using the specified formatting strategy.
 void format(org.eclipse.jface.text.IDocument document, org.eclipse.jface.text.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.
private  void format(org.eclipse.jface.text.IDocument document, org.eclipse.jface.text.TypedPosition[] ranges)
          Formats one partition after the other using the formatter strategy registered for the partition's content type.
private  void formatPartitions(org.eclipse.jface.text.IDocument document, org.eclipse.jface.text.IRegion region)
          Determines the partitioning of the given region of the document.
private  void formatRegion(org.eclipse.jface.text.IDocument document, org.eclipse.jface.text.IRegion region)
          Informs for the given region about the start, the process, and the termination of the formatting session.
private  int[] getAffectedPositions(org.eclipse.jface.text.IDocument document, int offset, int length)
          Returns all offset and the end offset of all positions overlapping with the specified document range.
 org.eclipse.jface.text.formatter.IFormattingStrategy getFormattingStrategy(java.lang.String contentType)
          Returns the formatting strategy registered for the given content type.
private  java.lang.String getIndentation(org.eclipse.jface.text.IDocument document, int offset)
          Returns the indentation of the line of the given offset.
private  org.eclipse.jface.text.TypedPosition[] getPartitioning(org.eclipse.jface.text.IDocument document, org.eclipse.jface.text.IRegion region)
          Returns the partitioning of the given region of the specified document.
private  boolean ignoreCategory(java.lang.String category)
          Determines whether the given document position category should be ignored by this formatter's position updating.
private  boolean isLineStart(org.eclipse.jface.text.IDocument document, int offset)
          Determines whether the offset is the beginning of a line in the given document.
(package private)  void removeAffectedPositions(org.eclipse.jface.text.IDocument document)
          Removes the affected positions from their categories to avoid that they are invalidly updated.
private  void removePartitioningUpdater(org.eclipse.jface.text.IDocument document)
          Removes the formatter's internal position updater and category.
 void setFormattingStrategy(org.eclipse.jface.text.formatter.IFormattingStrategy strategy, java.lang.String contentType)
          Registers a strategy for a particular content type.
 void setPartitionManagingPositionCategories(java.lang.String[] categories)
          Informs this content formatter about the names of those position categories which are used to manage the document's partitioning information and thus should be ignored when this formatter updates positions.
private  void start(org.eclipse.jface.text.TypedPosition[] regions, java.lang.String indentation)
          Fires formatterStarts to all formatter strategies which will be involved in the forthcoming formatting process.
private  void stop(org.eclipse.jface.text.TypedPosition[] regions)
          Fires formatterStops to all formatter strategies which were involved in the formatting process which is about to terminate.
(package private)  void updateAffectedPositions(org.eclipse.jface.text.IDocument document, int[] positions, int offset)
          Updates all the overlapping positions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARTITIONING

private static final java.lang.String PARTITIONING
Internal position category used for the formatter partitioning

See Also:
Constant Field Values

fStrategies

private java.util.Map fStrategies
The map of IFormattingStrategy objects


fIsPartitionAware

private boolean fIsPartitionAware
The indicator of whether the formatter operates in partition aware mode or not


fPartitionManagingCategories

private java.lang.String[] fPartitionManagingCategories
The partition information managing document position categories


fOverlappingPositionReferences

private java.util.List fOverlappingPositionReferences
The list of references to offset and end offset of all overlapping positions


fPartitioningUpdater

private org.eclipse.jface.text.IPositionUpdater fPartitioningUpdater
Position updater used for partitioning positions

Constructor Detail

RegionContentFormatter

public RegionContentFormatter()
Creates a new content formatter. The content formatter operates by default in the partition-aware mode. There are no preconfigured formatting strategies.

Method Detail

setFormattingStrategy

public void setFormattingStrategy(org.eclipse.jface.text.formatter.IFormattingStrategy strategy,
                                  java.lang.String contentType)
Registers a strategy for a particular content type. If there is already a strategy registered for this type, the new strategy is registered instead of the old one. If the given content type is null the given strategy is registered for all content types as is called only once per formatting session.


setPartitionManagingPositionCategories

public void setPartitionManagingPositionCategories(java.lang.String[] categories)
Informs this content formatter about the names of those position categories which are used to manage the document's partitioning information and thus should be ignored when this formatter updates positions.


enablePartitionAwareFormatting

public void enablePartitionAwareFormatting(boolean enable)
Sets the formatter's operation mode.


getFormattingStrategy

public org.eclipse.jface.text.formatter.IFormattingStrategy getFormattingStrategy(java.lang.String contentType)
Description copied from interface: org.eclipse.jface.text.formatter.IContentFormatter
Returns the formatting strategy registered for the given content type.

Specified by:
getFormattingStrategy in interface org.eclipse.jface.text.formatter.IContentFormatter

format

public void format(org.eclipse.jface.text.IDocument document,
                   org.eclipse.jface.text.IRegion region)
Description copied from interface: org.eclipse.jface.text.formatter.IContentFormatter
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.

Specified by:
format in interface org.eclipse.jface.text.formatter.IContentFormatter

removeAffectedPositions

void removeAffectedPositions(org.eclipse.jface.text.IDocument document)
Removes the affected positions from their categories to avoid that they are invalidly updated.


updateAffectedPositions

void updateAffectedPositions(org.eclipse.jface.text.IDocument document,
                             int[] positions,
                             int offset)
Updates all the overlapping positions. Note, all other positions are automatically updated by their document position updaters.


formatPartitions

private void formatPartitions(org.eclipse.jface.text.IDocument document,
                              org.eclipse.jface.text.IRegion region)
Determines the partitioning of the given region of the document. Informs for each partition about the start, the process, and the termination of the formatting session.


formatRegion

private void formatRegion(org.eclipse.jface.text.IDocument document,
                          org.eclipse.jface.text.IRegion region)
Informs for the given region about the start, the process, and the termination of the formatting session.


getPartitioning

private org.eclipse.jface.text.TypedPosition[] getPartitioning(org.eclipse.jface.text.IDocument document,
                                                               org.eclipse.jface.text.IRegion region)
                                                        throws org.eclipse.jface.text.BadLocationException
Returns the partitioning of the given region of the specified document. As one partition after the other will be formatted and formatting will probably change the length of the formatted partition, it must be kept track of the modifications in order to submit the correct partition to all formatting strategies. For this, all partitions are remembered as positions in a dedicated position category. (As formatting stratgies might rely on each other, calling them in reversed order is not an option.)


start

private void start(org.eclipse.jface.text.TypedPosition[] regions,
                   java.lang.String indentation)
Fires formatterStarts to all formatter strategies which will be involved in the forthcoming formatting process.


format

private void format(org.eclipse.jface.text.IDocument document,
                    org.eclipse.jface.text.TypedPosition[] ranges)
Formats one partition after the other using the formatter strategy registered for the partition's content type.


format

private void format(org.eclipse.jface.text.IDocument document,
                    org.eclipse.jface.text.formatter.IFormattingStrategy strategy,
                    org.eclipse.jface.text.TypedPosition region)
Formats the given region of the document using the specified formatting strategy. In order to maintain positions correctly, first all affected positions determined, after all document listeners have been informed about the upcoming change, the affected positions are removed to avoid that they are regularily updated. After all position updaters have run, the affected positions are updated with the formatter's information and added back to their categories, right before the first document listener is informed about that a change happend.


stop

private void stop(org.eclipse.jface.text.TypedPosition[] regions)
Fires formatterStops to all formatter strategies which were involved in the formatting process which is about to terminate.


addPartitioningUpdater

private void addPartitioningUpdater(org.eclipse.jface.text.IDocument document)
Installs those updaters which the formatter needs to keep track of the partitions.


removePartitioningUpdater

private void removePartitioningUpdater(org.eclipse.jface.text.IDocument document)
Removes the formatter's internal position updater and category.


ignoreCategory

private boolean ignoreCategory(java.lang.String category)
Determines whether the given document position category should be ignored by this formatter's position updating.


determinePositionsToUpdate

private void determinePositionsToUpdate(org.eclipse.jface.text.IDocument document,
                                        int offset,
                                        int length)
Determines all embracing, overlapping, and follow up positions for the given region of the document.


getAffectedPositions

private int[] getAffectedPositions(org.eclipse.jface.text.IDocument document,
                                   int offset,
                                   int length)
Returns all offset and the end offset of all positions overlapping with the specified document range.


getIndentation

private java.lang.String getIndentation(org.eclipse.jface.text.IDocument document,
                                        int offset)
Returns the indentation of the line of the given offset.


isLineStart

private boolean isLineStart(org.eclipse.jface.text.IDocument document,
                            int offset)
                     throws org.eclipse.jface.text.BadLocationException
Determines whether the offset is the beginning of a line in the given document.