Jump to: navigation, search

Difference between revisions of "Compare Word Documents"

(Compare Framework Extension Points)
m
Line 43: Line 43:
  
 
We will now look at how to integrate a compare merge viewer into Eclipse. First we'll discuss the extension points we need to extend and then we'll discuss the compare viewer implementation.
 
We will now look at how to integrate a compare merge viewer into Eclipse. First we'll discuss the extension points we need to extend and then we'll discuss the compare viewer implementation.
 
  
 
=== Compare Framework Extension Points ===
 
=== Compare Framework Extension Points ===

Revision as of 11:57, 12 June 2008

One this page, we describe support for comparing Word documents using Eclipse. The purpose of this page is two-fold. First, we will described the goals and features of the Word Document compare support. After that, we will dig a bit into how we integrated the Word comparison with the Eclipse Compare framework

Obtaining the Word Comparison Plug-in

The current plan is to ship this bundle with Eclipse 3.5. However, the bundle is compatible with 3.3. You can download the built bundle from here and put it in the plugins directory of you Eclipse install. The source code will be added to CVS once HEAD is opened in for 3.5 development.

Comparing Word Documents

In this section, we describe what our goals for the Word document merge viewer were. We then described the features of the viewer and show some screen shots of what the result looks like.

Goals and Features

When we started implementing the Word merge viewer, we had the following goals in mind:

  • Compare changes using the revision support that is provided by the Word application
  • Offer the user flexibility in whether they want to edit in-place (i.e. embedded in Eclipse) or in a separate Word Application window
  • Provide a means to save changes back to the Eclipse workspace.

To that end, we implemented a merge viewer with the following features:

  • The merge viewer is associated with the "doc" file extension and a "Word Document" content type. The use of a content type will allow the user to associate other file extensions with the merge viewer.
  • The merge viewer opens the Word based comparison in-place by default but there is a toggle in the toolbar that allows the document to be opened in a separate window.
  • The word application is opened on a temporary file containing the results of the comparison of the two files or file states being compared. Saving the compare editor (or clicking on the Save button in the compare viewer toolbar) will save any edits that have been made to the temporary file and then copy the contents of the temporary file into the Eclipse workspace files

What it Looks Like

The following screen shot shows the word comparison in-place. You can edit the text and save in the compare editor which will save the result to the 'important.doc' file that is being compared.

Wordinplace.png

This next screen shot shows the compare viewer in "external" mode where the word document is open in a separate window.

Wordseparate.png

We don't have a screen shot of the window since it is simply a full blown word application. Notice that the "In-place" toggle button in the above screen shot has been changed from the previous screen shot. Also notice that the editor is now dirty and the save action in the toolbar is enabled. The editor is dirty because we have made changes using the Word application. Even thought the document is shown in a separate window, we are still keeping a link to the document so we know when it has been modified. Saving in the compare editor will still work (as indicated by the text that appears in the compare viewer).

Caveats

A limitation of the viewer is that it doesn't offer the ability to save if neither or both sides of the comparison are editable. For the "both editable" case, we didn't feel we could adequately present the save options in the UI. The workaround is to open the comparison in a separate window and you can then save any changes to any location on disk.

Implementing a Compare Merge Viewer

We will now look at how to integrate a compare merge viewer into Eclipse. First we'll discuss the extension points we need to extend and then we'll discuss the compare viewer implementation.

Compare Framework Extension Points

The first extension point we are going to extend is not in the Compare framework. The Compare framework allows content merge viewers to be associated with either a file extension or a content type. The advantage of using a content type is that the user can associate other file extensions with the content type manually. Here is what our Word Document content type definition looks like:

    <extension point="org.eclipse.core.contenttype.contentTypes">
      <content-type
            name="Word Document"
            id="org.eclipse.compare.wordDoc"
            file-extensions="doc">
      </content-type>
   </extension>

Once we have the content type, we can then define our content merge viewer using the org.eclipse.compare.contentMergeViewers extension point and then associate that viewer with our content type. The XML for this looks like:

   <extension point="org.eclipse.compare.contentMergeViewers">
      <viewer
            class="org.eclipse.compare.internal.win32.WordViewerCreator"
            extensions="doc"
            id="org.eclipse.compare.wordMergeViewer">
      </viewer>
      <contentTypeBinding
            contentMergeViewerId="org.eclipse.compare.wordMergeViewer"
            contentTypeId="org.eclipse.compare.wordDoc">
      </contentTypeBinding>
   </extension>

The class that is registered with the extension point is a factory for creating our content merge viewer. The code for our class is fairly simple:

public class WordViewerCreator implements IViewerCreator {
	public Viewer createViewer(Composite parent, CompareConfiguration config) {
		return new WordMergeViewer(parent, config);
	}
}

In the next section, we'll look at several aspects of the content merge viewer class.

Compare Merge Viewer Basics