Skip to content

Commit

Permalink
Bug 355145 - Upgrade EMFCompareComparator to EMF Compare API version 3
Browse files Browse the repository at this point in the history
Also adapts target plattform, launch config (Example 1), and enablement
of the "Compare Revisions" context menu entry.

Change-Id: Ide31be7b1dd9de152873271713ca86a66d615e49
Signed-off-by: Philip Langer <planger@eclipsesource.com>
  • Loading branch information
planger committed May 28, 2015
1 parent 24cd202 commit f23024a
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ Bundle-SymbolicName: org.eclipse.emf.emfstore.client.ui.historybrowsercomparator
Bundle-Version: 1.5.0.qualifier
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: Eclipse Modeling Project
Require-Bundle: org.eclipse.emf.compare;bundle-version="[1.3.3,2.0.0)";visibility:=reexport,
org.eclipse.emf.compare.diff;bundle-version="[1.3.3,2.0.0)";visibility:=reexport,
org.eclipse.emf.compare.match;bundle-version="[1.3.3,2.0.0)";visibility:=reexport,
org.eclipse.emf.compare.ui;bundle-version="[1.3.3,2.0.0)";visibility:=reexport,
org.eclipse.emf.compare.diff.edit;bundle-version="[1.3.3,2.0.0)",
Require-Bundle: org.eclipse.emf.compare;bundle-version="[3.0.0,4.0.0)";visibility:=reexport,
org.eclipse.compare;bundle-version="[3.5.300,4.0.0)";visibility:=reexport,
org.eclipse.emf.emfstore.client;bundle-version="[1.5.0,2.0.0)",
org.eclipse.emf.emfstore.client.ui;bundle-version="[1.5.0,2.0.0)"
org.eclipse.emf.emfstore.client.ui;bundle-version="[1.5.0,2.0.0)",
org.eclipse.emf.compare.ide.ui;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
org.eclipse.emf.compare.ide;bundle-version="[3.1.0,4.0.0)";visibility:=reexport,
org.eclipse.emf.compare.edit;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
org.eclipse.swt;bundle-version="[3.0.0,4.0.0)",
org.eclipse.jface;bundle-version="[3.8.0,4.0.0)",
org.eclipse.ui.workbench;bundle-version="[3.0.0,4.0.0)"
Export-Package: org.eclipse.emf.emfstore.client.ui.historybrowsercompa
rator;version="1.5.0";x-internal:=true
Original file line number Diff line number Diff line change
@@ -1,28 +1,53 @@
/*******************************************************************************
* Copyright (c) 2013-2015 EclipseSource Muenchen GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* jsommerfeldt - initial API and implementation
* Johannes Faltermeier - JavaDoc
* Philip Langer - Upgrade to EMF Compare API version 3
******************************************************************************/
package org.eclipse.emf.emfstore.client.ui.historybrowsercomparator;

import java.util.Calendar;

import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareEditorInput;
import org.eclipse.compare.CompareUI;
import org.eclipse.emf.compare.diff.metamodel.ComparisonResourceSnapshot;
import org.eclipse.emf.compare.diff.metamodel.DiffFactory;
import org.eclipse.emf.compare.diff.service.DiffService;
import org.eclipse.emf.compare.match.metamodel.MatchModel;
import org.eclipse.emf.compare.match.service.MatchService;
import org.eclipse.emf.compare.ui.editor.ModelCompareEditorInput;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.domain.ICompareEditingDomain;
import org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain;
import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
import org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonEditorInput;
import org.eclipse.emf.compare.scope.DefaultComparisonScope;
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory.Descriptor.Registry;
import org.eclipse.emf.emfstore.client.ui.ESCompare;
import org.eclipse.emf.emfstore.internal.common.model.Project;
import org.eclipse.emf.emfstore.internal.common.model.util.ModelUtil;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;

/**
* Implementation of {@link ESCompare} using the EMF Compare Framework to compare to {@link Project}s.
*
* @author jsommerfeldt
*
*/
// Some EMF Compare classes are internal API
@SuppressWarnings("restriction")
public class EMFCompareComparator implements ESCompare {

private ComparisonResourceSnapshot snapshot;
private Comparison comparison;
private EObject eObject1;
private EObject eObject2;

/**
*
Expand All @@ -36,15 +61,14 @@ public void compare(EObject e1, EObject e2) {
throw new IllegalArgumentException("The objects have to be Projects!");
}

try {
snapshot = DiffFactory.eINSTANCE.createComparisonResourceSnapshot();
snapshot.setDate(Calendar.getInstance().getTime());
final MatchModel match = MatchService.doContentMatch(e1, e2, null);
snapshot.setMatch(match);
snapshot.setDiff(DiffService.doDiff(match, false));
} catch (final InterruptedException e) {
ModelUtil.logException(e);
}
eObject1 = e1;
eObject2 = e2;
comparison = EMFCompare.builder().build().compare(twoWayScope(eObject1, eObject2));
comparison.setDiagnostic(new BasicDiagnostic());
}

private IComparisonScope twoWayScope(EObject e1, EObject e2) {
return new DefaultComparisonScope(e1, e2, null);
}

/**
Expand All @@ -54,6 +78,25 @@ public void compare(EObject e1, EObject e2) {
* @see org.eclipse.emf.emfstore.client.ui.ESCompare#display()
*/
public void display() {
CompareUI.openCompareEditor(new ModelCompareEditorInput(snapshot), true);
if (comparison.getDifferences().isEmpty()) {
final Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
MessageDialog.openInformation(shell, "No changes", "There are no changes in the comparison.");
return;
}

final ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(eObject1, eObject2, null);
final Registry adapterFactoryRegistry = ComposedAdapterFactory.Descriptor.Registry.INSTANCE;
final AdapterFactory adapterFactory = new ComposedAdapterFactory(adapterFactoryRegistry);
final EMFCompareConfiguration config = createDefaultCompareConfiguration();
final CompareEditorInput input = new ComparisonEditorInput(config, comparison, editingDomain, adapterFactory);

CompareUI.openCompareEditor(input);
}

private EMFCompareConfiguration createDefaultCompareConfiguration() {
final CompareConfiguration config = new CompareConfiguration();
config.setLeftEditable(false);
config.setRightEditable(false);
return new EMFCompareConfiguration(config);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012-2013 EclipseSource Muenchen GmbH and others.
* Copyright (c) 2012-2015 EclipseSource Muenchen GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -8,11 +8,13 @@
*
* Contributors:
* Julian Sommerfeldt
* Philip Langer
******************************************************************************/
package org.eclipse.emf.emfstore.internal.client.ui.testers;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.emf.emfstore.internal.client.ui.views.historybrowserview.HistoryCompare;
import org.eclipse.emf.emfstore.internal.server.model.versioning.HistoryInfo;

/**
* Test if there is a history compare extension registered.
Expand All @@ -30,6 +32,24 @@ public class HistoryCompareEnabledTester extends PropertyTester {
* java.lang.Object)
*/
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
return HistoryCompare.hasRegisteredExtensions();
return HistoryCompare.hasRegisteredExtensions() && isHistoryInfoWithVersion(receiver);
}

/**
* Tests whether the given {@code object} is a {@link HistoryInfo} with an identifiable version.
* <p>
* A {@link HistoryInfo} doesn't have an identifiable version (i.e., -1), if it is the local revision.
* </p>
*
* @param object The object to test.
* @return <code>true</code> if {@code object} is a {@link HistoryInfo} with an identifiable version,
* <code>false</code> otherwise.
*/
private boolean isHistoryInfoWithVersion(Object object) {
if (object instanceof HistoryInfo) {
final HistoryInfo historyInfo = (HistoryInfo) object;
return historyInfo.getPrimarySpec().getIdentifier() != -1;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ public class HistoryBrowserView extends ViewPart implements ProjectSpaceContaine
* {@inheritDoc}
*/
public ProjectSpace getProjectSpace() {
if (isUnlinkedFromNavigator) {
return null;
}
return projectSpace;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
</license>

<requires>
<import plugin="org.eclipse.emf.compare" version="1.3.3" match="compatible"/>
<import plugin="org.eclipse.emf.compare.diff" version="1.3.3" match="compatible"/>
<import plugin="org.eclipse.emf.compare.match" version="1.3.3" match="compatible"/>
<import plugin="org.eclipse.emf.compare.ui" version="1.3.3" match="compatible"/>
<import plugin="org.eclipse.emf.compare.diff.edit" version="1.3.3" match="compatible"/>
<import plugin="org.eclipse.emf.compare" version="3.0.0" match="compatible"/>
<import plugin="org.eclipse.compare" version="3.5.300" match="compatible"/>
<import plugin="org.eclipse.emf.emfstore.client" version="1.0.0" match="compatible"/>
<import plugin="org.eclipse.emf.emfstore.client.ui" version="1.0.0" match="compatible"/>
<import plugin="org.eclipse.emf.emfstore.client" version="1.5.0" match="compatible"/>
<import plugin="org.eclipse.emf.emfstore.client.ui" version="1.5.0" match="compatible"/>
<import plugin="org.eclipse.emf.compare.ide.ui" version="4.0.0" match="compatible"/>
<import plugin="org.eclipse.emf.compare.ide" version="3.1.0" match="compatible"/>
<import plugin="org.eclipse.emf.compare.edit" version="4.0.0" match="compatible"/>
<import plugin="org.eclipse.swt" version="3.0.0" match="compatible"/>
<import plugin="org.eclipse.jface" version="3.8.0" match="compatible"/>
<import plugin="org.eclipse.ui.workbench" version="3.0.0" match="compatible"/>
</requires>

<plugin
Expand Down
Loading

0 comments on commit f23024a

Please sign in to comment.