Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EMF Compare/How To Open Compare Dialog With Comparison

< EMF Compare
Revision as of 04:34, 2 October 2012 by Unnamed Poltroon (Talk) (New page: This is only valid for the 2.0 release stream. In this page you will learn how to open a dialog displaying the result of a comparison. == Preparing the input == The first thing to do is...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is only valid for the 2.0 release stream.

In this page you will learn how to open a dialog displaying the result of a comparison.

Preparing the input

The first thing to do is to implement your own class of CompareEditorInput.

You must override two methods :

  • prepareInput(IProgressMonitor), that must return the Comparison object (result from the EMFCompare computation) adapted as an IDiffElement
  • createDiffViewer(Composite), that must return a new instance of EMFCompareStructureMergeViewer.

Here is a sample implementation that you can reuse as is :

/**
 * A custom implementation of the editor input.
 */
class CustomCompareEditorInput extends CompareEditorInput {

	private final Comparison comparison;

	private final AdapterFactory adapterFactory;

	/**
	 * Constructor.
	 * 
	 * @param configuration
	 *            the compare configuration
	 * @param comparison
	 *            the comparison
	 */
	public CustomCompareEditorInput(CompareConfiguration configuration) {
		super(configuration);
		this.comparison = (Comparison)configuration.getProperty(EMFCompareConstants.COMPARE_RESULT);
		this.adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); 
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.compare.CompareEditorInput#prepareInput(org.eclipse.core.runtime.IProgressMonitor)
	 */
	@Override
	protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException,
			InterruptedException {
		return (IDiffElement)adapterFactory.adapt(this.selection, IDiffElement.class);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.compare.CompareEditorInput#createDiffViewer(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public Viewer createDiffViewer(Composite parent) {
		return new EMFCompareStructureMergeViewer(parent, getCompareConfiguration());
	};
}

Back to the top