Compare Example - Structural Compare for Key/Value Pairs

Introduction

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
    lastname=Doe
    firstname=John
    city=Chicago
    state=IL
    
  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 org.eclipse.compare.examples.structurecreator:

 

Copyright IBM Corporation and others 2000, 2003. All Rights Reserved.