Implementing a Structure Viewer

The compare plug-in provides substantial support for implementing your own content viewer:

Differencer 

Differencer is a differencing engine for hierarchically structured data. It takes two or three inputs and performs a two-way or three-way compare on them.

If the input elements to the differencing engine implement the IStructureComparator interface, the engine recursively applies itself to the children of the input element. Leaf elements must implement the IStreamContentAccessor interface so that the differencer can perform a byte wise comparison on their contents.

There are several good examples of differencers included in the platform implementation:

By default the differencing engine returns the result of the compare operation as a tree of DiffNode objects.  A DiffNode describes the changes among two or three inputs.  The type of result nodes can be changed by overriding a single method of the engine.

Difference Viewers

A tree of DiffNodes can be displayed in a DiffTreeViewer. The DiffTreeViewer requires that inner nodes of the tree implement the IDiffContainer interface and leaves implement the IDiffElement interface.

The typical steps to compare hierarchically structured data and to display the differences are as follows:

  1. map the input data into a tree of objects implementing both the IStructureComparator and IStreamContentAccessor interfaces,
  2. perform the compare operation by means of the Differencer, and
  3. feed the differencing result into the DiffTreeViewer.
The StructureDiffViewer is a specialized DiffTreeViewer that automates the three steps from above. It takes a single input object of type ICompareInput from which it retrieves the two or three input elements to compare. It uses an IStructureCreator to extract a tree containing IStructureComparator and IStreamContentAccessor objects from them. These trees are then compared with the differencing engine and the result is displayed in the tree viewer.

The ZipFileStructureCreator is an implementation of the IStructureCreator interface and makes the contents of a zip archive available as a hierarchical structure of IStructureComparators which can be easily compared by the differencing engine (Differencer). It is a good example for how to make structured files available to the hierarchical compare functionality of the compare plug-in.

Copyright IBM Corp. and others 2000,2002.