blob: a7c76b54abcac5fb60fe5ecebba59ddc09f7babb [file] [log] [blame]
<?xml version='1.0' encoding='utf-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>How to open compare dialog</title>
<style type="text/css">
.tip {border: 1px solid #090;background-color: #dfd;margin: 20px;padding: 0px 6px 0px 6px;}
.note {border: 1px solid #F0C000;background-color: #FFFFCE;margin: 20px;padding: 0px 6px 0px 6px;}
.info {border: 1px solid #3c78b5;background-color: #D8E4F1;margin: 20px;padding: 0px 6px 0px 6px;}
.warning {border: 1px solid #c00;background-color: #fcc;margin: 20px;padding: 0px 6px 0px 6px;}
.panel {border: 1px solid #ccc;background-color: #FFFFCE;margin: 10px;padding: 0px 6px 0px 6px;}
</style>
<link type="text/css" rel="stylesheet" href="../resources/bootstrap.css"/>
<link type="text/css" rel="stylesheet" href="../resources/custom.css"/>
</head>
<body>
<h1 id="EMF_Compare_.E2.80.94__How_To_Open_Compare_Dialog">EMF Compare — How To Open Compare Dialog</h1>
<p>Version 3.1.0.201506080946</p>
<div class="toc">
<h3 class="toc-title">Table of Contents</h3>
<ol style="list-style: none">
<li>
<a href="#Preparing_the_input">Preparing the input</a>
</li>
<li>
<a href="#Preparing_the_configuration">Preparing the configuration</a>
<ol style="list-style: none">
<li>
<a href="#ComparisonEditorInput">ComparisonEditorInput</a>
</li>
<li>
<a href="#ComparisonScopeEditorInput">ComparisonScopeEditorInput</a>
</li>
</ol>
</li>
<li>
<a href="#Opening_the_compare_UI">Opening the compare UI</a>
</li>
<li>
<a href="#End-to-end_examples">End-to-end examples</a>
<ol style="list-style: none">
<li>
<a href="#With_pre-computed_comparison">With pre-computed comparison</a>
</li>
<li>
<a href="#With_a_comparison_scope">With a comparison scope</a>
</li>
</ol>
</li>
</ol>
</div>
<p>This is only valid since release 2.1M4. </p>
<p>In this page you will learn how to open a dialog displaying the result of a comparison. </p>
<h2 id="Preparing_the_input">Preparing the input</h2>
<p>The first thing to do is to choose an EMF Compare sub-implementation of the class of
<a href="http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fcompare%2FCompareEditorInput.html">CompareEditorInput</a>.
</p>
<p>Two implementations are provided: </p>
<ul>
<li>
<i>ComparisonEditorInput</i>, that should be use when you want to display a pre-computed Comparison (the results of EMFCompare).
</li>
<li>
<i>ComparisonScopeEditorInput</i>, that should be use when you want to open the compare editor or dialog and to let it perform the comparison.
</li>
</ul>
<p>Both are available from the
<b>org.eclipse.emf.compare.ide.ui</b> plug-in, in the package
<b>org.eclipse.emf.compare.ide.ui.internal.editor</b>. This is still provisional API so we may break it any time.
</p>
<h2 id="Preparing_the_configuration">Preparing the configuration</h2>
<p>When instantiating an EMF Compare specific implementation of CompareEditorInput, you have to give it at least three paramaters:</p>
<ul>
<li>a
<a href="http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fcompare%2FCompareConfiguration.html">CompareConfiguration</a>. This is a standard CompareConfiguration (no specific implementation needed) so you just instantiated it like this:
</li>
</ul>
<pre class="source-java">CompareConfiguration configuration = new CompareConfiguration();
</pre>
<ul>
<li>an EMFCompareEditingDomain. It is not an implementation of
<a href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.5.0/org/eclipse/emf/edit/domain/EditingDomain.html">EditingDomain</a> from EMF. It shares similar concepts (it has a command stack, it can create some commands) but is much simpler. You can create it through the factory method:
</li>
</ul>
<pre class="source-java">// ancestor may be null
ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(left, right, ancestor);
</pre>
<p>You can even give your own command(s) stack(s) if you need to know about executed merge commands. </p>
<ul>
<li>An
<a href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.5.0/org/eclipse/emf/common/notify/AdapterFactory.html">AdapterFactory</a> used by the framework to adapt EObjects to be nicely displayed. Most of the time, a
<a href="http://download.eclipse.org/modeling/emf/emf/javadoc/2.5.0/org/eclipse/emf/edit/provider/ComposedAdapterFactory.html">ComposedAdapterFactory</a> with the global registry is sufficient as created in the example below:
</li>
</ul>
<pre class="source-java">AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
</pre>
<p>Depending on the choosen sub-implementation of CompareEditorInput, you may need to provide additional parameters.</p>
<h3 id="ComparisonEditorInput">ComparisonEditorInput</h3>
<p>You must provide a Comparison object, the result of the comparison computation of EMFCompare.</p>
<pre class="source-java">EMFCompare comparator = EMFCompare.builder().build();
Comparison comparison = comparator.compare(EMFCompare.createDefaultScope(left, right, ancestor));
</pre>
<h3 id="ComparisonScopeEditorInput">ComparisonScopeEditorInput</h3>
<p>You must provide the comparator (instance of EMFCompare) and the scope of the comparison.</p>
<pre class="source-java">EMFCompare comparator = EMFCompare.builder().build();
IComparisonScope scope = EMFCompare.createDefaultScope(left, right, ancestor);
</pre>
<h2 id="Opening_the_compare_UI">Opening the compare UI</h2>
<p>Then, you can call the black magic method from Eclipse Compare framework. You have two choices. You may either open the compare UI wihtin a modal dialog or within an editor. Just call one of the two following methods: </p>
<ul>
<li>
<a href="http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fcompare%2FCompareUI.html&amp;anchor=openCompareEditorOnPage(org.eclipse.compare.CompareEditorInput,%20org.eclipse.ui.IWorkbenchPage)">CompareUI.openCompareEditorOnPage(CompareEditorInput, IWorkbenchPage)</a>, to open an editor.
</li>
<li>
<a href="http://help.eclipse.org/juno/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/compare/CompareUI.html#openCompareDialog(org.eclipse.compare.CompareEditorInput)">CompareUI.openCompareDialog(CompareEditorInput)</a>, to open a modal dialog.
</li>
</ul>
<h2 id="End-to-end_examples">End-to-end examples</h2>
<h3 id="With_pre-computed_comparison">With pre-computed comparison</h3>
<pre class="source-java">public void compare(Notifier left, Notifier right, Notifier ancestor) {
EMFCompare comparator = EMFCompare.builder().build();
Comparison comparison = comparator.compare(EMFCompare.createDefaultScope(left, right, ancestor));
ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(left, right, ancestor);
AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
CompareEditorInput input = new ComparisonEditorInput(new CompareConfiguration(), comparison, editingDomain, adapterFactory);
CompareUI.openCompareDialog(input); // or CompareUI.openCompareEditor(input);
}
</pre>
<h3 id="With_a_comparison_scope">With a comparison scope</h3>
<pre class="source-java">public void compare(Notifier left, Notifier right, Notifier ancestor) {
EMFCompare comparator = EMFCompare.builder().build();
IComparisonScope scope = EMFCompare.createDefaultScope(left, right, ancestor));
ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(left, right, ancestor);
AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
CompareEditorInput input = new ComparisonScopeEditorInput(new CompareConfiguration(),
editingDomain, adapterFactory, comparator, scope);
CompareUI.openCompareDialog(input); // or CompareUI.openCompareEditor(input);
}
</pre>
<p>Part of
<a href="../index.html">EMF Compare Documentation</a>
</p>
<p>Version 3.1.0.201506080946</p>
</body>
</html>