The compare plug-in provides substantial support for implementing your own content viewer:
ContentMergeViewer is an abstract compare and merge viewer with two side-by-side content areas and an optional content area for a common ancestor (for three-way compare). Because the implementation makes no assumptions about the content type it is a subclass responsibility to deal with a specific type. ImageMergeViewer in org.eclipse.compare.internal shows how to implement a simple merge viewer for images using a ContentMergeViewer. A ContentMergeViewer accesses its model by means of a content provider which must implement the IMergeViewerContentProvider interface.
TextMergeViewer is the standard concrete subclass of ContentMergeViewer for comparing and merging text content. A text merge viewer uses the RangeDifferencer to perform a textual, line-by-line comparison of two (or three) input documents. For text lines that differ, the TextMergeViewer uses an ITokenComparator to find the longest sequences of matching and non-matching tokens. The TextMergeViewer's default token compare works on characters separated by white space. If a different strategy is needed (for example, Java tokens in a Java-aware merge viewer), clients can create their own token comparators by implementing the ITokenComparator interface. TextMergeViewer works on whole documents and on sub ranges of documents. For partial documents, the viewer's input must be an IDocumentRange instead of an IDocument.
RangeDifferencer finds the longest sequences of matching and non-matching comparable entities. Its implementation is based on an objectified version of the algorithm described in: A File Comparison Program, by Webb Miller and Eugene W. Myers, Software Practice and Experience, Vol. 15, Nov. 1985. Clients must supply the input to the differencer as an implementation of the IRangeComparator interface. IRangeComparator breaks the input data into a sequence of entities and provides a method for comparing one entity with the entity in another IRangeComparator.
For example, to compare two text documents and find the longest common sequences of matching and non-matching lines, the implementation of IRangeComparator must break the document into lines and provide a method for testing whether two lines are considered equal. See org.eclipse.compare.internal.DocLineComparator for an example of how this can be done.
The differencer returns the differences among these sequences as an array of RangeDifference objects. Every single RangeDifference describes the kind of difference (no change, change, addition, deletion) and the corresponding ranges of the underlying comparable entities in the two or three inputs.