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/API OpenEditorWithSelection

THIS PAGE IS ARCHIVED. IT IS PROBABLY OUTDATED AND WILL NOT BE UPDATED

The API enables to compute differences between models and open an EMF Compare editor from the result of the comparison and to select the differences about given model object identifiers. It is the service class: CompareServices which contains this API:

  • void openEditor(final CompareEditorInput input, List<String> objectIds)

The input may be any input, instance of CompareEditorInput.

Here is an example to call this API in order to compare local models (ecoretools diagrams):

final IWorkbenchPage workBenchPage = TeamUIPlugin.getActivePage();

final IFile right = ResourcesPlugin.getWorkspace().getRoot().getFile("/org.eclipse.emf.compare.diagram.ui.tests/TC01_Added_nodes/TC2.ecorediag");
final IFile left = ResourcesPlugin.getWorkspace().getRoot().getFile("/org.eclipse.emf.compare.diagram.ui.tests/TC01_Added_nodes/TC1.ecorediag");

final ITypedElement iLeft = SaveablesCompareEditorInput.createFileElement(left);
final ITypedElement iRight = SaveablesCompareEditorInput.createFileElement(right);

final CompareEditorInput input = new SaveablesCompareEditorInput(null, iLeft, iRight, workBenchPage);

final List<String> uris = new ArrayList<String>();
for (String id : new String[] {"_sEwyAKfOEeC-6Yy0go4yvQ", "//EClass0" }) {
 uris.add(id);
}

CompareServices.openEditor(input, uris);

An other example to call this API in order to compare two model versions from the history of a GIT repository:

final IFile model = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/org.eclipse.emf.compare.diff/model/diff.ecore"));

final String commitName1 = "322349c45b00f6fe2bc9675772dfc51d37d5741e";
final String commitName2 = "48df5626b7c4e5cb8d584b21865a548ef9ae437e";

final CompareEditorInput input = new GitCompareEditorInput(commitName1, commitName2, model);

final List<String> uris = new ArrayList<String>();
for (String id : new String[] {"//DiffElement/requires"}) {
 uris.add(id);
}

CompareServices.openEditor(input, uris);

If there is an available opened EMF Compare editor, the selection of the differences can be updated afterwards. For that, it exists an other API:

  • void setSelection(List<String> objectIds, IEditorPart editor)

Back to the top