Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Eclipse Plug-in Developer Guide
Previous Page Home Next Page

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 key/value pairs.

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

  1. Create a project (not necessarily a Java project)
  2. Create a key/value pair file f1.kv
  3. Open Window > Preferences > Workbench > File Association and associate the default text editor with the file extension "kv"
  4. Open f1.kv with the editor and enter this contents
  5. Make a copy of this file and rename it f2.kv
  6. Open f2.kv and change the firstname "John" to "Mary"
  7. Add another key/value pair "country=US" to f2.kv
  8. Select both files f1.kv and f2.kv
  9. From the context menu select Compare With > Each Other
  10. 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
  • KeyValuePairStructureCreator
    is the structure creator that parses the contents of a stream into a tree of IStructureComparators.
  • TextMergeViewerCreator
    is a factory for TextMergeViewers. It is registered for the type "kvtxt" which is the type of an individual key/value pair.
  • Util
    provides utility methods for NLS support and for reading an InputStream as a String.

  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire