Compare Example - Structural Compare for Key/Value Pairs
This example demonstrates how to support structural compare for
files consisting of key/value pairs. It shows how to implement and register a
custom structure creator that parses key/value pairs into a tree structure
that is used as the input to the structural compare framework provided by the
Compare plugin. In addition, it registers a standard text viewer for the individual
This example is only for demonstration purposes. Structural compare support
for Java property files (another key/value format) is provided by the Eclipse Java Tooling.
Running the example
- Create a project (not necessarily a Java project)
- Create a key/value pair file f1.kv
- Open Window > Preferences > Workbench > File Association
and associate the default text editor with the file extension "kv"
- Open f1.kv with the editor and enter this contents
- Make a copy of this file and rename it f2.kv
- Open f2.kv and change the firstname "John" to "Mary"
- Add another key/value pair "country=US" to f2.kv
- Select both files f1.kv and f2.kv
- From the context menu select Compare With > Each Other
- A new compare editor opens that shows the structural differences of both files in its
top pane. Selecting one of the properties "firstname" or "country" feeds the text of the
corresponding key/value pair into the standard text compare viewer in the bottom pane.
Code organization of the example
The example code is organized in a single package org.eclipse.compare.examples.structurecreator:
is the structure creator that parses the contents of a stream into a tree of
is a factory for TextMergeViewers. It is registered for the type "kvtxt" which is the
type of an individual key/value pair.
provides utility methods for NLS support and for reading an InputStream as a String.