Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikaƫl Barbero2013-06-23 17:16:25 -0400
committerAxel Richard2013-07-16 04:56:24 -0400
commit51c49e147dbd1113ac4c9ec22a4d735a4cb0f580 (patch)
treef4b035fdc0cb2bb5ea17b7d8415c8dddf62d51b8
parentba590393675ff110a533ebd23eef897b6b23b7e0 (diff)
downloadorg.eclipse.emf.compare-51c49e147dbd1113ac4c9ec22a4d735a4cb0f580.tar.gz
org.eclipse.emf.compare-51c49e147dbd1113ac4c9ec22a4d735a4cb0f580.tar.xz
org.eclipse.emf.compare-51c49e147dbd1113ac4c9ec22a4d735a4cb0f580.zip
Refactor Groups.
-IDifferenceGroup are now Adapters. -Use TreeNode as new ItemProviders instead of EDiffNodes. -Add a new Group: By Resource. Change-Id: I26b451997ce42ce37cee266bb0d9e80c07287984
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/structuremergeviewer/filters/GMFRefinedElementsFilter.java23
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/AdapterFactoryUtil.java180
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/AttributeChangeItemProviderSpec.java24
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ComparisonItemProviderSpec.java91
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ConflictItemProviderSpec.java55
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchItemProviderSpec.java170
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchResourceItemProviderSpec.java42
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ReferenceChangeItemProviderSpec.java134
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ResourceAttachmentChangeItemProviderSpec.java111
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/plugin.xml12
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/text/EMFCompareTextMergeViewer.java13
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/CompareInputAdapter.java (renamed from plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractEDiffNode.java)82
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/CompareInputComparer.java (renamed from plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/DiffNodeComparer.java)190
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java34
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java134
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java45
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewerContentProvider.java439
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewerLabelProvider.java64
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergeAllHandler.java (renamed from plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedAllTo.java)2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergeHandler.java (renamed from plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedTo.java)17
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergeAllToLeftHandler.java (renamed from plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToLeft.java)2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergeAllToRightHandler.java (renamed from plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToRight.java)2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergeToLeftHandler.java (renamed from plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToLeft.java)2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergeToRightHandler.java (renamed from plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToRight.java)2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/AcceptRejectChangePropertyTester.java2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/DiffSelectedPropertyTester.java11
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/MergedToPropertyTester.java2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/AttributeChangeNode.java42
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ComparisonNode.java44
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/DiffNode.java127
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/EquivalenceNode.java43
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/MatchNode.java122
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/MatchResourceNode.java43
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ReferenceChangeNode.java42
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ResourceAttachmentChangeNode.java42
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/TreeCompareInputAdapterFactory.java (renamed from plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/CompareNodeAdapterFactory.java)147
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/TreeNodeCompareInput.java (renamed from plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ConflictNode.java)74
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/plugin.xml20
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupAction.java6
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupActionMenu.java6
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/StructureMergeViewerFilter.java89
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/CascadingDifferencesFilter.java60
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/EmptyMatchedResourcesFilter.java25
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/IdenticalElementsFilter.java34
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/PseudoConflictsFilter.java14
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/BasicDifferenceGroupImpl.java216
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/IDifferenceGroup.java32
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/IDifferenceGroupProvider.java7
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/StructureMergeViewerGrouper.java38
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/ByResourceGroupProvider.java210
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/DefaultGroupProvider.java30
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/KindGroupProvider.java64
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/ThreeWayComparisonGroupProvider.java217
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/provider/GroupItemProviderAdapter.java147
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/provider/TreeItemProviderAdapterFactorySpec.java63
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/provider/TreeNodeItemProviderSpec.java128
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestComparisonItemProviderSpec.java108
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestMatchItemProviderSpec.java40
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestReferenceChangeItemProviderSpec.java157
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.rcp.ui/src/org/eclipse/emf/compare/uml2/rcp/ui/internal/structuremergeviewer/filters/UMLRefinedElementsFilter.java29
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java2194
62 files changed, 2959 insertions, 3590 deletions
diff --git a/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/structuremergeviewer/filters/GMFRefinedElementsFilter.java b/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/structuremergeviewer/filters/GMFRefinedElementsFilter.java
index 01c87027f..b6826781a 100644
--- a/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/structuremergeviewer/filters/GMFRefinedElementsFilter.java
+++ b/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/structuremergeviewer/filters/GMFRefinedElementsFilter.java
@@ -22,6 +22,7 @@ import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.impl
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.edit.tree.TreeNode;
/**
* A filter used by default that filtered out refined GMF differences.
@@ -36,9 +37,12 @@ public class GMFRefinedElementsFilter extends AbstractDifferenceFilter {
*/
private static final Predicate<? super EObject> PREDICATE_WHEN_SELECTED = new Predicate<EObject>() {
public boolean apply(EObject input) {
- if (input instanceof Diff) {
- Diff diff = (Diff)input;
- return Iterables.any(diff.getRefines(), instanceOf(DiagramDiff.class));
+ if (input instanceof TreeNode) {
+ EObject data = ((TreeNode)input).getData();
+ if (data instanceof Diff) {
+ Diff diff = (Diff)data;
+ return Iterables.any(diff.getRefines(), instanceOf(DiagramDiff.class));
+ }
}
return false;
}
@@ -49,9 +53,14 @@ public class GMFRefinedElementsFilter extends AbstractDifferenceFilter {
*/
private static final Predicate<? super EObject> PREDICATE_WHEN_UNSELECTED = new Predicate<EObject>() {
public boolean apply(EObject input) {
- EPackage p = input.eClass().getEPackage();
- if (p != null) {
- return p.getNsURI().startsWith("http://www.eclipse.org/emf/compare/diagram"); //$NON-NLS-1$
+ if (input instanceof TreeNode) {
+ EObject data = ((TreeNode)input).getData();
+ if (data != null) {
+ EPackage p = input.eClass().getEPackage();
+ if (p != null) {
+ return p.getNsURI().startsWith("http://www.eclipse.org/emf/compare/diagram"); //$NON-NLS-1$
+ }
+ }
}
return false;
}
@@ -67,7 +76,7 @@ public class GMFRefinedElementsFilter extends AbstractDifferenceFilter {
public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
if (scope != null) {
for (String nsURI : scope.getNsURIs()) {
- if (nsURI.matches("http://www\\.eclipse\\.org/gmf/runtime/.*/notation")) {
+ if (nsURI.matches("http://www\\.eclipse\\.org/gmf/runtime/.*/notation")) { //$NON-NLS-1$
return true;
}
}
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/AdapterFactoryUtil.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/AdapterFactoryUtil.java
index 9bd98e4ef..716180734 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/AdapterFactoryUtil.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/AdapterFactoryUtil.java
@@ -1,80 +1,100 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.provider;
-
-import com.google.common.base.Preconditions;
-
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.edit.provider.IItemLabelProvider;
-
-/**
- * Some utility methods to work with {@link AdapterFactory}.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public final class AdapterFactoryUtil {
-
- private AdapterFactoryUtil() {
- // prevents instantiation
- }
-
- /**
- * Returns the text of the given <code>object</code> by adapting it to {@link IItemLabelProvider} and
- * asking for its {@link IItemLabelProvider#getText(Object) text}. Returns null if <code>object</code> is
- * null.
- *
- * @param adapterFactory
- * the adapter factory to adapt from
- * @param object
- * the object from which we want a text
- * @return the text, or null if object is null.
- * @throws NullPointerException
- * if <code>adapterFactory</code> is null.
- */
- public static String getText(final AdapterFactory adapterFactory, final Object object) {
- Preconditions.checkNotNull(adapterFactory);
- if (object == null) {
- return null;
- }
-
- Object itemLabelProvider = adapterFactory.adapt(object, IItemLabelProvider.class);
- if (itemLabelProvider instanceof IItemLabelProvider) {
- return ((IItemLabelProvider)itemLabelProvider).getText(object);
- }
- return null;
- }
-
- /**
- * Returns the image of the given <code>object</code> by adapting it to {@link IItemLabelProvider} and
- * asking for its {@link IItemLabelProvider#getImage(Object) image}. Returns null if <code>object</code>
- * is null.
- *
- * @param adapterFactory
- * the adapter factory to adapt from
- * @param object
- * the object from which we want a image
- * @return the image, or null if object is null.
- * @throws NullPointerException
- * if <code>adapterFactory</code> is null.
- */
- public static Object getImage(AdapterFactory adapterFactory, Object object) {
- Preconditions.checkNotNull(adapterFactory);
- if (object == null) {
- return null;
- }
-
- Object adapter = adapterFactory.adapt(object, IItemLabelProvider.class);
- if (adapter instanceof IItemLabelProvider) {
- return ((IItemLabelProvider)adapter).getImage(object);
- }
- return null;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.provider;
+
+import com.google.common.base.Preconditions;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+
+/**
+ * Some utility methods to work with {@link AdapterFactory}.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public final class AdapterFactoryUtil {
+
+ private AdapterFactoryUtil() {
+ // prevents instantiation
+ }
+
+ /**
+ * Returns the text of the given <code>object</code> by adapting it to {@link IItemLabelProvider} and
+ * asking for its {@link IItemLabelProvider#getText(Object) text}. Returns null if <code>object</code> is
+ * null.
+ *
+ * @param adapterFactory
+ * the adapter factory to adapt from
+ * @param object
+ * the object from which we want a text
+ * @return the text, or null if object is null.
+ * @throws NullPointerException
+ * if <code>adapterFactory</code> is null.
+ */
+ public static String getText(final AdapterFactory adapterFactory, final Object object) {
+ Preconditions.checkNotNull(adapterFactory);
+ if (object == null) {
+ return null;
+ }
+
+ Object itemLabelProvider = adapterFactory.adapt(object, IItemLabelProvider.class);
+ if (itemLabelProvider instanceof IItemLabelProvider) {
+ return ((IItemLabelProvider)itemLabelProvider).getText(object);
+ }
+ return null;
+ }
+
+ /**
+ * Returns the image of the given <code>object</code> by adapting it to {@link IItemLabelProvider} and
+ * asking for its {@link IItemLabelProvider#getImage(Object) image}. Returns null if <code>object</code>
+ * is null.
+ *
+ * @param adapterFactory
+ * the adapter factory to adapt from
+ * @param object
+ * the object from which we want a image
+ * @return the image, or null if object is null.
+ * @throws NullPointerException
+ * if <code>adapterFactory</code> is null.
+ */
+ public static Object getImage(AdapterFactory adapterFactory, Object object) {
+ Preconditions.checkNotNull(adapterFactory);
+ if (object == null) {
+ return null;
+ }
+
+ Object adapter = adapterFactory.adapt(object, IItemLabelProvider.class);
+ if (adapter instanceof IItemLabelProvider) {
+ return ((IItemLabelProvider)adapter).getImage(object);
+ }
+ return null;
+ }
+
+ /**
+ * Returns the StyledText for the given object and the given adapter factory.
+ *
+ * @param adapterFactory
+ * the given adapter factory.
+ * @param object
+ * the given object.
+ * @return the StyledText as an Object.
+ */
+ public static Object getStyledText(AdapterFactory adapterFactory, Object object) {
+ Preconditions.checkNotNull(adapterFactory);
+ if (object != null) {
+ Object adapter = adapterFactory.adapt(object, IItemStyledLabelProvider.class);
+ if (adapter instanceof IItemStyledLabelProvider) {
+ return ((IItemStyledLabelProvider)adapter).getStyledText(object);
+ }
+ }
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/AttributeChangeItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/AttributeChangeItemProviderSpec.java
index 8f9483165..f81909040 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/AttributeChangeItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/AttributeChangeItemProviderSpec.java
@@ -10,17 +10,11 @@
*******************************************************************************/
package org.eclipse.emf.compare.provider.spec;
-import static com.google.common.collect.Lists.newArrayList;
-
import com.google.common.base.Strings;
-import java.util.Collection;
-import java.util.List;
-
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.AttributeChange;
-import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceSource;
import org.eclipse.emf.compare.provider.AdapterFactoryUtil;
@@ -143,24 +137,6 @@ public class AttributeChangeItemProviderSpec extends AttributeChangeItemProvider
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
- */
- @Override
- public Collection<?> getChildren(Object object) {
- Collection<?> children = super.getChildren(object);
- List<? super Object> ret = newArrayList(children);
- AttributeChange attributeChange = (AttributeChange)object;
- Conflict conflict = attributeChange.getConflict();
- if (conflict != null) {
- // ret.add(conflict);
- }
-
- return ret;
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getForeground(java.lang.Object)
*/
@Override
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ComparisonItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ComparisonItemProviderSpec.java
index e66ce917a..c6894e787 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ComparisonItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ComparisonItemProviderSpec.java
@@ -10,30 +10,12 @@
*******************************************************************************/
package org.eclipse.emf.compare.provider.spec;
-import static com.google.common.collect.Iterables.concat;
-import static com.google.common.collect.Iterables.filter;
-import static com.google.common.collect.Iterables.isEmpty;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-
-import java.util.Collection;
-import java.util.List;
-
import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.provider.ComparisonItemProvider;
import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
import org.eclipse.emf.compare.provider.utils.IStyledString;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
/**
* Specialized {@link ComparisonItemProvider} returning nice output for {@link #getText(Object)} and
@@ -56,79 +38,6 @@ public class ComparisonItemProviderSpec extends ComparisonItemProvider implement
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
- */
- @Override
- public Collection<?> getChildren(Object object) {
- Comparison comparison = (Comparison)object;
- return ImmutableList.copyOf(getChildrenIterable(comparison));
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#hasChildren(java.lang.Object)
- */
- @Override
- public boolean hasChildren(Object object) {
- Comparison comparison = (Comparison)object;
- return !isEmpty(getChildrenIterable(comparison));
- }
-
- /**
- * Returns the children of the given {@link Comparison}. In this case children means: non empty matches
- * (see {@link ComparisonItemProviderSpec#getNonEmptyMatches(Comparison)}), matches which not only
- * contains {@link ResourceAttachmentChange} differences, and matched resources.
- *
- * @param comparison
- * the given {@link Comparison}.
- * @return the filtered list of children of the given {@link Comparison}.
- */
- private Iterable<EObject> getChildrenIterable(Comparison comparison) {
- Iterable<? extends EObject> matches = getNonEmptyMatches(comparison);
- List<EObject> children = Lists.newArrayList(matches);
- for (EObject match : matches) {
- EList<Diff> differences = ((Match)match).getDifferences();
- if (!isEmpty(filter(differences, ResourceAttachmentChange.class))) {
- children.remove(match);
- }
- }
-
- return concat(children, comparison.getMatchedResources());
- }
-
- /**
- * Filters out the empty matches of the given {@link Comparison}.
- *
- * @param comparison
- * the given {@link Comparison}.
- * @return an iterable of non empty matches.
- */
- private Iterable<Match> getNonEmptyMatches(Comparison comparison) {
- Iterable<Match> match = filter(comparison.getMatches(), new Predicate<Match>() {
- public boolean apply(Match input) {
- final boolean ret;
- IEditingDomainItemProvider editingDomainItemProvider = (IEditingDomainItemProvider)adapterFactory
- .adapt(input, IEditingDomainItemProvider.class);
-
- if (editingDomainItemProvider instanceof MatchItemProviderSpec) {
- ret = !isEmpty(((MatchItemProviderSpec)editingDomainItemProvider)
- .getChildrenIterable(input));
- } else if (editingDomainItemProvider != null) {
- ret = !editingDomainItemProvider.getChildren(input).isEmpty();
- } else {
- ret = false;
- }
-
- return ret;
- }
- });
- return match;
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object)
*/
public IStyledString.IComposedStyledString getStyledText(Object object) {
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ConflictItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ConflictItemProviderSpec.java
index add9adbd3..4b801c696 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ConflictItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ConflictItemProviderSpec.java
@@ -10,20 +10,9 @@
*******************************************************************************/
package org.eclipse.emf.compare.provider.spec;
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
-import java.util.Collection;
-
import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.ConflictKind;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.ReferenceChange;
import org.eclipse.emf.compare.internal.EMFCompareEditMessages;
import org.eclipse.emf.compare.provider.ConflictItemProvider;
import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
@@ -41,24 +30,6 @@ import org.eclipse.emf.compare.provider.utils.IStyledString.Style;
public class ConflictItemProviderSpec extends ConflictItemProvider implements IItemStyledLabelProvider, IItemDescriptionProvider {
/**
- * Returns the sub diffs of a given diff.
- */
- private static Function<Diff, Iterable<Diff>> getSubDiffs = new Function<Diff, Iterable<Diff>>() {
- public Iterable<Diff> apply(Diff diff) {
- if (diff instanceof ReferenceChange) {
- Match match = diff.getMatch();
- Match matchOfValue = diff.getMatch().getComparison().getMatch(
- ((ReferenceChange)diff).getValue());
- if (!match.equals(matchOfValue) && match.getSubmatches().contains(matchOfValue)) {
- final Iterable<Diff> subDiffs = matchOfValue.getAllDifferences();
- return ImmutableSet.copyOf(subDiffs);
- }
- }
- return ImmutableSet.of();
- }
- };
-
- /**
* Constructs a ComparisonItemProviderSpec with the given factory.
*
* @param adapterFactory
@@ -95,32 +66,6 @@ public class ConflictItemProviderSpec extends ConflictItemProvider implements II
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
- */
- @Override
- public Collection<?> getChildren(Object object) {
- Conflict conflict = (Conflict)object;
- EList<Diff> differences = conflict.getDifferences();
- Collection<Diff> filteredDifferences = Sets.newLinkedHashSet();
- for (Diff diff : differences) {
- boolean subdiff = false;
- for (Diff diffParent : differences) {
- if (!diff.equals(diffParent) && Iterables.contains(getSubDiffs.apply(diffParent), diff)) {
- subdiff = true;
- break;
- }
- }
- if (!subdiff) {
- filteredDifferences.add(diff);
- }
- }
-
- return filteredDifferences;
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object)
*/
public IStyledString.IComposedStyledString getStyledText(Object object) {
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchItemProviderSpec.java
index 294448df2..9faab3719 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchItemProviderSpec.java
@@ -10,31 +10,12 @@
*******************************************************************************/
package org.eclipse.emf.compare.provider.spec;
-import static com.google.common.base.Predicates.instanceOf;
-import static com.google.common.base.Predicates.not;
-import static com.google.common.base.Predicates.or;
import static com.google.common.collect.Iterables.any;
-import static com.google.common.collect.Iterables.filter;
-import static com.google.common.collect.Iterables.isEmpty;
-import static com.google.common.collect.Iterables.transform;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.containmentReferenceChange;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasState;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-
-import java.util.Collection;
-
import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.ReferenceChange;
-import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.provider.AdapterFactoryUtil;
import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
@@ -42,7 +23,6 @@ import org.eclipse.emf.compare.provider.MatchItemProvider;
import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
import org.eclipse.emf.compare.provider.utils.IStyledString;
import org.eclipse.emf.compare.provider.utils.IStyledString.Style;
-import org.eclipse.emf.ecore.EObject;
/**
* Specialized {@link MatchItemProvider} returning nice output for {@link #getText(Object)} and
@@ -121,156 +101,6 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
- */
- @Override
- public Collection<?> getChildren(Object object) {
- Match match = (Match)object;
- Iterable<?> filteredChildren = getChildrenIterable(match);
- return ImmutableList.copyOf(filteredChildren);
- }
-
- /**
- * Returns the children that will be displayed under the given Match.
- *
- * @param match
- * the given Match.
- * @return an iterable of children that will be displayed under the given Match.
- * @since 3.0
- */
- public Iterable<?> getChildrenIterable(Match match) {
- ImmutableSet<EObject> containementDifferenceValues = containmentReferencesValues(match);
-
- @SuppressWarnings("unchecked")
- Predicate<Object> childrenFilter = not(or(matchOfContainmentDiff(containementDifferenceValues),
- emptyMatch(), instanceOf(ResourceAttachmentChange.class)));
-
- Iterable<?> filteredChildren = filter(super.getChildren(match), childrenFilter);
- return filteredChildren;
- }
-
- /**
- * Returns the filtered children (children without those who don't have children) that will be displayed
- * under the given Match.
- *
- * @param match
- * the given Match.
- * @return an iterable of the filtered children (children without those who don't have children) that will
- * be displayed under the given Match.
- * @since 3.0
- */
- public Iterable<?> getFilteredChildren(Match match) {
- ImmutableSet<EObject> containementDifferenceValues = containmentReferencesValues(match);
-
- @SuppressWarnings("unchecked")
- Predicate<Object> childrenFilter = not(or(matchOfContainmentDiff(containementDifferenceValues),
- matchWithNoChildren(), emptyMatch(), instanceOf(ResourceAttachmentChange.class)));
-
- Iterable<?> filteredChildren = filter(super.getChildren(match), childrenFilter);
- return filteredChildren;
- }
-
- /**
- * Returns the containment references values of the given Match.
- *
- * @param match
- * the given Match.
- * @return the containment references values of the given Match.
- * @since 3.0
- */
- public static ImmutableSet<EObject> containmentReferencesValues(Match match) {
- EList<Diff> differences = match.getDifferences();
-
- Iterable<Diff> containmentReferenceChanges = filter(differences, containmentReferenceChange());
-
- final Function<Diff, EObject> valueGetter = new Function<Diff, EObject>() {
- public EObject apply(Diff input) {
- return ((ReferenceChange)input).getValue();
- }
- };
- ImmutableSet<EObject> containementDifferenceValues = ImmutableSet.copyOf(transform(
- containmentReferenceChanges, valueGetter));
-
- return containementDifferenceValues;
- }
-
- /**
- * A predicate to know if the given object is a {@link Match} containing a {@link Diff} of type
- * containment.
- *
- * @param containementDifferenceValues
- * the list of containment values.
- * @return a predicate to know if the given object is a {@link Match} containing a {@link Diff} of type
- * containment.
- * @since 3.0
- */
- public static Predicate<? super Object> matchOfContainmentDiff(
- final ImmutableSet<? extends EObject> containementDifferenceValues) {
- return new Predicate<Object>() {
- public boolean apply(Object input) {
- boolean ret = false;
- if (input instanceof Match) {
- Match match = (Match)input;
- if (containementDifferenceValues.contains(match.getLeft())
- || containementDifferenceValues.contains(match.getRight())
- || containementDifferenceValues.contains(match.getOrigin())) {
- ret = true;
- }
- }
- return ret;
- }
- };
- }
-
- /**
- * A predicate to know if the given object is a {@link Match} with no children.
- *
- * @return A predicate to know if the given object is a {@link Match} with no children.
- */
- private Predicate<? super Object> matchWithNoChildren() {
- return new Predicate<Object>() {
- public boolean apply(Object input) {
- boolean ret = false;
- if (input instanceof Match) {
- Match match = (Match)input;
- ret = Iterables.isEmpty(MatchItemProviderSpec.this.getFilteredChildren(match));
- }
- return ret;
- }
- };
- }
-
- /**
- * A predicate to know if the given object is an empty match (no left, right and origin).
- *
- * @return A predicate to know if the given object is an empty match (no left, right and origin).
- */
- private static Predicate<? super Object> emptyMatch() {
- return new Predicate<Object>() {
- public boolean apply(Object input) {
- if (input instanceof Match) {
- final Match match = (Match)input;
- return match.getLeft() == null && match.getRight() == null && match.getOrigin() == null;
- }
- return false;
- }
- };
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#hasChildren(java.lang.Object)
- */
- @Override
- public boolean hasChildren(Object object) {
- Match match = (Match)object;
- return !isEmpty(getChildrenIterable(match));
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object)
* @since 3.0
*/
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchResourceItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchResourceItemProviderSpec.java
index 04b884db1..86d363014 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchResourceItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchResourceItemProviderSpec.java
@@ -13,15 +13,9 @@ package org.eclipse.emf.compare.provider.spec;
import static com.google.common.base.Predicates.not;
import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Iterators;
-
-import java.util.ArrayList;
-import java.util.Collection;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.MatchResource;
import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
@@ -51,42 +45,6 @@ public class MatchResourceItemProviderSpec extends MatchResourceItemProvider imp
}
/**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
- */
- @Override
- public Collection<?> getChildren(Object object) {
- Collection<Object> children = new ArrayList<Object>();
- MatchResource matchResource = (MatchResource)object;
- Comparison comparison = matchResource.getComparison();
- for (Diff diff : Collections2.filter(comparison.getDifferences(), isCandidate(matchResource))) {
- children.add(diff);
- }
- return children;
- }
-
- /**
- * Predicate to check that the current difference is candidate to be added under the given
- * <code>MatchResource</code>.
- *
- * @param matchResource
- * The match resource.
- * @return The predicate.
- */
- private Predicate<Diff> isCandidate(final MatchResource matchResource) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- if (input instanceof ResourceAttachmentChange) {
- return uriEqualToOneAtLeast(matchResource).apply((ResourceAttachmentChange)input);
- } else {
- return Iterators.any(input.getRefinedBy().iterator(), isCandidate(matchResource));
- }
- }
- };
- }
-
- /**
* Predicate to check if the URI of the current attachment change is equal to one (at least) of the URIs
* of the resources matched by the given <code>MatchResource</code>.
*
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ReferenceChangeItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ReferenceChangeItemProviderSpec.java
index b567b65eb..46ea47786 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ReferenceChangeItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ReferenceChangeItemProviderSpec.java
@@ -10,32 +10,18 @@
*******************************************************************************/
package org.eclipse.emf.compare.provider.spec;
-import static com.google.common.base.Predicates.instanceOf;
-import static com.google.common.base.Predicates.not;
import static com.google.common.collect.Iterables.any;
-import static com.google.common.collect.Iterables.filter;
-import static com.google.common.collect.Lists.newArrayList;
-import com.google.common.base.Predicate;
import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableCollection;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.compare.ConflictKind;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceSource;
import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ReferenceChange;
-import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.provider.AdapterFactoryUtil;
import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
@@ -46,11 +32,9 @@ import org.eclipse.emf.compare.provider.utils.IStyledString.Style;
import org.eclipse.emf.compare.utils.EMFComparePredicates;
import org.eclipse.emf.compare.utils.ReferenceUtil;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.edit.provider.IItemFontProvider;
-import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
/**
* Specialized {@link ReferenceChangeItemProvider} returning nice output for {@link #getText(Object)} and
@@ -208,124 +192,6 @@ public class ReferenceChangeItemProviderSpec extends ReferenceChangeItemProvider
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
- */
- @Override
- public Collection<?> getChildren(Object object) {
- Collection<?> superChildren = super.getChildren(object);
- List<? super Object> ret = newArrayList(superChildren);
-
- ReferenceChange referenceChange = (ReferenceChange)object;
- EReference reference = referenceChange.getReference();
-
- if (reference.isContainment()) {
- Match matchOfValue = referenceChange.getMatch().getComparison().getMatch(
- referenceChange.getValue());
- if (matchOfValue == null && DifferenceState.MERGED == referenceChange.getState()) {
- Match parentMatch = referenceChange.getMatch();
- matchOfValue = getMatchWithNullValues(parentMatch);
- }
- if (matchOfValue != null) {
- Collection<?> children = getChildren(matchOfValue);
- children.remove(referenceChange);
- Iterable<?> filter = filter(children, fromSideOrInRealConflict(((Diff)object).getSource()));
- Iterables.addAll(ret, filter);
- }
- }
-
- return ImmutableList.copyOf(filter(ret, not(instanceOf(ResourceAttachmentChange.class))));
-
- }
-
- /**
- * After merging a diff which will lead to have an insertion point on both sides, the match associated
- * with this diff will be unreacheable because its left and right sides will be null. This method will
- * find this match.
- *
- * @param match
- * the given match.
- * @return the match associated with the given merged diff.
- */
- private Match getMatchWithNullValues(Match match) {
- for (Match subMatch : match.getSubmatches()) {
- if (subMatch.getLeft() == null && subMatch.getRight() == null) {
- return subMatch;
- }
- }
- return null;
- }
-
- /**
- * This can be used to check that a given Object originates from the given {@code source} side, and is not
- * in real conflict.
- *
- * @param source
- * The side from which we expect this diff to originate.
- * @return The created predicate.
- */
- private Predicate<? super Object> fromSideOrInRealConflict(final DifferenceSource source) {
- return new Predicate<Object>() {
- public boolean apply(Object object) {
- boolean ret = false;
- if (object instanceof Diff) {
- Diff diff = (Diff)object;
- if (source == diff.getSource()) {
- ret = true;
- } else if (EMFComparePredicates.hasConflict(ConflictKind.REAL).apply(diff)) {
- ret = true;
- } else if (EMFComparePredicates.hasConflict(ConflictKind.PSEUDO).apply(diff)) {
- ret = !(diff instanceof ReferenceChange)
- || (diff instanceof ReferenceChange && ((ReferenceChange)diff).getReference()
- .isContainment());
- } else {
- ret = true;
- }
- } else if (object instanceof Match) {
- ret = true;
- }
- return ret;
- }
- };
- }
-
- /**
- * Returns the children of the given {@link Match}.
- *
- * @param matchOfValue
- * the given {@link Match}.
- * @return the children of the given {@link Match}.
- */
- private Collection<?> getChildren(Match matchOfValue) {
- final Collection<?> children;
- ITreeItemContentProvider matchItemContentProvider = (ITreeItemContentProvider)adapterFactory.adapt(
- matchOfValue, ITreeItemContentProvider.class);
- if (matchItemContentProvider != null) {
- Collection<?> itemProviderChildren = matchItemContentProvider.getChildren(matchOfValue);
- if (itemProviderChildren instanceof ImmutableCollection<?>) {
- children = newArrayList(itemProviderChildren);
- } else {
- children = itemProviderChildren;
- }
-
- Iterator<?> childrenIterator = children.iterator();
- while (childrenIterator.hasNext()) {
- Object child = childrenIterator.next();
- if (child instanceof Match) {
- if (!matchItemContentProvider.hasChildren(child)) {
- childrenIterator.remove();
- }
- }
-
- }
- } else {
- children = ImmutableList.of();
- }
- return children;
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getForeground(java.lang.Object)
*/
@Override
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ResourceAttachmentChangeItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ResourceAttachmentChangeItemProviderSpec.java
index 9ae53a57d..078d31749 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ResourceAttachmentChangeItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ResourceAttachmentChangeItemProviderSpec.java
@@ -10,15 +10,6 @@
*******************************************************************************/
package org.eclipse.emf.compare.provider.spec;
-import static com.google.common.collect.Lists.newArrayList;
-
-import com.google.common.collect.ImmutableCollection;
-import com.google.common.collect.ImmutableList;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceSource;
@@ -31,8 +22,6 @@ import org.eclipse.emf.compare.provider.ResourceAttachmentChangeItemProvider;
import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
import org.eclipse.emf.compare.provider.utils.IStyledString.IComposedStyledString;
import org.eclipse.emf.compare.provider.utils.IStyledString.Style;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
/**
* Specialized {@link ResourceAttachmentChangeItemProvider} returning nice output for {@link #getText(Object)}
@@ -60,85 +49,6 @@ public class ResourceAttachmentChangeItemProviderSpec extends ResourceAttachment
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.provider.ResourceAttachmentChangeItemProvider#getChildren(java.lang.Object)
- */
- @Override
- public Collection<?> getChildren(Object object) {
- Collection<?> superChildren = super.getChildren(object);
- List<? super Object> ret = newArrayList(superChildren);
-
- ResourceAttachmentChange resourceAttachmentChange = (ResourceAttachmentChange)object;
- final EObject value;
- DifferenceSource source = resourceAttachmentChange.getSource();
- DifferenceKind kind = resourceAttachmentChange.getKind();
- switch (source) {
- case LEFT:
- if (kind == DifferenceKind.ADD) {
- value = resourceAttachmentChange.getMatch().getLeft();
- } else {
- value = resourceAttachmentChange.getMatch().getRight();
- }
- break;
- case RIGHT:
- if (kind == DifferenceKind.ADD) {
- value = resourceAttachmentChange.getMatch().getRight();
- } else {
- value = resourceAttachmentChange.getMatch().getLeft();
- }
- break;
- default:
- value = null;
- throw new IllegalStateException();
- }
-
- Match matchOfValue = resourceAttachmentChange.getMatch().getComparison().getMatch(value);
- if (matchOfValue != null) {
- Collection<?> children = getChildren(matchOfValue);
- children.remove(resourceAttachmentChange);
- ret.addAll(children);
- }
-
- return ImmutableList.copyOf(ret);
- }
-
- /**
- * Returns the children of the given {@link Match}.
- *
- * @param matchOfValue
- * the given {@link Match}.
- * @return the children of the given {@link Match}.
- */
- private Collection<?> getChildren(Match matchOfValue) {
- final Collection<?> children;
- ITreeItemContentProvider matchItemContentProvider = (ITreeItemContentProvider)adapterFactory.adapt(
- matchOfValue, ITreeItemContentProvider.class);
- if (matchItemContentProvider != null) {
- Collection<?> itemProviderChildren = matchItemContentProvider.getChildren(matchOfValue);
- if (itemProviderChildren instanceof ImmutableCollection<?>) {
- children = newArrayList(itemProviderChildren);
- } else {
- children = itemProviderChildren;
- }
-
- Iterator<?> childrenIterator = children.iterator();
- while (childrenIterator.hasNext()) {
- Object child = childrenIterator.next();
- if (child instanceof Match) {
- if (!matchItemContentProvider.hasChildren(child)) {
- childrenIterator.remove();
- }
- }
-
- }
- } else {
- children = ImmutableList.of();
- }
- return children;
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.eclipse.emf.compare.provider.MatchItemProvider#getImage(java.lang.Object)
*/
@Override
@@ -177,7 +87,8 @@ public class ResourceAttachmentChangeItemProviderSpec extends ResourceAttachment
* @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object)
*/
public IComposedStyledString getStyledText(Object object) {
- final Match match = ((ResourceAttachmentChange)object).getMatch();
+ ResourceAttachmentChange resourceAttachmentChange = (ResourceAttachmentChange)object;
+ final Match match = resourceAttachmentChange.getMatch();
String value = AdapterFactoryUtil.getText(getRootAdapterFactory(), match.getLeft());
if (value == null) {
value = AdapterFactoryUtil.getText(getRootAdapterFactory(), match.getRight());
@@ -190,12 +101,20 @@ public class ResourceAttachmentChangeItemProviderSpec extends ResourceAttachment
}
ComposedStyledString ret = new ComposedStyledString(value);
+ ret.append(" [", Style.DECORATIONS_STYLER); //$NON-NLS-1$
+ switch (resourceAttachmentChange.getKind()) {
+ case ADD:
+ ret.append("controlled in ", Style.DECORATIONS_STYLER);
+ break;
+ case DELETE:
+ ret.append("uncontrolled from ", Style.DECORATIONS_STYLER);
+ break;
+ default:
+ break;
+ }
+ ret.append(resourceAttachmentChange.getResourceURI(), Style.DECORATIONS_STYLER);
- DifferenceKind labelValue = ((ResourceAttachmentChange)object).getKind();
- String label = labelValue == null ? "" : labelValue.toString().toLowerCase(); //$NON-NLS-1$
-
- return ret.append(" [resource contents " + label + "]", Style.DECORATIONS_STYLER); //$NON-NLS-1$ //$NON-NLS-2$
-
+ return ret.append("]", Style.DECORATIONS_STYLER); //$NON-NLS-1$
}
/**
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/plugin.xml b/plugins/org.eclipse.emf.compare.ide.ui/plugin.xml
index 124535c5e..c56f63b6a 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/plugin.xml
+++ b/plugins/org.eclipse.emf.compare.ide.ui/plugin.xml
@@ -64,9 +64,9 @@
<extension
point="org.eclipse.emf.edit.itemProviderAdapterFactories">
<factory
- class="org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider.CompareNodeAdapterFactory"
+ class="org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider.TreeCompareInputAdapterFactory"
supportedTypes="org.eclipse.compare.structuremergeviewer.ICompareInput"
- uri="http://www.eclipse.org/emf/compare">
+ uri="http://www.eclipse.org/emf/2002/Tree">
</factory>
</extension>
<extension
@@ -505,7 +505,7 @@
</enabledWhen>
</handler>
<handler
- class="org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.MergedToRight"
+ class="org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.MergeToRightHandler"
commandId="org.eclipse.emf.compare.ide.ui.mergedToRight">
<activeWhen>
<with
@@ -530,7 +530,7 @@
</enabledWhen>
</handler>
<handler
- class="org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.MergedAllToRight"
+ class="org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.MergeAllToRightHandler"
commandId="org.eclipse.emf.compare.ide.ui.mergedAllToRight">
<activeWhen>
<with
@@ -542,7 +542,7 @@
</activeWhen>
</handler>
<handler
- class="org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.MergedToLeft"
+ class="org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.MergeToLeftHandler"
commandId="org.eclipse.emf.compare.ide.ui.mergedToLeft">
<activeWhen>
<with
@@ -567,7 +567,7 @@
</enabledWhen>
</handler>
<handler
- class="org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.MergedAllToLeft"
+ class="org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.MergeAllToLeftHandler"
commandId="org.eclipse.emf.compare.ide.ui.mergedAllToLeft">
<activeWhen>
<with
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/text/EMFCompareTextMergeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/text/EMFCompareTextMergeViewer.java
index ce0816fef..890b8acc5 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/text/EMFCompareTextMergeViewer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/text/EMFCompareTextMergeViewer.java
@@ -60,7 +60,7 @@ import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.DynamicObject;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.RedoAction;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.UndoAction;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider.AttributeChangeNode;
+import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.CompareInputAdapter;
import org.eclipse.emf.compare.ide.ui.internal.util.SWTUtil;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
@@ -278,8 +278,10 @@ public class EMFCompareTextMergeViewer extends TextMergeViewer implements IPrope
protected void copyDiff(boolean leftToRight) {
Object input = getInput();
- if (input instanceof AttributeChangeNode) {
- final AttributeChange attributeChange = ((AttributeChangeNode)input).getTarget();
+ if (input instanceof CompareInputAdapter
+ && ((CompareInputAdapter)input).getComparisonObject() instanceof AttributeChange) {
+ final AttributeChange attributeChange = (AttributeChange)((CompareInputAdapter)input)
+ .getComparisonObject();
final Command copyCommand = getEditingDomain().createCopyCommand(
Collections.singletonList(attributeChange), leftToRight,
@@ -404,8 +406,9 @@ public class EMFCompareTextMergeViewer extends TextMergeViewer implements IPrope
public void run() {
// When we leave the current input
Object oldInput = getInput();
- if (oldInput instanceof AttributeChangeNode) {
- final AttributeChange diff = ((AttributeChangeNode)oldInput).getTarget();
+ if (oldInput instanceof CompareInputAdapter) {
+ final AttributeChange diff = (AttributeChange)((CompareInputAdapter)oldInput)
+ .getComparisonObject();
final EAttribute eAttribute = diff.getAttribute();
final Match match = diff.getMatch();
final IEqualityHelper equalityHelper = match.getComparison().getEqualityHelper();
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractEDiffNode.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/CompareInputAdapter.java
index a9a448ecc..6f995bdb2 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractEDiffNode.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/CompareInputAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Obeo.
+ * Copyright (c) 2013 Obeo.
* 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
@@ -16,7 +16,6 @@ import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
@@ -25,9 +24,11 @@ import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.MatchResource;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.accessor.AccessorAdapter;
+import org.eclipse.emf.compare.provider.AdapterFactoryUtil;
import org.eclipse.emf.compare.rcp.ui.EMFCompareRCPUIPlugin;
import org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.factory.IAccessorFactory;
-import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.swt.graphics.Image;
@@ -35,10 +36,10 @@ import org.eclipse.swt.graphics.Image;
/**
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
*/
-public abstract class AbstractEDiffNode extends AdapterImpl implements ICompareInput {
+public abstract class CompareInputAdapter extends AdapterImpl implements ICompareInput {
/**
- *
+ * Store the listeners for notifications.
*/
private final ListenerList fListener;
@@ -53,11 +54,16 @@ public abstract class AbstractEDiffNode extends AdapterImpl implements ICompareI
* @param adapterFactory
* the factory.
*/
- public AbstractEDiffNode(AdapterFactory adapterFactory) {
+ public CompareInputAdapter(AdapterFactory adapterFactory) {
fAdapterFactory = adapterFactory;
fListener = new ListenerList();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.notify.impl.AdapterImpl#isAdapterForType(java.lang.Object)
+ */
@Override
public boolean isAdapterForType(Object type) {
return type == fAdapterFactory;
@@ -100,7 +106,7 @@ public abstract class AbstractEDiffNode extends AdapterImpl implements ICompareI
final ICompareInputChangeListener listener = (ICompareInputChangeListener)listeners[i];
SafeRunnable runnable = new SafeRunnable() {
public void run() throws Exception {
- listener.compareInputChanged(AbstractEDiffNode.this);
+ listener.compareInputChanged(CompareInputAdapter.this);
}
};
SafeRunner.run(runnable);
@@ -110,6 +116,13 @@ public abstract class AbstractEDiffNode extends AdapterImpl implements ICompareI
/**
* {@inheritDoc}
+ */
+ public EObject getComparisonObject() {
+ return ((TreeNode)getTarget()).getData();
+ }
+
+ /**
+ * {@inheritDoc}
*
* @see org.eclipse.compare.structuremergeviewer.ICompareInput#copy(boolean)
*/
@@ -117,10 +130,15 @@ public abstract class AbstractEDiffNode extends AdapterImpl implements ICompareI
}
+ /**
+ * Returns the appropriate {@link IAccessorFactory} from the accessor factory registry.
+ *
+ * @return the appropriate {@link IAccessorFactory}.
+ */
protected IAccessorFactory getAccessorFactoryForTarget() {
IAccessorFactory.Registry factoryRegistry = EMFCompareRCPUIPlugin.getDefault()
.getAccessorFactoryRegistry();
- return factoryRegistry.getHighestRankingFactory(getTarget());
+ return factoryRegistry.getHighestRankingFactory(getComparisonObject());
}
/**
@@ -129,26 +147,40 @@ public abstract class AbstractEDiffNode extends AdapterImpl implements ICompareI
* @see org.eclipse.compare.ITypedElement#getImage()
*/
public Image getImage() {
- Image ret = null;
- Adapter adapter = getAdapterFactory().adapt(target, IItemLabelProvider.class);
- if (adapter instanceof IItemLabelProvider) {
- Object imageObject = ((IItemLabelProvider)adapter).getImage(target);
- ret = ExtendedImageRegistry.getInstance().getImage(imageObject);
- }
- return ret;
+ Object imageObject = AdapterFactoryUtil.getImage(getAdapterFactory(), getComparisonObject());
+ return ExtendedImageRegistry.getInstance().getImage(imageObject);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.compare.structuremergeviewer.ICompareInput#getKind()
+ */
public int getKind() {
+ Notifier notifier = getComparisonObject();
+ boolean isThreeWay = false;
+ if (notifier instanceof Diff) {
+ isThreeWay = ((Diff)notifier).getMatch().getComparison().isThreeWay();
+ } else if (notifier instanceof Match) {
+ isThreeWay = ((Match)notifier).getComparison().isThreeWay();
+ } else if (notifier instanceof Conflict) {
+ isThreeWay = true;
+ } else if (notifier instanceof MatchResource) {
+ isThreeWay = ((MatchResource)notifier).getComparison().isThreeWay();
+ }
+ if (isThreeWay) {
+ return Differencer.CONFLICTING;
+ }
return Differencer.NO_CHANGE;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.compare.structuremergeviewer.ICompareInput#getName()
+ */
public String getName() {
- String ret = null;
- Adapter adapter = getAdapterFactory().adapt(target, IItemLabelProvider.class);
- if (adapter instanceof IItemLabelProvider) {
- ret = ((IItemLabelProvider)adapter).getText(target);
- }
- return ret;
+ return AdapterFactoryUtil.getText(getAdapterFactory(), getComparisonObject());
}
/**
@@ -158,7 +190,7 @@ public abstract class AbstractEDiffNode extends AdapterImpl implements ICompareI
*/
public ITypedElement getAncestor() {
final ITypedElement ret;
- Notifier notifier = getTarget();
+ Notifier notifier = getComparisonObject();
boolean isThreeWay = false;
if (notifier instanceof Diff) {
isThreeWay = ((Diff)notifier).getMatch().getComparison().isThreeWay();
@@ -173,7 +205,7 @@ public abstract class AbstractEDiffNode extends AdapterImpl implements ICompareI
IAccessorFactory accessorFactory = getAccessorFactoryForTarget();
if (accessorFactory != null) {
org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.legacy.ITypedElement typedElement = accessorFactory
- .createAncestor(getAdapterFactory(), getTarget());
+ .createAncestor(getAdapterFactory(), getComparisonObject());
if (typedElement != null) {
ret = AccessorAdapter.adapt(typedElement);
} else {
@@ -198,7 +230,7 @@ public abstract class AbstractEDiffNode extends AdapterImpl implements ICompareI
IAccessorFactory accessorFactory = getAccessorFactoryForTarget();
if (accessorFactory != null) {
org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.legacy.ITypedElement typedElement = accessorFactory
- .createLeft(getAdapterFactory(), getTarget());
+ .createLeft(getAdapterFactory(), getComparisonObject());
if (typedElement != null) {
ret = AccessorAdapter.adapt(typedElement);
} else {
@@ -220,7 +252,7 @@ public abstract class AbstractEDiffNode extends AdapterImpl implements ICompareI
IAccessorFactory accessorFactory = getAccessorFactoryForTarget();
if (accessorFactory != null) {
org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.legacy.ITypedElement typedElement = accessorFactory
- .createRight(getAdapterFactory(), getTarget());
+ .createRight(getAdapterFactory(), getComparisonObject());
if (typedElement != null) {
ret = AccessorAdapter.adapt(typedElement);
} else {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/DiffNodeComparer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/CompareInputComparer.java
index cbb779b68..320fc4048 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/DiffNodeComparer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/CompareInputComparer.java
@@ -1,95 +1,95 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.jface.viewers.IElementComparer;
-
-/**
- * We'll use this in order to compare our diff nodes through their target's {@link Object#equals(Object)}
- * instead of the nodes' own equals (which only resorts to instance equality).
- * <p>
- * Note that this will fall back to the default behavior for anything that is not an
- * {@link AbstractEDiffElement}.
- * </p>
- * <p>
- * This class most likely breaks the implicit contract of equals() since we are comparing AbstractEDiffElement
- * through two different means : if we have a target, use it... otherwise fall back to instance equality. Both
- * equals() and hashCode() follow this same rule.
- * </p>
- *
- * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
- */
-public class DiffNodeComparer implements IElementComparer {
- /** Our delegate comparer. May be {@code null}. */
- private IElementComparer delegate;
-
- /**
- * Constructs this comparer given the previous one that was installed on this viewer.
- *
- * @param delegate
- * The comparer to which we should delegate our default behavior. May be {@code null}.
- */
- public DiffNodeComparer(IElementComparer delegate) {
- this.delegate = delegate;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.IElementComparer#equals(java.lang.Object, java.lang.Object)
- */
- public boolean equals(Object a, Object b) {
- final boolean equal;
- if (a instanceof Adapter && b instanceof Adapter) {
- final Notifier targetA = ((Adapter)a).getTarget();
- if (targetA == null) {
- // Fall back to default behavior
- equal = a.equals(b);
- } else {
- equal = targetA.equals(((Adapter)b).getTarget());
- }
- } else if (delegate != null) {
- equal = delegate.equals(a, b);
- } else if (a != null) {
- equal = a.equals(b);
- } else {
- equal = b == null;
- }
- return equal;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.IElementComparer#hashCode(java.lang.Object)
- */
- public int hashCode(Object element) {
- final int hashCode;
- if (element instanceof Adapter) {
- final Notifier target = ((Adapter)element).getTarget();
- if (target == null) {
- // Fall back to default behavior
- hashCode = element.hashCode();
- } else {
- hashCode = target.hashCode();
- }
- } else if (delegate != null) {
- hashCode = delegate.hashCode(element);
- } else if (element != null) {
- hashCode = element.hashCode();
- } else {
- hashCode = 0;
- }
- return hashCode;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.jface.viewers.IElementComparer;
+
+/**
+ * We'll use this in order to compare our diff nodes through their target's {@link Object#equals(Object)}
+ * instead of the nodes' own equals (which only resorts to instance equality).
+ * <p>
+ * Note that this will fall back to the default behavior for anything that is not an
+ * {@link AbstractEDiffElement}.
+ * </p>
+ * <p>
+ * This class most likely breaks the implicit contract of equals() since we are comparing AbstractEDiffElement
+ * through two different means : if we have a target, use it... otherwise fall back to instance equality. Both
+ * equals() and hashCode() follow this same rule.
+ * </p>
+ *
+ * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
+ */
+public class CompareInputComparer implements IElementComparer {
+ /** Our delegate comparer. May be {@code null}. */
+ private IElementComparer delegate;
+
+ /**
+ * Constructs this comparer given the previous one that was installed on this viewer.
+ *
+ * @param delegate
+ * The comparer to which we should delegate our default behavior. May be {@code null}.
+ */
+ public CompareInputComparer(IElementComparer delegate) {
+ this.delegate = delegate;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.IElementComparer#equals(java.lang.Object, java.lang.Object)
+ */
+ public boolean equals(Object a, Object b) {
+ final boolean equal;
+ if (a instanceof Adapter && b instanceof Adapter) {
+ final Notifier targetA = ((Adapter)a).getTarget();
+ if (targetA == null) {
+ // Fall back to default behavior
+ equal = a.equals(b);
+ } else {
+ equal = targetA.equals(((Adapter)b).getTarget());
+ }
+ } else if (delegate != null) {
+ equal = delegate.equals(a, b);
+ } else if (a != null) {
+ equal = a.equals(b);
+ } else {
+ equal = b == null;
+ }
+ return equal;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.IElementComparer#hashCode(java.lang.Object)
+ */
+ public int hashCode(Object element) {
+ final int hashCode;
+ if (element instanceof Adapter) {
+ final Notifier target = ((Adapter)element).getTarget();
+ if (target == null) {
+ // Fall back to default behavior
+ hashCode = element.hashCode();
+ } else {
+ hashCode = target.hashCode();
+ }
+ } else if (delegate != null) {
+ hashCode = delegate.hashCode(element);
+ } else if (element != null) {
+ hashCode = element.hashCode();
+ } else {
+ hashCode = 0;
+ }
+ return hashCode;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java
index 7cefbdb91..5b3c78ecf 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java
@@ -31,6 +31,8 @@ import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.internal.utils.DiffUtil;
import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -216,9 +218,12 @@ public class EMFCompareDiffTreeRuler extends Canvas {
Object element = ((IStructuredSelection)selection).getFirstElement();
if (element instanceof Adapter) {
Object target = ((Adapter)element).getTarget();
- if (target instanceof Diff) {
- selectedDiff = (Diff)target;
- computeConsequences();
+ if (target instanceof TreeNode) {
+ EObject data = ((TreeNode)target).getData();
+ if (data instanceof Diff) {
+ selectedDiff = (Diff)data;
+ computeConsequences();
+ }
}
}
}
@@ -274,8 +279,11 @@ public class EMFCompareDiffTreeRuler extends Canvas {
Object data = item.getData();
if (data instanceof Adapter) {
Notifier target = ((Adapter)data).getTarget();
- if (diffs.contains(target)) {
- diffItems.put((Diff)target, item);
+ if (target instanceof TreeNode) {
+ EObject treeNodeData = ((TreeNode)target).getData();
+ if (diffs.contains(treeNodeData)) {
+ diffItems.put((Diff)treeNodeData, item);
+ }
}
}
for (TreeItem child : item.getItems()) {
@@ -496,13 +504,15 @@ public class EMFCompareDiffTreeRuler extends Canvas {
*/
private TreeItem getDeepestVisibleTreeItem(final TreeItem currentItem, final TreeItem deepestVisibleItem) {
TreeItem item = null;
- TreeItem parent = currentItem.getParentItem();
- if (parent == null) {
- item = deepestVisibleItem;
- } else if (parent.getExpanded()) {
- item = getDeepestVisibleTreeItem(parent, deepestVisibleItem);
- } else {
- item = getDeepestVisibleTreeItem(parent, parent);
+ if (!currentItem.isDisposed()) {
+ TreeItem parent = currentItem.getParentItem();
+ if (parent == null) {
+ item = deepestVisibleItem;
+ } else if (parent.getExpanded()) {
+ item = getDeepestVisibleTreeItem(parent, deepestVisibleItem);
+ } else {
+ item = getDeepestVisibleTreeItem(parent, parent);
+ }
}
return item;
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java
index d5171601d..fde2f0e1a 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java
@@ -28,6 +28,7 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceSource;
@@ -44,6 +45,9 @@ import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.Stru
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.StructureMergeViewerGrouper;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl.DefaultGroupProvider;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.MenuManager;
@@ -156,8 +160,7 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
setLabelProvider(new DelegatingStyledCellLabelProvider(
new EMFCompareStructureMergeViewerLabelProvider(adapterFactory, this)));
- setContentProvider(new EMFCompareStructureMergeViewerContentProvider(adapterFactory,
- getStructureMergeViewerGrouper(), getStructureMergeViewerFilter(), configuration));
+ setContentProvider(new EMFCompareStructureMergeViewerContentProvider(adapterFactory));
if (parent instanceof CompareViewerSwitchingPane) {
fParent = (CompareViewerSwitchingPane)parent;
@@ -187,7 +190,7 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
getControl().addListener(SWT.EraseItem, fEraseItemListener);
// Wrap the defined comparer in our own.
- setComparer(new DiffNodeComparer(super.getComparer()));
+ setComparer(new CompareInputComparer(super.getComparer()));
if (eventBus == null) {
eventBus = new EventBus();
@@ -239,6 +242,13 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
@Subscribe
public void recordGroupProviderSelectionChange(IDifferenceGroupProvider differenceGroupProvider) {
+ EList<Adapter> eAdapters = ((Adapter)fRoot).getTarget().eAdapters();
+ IDifferenceGroupProvider oldDifferenceGroupProvider = (IDifferenceGroupProvider)EcoreUtil.getAdapter(
+ eAdapters, IDifferenceGroupProvider.class);
+ if (oldDifferenceGroupProvider != null) {
+ eAdapters.remove(oldDifferenceGroupProvider);
+ }
+ eAdapters.add(differenceGroupProvider);
getCompareConfiguration().setProperty(EMFCompareConstants.SELECTED_GROUP, differenceGroupProvider);
}
@@ -367,7 +377,7 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
@Override
public void setComparer(IElementComparer comparer) {
// Wrap this new comparer in our own
- super.setComparer(new DiffNodeComparer(comparer));
+ super.setComparer(new CompareInputComparer(comparer));
}
/**
@@ -522,10 +532,7 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
* @return The default group provider that is to be applied on the structure viewer.
*/
public DefaultGroupProvider getDefaultGroupProvider() {
- if (defaultGroupProvider == null) {
- defaultGroupProvider = new DefaultGroupProvider();
- }
- return defaultGroupProvider;
+ return new DefaultGroupProvider();
}
/**
@@ -548,28 +555,38 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
@Override
protected Object[] getSortedChildren(Object parentElementOrTreePath) {
Object[] result = super.getSortedChildren(parentElementOrTreePath);
- if (parentElementOrTreePath instanceof Adapter
- && ((Adapter)parentElementOrTreePath).getTarget() instanceof Conflict) {
-
- Collections.sort(Arrays.asList(result), new Comparator<Object>() {
- public int compare(Object o1, Object o2) {
- return getValue(o1) - getValue(o2);
- }
+ if (parentElementOrTreePath instanceof Adapter) {
+ Notifier target = ((Adapter)parentElementOrTreePath).getTarget();
+ if (target instanceof TreeNode) {
+ EObject data = ((TreeNode)target).getData();
+ if (data instanceof Conflict) {
+ Collections.sort(Arrays.asList(result), new Comparator<Object>() {
+ public int compare(Object o1, Object o2) {
+ return getValue(o1) - getValue(o2);
+ }
- public int getValue(Object o) {
- int value = 0;
- if (o instanceof Adapter && ((Adapter)o).getTarget() instanceof Diff) {
- if (((Diff)((Adapter)o).getTarget()).getSource() == DifferenceSource.LEFT) {
- value = 1;
- } else {
- value = 2;
+ public int getValue(Object o) {
+ int value = 0;
+ if (o instanceof Adapter) {
+ Notifier n = ((Adapter)o).getTarget();
+ if (n instanceof TreeNode) {
+ EObject d = ((TreeNode)n).getData();
+ if (d instanceof Diff) {
+ if (((Diff)d).getSource() == DifferenceSource.LEFT) {
+ value = 1;
+ } else {
+ value = 2;
+ }
+ }
+ }
+ }
+ return value;
}
- }
- return value;
+ });
}
- });
-
+ }
}
+
return result;
}
@@ -585,35 +602,42 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
Object firstElement = ((IStructuredSelection)selection).getFirstElement();
if (firstElement instanceof Adapter) {
Notifier target = ((Adapter)firstElement).getTarget();
- if (target instanceof Diff) {
- TreeItem item = (TreeItem)event.item;
- Object dataTreeItem = item.getData();
- if (dataTreeItem instanceof Adapter) {
- final Set<Diff> unmergeables;
- final Set<Diff> requires;
- Boolean leftToRight = (Boolean)getCompareConfiguration().getProperty(
- EMFCompareConstants.MERGE_WAY);
- boolean ltr = false;
- if (leftToRight == null || leftToRight.booleanValue()) {
- ltr = true;
- }
- boolean leftEditable = getCompareConfiguration().isLeftEditable();
- boolean rightEditable = getCompareConfiguration().isRightEditable();
- boolean bothSidesEditable = leftEditable && rightEditable;
- Diff diff = (Diff)target;
- if ((ltr && (leftEditable || bothSidesEditable))
- || (!ltr && (rightEditable && !leftEditable))) {
- requires = DiffUtil.getRequires(diff, true, diff.getSource());
- unmergeables = DiffUtil.getUnmergeables(diff, true);
- } else {
- requires = DiffUtil.getRequires(diff, false, diff.getSource());
- unmergeables = DiffUtil.getUnmergeables(diff, false);
- }
- final GC g = event.gc;
- if (requires.contains(((Adapter)dataTreeItem).getTarget())) {
- paintItemBackground(g, item, requiredDiffColor);
- } else if (unmergeables.contains(((Adapter)dataTreeItem).getTarget())) {
- paintItemBackground(g, item, unmergeableDiffColor);
+ if (target instanceof TreeNode) {
+ EObject selectionData = ((TreeNode)target).getData();
+ if (selectionData instanceof Diff) {
+ TreeItem item = (TreeItem)event.item;
+ Object dataTreeItem = item.getData();
+ if (dataTreeItem instanceof Adapter) {
+ Notifier targetItem = ((Adapter)dataTreeItem).getTarget();
+ if (targetItem instanceof TreeNode) {
+ EObject dataItem = ((TreeNode)targetItem).getData();
+ final Set<Diff> unmergeables;
+ final Set<Diff> requires;
+ Boolean leftToRight = (Boolean)getCompareConfiguration().getProperty(
+ EMFCompareConstants.MERGE_WAY);
+ boolean ltr = false;
+ if (leftToRight == null || leftToRight.booleanValue()) {
+ ltr = true;
+ }
+ boolean leftEditable = getCompareConfiguration().isLeftEditable();
+ boolean rightEditable = getCompareConfiguration().isRightEditable();
+ boolean bothSidesEditable = leftEditable && rightEditable;
+ Diff diff = (Diff)selectionData;
+ if ((ltr && (leftEditable || bothSidesEditable))
+ || (!ltr && (rightEditable && !leftEditable))) {
+ requires = DiffUtil.getRequires(diff, true, diff.getSource());
+ unmergeables = DiffUtil.getUnmergeables(diff, true);
+ } else {
+ requires = DiffUtil.getRequires(diff, false, diff.getSource());
+ unmergeables = DiffUtil.getUnmergeables(diff, false);
+ }
+ final GC g = event.gc;
+ if (requires.contains(dataItem)) {
+ paintItemBackground(g, item, requiredDiffColor);
+ } else if (unmergeables.contains(dataItem)) {
+ paintItemBackground(g, item, unmergeableDiffColor);
+ }
+ }
}
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java
index a9968c40e..f6c9b4494 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java
@@ -35,7 +35,6 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.command.CommandStackListener;
-import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.EMFCompare;
@@ -51,7 +50,6 @@ import org.eclipse.emf.compare.ide.ui.internal.logical.ComparisonScopeBuilder;
import org.eclipse.emf.compare.ide.ui.internal.logical.IdenticalResourceMinimizer;
import org.eclipse.emf.compare.ide.ui.internal.logical.StreamAccessorStorage;
import org.eclipse.emf.compare.ide.ui.internal.logical.SubscriberStorageAccessor;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider.ComparisonNode;
import org.eclipse.emf.compare.ide.ui.internal.util.PlatformElementUtil;
import org.eclipse.emf.compare.ide.ui.internal.util.SWTUtil;
import org.eclipse.emf.compare.ide.ui.logical.IModelResolver;
@@ -65,6 +63,8 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
+import org.eclipse.emf.edit.tree.TreeFactory;
+import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ITreeViewerListener;
@@ -92,8 +92,10 @@ import org.eclipse.ui.actions.ActionFactory;
*/
public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implements CommandStackListener {
+ /** The width of the tree ruler. */
private static final int TREE_RULER_WIDTH = 17;
+ /** The adapter factory. */
private ComposedAdapterFactory fAdapterFactory;
/** The tree ruler associated with this viewer. */
@@ -110,10 +112,13 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
/** The tree viewer. */
private EMFCompareDiffTreeViewer diffTreeViewer;
+ /** The undo action. */
private UndoAction undoAction;
+ /** The redo action. */
private RedoAction redoAction;
+ /** The compare handler service. */
private CompareHandlerService fHandlerService;
/**
@@ -251,6 +256,7 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
compareInputChanged(ci);
}
+ getViewer().setInput(input);
}
/**
@@ -304,13 +310,17 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
if (!affectedObjects.isEmpty()) {
// MUST NOT call a setSelection with a list, o.e.compare does not handle it (cf
// org.eclipse.compare.CompareEditorInput#getElement(ISelection))
- final Object adaptedAffectedObject = fAdapterFactory.adapt(getFirst(affectedObjects, null),
- ICompareInput.class);
- SWTUtil.safeAsyncExec(new Runnable() {
- public void run() {
- setSelectionToWidget(new StructuredSelection(adaptedAffectedObject), true);
- }
- });
+ Object first = getFirst(affectedObjects, null);
+ if (first instanceof EObject) {
+ TreeNode treeNode = TreeFactory.eINSTANCE.createTreeNode();
+ treeNode.setData((EObject)first);
+ final Object adaptedAffectedObject = fAdapterFactory.adapt(treeNode, ICompareInput.class);
+ SWTUtil.safeAsyncExec(new Runnable() {
+ public void run() {
+ setSelectionToWidget(new StructuredSelection(adaptedAffectedObject), true);
+ }
+ });
+ }
}
} else {
// FIXME, should recompute the difference, something happened outside of this compare editor
@@ -343,12 +353,12 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
}
}
- void compareInputChanged(ComparisonNode input, IProgressMonitor monitor) {
+ void compareInputChanged(CompareInputAdapter input, IProgressMonitor monitor) {
ICompareEditingDomain editingDomain = (ICompareEditingDomain)getCompareConfiguration().getProperty(
EMFCompareConstants.EDITING_DOMAIN);
editingDomain.getCommandStack().addCommandStackListener(this);
- compareInputChanged(null, input.getTarget());
+ compareInputChanged(null, (Comparison)input.getComparisonObject());
}
void compareInputChanged(ComparisonScopeInput input, IProgressMonitor monitor) {
@@ -366,7 +376,11 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
void compareInputChanged(final IComparisonScope scope, final Comparison comparison) {
if (!getControl().isDisposed()) { // guard against disposal
- diffTreeViewer.setRoot(fAdapterFactory.adapt(comparison, ICompareInput.class));
+ TreeNode treeNode = TreeFactory.eINSTANCE.createTreeNode();
+ treeNode.setData(comparison);
+ treeNode.eAdapters().add(diffTreeViewer.getDefaultGroupProvider());
+
+ diffTreeViewer.setRoot(fAdapterFactory.adapt(treeNode, ICompareInput.class));
getCompareConfiguration().setProperty(EMFCompareConstants.COMPARE_RESULT, comparison);
String message = null;
@@ -403,9 +417,9 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
void compareInputChanged(ICompareInput input, IProgressMonitor monitor) {
if (input != null) {
- if (input instanceof ComparisonNode) {
+ if (input instanceof CompareInputAdapter) {
resourcesShouldBeUnload = false;
- compareInputChanged((ComparisonNode)input, monitor);
+ compareInputChanged((CompareInputAdapter)input, monitor);
} else if (input instanceof ComparisonScopeInput) {
resourcesShouldBeUnload = false;
compareInputChanged((ComparisonScopeInput)input, monitor);
@@ -452,7 +466,8 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
ResourceSet originResourceSet = null;
if (diffTreeViewer.getRoot() != null) {
- Comparison comparison = (Comparison)((Adapter)diffTreeViewer.getRoot()).getTarget();
+ Comparison comparison = (Comparison)((CompareInputAdapter)diffTreeViewer.getRoot())
+ .getComparisonObject();
Iterator<Match> matchIt = comparison.getMatches().iterator();
if (comparison.isThreeWay()) {
while (matchIt.hasNext()
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewerContentProvider.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewerContentProvider.java
index 901488d5b..93656cbc7 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewerContentProvider.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewerContentProvider.java
@@ -10,46 +10,17 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer;
-import static com.google.common.base.Predicates.not;
-import static com.google.common.base.Predicates.or;
-import static com.google.common.collect.Iterables.filter;
-import static com.google.common.collect.Iterables.isEmpty;
import static com.google.common.collect.Iterables.toArray;
import static com.google.common.collect.Iterables.transform;
import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.List;
-
-import org.eclipse.compare.CompareConfiguration;
-import org.eclipse.compare.ITypedElement;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
-import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Conflict;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.ReferenceChange;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider.ComparisonNode;
-import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.StructureMergeViewerFilter;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.StructureMergeViewerGrouper;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl.ThreeWayComparisonGroupProvider;
-import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.provider.ItemProviderAdapter;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
-import org.eclipse.swt.graphics.Image;
/**
* Specialized AdapterFactoryContentProvider for the emf compare structure merge viewer.
@@ -58,34 +29,14 @@ import org.eclipse.swt.graphics.Image;
*/
class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryContentProvider {
- /** The viewer grouper associated with this content provider. */
- private final StructureMergeViewerGrouper fViewerGrouper;
-
- /** The viewer filter associated with this content provider. */
- private final StructureMergeViewerFilter fViewerFilter;
-
- /** The configuration associated with this content provider. */
- private final CompareConfiguration configuration;
-
/**
* Constructs the content provider with the appropriate adapter factory.
*
* @param adapterFactory
* The adapter factory used to construct the content provider.
- * @param structureMergeViewerGrouper
- * The viewer grouper associated with this content provider.
- * @param structureMergeViewerFilter
- * The viewer filter associated with this content provider.
- * @param configuration
- * The configuration associated with this content provider.
*/
- public EMFCompareStructureMergeViewerContentProvider(AdapterFactory adapterFactory,
- StructureMergeViewerGrouper structureMergeViewerGrouper,
- StructureMergeViewerFilter structureMergeViewerFilter, CompareConfiguration configuration) {
+ public EMFCompareStructureMergeViewerContentProvider(AdapterFactory adapterFactory) {
super(adapterFactory);
- this.fViewerGrouper = structureMergeViewerGrouper;
- this.fViewerFilter = structureMergeViewerFilter;
- this.configuration = configuration;
}
/**
@@ -95,25 +46,13 @@ class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryConten
*/
@Override
public Object getParent(Object element) {
- Object ret;
- if (element instanceof Adapter) {
- ret = getAdapterFactory().adapt(super.getParent(((Adapter)element).getTarget()),
- ICompareInput.class);
- if (ret instanceof ComparisonNode) {
- Comparison root = ((ComparisonNode)ret).getTarget();
- final Iterable<? extends IDifferenceGroup> groups = fViewerGrouper.getGroups(root);
- Collection<IDifferenceGroup> parentGroups = new LinkedHashSet<IDifferenceGroup>();
- for (IDifferenceGroup iDifferenceGroup : groups) {
- parentGroups.add(iDifferenceGroup);
- }
- if (!parentGroups.isEmpty()) {
- ret = parentGroups;
- }
- }
- } else if (element instanceof IDifferenceGroup) {
- ret = getAdapterFactory().adapt(((IDifferenceGroup)element).getComparison(), ICompareInput.class);
+ final Object ret;
+ if (element instanceof ItemProviderAdapter) {
+ ret = super.getParent(element);
+ } else if (element instanceof Adapter) {
+ ret = super.getParent(((Adapter)element).getTarget());
} else {
- ret = null;
+ ret = super.getParent(element);
}
return ret;
}
@@ -126,16 +65,8 @@ class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryConten
@Override
public final boolean hasChildren(Object element) {
final boolean ret;
- if (element instanceof ComparisonNode) {
- Comparison target = ((ComparisonNode)element).getTarget();
- final Iterable<? extends IDifferenceGroup> groups = fViewerGrouper.getGroups(target);
- if (isEmpty(groups)) {
- ret = super.hasChildren(((Adapter)element).getTarget());
- } else {
- ret = true;
- }
- } else if (element instanceof IDifferenceGroup) {
- ret = !isEmpty(((IDifferenceGroup)element).getDifferences());
+ if (element instanceof ItemProviderAdapter) {
+ ret = super.hasChildren(element);
} else if (element instanceof Adapter) {
ret = super.hasChildren(((Adapter)element).getTarget());
} else {
@@ -151,46 +82,17 @@ class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryConten
*/
@Override
public final Object[] getChildren(Object element) {
- final Object[] ret;
- if (element instanceof ComparisonNode) {
- Comparison target = ((ComparisonNode)element).getTarget();
- final Iterable<? extends IDifferenceGroup> groups = fViewerGrouper.getGroups(target);
- if (!isEmpty(groups)) {
- ret = toArray(groups, IDifferenceGroup.class);
- } else {
- Iterable<ICompareInput> compareInputs = adapt(super.getChildren(((Adapter)element)
- .getTarget()), getAdapterFactory(), ICompareInput.class);
- ret = toArray(compareInputs, ICompareInput.class);
- }
- } else if (element instanceof IDifferenceGroup) {
- final Comparison target = ((IDifferenceGroup)element).getComparison();
- Iterable<ICompareInput> compareInputs = null;
- if (isThreeWayComparisonGroupProviderEnabled()
- && ("Conflicts".equals(((IDifferenceGroup)element).getName()))) {
- compareInputs = adapt(target.getConflicts(), getAdapterFactory(), ICompareInput.class);
- } else {
- compareInputs = adapt(super.getChildren(target), getAdapterFactory(), ICompareInput.class);
- }
- Iterable<FilteredEDiffNode> filteredCompareInputs = filteredEDiffNodes(filter(compareInputs,
- AbstractEDiffNode.class), ((IDifferenceGroup)element).getDifferences());
- ret = toArray(filteredCompareInputs, FilteredEDiffNode.class);
- } else if (element instanceof FilteredEDiffNode) {
- Notifier target = ((Adapter)element).getTarget();
- final Iterable<Object> children = filteredElements(super.getChildren(target),
- ((FilteredEDiffNode)element).getDifferences());
- Iterable<ICompareInput> compareInputs = adapt(children, getAdapterFactory(), ICompareInput.class);
- Iterable<FilteredEDiffNode> filteredCompareInputs = filteredEDiffNodes(filter(compareInputs,
- AbstractEDiffNode.class), ((FilteredEDiffNode)element).getDifferences());
- ret = toArray(filteredCompareInputs, FilteredEDiffNode.class);
+ final Object[] children;
+ if (element instanceof ItemProviderAdapter) {
+ children = super.getChildren(element);
} else if (element instanceof Adapter) {
- final Iterable<Object> children = Lists.newArrayList(super.getChildren(((Adapter)element)
- .getTarget()));
- Iterable<ICompareInput> compareInputs = adapt(children, getAdapterFactory(), ICompareInput.class);
- ret = toArray(compareInputs, ICompareInput.class);
+ children = super.getChildren(((Adapter)element).getTarget());
} else {
- ret = new Object[0];
+ children = super.getChildren(element);
}
- return ret;
+
+ Iterable<?> compareInputs = adapt(children, getAdapterFactory(), ICompareInput.class);
+ return toArray(compareInputs, Object.class);
}
/**
@@ -204,25 +106,6 @@ class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryConten
}
/**
- * Checks the state of the three way comparison group provider.
- *
- * @return true, if the three way comparison group provider is enabled, false otherwise.
- */
- private boolean isThreeWayComparisonGroupProviderEnabled() {
- Object property = configuration.getProperty(EMFCompareConstants.SELECTED_GROUP);
- final IDifferenceGroupProvider selectedGroup;
- if (property == null) {
- return false;
- } else {
- selectedGroup = (IDifferenceGroupProvider)property;
- if (selectedGroup instanceof ThreeWayComparisonGroupProvider) {
- return true;
- }
- }
- return false;
- }
-
- /**
* Adapts each elements of the the given <code>iterable</code> to the given <code>type</code> by using the
* given <code>adapterFactory</code>.
*
@@ -236,14 +119,18 @@ class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryConten
* the target type of adapted elements.
* @return an iterable with element of type <code>type</code>.
*/
- static <T> Iterable<T> adapt(Iterable<?> iterable, final AdapterFactory adapterFactory,
- final Class<T> type) {
+ private static Iterable<?> adapt(Iterable<?> iterable, final AdapterFactory adapterFactory,
+ final Class<?> type) {
Function<Object, Object> adaptFunction = new Function<Object, Object>() {
public Object apply(Object input) {
- return adapterFactory.adapt(input, type);
+ Object ret = adapterFactory.adapt(input, type);
+ if (ret == null) {
+ return input;
+ }
+ return ret;
}
};
- return filter(transform(iterable, adaptFunction), type);
+ return transform(iterable, adaptFunction);
}
/**
@@ -260,278 +147,8 @@ class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryConten
* the target type of adapted elements
* @return an iterable with element of type <code>type</code>.
*/
- static <T> Iterable<T> adapt(Object[] iterable, final AdapterFactory adapterFactory, final Class<T> type) {
+ private static Iterable<?> adapt(Object[] iterable, final AdapterFactory adapterFactory,
+ final Class<?> type) {
return adapt(Lists.newArrayList(iterable), adapterFactory, type);
}
-
- /**
- * Filter out each element of the given <code>array</code> that should not be contained in the given
- * differences.
- *
- * @param unfiltered
- * the array to filter.
- * @param differences
- * the given iterable of {@link Diff}.
- * @return an iterable of elements that should be contained in the given differences.
- */
- private Iterable<Object> filteredElements(Object[] unfiltered, final Iterable<? extends Diff> differences) {
- return filteredElements(Lists.newArrayList(unfiltered), differences);
- }
-
- /**
- * Filter out each element of the given unflitered iterable that is not part of the given group of
- * differences.
- *
- * @param unfiltered
- * the iterable to filter.
- * @param differences
- * the given iterable of {@link Diff}.
- * @return an iterable of elements that should be contained in the given differences.
- */
- private Iterable<Object> filteredElements(Iterable<Object> unfiltered,
- final Iterable<? extends Diff> differences) {
- final List<? extends Diff> filteredDiffs = ImmutableList.copyOf(filter(differences,
- not(or(fViewerFilter.getPredicates()))));
-
- final Predicate<? super Object> isPartOfTree = new Predicate<Object>() {
- public boolean apply(Object input) {
- return isPartOfGroup(input, filteredDiffs);
- }
- };
-
- return filter(unfiltered, isPartOfTree);
- }
-
- /**
- * Returns whether this object should be contained in the given differences.
- *
- * @param object
- * the object to filter.
- * @param diffGroup
- * the given differences.
- * @return true if the object should be contained in the given differences, false otherwise.
- */
- public static boolean isPartOfGroup(Object object, final Iterable<? extends Diff> differences) {
- final Predicate<? super EObject> isPartOfTree = new Predicate<EObject>() {
- public boolean apply(EObject input) {
- return Iterables.contains(differences, input);
- }
- };
- boolean ret = false;
- if (object instanceof Match) {
- ret = Iterables.any(((Match)object).getAllDifferences(), isPartOfTree);
- } else if (object instanceof Diff) {
- if (!isPartOfTree.apply((Diff)object)) {
- if (object instanceof ReferenceChange
- && ((ReferenceChange)object).getReference().isContainment()) {
- Match match = ((Diff)object).getMatch().getComparison().getMatch(
- ((ReferenceChange)object).getValue());
- if (match != null) {
- ret = Iterables.any(match.getAllDifferences(), isPartOfTree);
- } else {
- ret = false;
- }
- }
- } else {
- ret = true;
- }
- }
- return ret;
- }
-
- /**
- * Creates an iterable of {@link FilteredEDiffNode} from an iterable of {@link AbstractEDiffNode} and an
- * iterable of {@link Diff}.
- *
- * @param iterable
- * the iterable of {@link AbstractEDiffNode} to transform.
- * @param differences
- * the iterable of {@link Diff} to associate with the FilteredEDiffNodes.
- * @return an iterable of {@link FilteredEDiffNode}.
- */
- private Iterable<FilteredEDiffNode> filteredEDiffNodes(Iterable<AbstractEDiffNode> iterable,
- final Iterable<? extends Diff> differences) {
- Function<AbstractEDiffNode, FilteredEDiffNode> adaptFunction = new Function<AbstractEDiffNode, FilteredEDiffNode>() {
- public FilteredEDiffNode apply(AbstractEDiffNode input) {
- return new FilteredEDiffNode(input, differences);
- }
- };
- return transform(iterable, adaptFunction);
- }
-
- /**
- * AbstractEDiffNodes that know a list of differences (from a {@link IDifferenceGroup} or a
- * {@link Conflict}). This class wraps an AbstractEDiffNode and it delegates its interfaces to
- * corresponding AbstractEDiffNode implemented interfaces.
- *
- * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
- */
- public class FilteredEDiffNode implements ICompareInput, Adapter {
-
- /** The AbstractEDiffNode wrapped. */
- private AbstractEDiffNode fDelegate;
-
- /** The differences associated with the node. */
- private Iterable<? extends Diff> differences;
-
- /**
- * This constructs an instance that wraps this {@link AbstractEDiffNode} and associate it with the
- * given differences.
- *
- * @param delegate
- * the given AbstractEDiffNode.
- * @param differences
- * the given differences (from a {@link IDifferenceGroup} or a {@link Conflict}).
- */
- public FilteredEDiffNode(AbstractEDiffNode delegate, Iterable<? extends Diff> differences) {
- fDelegate = delegate;
- this.differences = differences;
- }
-
- /**
- * Returns the backing delegate instance that methods are forwarded to.
- *
- * @return the wrapped AbstractEDiffNode.
- */
- public AbstractEDiffNode delegate() {
- return fDelegate;
- }
-
- /**
- * Returns the differences associated with the wrapped {@link AbstractEDiffNode}.
- *
- * @return the difference group.
- */
- public Iterable<? extends Diff> getDifferences() {
- return differences;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.compare.structuremergeviewer.ICompareInput#getName()
- */
- public String getName() {
- return delegate().getName();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.compare.structuremergeviewer.ICompareInput#getImage()
- */
- public Image getImage() {
- return delegate().getImage();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.compare.structuremergeviewer.ICompareInput#getKind()
- */
- public int getKind() {
- return delegate().getKind();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.compare.structuremergeviewer.ICompareInput#getAncestor()
- */
- public ITypedElement getAncestor() {
- return delegate().getAncestor();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.compare.structuremergeviewer.ICompareInput#getLeft()
- */
- public ITypedElement getLeft() {
- return delegate().getLeft();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.compare.structuremergeviewer.ICompareInput#getRight()
- */
- public ITypedElement getRight() {
- return delegate().getRight();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.compare.structuremergeviewer.ICompareInput#addCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener)
- */
- public void addCompareInputChangeListener(ICompareInputChangeListener listener) {
- delegate().addCompareInputChangeListener(listener);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.compare.structuremergeviewer.ICompareInput#removeCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener)
- */
- public void removeCompareInputChangeListener(ICompareInputChangeListener listener) {
- delegate().removeCompareInputChangeListener(listener);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.compare.structuremergeviewer.ICompareInput#copy(boolean)
- */
- public void copy(boolean leftToRight) {
- delegate().copy(leftToRight);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.common.notify.Adapter#notifyChanged(org.eclipse.emf.common.notify.Notification)
- */
- public void notifyChanged(Notification notification) {
- delegate().notifyChanged(notification);
-
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.common.notify.Adapter#getTarget()
- */
- public Notifier getTarget() {
- return delegate().getTarget();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.common.notify.Adapter#setTarget(org.eclipse.emf.common.notify.Notifier)
- */
- public void setTarget(Notifier newTarget) {
- delegate().setTarget(newTarget);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.common.notify.Adapter#isAdapterForType(Object)
- */
- public boolean isAdapterForType(Object type) {
- return delegate().isAdapterForType(type);
- }
-
- @Override
- public boolean equals(Object obj) {
- return delegate().equals(obj);
- }
-
- @Override
- public int hashCode() {
- return delegate().hashCode();
- }
- }
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewerLabelProvider.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewerLabelProvider.java
index 3d96ab33c..b0e7b474a 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewerLabelProvider.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewerLabelProvider.java
@@ -10,15 +10,11 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer;
-import com.google.common.base.Preconditions;
-
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.compare.ide.ui.internal.util.StyledStringConverter;
import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
-import org.eclipse.emf.compare.rcp.ui.EMFCompareRCPUIPlugin;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup;
+import org.eclipse.emf.edit.provider.ItemProviderAdapter;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.StyledString;
@@ -34,6 +30,8 @@ import org.eclipse.swt.graphics.Image;
*/
class EMFCompareStructureMergeViewerLabelProvider extends AdapterFactoryLabelProvider.FontAndColorProvider implements IStyledLabelProvider {
+ protected StyledStringConverter styledStringConverter;
+
/**
* Constructor calling super {@link #FontAndColorProvider(AdapterFactory, Viewer)}.
*
@@ -103,15 +101,10 @@ class EMFCompareStructureMergeViewerLabelProvider extends AdapterFactoryLabelPro
@Override
public Image getImage(Object element) {
final Image ret;
- if (element instanceof Adapter) {
+ if (element instanceof ItemProviderAdapter) {
+ ret = super.getImage(element);
+ } else if (element instanceof Adapter) {
ret = super.getImage(((Adapter)element).getTarget());
- } else if (element instanceof IDifferenceGroup) {
- final Image groupImage = ((IDifferenceGroup)element).getImage();
- if (groupImage != null) {
- ret = groupImage;
- } else {
- ret = EMFCompareRCPUIPlugin.getImage("icons/full/toolb16/group.gif"); //$NON-NLS-1$
- }
} else {
ret = super.getImage(element);
}
@@ -128,23 +121,14 @@ class EMFCompareStructureMergeViewerLabelProvider extends AdapterFactoryLabelPro
*/
public StyledString getStyledText(Object element) {
final StyledString ret;
- if (element instanceof Adapter) {
- Notifier target = ((Adapter)element).getTarget();
- StyledString styledText = getStyledText(getAdapterFactory(), target);
- if (styledText == null) {
- ret = new StyledString(super.getText(target));
- } else {
- ret = styledText;
- }
- } else if (element instanceof IDifferenceGroup) {
- StyledStringConverter stringConverter = new StyledStringConverter(getDefaultFont(),
- getDefaultForeground(), getDefaultBackground());
- return stringConverter.toJFaceStyledString(((IDifferenceGroup)element).getStyledName());
+ if (element instanceof ItemProviderAdapter) {
+ ret = getStyledTextFromObject(element);
+ } else if (element instanceof Adapter) {
+ ret = getStyledTextFromObject(((Adapter)element).getTarget());
} else {
- ret = new StyledString(super.getText(element));
+ ret = getStyledTextFromObject(element);
}
return ret;
-
}
/**
@@ -153,27 +137,35 @@ class EMFCompareStructureMergeViewerLabelProvider extends AdapterFactoryLabelPro
* {@link IItemStyledLabelProvider#getStyledText(Object) text}. Returns null if <code>object</code> is
* null.
*
- * @param adapterFactory
- * the adapter factory to adapt from
* @param object
* the object from which we want a text
* @return the text, or null if object is null.
* @throws NullPointerException
* if <code>adapterFactory</code> is null.
*/
- private StyledString getStyledText(final AdapterFactory adapterFactory, final Object object) {
- Preconditions.checkNotNull(adapterFactory);
+ private StyledString getStyledTextFromObject(final Object object) {
if (object == null) {
return null;
}
StyledString ret = null;
- Object itemStyledLabelProvider = adapterFactory.adapt(object, IItemStyledLabelProvider.class);
+ Object itemStyledLabelProvider = getAdapterFactory().adapt(object, IItemStyledLabelProvider.class);
if (itemStyledLabelProvider instanceof IItemStyledLabelProvider) {
- StyledStringConverter stringConverter = new StyledStringConverter(getDefaultFont(),
- getDefaultForeground(), getDefaultBackground());
- ret = stringConverter.toJFaceStyledString(((IItemStyledLabelProvider)itemStyledLabelProvider)
- .getStyledText(object));
+ ret = getStyledStringConverter().toJFaceStyledString(
+ ((IItemStyledLabelProvider)itemStyledLabelProvider).getStyledText(object));
}
return ret;
}
+
+ /**
+ * Returns the StyledStringConverter used to convert emf compare styled strings to jface styled strings.
+ *
+ * @return the styledStringConverter.
+ */
+ protected StyledStringConverter getStyledStringConverter() {
+ if (styledStringConverter == null) {
+ styledStringConverter = new StyledStringConverter(getDefaultFont(), getDefaultForeground(),
+ getDefaultBackground());
+ }
+ return styledStringConverter;
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedAllTo.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergeAllHandler.java
index 0cc28123a..1c9b059b3 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedAllTo.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergeAllHandler.java
@@ -25,7 +25,7 @@ import org.eclipse.ui.handlers.HandlerUtil;
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
* @since 3.0
*/
-public abstract class AbstractMergedAllTo extends AbstractHandler {
+public abstract class AbstractMergeAllHandler extends AbstractHandler {
/** The compare configuration object used to get the compare model. */
private CompareConfiguration configuration;
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedTo.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergeHandler.java
index ddb017340..50286e710 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedTo.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergeHandler.java
@@ -19,6 +19,8 @@ import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.util.EMFCompareUIHandlerUtil;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
@@ -28,7 +30,7 @@ import org.eclipse.ui.handlers.HandlerUtil;
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
* @since 3.0
*/
-public abstract class AbstractMergedTo extends AbstractHandler {
+public abstract class AbstractMergeHandler extends AbstractHandler {
/** The compare configuration object used to get the compare model. */
private CompareConfiguration configuration;
@@ -44,11 +46,14 @@ public abstract class AbstractMergedTo extends AbstractHandler {
setConfiguration(((CompareEditorInput)editorInput).getCompareConfiguration());
Object diffNode = ((CompareEditorInput)editorInput).getSelectedEdition();
if (diffNode instanceof Adapter) {
- Notifier diff = ((Adapter)diffNode).getTarget();
- if (diff instanceof Diff) {
- copyDiff((Diff)diff);
- // Select next diff
- EMFCompareUIHandlerUtil.navigate(true, configuration);
+ Notifier target = ((Adapter)diffNode).getTarget();
+ if (target instanceof TreeNode) {
+ EObject data = ((TreeNode)target).getData();
+ if (data instanceof Diff) {
+ copyDiff((Diff)data);
+ // Select next diff
+ EMFCompareUIHandlerUtil.navigate(true, configuration);
+ }
}
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToLeft.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergeAllToLeftHandler.java
index 543f4c945..2055cdb88 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToLeft.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergeAllToLeftHandler.java
@@ -19,7 +19,7 @@ import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.util
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
* @since 3.0
*/
-public class MergedAllToLeft extends AbstractMergedAllTo {
+public class MergeAllToLeftHandler extends AbstractMergeAllHandler {
@Override
protected void copyAllDiffs() {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToRight.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergeAllToRightHandler.java
index eab8d32f0..b7e83ab97 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToRight.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergeAllToRightHandler.java
@@ -19,7 +19,7 @@ import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.util
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
* @since 3.0
*/
-public class MergedAllToRight extends AbstractMergedAllTo {
+public class MergeAllToRightHandler extends AbstractMergeAllHandler {
@Override
protected void copyAllDiffs() {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToLeft.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergeToLeftHandler.java
index dde61ec92..d20101008 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToLeft.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergeToLeftHandler.java
@@ -20,7 +20,7 @@ import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.util
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
* @since 3.0
*/
-public class MergedToLeft extends AbstractMergedTo {
+public class MergeToLeftHandler extends AbstractMergeHandler {
@Override
protected void copyDiff(Diff diff) {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToRight.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergeToRightHandler.java
index 5e754f386..660c2335d 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToRight.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergeToRightHandler.java
@@ -20,7 +20,7 @@ import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.util
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
* @since 3.0
*/
-public class MergedToRight extends AbstractMergedTo {
+public class MergeToRightHandler extends AbstractMergeHandler {
@Override
protected void copyDiff(Diff diff) {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/AcceptRejectChangePropertyTester.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/AcceptRejectChangePropertyTester.java
index a79978c13..da011a225 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/AcceptRejectChangePropertyTester.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/AcceptRejectChangePropertyTester.java
@@ -18,7 +18,7 @@ import org.eclipse.ui.IEditorPart;
/**
* A property tester linked with
- * {@link org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.handler.AbstractMergedTo}. It returns
+ * {@link org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.AbstractMergeHandler.AbstractMergedTo}. It returns
* true when only one model side is editable.
*
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/DiffSelectedPropertyTester.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/DiffSelectedPropertyTester.java
index ebad5be65..196385c31 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/DiffSelectedPropertyTester.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/DiffSelectedPropertyTester.java
@@ -17,6 +17,8 @@ import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorInput;
@@ -46,9 +48,12 @@ public class DiffSelectedPropertyTester extends PropertyTester {
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection)selection).getFirstElement();
if (element instanceof Adapter) {
- Notifier diffNode = ((Adapter)element).getTarget();
- if (diffNode instanceof Diff) {
- return true;
+ Notifier target = ((Adapter)element).getTarget();
+ if (target instanceof TreeNode) {
+ EObject data = ((TreeNode)target).getData();
+ if (data instanceof Diff) {
+ return true;
+ }
}
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/MergedToPropertyTester.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/MergedToPropertyTester.java
index 75447c35f..3de306ca6 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/MergedToPropertyTester.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/MergedToPropertyTester.java
@@ -18,7 +18,7 @@ import org.eclipse.ui.IEditorPart;
/**
* A property tester linked with
- * {@link org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.handler.AbstractMergedTo}. It returns
+ * {@link org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.AbstractMergeHandler.AbstractMergedTo}. It returns
* true when both model sides are editable.
*
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/AttributeChangeNode.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/AttributeChangeNode.java
deleted file mode 100644
index 8e2e01d19..000000000
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/AttributeChangeNode.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider;
-
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.compare.AttributeChange;
-
-/**
- * Specific AbstractEDiffNode for {@link AttributeChange} objects.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class AttributeChangeNode extends DiffNode {
-
- /**
- * Creates a node with the given factory.
- *
- * @param adapterFactory
- * the factory given to the super constructor.
- */
- public AttributeChangeNode(AdapterFactory adapterFactory) {
- super(adapterFactory);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider.DiffNode#getTarget()
- */
- @Override
- public AttributeChange getTarget() {
- return (AttributeChange)super.getTarget();
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ComparisonNode.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ComparisonNode.java
deleted file mode 100644
index 17d94879f..000000000
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ComparisonNode.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider;
-
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.AbstractEDiffNode;
-
-/**
- * Specific AbstractEDiffNode for {@link Comparison} objects.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class ComparisonNode extends AbstractEDiffNode {
-
- /**
- * Creates a node with the given factory.
- *
- * @param adapterFactory
- * the factory given to the super constructor.
- */
- public ComparisonNode(AdapterFactory adapterFactory) {
- super(adapterFactory);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.common.notify.impl.AdapterImpl#getTarget()
- */
- @Override
- public Comparison getTarget() {
- return (Comparison)super.getTarget();
- }
-
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/DiffNode.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/DiffNode.java
deleted file mode 100644
index 2b3eb1ac5..000000000
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/DiffNode.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider;
-
-import static com.google.common.collect.Iterables.any;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasConflict;
-
-import org.eclipse.compare.structuremergeviewer.Differencer;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Conflict;
-import org.eclipse.emf.compare.ConflictKind;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceKind;
-import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.AbstractEDiffNode;
-
-/**
- * Specific {@link AbstractEDiffNode} for {@link Diff} objects.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class DiffNode extends AbstractEDiffNode {
- /**
- * Call {@link AbstractEDiffNode super} constructor.
- *
- * @param adapterFactory
- * the adapter factory
- */
- public DiffNode(AdapterFactory adapterFactory) {
- super(adapterFactory);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.common.notify.impl.AdapterImpl#getTarget()
- */
- @Override
- public Diff getTarget() {
- return (Diff)super.getTarget();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.AbstractEDiffElement#getKind()
- */
- @Override
- public int getKind() {
- int ret = Differencer.NO_CHANGE;
- final Diff diff = getTarget();
- final DifferenceSource source = diff.getSource();
- final Match match = diff.getMatch();
- final Conflict conflict = diff.getConflict();
- final DifferenceKind diffKind = diff.getKind();
- final Comparison c = match.getComparison();
- if (c.isThreeWay()) {
- switch (source) {
- case LEFT:
- ret |= Differencer.LEFT;
- break;
- case RIGHT:
- ret |= Differencer.RIGHT;
- break;
- default:
- // Cannot happen ... for now.
- break;
- }
- if (conflict != null) {
- ret |= Differencer.CONFLICTING;
- if (conflict.getKind() == ConflictKind.PSEUDO) {
- ret |= Differencer.PSEUDO_CONFLICT;
- }
- } else if (any(diff.getRequiredBy(), hasConflict(ConflictKind.REAL))) {
- ret |= Differencer.CONFLICTING;
- } else if (any(diff.getRequiredBy(), hasConflict(ConflictKind.PSEUDO))) {
- // We know there is no real conflict as that would have been handled above
- ret |= Differencer.CONFLICTING | Differencer.PSEUDO_CONFLICT;
- }
-
- switch (diffKind) {
- case ADD:
- ret |= Differencer.ADDITION;
- break;
- case DELETE:
- ret |= Differencer.DELETION;
- break;
- case CHANGE:
- // fallthrough
- case MOVE:
- ret |= Differencer.CHANGE;
- break;
- default:
- // Cannot happen ... for now
- break;
- }
- } else {
- switch (diffKind) {
- case ADD:
- ret |= Differencer.DELETION;
- break;
- case DELETE:
- ret |= Differencer.ADDITION;
- break;
- case CHANGE:
- // fallthrough
- case MOVE:
- ret |= Differencer.CHANGE;
- break;
- default:
- // Cannot happen ... for now
- break;
- }
- }
- return ret;
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/EquivalenceNode.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/EquivalenceNode.java
deleted file mode 100644
index a0f284abe..000000000
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/EquivalenceNode.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider;
-
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.compare.Equivalence;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.AbstractEDiffNode;
-
-/**
- * Specific AbstractEDiffNode for {@link Equivalence} objects.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class EquivalenceNode extends AbstractEDiffNode {
-
- /**
- * Creates a node with the given factory.
- *
- * @param adapterFactory
- * the factory given to the super constructor.
- */
- public EquivalenceNode(AdapterFactory adapterFactory) {
- super(adapterFactory);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.common.notify.impl.AdapterImpl#getTarget()
- */
- @Override
- public Equivalence getTarget() {
- return (Equivalence)super.getTarget();
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/MatchNode.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/MatchNode.java
deleted file mode 100644
index 1ebdefce6..000000000
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/MatchNode.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider;
-
-import static com.google.common.collect.Iterables.any;
-import static com.google.common.collect.Iterables.isEmpty;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasConflict;
-
-import com.google.common.base.Predicate;
-
-import org.eclipse.compare.structuremergeviewer.Differencer;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.compare.ConflictKind;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.AbstractEDiffNode;
-import org.eclipse.emf.ecore.EObject;
-
-/**
- * Specific AbstractEDiffNode for {@link Match} objects.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class MatchNode extends AbstractEDiffNode {
-
- /**
- *
- */
- private static final Predicate<Diff> CONFLICTUAL_DIFF = new Predicate<Diff>() {
- public boolean apply(Diff input) {
- return input != null && input.getConflict() != null;
- }
- };
-
- /**
- * Creates a node with the given factory.
- *
- * @param adapterFactory
- * the factory given to the super constructor.
- */
- public MatchNode(AdapterFactory adapterFactory) {
- super(adapterFactory);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.common.notify.impl.AdapterImpl#getTarget()
- */
- @Override
- public Match getTarget() {
- return (Match)super.getTarget();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.AbstractEDiffNode#getKind()
- */
- @Override
- public int getKind() {
- int ret = super.getKind();
-
- final EObject ancestor = getTarget().getOrigin();
- final EObject left = getTarget().getLeft();
- final EObject right = getTarget().getRight();
-
- final Iterable<Diff> differences = getTarget().getAllDifferences();
-
- if (getTarget().getComparison().isThreeWay()) {
- /*
- * Differencer.CONFLICTING == Differencer.LEFT | Differencer.RIGHT. With that in mind, all we need
- * to check is whether this is a pseudo conflict, and the kind of diff (deletion, addition).
- */
- if (any(differences, hasConflict(ConflictKind.REAL))) {
- ret |= Differencer.CONFLICTING;
- } else if (any(differences, hasConflict(ConflictKind.PSEUDO))) {
- // "pseudo" does not include the direction bits, we add them both through "CONFLITING"
- ret |= Differencer.CONFLICTING | Differencer.PSEUDO_CONFLICT;
- } else {
- if (any(differences, fromSide(DifferenceSource.LEFT))) {
- ret |= Differencer.LEFT;
- }
- if (any(differences, fromSide(DifferenceSource.RIGHT))) {
- ret |= Differencer.RIGHT;
- }
- }
-
- if (ancestor == null) {
- if (left == null || right == null) {
- ret |= Differencer.ADDITION;
- } else {
- // Can't have all three sides null.
- }
- } else if (left == null || right == null) {
- ret |= Differencer.DELETION;
- } else if (!isEmpty(differences)) {
- ret |= Differencer.CHANGE;
- }
- } else {
- // no direction bit in two-way
- if (left == null) {
- ret |= Differencer.DELETION;
- } else if (right == null) {
- ret |= Differencer.ADDITION;
- } else if (!isEmpty(differences)) {
- ret |= Differencer.CHANGE;
- }
- }
- return ret;
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/MatchResourceNode.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/MatchResourceNode.java
deleted file mode 100644
index 6f99dc91d..000000000
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/MatchResourceNode.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider;
-
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.compare.MatchResource;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.AbstractEDiffNode;
-
-/**
- * Specific AbstractEDiffNode for {@link MatchResource} objects.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class MatchResourceNode extends AbstractEDiffNode {
-
- /**
- * Creates a node with the given factory.
- *
- * @param adapterFactory
- * the factory given to the super constructor.
- */
- public MatchResourceNode(AdapterFactory adapterFactory) {
- super(adapterFactory);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.common.notify.impl.AdapterImpl#getTarget()
- */
- @Override
- public MatchResource getTarget() {
- return (MatchResource)super.getTarget();
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ReferenceChangeNode.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ReferenceChangeNode.java
deleted file mode 100644
index 1f91e8a13..000000000
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ReferenceChangeNode.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider;
-
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.compare.ReferenceChange;
-
-/**
- * Specific AbstractEDiffNode for {@link ReferenceChange} objects.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class ReferenceChangeNode extends DiffNode {
-
- /**
- * Creates a node with the given factory.
- *
- * @param adapterFactory
- * the factory given to the super constructor.
- */
- public ReferenceChangeNode(AdapterFactory adapterFactory) {
- super(adapterFactory);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider.DiffNode#getTarget()
- */
- @Override
- public ReferenceChange getTarget() {
- return (ReferenceChange)super.getTarget();
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ResourceAttachmentChangeNode.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ResourceAttachmentChangeNode.java
deleted file mode 100644
index b7fab9e89..000000000
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ResourceAttachmentChangeNode.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider;
-
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.compare.ResourceAttachmentChange;
-
-/**
- * Specific AbstractEDiffNode for {@link ResourceAttachmentChange} objects.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class ResourceAttachmentChangeNode extends DiffNode {
-
- /**
- * Creates a node with the given factory.
- *
- * @param adapterFactory
- * the factory given to the super constructor.
- */
- public ResourceAttachmentChangeNode(AdapterFactory adapterFactory) {
- super(adapterFactory);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider.DiffNode#getTarget()
- */
- @Override
- public ResourceAttachmentChange getTarget() {
- return (ResourceAttachmentChange)super.getTarget();
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/CompareNodeAdapterFactory.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/TreeCompareInputAdapterFactory.java
index 1ed9c125c..fcd156715 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/CompareNodeAdapterFactory.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/TreeCompareInputAdapterFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Obeo.
+ * Copyright (c) 2013 Obeo.
* 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
@@ -16,22 +16,17 @@ import java.util.Collection;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.compare.util.CompareAdapterFactory;
import org.eclipse.emf.edit.provider.ChangeNotifier;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IChangeNotifier;
-import org.eclipse.emf.edit.provider.IDisposable;
-import org.eclipse.emf.edit.provider.INotifyChangedListener;
+import org.eclipse.emf.edit.tree.util.TreeAdapterFactory;
/**
- * Adapter factory that creates structures for Compare framework.
- *
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
*/
-public class CompareNodeAdapterFactory extends CompareAdapterFactory implements ComposeableAdapterFactory, IChangeNotifier, IDisposable {
+public class TreeCompareInputAdapterFactory extends TreeAdapterFactory implements ComposeableAdapterFactory {
/**
* This keeps track of the root adapter factory that delegates to this adapter factory.
@@ -57,10 +52,15 @@ public class CompareNodeAdapterFactory extends CompareAdapterFactory implements
* @param grouper
* This will be used by the comparison adapter to group differences together.
*/
- public CompareNodeAdapterFactory() {
+ public TreeCompareInputAdapterFactory() {
supportedTypes.add(ICompareInput.class);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.notify.AdapterFactory#isFactoryForType(java.lang.Object)
+ */
@Override
public boolean isFactoryForType(Object type) {
return supportedTypes.contains(type) || super.isFactoryForType(type);
@@ -124,133 +124,10 @@ public class CompareNodeAdapterFactory extends CompareAdapterFactory implements
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.util.CompareAdapterFactory#createComparisonAdapter()
- */
- @Override
- public Adapter createComparisonAdapter() {
- return new ComparisonNode(getRootAdapterFactory());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.util.CompareAdapterFactory#createMatchResourceAdapter()
- */
- @Override
- public Adapter createMatchResourceAdapter() {
- return new MatchResourceNode(getRootAdapterFactory());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.util.CompareAdapterFactory#createMatchAdapter()
- */
- @Override
- public Adapter createMatchAdapter() {
- return new MatchNode(getRootAdapterFactory());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.util.CompareAdapterFactory#createDiffAdapter()
- */
- @Override
- public Adapter createDiffAdapter() {
- return new DiffNode(getRootAdapterFactory());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.util.CompareAdapterFactory#createResourceAttachmentChangeAdapter()
- */
- @Override
- public Adapter createResourceAttachmentChangeAdapter() {
- return new ResourceAttachmentChangeNode(getRootAdapterFactory());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.util.CompareAdapterFactory#createReferenceChangeAdapter()
- */
- @Override
- public Adapter createReferenceChangeAdapter() {
- return new ReferenceChangeNode(getRootAdapterFactory());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.util.CompareAdapterFactory#createAttributeChangeAdapter()
- */
- @Override
- public Adapter createAttributeChangeAdapter() {
- return new AttributeChangeNode(getRootAdapterFactory());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.util.CompareAdapterFactory#createConflictAdapter()
+ * @see org.eclipse.emf.edit.tree.util.TreeAdapterFactory#createTreeNodeAdapter()
*/
@Override
- public Adapter createConflictAdapter() {
- return new ConflictNode(getRootAdapterFactory());
+ public Adapter createTreeNodeAdapter() {
+ return new TreeNodeCompareInput(getRootAdapterFactory());
}
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.util.CompareAdapterFactory#createEquivalenceAdapter()
- */
- @Override
- public Adapter createEquivalenceAdapter() {
- return new EquivalenceNode(getRootAdapterFactory());
- }
-
- /**
- * This adds a listener.
- *
- * @param notifyChangedListener
- * the listener to add.
- */
- public void addListener(INotifyChangedListener notifyChangedListener) {
- changeNotifier.addListener(notifyChangedListener);
- }
-
- /**
- * This removes a listener.
- *
- * @param notifyChangedListener
- * the listener to remove.
- */
- public void removeListener(INotifyChangedListener notifyChangedListener) {
- changeNotifier.removeListener(notifyChangedListener);
- }
-
- /**
- * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}.
- *
- * @param notification
- * the notification to fire.
- */
- public void fireNotifyChanged(Notification notification) {
- changeNotifier.fireNotifyChanged(notification);
-
- if (parentAdapterFactory != null) {
- parentAdapterFactory.fireNotifyChanged(notification);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.edit.provider.IDisposable#dispose()
- */
- public void dispose() {
- }
-
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ConflictNode.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/TreeNodeCompareInput.java
index e9fcb0457..b59cdf89e 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/ConflictNode.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/provider/TreeNodeCompareInput.java
@@ -1,43 +1,31 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider;
-
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.compare.Conflict;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.AbstractEDiffNode;
-
-/**
- * Specific AbstractEDiffNode for {@link Conflict} objects.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class ConflictNode extends AbstractEDiffNode {
-
- /**
- * Creates a node with the given factory.
- *
- * @param adapterFactory
- * the factory given to the super constructor.
- */
- public ConflictNode(AdapterFactory adapterFactory) {
- super(adapterFactory);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.common.notify.impl.AdapterImpl#getTarget()
- */
- @Override
- public Conflict getTarget() {
- return (Conflict)super.getTarget();
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.provider;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.CompareInputAdapter;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class TreeNodeCompareInput extends CompareInputAdapter {
+
+ /**
+ * Constructor.
+ *
+ * @param adapterFactory
+ * the given adapter factory.
+ */
+ public TreeNodeCompareInput(AdapterFactory adapterFactory) {
+ super(adapterFactory);
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.compare.rcp.ui/META-INF/MANIFEST.MF
index ea68c18b7..753cbc4c0 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/META-INF/MANIFEST.MF
@@ -17,10 +17,10 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0",
Export-Package: org.eclipse.emf.compare.rcp.ui,
org.eclipse.emf.compare.rcp.ui.internal;x-friends:="org.eclipse.emf.compare.diagram.ide.ui,org.eclipse.emf.compare.ide.ui",
org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor;x-friends:="org.eclipse.emf.compare.ide.ui",
- org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.factory;x-internal:=true,
+ org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.factory;x-friends:="org.eclipse.emf.compare.ide.ui",
org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.factory.impl;x-internal:=true,
org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.impl;x-internal:=true,
- org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.legacy;x-internal:=true,
+ org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.legacy;x-friends:="org.eclipse.emf.compare.ide.ui",
org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.legacy.impl;x-internal:=true,
org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.impl;x-internal:=true,
org.eclipse.emf.compare.rcp.ui.internal.mergeviewer;x-friends:="org.eclipse.emf.compare.ide.ui",
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/plugin.xml b/plugins/org.eclipse.emf.compare.rcp.ui/plugin.xml
index 7ff17a8dd..da331b24f 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/plugin.xml
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/plugin.xml
@@ -28,6 +28,11 @@
class="org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl.ThreeWayComparisonGroupProvider"
label="By Side">
</group>
+ <group
+ activeByDefault="false"
+ class="org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl.ByResourceGroupProvider"
+ label="By Resource">
+ </group>
</extension>
<extension
point="org.eclipse.emf.compare.rcp.ui.filters">
@@ -83,4 +88,19 @@
ranking="15">
</factory>
</extension>
+
+ <extension point="org.eclipse.emf.compare.edit.adapterFactory">
+ <factory
+ ranking="10"
+ uri="http://www.eclipse.org/emf/2002/Tree"
+ class="org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.provider.TreeItemProviderAdapterFactorySpec"
+ supportedTypes=
+ "org.eclipse.emf.edit.provider.IEditingDomainItemProvider
+ org.eclipse.emf.edit.provider.IStructuredItemContentProvider
+ org.eclipse.emf.edit.provider.ITreeItemContentProvider
+ org.eclipse.emf.edit.provider.IItemLabelProvider
+ org.eclipse.emf.edit.provider.IItemPropertySource
+ org.eclipse.emf.compare.provider.IItemStyledLabelProvider
+ org.eclipse.emf.compare.provider.IItemDescriptionProvider"/>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupAction.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupAction.java
index 39f4ba3df..cfe6b48d9 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupAction.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupAction.java
@@ -31,16 +31,14 @@ public class GroupAction extends Action {
/**
* Instantiates our action given its target grouper.
*
- * @param text
- * Will be used as the action's tooltip.
* @param structureMergeViewerGrouper
* The grouper to which we'll provide our DifferenceGroupProvider.
* @param provider
* The group provider associated with this action.
*/
- public GroupAction(String text, StructureMergeViewerGrouper structureMergeViewerGrouper,
+ public GroupAction(StructureMergeViewerGrouper structureMergeViewerGrouper,
IDifferenceGroupProvider provider) {
- super(text, IAction.AS_RADIO_BUTTON);
+ super(provider.getLabel(), IAction.AS_RADIO_BUTTON);
this.structureMergeViewerGrouper = structureMergeViewerGrouper;
this.provider = provider;
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupActionMenu.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupActionMenu.java
index 581464c91..cd1ddbaf6 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupActionMenu.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupActionMenu.java
@@ -72,15 +72,15 @@ public class GroupActionMenu extends Action implements IMenuCreator {
*/
public void createActions(IComparisonScope scope, Comparison comparison) {
if (menuManager.isEmpty()) {
- final IAction defaultAction = new GroupAction(defaultGroupProvider.getLabel(),
- structureMergeViewerGrouper, defaultGroupProvider);
+ final IAction defaultAction = new GroupAction(structureMergeViewerGrouper, defaultGroupProvider);
defaultAction.setChecked(true);
+ defaultAction.run(); // must run to activate the adapter factory
menuManager.add(defaultAction);
IDifferenceGroupProvider.Registry registry = EMFCompareRCPUIPlugin.getDefault()
.getDifferenceGroupProviderRegistry();
boolean alreadyChecked = false;
for (IDifferenceGroupProvider dgp : registry.getGroupProviders(scope, comparison)) {
- GroupAction action = new GroupAction(dgp.getLabel(), structureMergeViewerGrouper, dgp);
+ GroupAction action = new GroupAction(structureMergeViewerGrouper, dgp);
menuManager.add(action);
if (dgp.defaultSelected() && !alreadyChecked) {
defaultAction.setChecked(false);
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/StructureMergeViewerFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/StructureMergeViewerFilter.java
index e3c079849..7d1ae35a8 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/StructureMergeViewerFilter.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/StructureMergeViewerFilter.java
@@ -10,29 +10,25 @@
*******************************************************************************/
package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters;
-import static com.google.common.base.Predicates.not;
+import static com.google.common.base.Predicates.or;
import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.eventbus.EventBus;
-import java.util.Iterator;
+import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.compare.Conflict;
-import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.MatchResource;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilterSelectionChangeEvent.Action;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup;
+import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.provider.GroupItemProviderAdapter;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
@@ -56,13 +52,13 @@ import org.eclipse.swt.events.DisposeListener;
*/
public class StructureMergeViewerFilter extends ViewerFilter {
/** The set of predicates known by this filter. */
- private Set<Predicate<? super EObject>> predicates = Sets.newLinkedHashSet();
+ private final Set<Predicate<? super EObject>> predicates;
/** List of all TreeViewers on which this filter is applied. */
- private List<TreeViewer> viewers = Lists.newArrayList();
+ private final List<TreeViewer> viewers;
/** The {@link EventBus} associated with this filter. */
- private EventBus eventBus;
+ private final EventBus eventBus;
/**
* Constructs the difference filter.
@@ -72,6 +68,8 @@ public class StructureMergeViewerFilter extends ViewerFilter {
*/
public StructureMergeViewerFilter(EventBus eventBus) {
this.eventBus = eventBus;
+ this.predicates = Sets.newLinkedHashSet();
+ this.viewers = Lists.newArrayList();
}
/**
@@ -85,47 +83,54 @@ public class StructureMergeViewerFilter extends ViewerFilter {
if (getPredicates().isEmpty()) {
return true;
}
- boolean result = false;
- final Predicate<? super EObject> predicate = Predicates.or(getPredicates());
- if (getPredicates().isEmpty()) {
- result = true;
+ boolean result = true;
+ final Predicate<? super EObject> predicate = or(getPredicates());
+
+ if (element instanceof GroupItemProviderAdapter) {
+ result = ((GroupItemProviderAdapter)element).hasChildren(element);
} else if (element instanceof Adapter) {
Notifier notifier = ((Adapter)element).getTarget();
- if (notifier instanceof Diff) {
- final Diff diff = (Diff)notifier;
- result = !predicate.apply(diff);
- } else if (notifier instanceof Match) {
- final Match match = (Match)notifier;
- result = !predicate.apply(match);
- if (result && !Iterables.isEmpty(match.getAllDifferences())) {
- final Iterator<Diff> differences = match.getAllDifferences().iterator();
- return Iterators.any(differences, not(predicate));
- }
- } else if (notifier instanceof MatchResource) {
- final MatchResource matchResource = (MatchResource)notifier;
- result = !predicate.apply(matchResource);
- } else if (notifier instanceof Conflict) {
- final Iterator<Diff> differences = ((Conflict)notifier).getDifferences().iterator();
- result = Iterators.any(differences, not(predicate));
+ if (notifier instanceof EObject) {
+ EObject eObject = (EObject)notifier;
+
+ // Keep node only if it is not filtered or if it is a Match with only filtered children.
+ result = keepNode(eObject, predicate);
}
- } else if (element instanceof IDifferenceGroup) {
- final Iterator<? extends Diff> differences = ((IDifferenceGroup)element).getDifferences()
- .iterator();
- result = Iterators.any(differences, not(predicate));
- } else if (element instanceof Adapter && ((Adapter)element).getTarget() instanceof EObject) {
- /*
- * Same code as the DiffNode case... extracted here as this is aimed at handling the cases not
- * known at the time of writing (and the case of the "MatchResource" elements).
- */
- final EObject target = (EObject)((Adapter)element).getTarget();
- result = !predicate.apply(target);
}
return result;
}
/**
+ * Keep node only if it is not filtered or if it is a Match with only filtered children.
+ *
+ * @param eObject
+ * the node we want to keep.
+ * @param predicate
+ * the predicate used to keep the node or not.
+ * @return true if the node has to be keeped, false otherwise.
+ */
+ private boolean keepNode(EObject eObject, final Predicate<? super EObject> predicate) {
+ boolean result = !predicate.apply(eObject);
+ Collection<EObject> eContents = eObject.eContents();
+ if (result && !eContents.isEmpty() && eObject instanceof TreeNode) {
+ EObject data = ((TreeNode)eObject).getData();
+ if ((data instanceof Match || data instanceof Conflict)) {
+ result = false;
+ for (EObject child : eContents) {
+ if (keepNode(child, predicate)) {
+ result = true;
+ break;
+ }
+ }
+ }
+ }
+ return result;
+
+ }
+
+ /**
* Add the predicate of the given {@link IDifferenceFilter}.
*
* @param filter
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/CascadingDifferencesFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/CascadingDifferencesFilter.java
index 370b6b7bf..9d25ac8c5 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/CascadingDifferencesFilter.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/CascadingDifferencesFilter.java
@@ -10,16 +10,23 @@
*******************************************************************************/
package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.impl;
+import static com.google.common.base.Predicates.and;
+import static com.google.common.base.Predicates.instanceOf;
+import static com.google.common.base.Predicates.not;
+import static com.google.common.collect.Iterators.any;
+import static com.google.common.collect.Iterators.transform;
+
import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableSet;
+
+import java.util.Iterator;
import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.ConflictKind;
import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ResourceAttachmentChange;
-import org.eclipse.emf.compare.provider.spec.MatchItemProviderSpec;
+import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeNode;
/**
* A filter used by default that filtered out cascading differences (differences located under differences,
@@ -36,24 +43,16 @@ public class CascadingDifferencesFilter extends AbstractDifferenceFilter {
private static final Predicate<? super EObject> predicateWhenSelected = new Predicate<EObject>() {
public boolean apply(EObject input) {
boolean ret = false;
- if (input instanceof Diff && !(input instanceof ResourceAttachmentChange)) {
- final Diff diff = (Diff)input;
- final Conflict conflict = diff.getConflict();
- if (conflict == null || ConflictKind.PSEUDO == conflict.getKind()) {
- final Match match = diff.getMatch();
- final EObject grandParent = match.eContainer();
- if (grandParent instanceof Match) {
- ImmutableSet<EObject> containementDifferenceValues = MatchItemProviderSpec
- .containmentReferencesValues((Match)grandParent);
- if (MatchItemProviderSpec.matchOfContainmentDiff(containementDifferenceValues).apply(
- match)) {
- ret = true;
- } else if (match.getLeft() == null && match.getRight() == null
- && match.getOrigin() == null) {
- ret = true;
- }
-
- }
+ if (input instanceof TreeNode) {
+ TreeNode treeNode = (TreeNode)input;
+ EObject data = treeNode.getData();
+ TreeNode parent = treeNode.getParent();
+ EObject parentData = (parent != null ? parent.getData() : null);
+ if (parentData instanceof Diff && !(parentData instanceof ResourceAttachmentChange)
+ && data instanceof Diff) {
+ Iterator<EObject> eAllDataContents = transform(treeNode.eAllContents(),
+ IDifferenceGroup.TREE_NODE_DATA);
+ return CASCADING_DIFF.apply(data) && !any(eAllDataContents, not(CASCADING_DIFF));
}
}
return ret;
@@ -61,6 +60,25 @@ public class CascadingDifferencesFilter extends AbstractDifferenceFilter {
};
/**
+ * Predicate to know if the given diff is a conflictual diff.
+ */
+ private static final Predicate<EObject> IS_NON_CONFLICTUAL_DIFF = new Predicate<EObject>() {
+ public boolean apply(EObject eObject) {
+ if (eObject instanceof Diff) {
+ Conflict conflict = ((Diff)eObject).getConflict();
+ return conflict == null || ConflictKind.PSEUDO == conflict.getKind();
+ }
+ return false;
+ }
+ };
+
+ /**
+ * Predicate to know if the given diff respects the requirements of a cascading diff.
+ */
+ private static final Predicate<EObject> CASCADING_DIFF = and(IS_NON_CONFLICTUAL_DIFF,
+ not(instanceOf(ResourceAttachmentChange.class)));
+
+ /**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter#getPredicateWhenSelected()
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/EmptyMatchedResourcesFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/EmptyMatchedResourcesFilter.java
index acd374e64..a4531ca09 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/EmptyMatchedResourcesFilter.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/EmptyMatchedResourcesFilter.java
@@ -10,18 +10,11 @@
*******************************************************************************/
package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.impl;
-import static com.google.common.collect.Iterables.filter;
-import static com.google.common.collect.Iterables.isEmpty;
-
import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.MatchResource;
-import org.eclipse.emf.compare.ResourceAttachmentChange;
-import org.eclipse.emf.compare.provider.spec.MatchResourceItemProviderSpec;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeNode;
/**
* A filter used by default that filtered out matched elements.
@@ -36,18 +29,14 @@ public class EmptyMatchedResourcesFilter extends AbstractDifferenceFilter {
*/
private static final Predicate<? super EObject> predicateWhenSelected = new Predicate<EObject>() {
public boolean apply(EObject input) {
- if (input instanceof MatchResource) {
- EList<Diff> differences = ((MatchResource)input).getComparison().getDifferences();
- Iterable<ResourceAttachmentChange> resourceAttachmentchanges = filter(differences,
- ResourceAttachmentChange.class);
- if (!isEmpty(resourceAttachmentchanges)) {
- return Iterables.all(resourceAttachmentchanges, MatchResourceItemProviderSpec
- .uriDifferentFromAll((MatchResource)input));
- } else {
- return true;
+ boolean ret = false;
+ if (input instanceof TreeNode) {
+ TreeNode treeNode = (TreeNode)input;
+ if (treeNode.getData() instanceof MatchResource) {
+ ret = treeNode.getChildren().isEmpty();
}
}
- return false;
+ return ret;
}
};
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/IdenticalElementsFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/IdenticalElementsFilter.java
index 6a9fe5bdc..2487979e5 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/IdenticalElementsFilter.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/IdenticalElementsFilter.java
@@ -10,16 +10,14 @@
*******************************************************************************/
package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.impl;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
+import static com.google.common.collect.Iterators.any;
-import java.util.Iterator;
+import com.google.common.base.Predicate;
-import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.provider.spec.MatchItemProviderSpec;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeNode;
/**
* A filter used by default that filtered out identical elements.
@@ -34,23 +32,27 @@ public class IdenticalElementsFilter extends AbstractDifferenceFilter {
*/
private static final Predicate<? super EObject> predicateWhenSelected = new Predicate<EObject>() {
public boolean apply(EObject input) {
- if (input instanceof Match) {
- Match match = (Match)input;
- Iterator<Adapter> adapters = match.eAdapters().iterator();
- while (adapters.hasNext()) {
- Adapter adapter = adapters.next();
- if (adapter instanceof MatchItemProviderSpec) {
- MatchItemProviderSpec matchItem = (MatchItemProviderSpec)adapter;
- return Iterables.isEmpty(matchItem.getFilteredChildren((match)));
- }
+ if (input instanceof TreeNode) {
+ TreeNode treeNode = (TreeNode)input;
+ EObject data = treeNode.getData();
+ if (data instanceof Match) {
+ return !any(treeNode.eAllContents(), DATA_IS_DIFF);
}
- return Iterables.isEmpty(match.getAllDifferences());
}
return false;
}
};
/**
+ * Predicate to know if the given TreeNode is a diff.
+ */
+ private static final Predicate<EObject> DATA_IS_DIFF = new Predicate<EObject>() {
+ public boolean apply(EObject treeNode) {
+ return treeNode instanceof TreeNode && ((TreeNode)treeNode).getData() instanceof Diff;
+ }
+ };
+
+ /**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter#getPredicateWhenSelected()
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/PseudoConflictsFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/PseudoConflictsFilter.java
index a4d283fa4..050771207 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/PseudoConflictsFilter.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/PseudoConflictsFilter.java
@@ -16,9 +16,9 @@ import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.ConflictKind;
import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeNode;
/**
* A filter used by default that filtered out pseudo conflicts differences.
@@ -34,11 +34,13 @@ public class PseudoConflictsFilter extends AbstractDifferenceFilter {
private static final Predicate<? super EObject> predicateWhenSelected = new Predicate<EObject>() {
public boolean apply(EObject input) {
boolean ret = false;
- if (input instanceof Diff) {
- Diff diff = (Diff)input;
- Conflict conflict = diff.getConflict();
- if (conflict != null && conflict.getKind() == ConflictKind.PSEUDO) {
- ret = true;
+ if (input instanceof TreeNode) {
+ TreeNode treeNode = (TreeNode)input;
+ EObject data = treeNode.getData();
+ if (data instanceof Diff) {
+ Diff diff = (Diff)data;
+ Conflict conflict = diff.getConflict();
+ ret = conflict != null && conflict.getKind() == ConflictKind.PSEUDO;
}
}
return ret;
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/BasicDifferenceGroupImpl.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/BasicDifferenceGroupImpl.java
index 7747cb2a7..02e00f8d0 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/BasicDifferenceGroupImpl.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/BasicDifferenceGroupImpl.java
@@ -10,17 +10,42 @@
*******************************************************************************/
package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups;
+import static com.google.common.base.Predicates.and;
+import static com.google.common.base.Predicates.not;
+import static com.google.common.base.Predicates.or;
+import static com.google.common.collect.Collections2.filter;
+import static com.google.common.collect.Iterators.concat;
+import static com.google.common.collect.Iterators.size;
+import static com.google.common.collect.Iterators.transform;
+import static com.google.common.collect.Lists.newArrayList;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.containmentReferenceChange;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasState;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.valueIs;
+import com.google.common.base.Function;
import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Lists;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceState;
+import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.MatchResource;
+import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
import org.eclipse.emf.compare.provider.utils.IStyledString;
import org.eclipse.emf.compare.provider.utils.IStyledString.Style;
+import org.eclipse.emf.compare.rcp.ui.EMFCompareRCPUIPlugin;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeFactory;
+import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.swt.graphics.Image;
/**
@@ -32,9 +57,7 @@ import org.eclipse.swt.graphics.Image;
* @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
* @since 3.0
*/
-public class BasicDifferenceGroupImpl implements IDifferenceGroup {
- /** The whole unfiltered list of differences. */
- protected final Iterable<? extends Diff> candidates;
+public class BasicDifferenceGroupImpl extends AdapterImpl implements IDifferenceGroup {
/** The filter we'll use in order to filter the differences that are part of this group. */
protected final Predicate<? super Diff> filter;
@@ -48,6 +71,9 @@ public class BasicDifferenceGroupImpl implements IDifferenceGroup {
/** The comparison that is the parent of this group. */
protected final Comparison comparison;
+ /** The list of children of this group. */
+ protected List<TreeNode> children;
+
/**
* Instantiates this group given the comparison and filter that should be used in order to determine its
* list of differences.
@@ -62,18 +88,16 @@ public class BasicDifferenceGroupImpl implements IDifferenceGroup {
* @param filter
* The filter we'll use in order to filter the differences that are part of this group.
*/
- public BasicDifferenceGroupImpl(Comparison comparison, Iterable<? extends Diff> unfiltered,
- Predicate<? super Diff> filter) {
- this(comparison, unfiltered, filter, "Group", null);
+ public BasicDifferenceGroupImpl(Comparison comparison, Predicate<? super Diff> filter) {
+ this(comparison, filter, "Group", EMFCompareRCPUIPlugin.getImage("icons/full/toolb16/group.gif")); //$NON-NLS-1$//$NON-NLS-2$
}
/**
* Instantiates this group given the comparison and filter that should be used in order to determine its
- * list of differences. It will be displayed in the UI with the default icon and the given name. * @param
- * comparison The comparison that is the parent of this group.
+ * list of differences. It will be displayed in the UI with the default icon and the given name.
*
* @param comparison
- * The comparison that is the parent of this group.*
+ * The comparison that is the parent of this group.
* @param unfiltered
* The whole unfiltered list of differences.
* @param filter
@@ -81,9 +105,8 @@ public class BasicDifferenceGroupImpl implements IDifferenceGroup {
* @param name
* The name that the EMF Compare UI will display for this group.
*/
- public BasicDifferenceGroupImpl(Comparison comparison, Iterable<? extends Diff> unfiltered,
- Predicate<? super Diff> filter, String name) {
- this(comparison, unfiltered, filter, name, null);
+ public BasicDifferenceGroupImpl(Comparison comparison, Predicate<? super Diff> filter, String name) {
+ this(comparison, filter, name, EMFCompareRCPUIPlugin.getImage("icons/full/toolb16/group.gif")); //$NON-NLS-1$
}
/**
@@ -101,17 +124,22 @@ public class BasicDifferenceGroupImpl implements IDifferenceGroup {
* @param image
* The icon that the EMF Compare UI will display for this group.
*/
- public BasicDifferenceGroupImpl(Comparison comparison, Iterable<? extends Diff> unfiltered,
- Predicate<? super Diff> filter, String name, Image image) {
+ public BasicDifferenceGroupImpl(Comparison comparison, Predicate<? super Diff> filter, String name,
+ Image image) {
this.comparison = comparison;
- this.candidates = unfiltered;
this.filter = filter;
this.name = name;
this.image = image;
}
- public Iterable<? extends Diff> getDifferences() {
- return Iterables.filter(candidates, filter);
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.notify.impl.AdapterImpl#isAdapterForType(java.lang.Object)
+ */
+ @Override
+ public boolean isAdapterForType(Object type) {
+ return type == IDifferenceGroup.class;
}
/**
@@ -139,7 +167,9 @@ public class BasicDifferenceGroupImpl implements IDifferenceGroup {
*/
public IStyledString.IComposedStyledString getStyledName() {
final IStyledString.IComposedStyledString ret = new ComposedStyledString(getName());
- int unresolvedDiffs = Iterables.size(Iterables.filter(getDifferences(),
+ Iterator<EObject> eAllContents = concat(transform(getGroupTree().iterator(), E_ALL_CONTENTS));
+ Iterator<EObject> eAllData = transform(eAllContents, TREE_NODE_DATA);
+ int unresolvedDiffs = size(Iterators.filter(Iterators.filter(eAllData, Diff.class),
hasState(DifferenceState.UNRESOLVED)));
ret.append(" [" + unresolvedDiffs + " unresolved difference", Style.DECORATIONS_STYLER);
if (unresolvedDiffs > 1) {
@@ -150,6 +180,15 @@ public class BasicDifferenceGroupImpl implements IDifferenceGroup {
}
/**
+ * Function that returns all contents of the given EObject.
+ */
+ protected static final Function<EObject, Iterator<EObject>> E_ALL_CONTENTS = new Function<EObject, Iterator<EObject>>() {
+ public Iterator<EObject> apply(EObject eObject) {
+ return eObject.eAllContents();
+ }
+ };
+
+ /**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup#getImage()
@@ -157,4 +196,143 @@ public class BasicDifferenceGroupImpl implements IDifferenceGroup {
public Image getImage() {
return image;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup#getGroupTree()
+ */
+ public List<? extends TreeNode> getGroupTree() {
+ if (children == null) {
+ children = newArrayList();
+ for (Match match : comparison.getMatches()) {
+ List<? extends TreeNode> buildSubTree = buildSubTree(null, match);
+ if (buildSubTree != null) {
+ children.addAll(buildSubTree);
+ }
+ }
+ for (MatchResource matchResource : comparison.getMatchedResources()) {
+ TreeNode buildSubTree = buildSubTree(matchResource);
+ if (buildSubTree != null) {
+ children.add(buildSubTree);
+ }
+ }
+ }
+ return children;
+ }
+
+ /**
+ * Build the sub tree of the given {@link MatchResource}.
+ *
+ * @param matchResource
+ * the given MatchResource.
+ * @return the sub tree of the given MatchResource.
+ */
+ protected TreeNode buildSubTree(MatchResource matchResource) {
+ if (filter.equals(Predicates.alwaysTrue())) {
+ return wrap(matchResource);
+ }
+ return null;
+ }
+
+ /**
+ * Build the sub tree of the given {@link Match}.
+ *
+ * @param parentMatch
+ * the parent of the given Match.
+ * @param match
+ * the given Match.
+ * @return the sub tree of the given Match.
+ */
+ protected List<TreeNode> buildSubTree(Match parentMatch, Match match) {
+ final List<TreeNode> ret = Lists.newArrayList();
+ boolean isContainment = false;
+
+ if (parentMatch != null) {
+ Collection<Diff> containmentChanges = filter(parentMatch.getDifferences(),
+ containmentReferenceForMatch(match));
+ if (!containmentChanges.isEmpty()) {
+ isContainment = true;
+ for (Diff diff : containmentChanges) {
+ ret.add(wrap(diff));
+ }
+ } else {
+ ret.add(wrap(match));
+ }
+ } else {
+ Collection<Diff> resourceAttachmentChanges = filter(match.getDifferences(),
+ resourceAttachmentChange());
+ if (!resourceAttachmentChanges.isEmpty()) {
+ for (Diff diff : resourceAttachmentChanges) {
+ ret.add(wrap(diff));
+ }
+ } else {
+ ret.add(wrap(match));
+ }
+
+ }
+
+ Collection<TreeNode> toRemove = Lists.newArrayList();
+ for (TreeNode treeNode : ret) {
+ boolean hasDiff = false;
+ boolean hasNonEmptySubMatch = false;
+ for (Diff diff : filter(match.getDifferences(), and(filter, not(or(containmentReferenceChange(),
+ resourceAttachmentChange()))))) {
+ hasDiff = true;
+ treeNode.getChildren().add(wrap(diff));
+ }
+ for (Match subMatch : match.getSubmatches()) {
+ List<TreeNode> buildSubTree = buildSubTree(match, subMatch);
+ if (!buildSubTree.isEmpty()) {
+ hasNonEmptySubMatch = true;
+ treeNode.getChildren().addAll(buildSubTree);
+ }
+ }
+ if (!(isContainment || hasDiff || hasNonEmptySubMatch || filter.equals(Predicates.alwaysTrue()))) {
+ toRemove.add(treeNode);
+ }
+ }
+
+ ret.removeAll(toRemove);
+
+ return ret;
+ }
+
+ /**
+ * This can be used to check whether a givan diff is a resource attachment change.
+ *
+ * @return The created predicate.
+ */
+ protected static Predicate<? super Diff> resourceAttachmentChange() {
+ return Predicates.instanceOf(ResourceAttachmentChange.class);
+ }
+
+ /**
+ * Predicate to know if the given match contains containment refernce change according to the filter of
+ * the group.
+ *
+ * @param subMatch
+ * the given Match.
+ * @return a predicate to know if the given match contains containment refernce change according to the
+ * filter of the group.
+ */
+ @SuppressWarnings("unchecked")
+ protected Predicate<Diff> containmentReferenceForMatch(Match subMatch) {
+ return and(filter, containmentReferenceChange(), or(valueIs(subMatch.getLeft()), valueIs(subMatch
+ .getRight()), valueIs(subMatch.getOrigin())));
+ }
+
+ /**
+ * Creates a TreeNode form the given EObject.
+ *
+ * @param data
+ * the given EObject.
+ * @return a TreeNode.
+ */
+ protected TreeNode wrap(EObject data) {
+ TreeNode treeNode = TreeFactory.eINSTANCE.createTreeNode();
+ treeNode.setData(data);
+ treeNode.eAdapters().add(this);
+ return treeNode;
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/IDifferenceGroup.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/IDifferenceGroup.java
index c43c5ec77..5bd407039 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/IDifferenceGroup.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/IDifferenceGroup.java
@@ -10,9 +10,15 @@
*******************************************************************************/
package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups;
+import com.google.common.base.Function;
+
+import java.util.List;
+
+import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.provider.utils.IStyledString;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.swt.graphics.Image;
/**
@@ -23,13 +29,7 @@ import org.eclipse.swt.graphics.Image;
* @see BasicDifferenceGroupImpl
* @since 3.0
*/
-public interface IDifferenceGroup {
- /**
- * Returns all differences that should be considered a part of this group.
- *
- * @return All differences that should be considered a part of this group.
- */
- Iterable<? extends Diff> getDifferences();
+public interface IDifferenceGroup extends Adapter {
/**
* Returns the {@link Comparison} in which this group is defined.
@@ -59,4 +59,20 @@ public interface IDifferenceGroup {
* be used instead.
*/
Image getImage();
+
+ /**
+ * The list of TreeNode containded in this group.
+ *
+ * @return the list of TreeNode containded in this group.
+ */
+ List<? extends TreeNode> getGroupTree();
+
+ /**
+ * Function that retrieve the data of the given TreeNode.
+ */
+ public static final Function<EObject, EObject> TREE_NODE_DATA = new Function<EObject, EObject>() {
+ public EObject apply(EObject node) {
+ return node instanceof TreeNode ? ((TreeNode)node).getData() : node;
+ }
+ };
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/IDifferenceGroupProvider.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/IDifferenceGroupProvider.java
index aff7f21da..b8fbac32e 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/IDifferenceGroupProvider.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/IDifferenceGroupProvider.java
@@ -10,10 +10,9 @@
*******************************************************************************/
package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups;
-
-
import java.util.Collection;
+import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.scope.IComparisonScope;
@@ -24,7 +23,7 @@ import org.eclipse.emf.compare.scope.IComparisonScope;
* @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
* @since 3.0
*/
-public interface IDifferenceGroupProvider {
+public interface IDifferenceGroupProvider extends Adapter {
/**
* This will be called internally by the grouping actions in order to determine how the differences should
@@ -36,7 +35,7 @@ public interface IDifferenceGroupProvider {
* @return The collection of difference groups that are to be displayed in the structural viewer. An empty
* group will not be displayed at all. If {@code null}, we'll fall back to the default behavior.
*/
- Iterable<? extends IDifferenceGroup> getGroups(Comparison comparison);
+ Collection<? extends IDifferenceGroup> getGroups(Comparison comparison);
/**
* A human-readable label for this group. This will be displayed in the EMF Compare UI.
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/StructureMergeViewerGrouper.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/StructureMergeViewerGrouper.java
index 29970dfa2..118e65745 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/StructureMergeViewerGrouper.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/StructureMergeViewerGrouper.java
@@ -10,9 +10,6 @@
*******************************************************************************/
package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.eventbus.EventBus;
@@ -45,12 +42,6 @@ public final class StructureMergeViewerGrouper {
private EventBus eventBus;
/**
- * Caches the result of {@link #getGroups(Comparison)}. We need the groups to be identical between calls
- * in order for the viewer to be able to keep its expanded state.
- */
- private Iterable<? extends IDifferenceGroup> filteredGroups;
-
- /**
* Constructs the difference grouper.
*
* @param eventBus
@@ -70,15 +61,7 @@ public final class StructureMergeViewerGrouper {
* {@link Iterable} if we have no group provider set.
*/
public Iterable<? extends IDifferenceGroup> getGroups(final Comparison comparison) {
- if (provider == null) {
- return ImmutableList.of();
- }
-
- if (filteredGroups == null) {
- final Iterable<? extends IDifferenceGroup> groups = provider.getGroups(comparison);
- filteredGroups = Iterables.filter(groups, new NonEmptyGroup());
- }
- return filteredGroups;
+ return provider.getGroups(comparison);
}
/**
@@ -90,9 +73,8 @@ public final class StructureMergeViewerGrouper {
public void setProvider(IDifferenceGroupProvider provider) {
if (this.provider != provider) {
this.provider = provider;
- filteredGroups = null;
- refreshViewers();
eventBus.post(provider);
+ refreshViewers();
}
}
@@ -136,20 +118,4 @@ public final class StructureMergeViewerGrouper {
public void uninstall(TreeViewer viewer) {
viewers.remove(viewer);
}
-
- /**
- * This predicate will be used to filter the empty groups out of the displayed list.
- *
- * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
- */
- private static class NonEmptyGroup implements Predicate<IDifferenceGroup> {
- /**
- * {@inheritDoc}
- *
- * @see com.google.common.base.Predicate#apply(java.lang.Object)
- */
- public boolean apply(IDifferenceGroup input) {
- return input != null && !Iterables.isEmpty(input.getDifferences());
- }
- }
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/ByResourceGroupProvider.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/ByResourceGroupProvider.java
new file mode 100644
index 000000000..534d5abe5
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/ByResourceGroupProvider.java
@@ -0,0 +1,210 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.MatchResource;
+import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.BasicDifferenceGroupImpl;
+import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup;
+import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeNode;
+
+/**
+ * This implementation of a {@link IDifferenceGroupProvider} will be used to group the differences by their
+ * Resource.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ * @since 3.0
+ */
+public class ByResourceGroupProvider extends AdapterImpl implements IDifferenceGroupProvider {
+
+ /** A human-readable label for this group provider. This will be displayed in the EMF Compare UI. */
+ private String label;
+
+ /** The initial activation state of the group provider. */
+ private boolean activeByDefault;
+
+ /** The unique group provided by this provider. */
+ private IDifferenceGroup group;
+
+ /** The comparison object. */
+ private Comparison comp;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.notify.impl.AdapterImpl#isAdapterForType(java.lang.Object)
+ */
+ @Override
+ public boolean isAdapterForType(Object type) {
+ return type == IDifferenceGroupProvider.class;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider#getGroups(org.eclipse.emf.compare.Comparison)
+ */
+ public Collection<? extends IDifferenceGroup> getGroups(Comparison comparison) {
+ if (group == null || !comparison.equals(comp)) {
+ this.comp = comparison;
+ group = new ResourceGroup(comparison);
+ }
+ return ImmutableList.of(group);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider#getLabel()
+ */
+ public String getLabel() {
+ return label;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider#setLabel(java.lang.String)
+ */
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider#defaultSelected()
+ */
+ public boolean defaultSelected() {
+ return activeByDefault;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider#setDefaultSelected(boolean)
+ */
+ public void setDefaultSelected(boolean activeByDefault) {
+ this.activeByDefault = activeByDefault;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider#isEnabled(org
+ * .eclipse.emf.compare.scope.IComparisonScope, org.eclipse.emf.compare.Comparison)
+ */
+ public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
+ return true;
+ }
+
+ /**
+ * Specialized {@link BasicDifferenceGroupImpl} for Resources.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+ public static class ResourceGroup extends BasicDifferenceGroupImpl {
+
+ /**
+ * {@inheritDoc}.
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.BasicDifferenceGroupImpl#BasicDifferenceGroupImpl(org.eclipse.emf.compare.Comparison)
+ */
+ public ResourceGroup(Comparison comparison) {
+ super(comparison, Predicates.<Diff> alwaysTrue());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.BasicDifferenceGroupImpl#getGroupTree()
+ */
+ @Override
+ public List<? extends TreeNode> getGroupTree() {
+ if (children == null) {
+ children = newArrayList();
+ for (MatchResource matchResource : comparison.getMatchedResources()) {
+ children.add(buildSubTree(matchResource));
+ }
+ }
+ return children;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.BasicDifferenceGroupImpl#buildSubTree(org.eclipse.emf.compare.Match,
+ * org.eclipse.emf.compare.MatchResource)
+ */
+ @Override
+ protected TreeNode buildSubTree(MatchResource matchResource) {
+ TreeNode ret = wrap(matchResource);
+
+ for (Match match : comparison.getMatches()) {
+ ret.getChildren().addAll(buildSubTree(matchResource, match));
+ }
+
+ return ret;
+ }
+
+ /**
+ * Build the sub tree of the given Match that is a root of the given MatchResource.
+ *
+ * @param matchResource
+ * the given MatchResource.
+ * @param match
+ * the given Match.
+ * @return the sub tree of the given Match that is a root of the given MatchResource.
+ */
+ protected List<TreeNode> buildSubTree(MatchResource matchResource, Match match) {
+ List<TreeNode> ret = newArrayList();
+ if (isRootOfResourceURI(match.getLeft(), matchResource.getLeftURI())
+ || isRootOfResourceURI(match.getRight(), matchResource.getRightURI())
+ || isRootOfResourceURI(match.getOrigin(), matchResource.getOriginURI())) {
+ ret.addAll(buildSubTree((Match)null, match));
+ } else {
+ for (Match subMatch : match.getSubmatches()) {
+ ret.addAll(buildSubTree(matchResource, subMatch));
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * Check if the resource of the given object as the same uri as the given uri.
+ *
+ * @param eObject
+ * the given object.
+ * @param uri
+ * the given uri.
+ * @return true if the resource of the given object as the same uri as the given uri, false otherwise.
+ */
+ protected boolean isRootOfResourceURI(EObject eObject, String uri) {
+ return eObject != null && uri != null && eObject.eResource() != null
+ && uri.equals(eObject.eResource().getURI().toString());
+ }
+
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/DefaultGroupProvider.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/DefaultGroupProvider.java
index 7e3a97859..e599241df 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/DefaultGroupProvider.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/DefaultGroupProvider.java
@@ -10,9 +10,15 @@
*******************************************************************************/
package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl;
-import java.util.Collections;
+import static com.google.common.base.Predicates.alwaysTrue;
+import com.google.common.collect.ImmutableList;
+
+import java.util.Collection;
+
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.BasicDifferenceGroupImpl;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
import org.eclipse.emf.compare.scope.IComparisonScope;
@@ -23,16 +29,31 @@ import org.eclipse.emf.compare.scope.IComparisonScope;
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
* @since 3.0
*/
-public class DefaultGroupProvider implements IDifferenceGroupProvider {
+public class DefaultGroupProvider extends AdapterImpl implements IDifferenceGroupProvider {
+
+ /** The unique group provided by this provider. */
+ private IDifferenceGroup group;
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider#getGroups(org.eclipse.emf.compare.Comparison)
*/
- public Iterable<? extends IDifferenceGroup> getGroups(Comparison comparison) {
+ public Collection<? extends IDifferenceGroup> getGroups(Comparison comparison) {
+ if (group == null) {
+ group = new BasicDifferenceGroupImpl(comparison, alwaysTrue());
+ }
+ return ImmutableList.of(group);
+ }
- return Collections.emptyList();
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.notify.impl.AdapterImpl#isAdapterForType(java.lang.Object)
+ */
+ @Override
+ public boolean isAdapterForType(Object type) {
+ return type == IDifferenceGroupProvider.class;
}
/**
@@ -80,5 +101,4 @@ public class DefaultGroupProvider implements IDifferenceGroupProvider {
public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
return true;
}
-
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/KindGroupProvider.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/KindGroupProvider.java
index 8d725553c..d91c8ec45 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/KindGroupProvider.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/KindGroupProvider.java
@@ -13,11 +13,12 @@ package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl
import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
-import java.util.List;
+import java.util.Collection;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.BasicDifferenceGroupImpl;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup;
@@ -31,7 +32,7 @@ import org.eclipse.emf.compare.scope.IComparisonScope;
* @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
* @since 3.0
*/
-public class KindGroupProvider implements IDifferenceGroupProvider {
+public class KindGroupProvider extends AdapterImpl implements IDifferenceGroupProvider {
/** A human-readable label for this group provider. This will be displayed in the EMF Compare UI. */
private String label;
@@ -39,24 +40,54 @@ public class KindGroupProvider implements IDifferenceGroupProvider {
/** The initial activation state of the group provider. */
private boolean activeByDefault;
+ /** The groups provided by this provider. */
+ private ImmutableList<IDifferenceGroup> differenceGroups;
+
+ /** The comparison object. */
+ private Comparison comp;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.notify.impl.AdapterImpl#isAdapterForType(java.lang.Object)
+ */
+ @Override
+ public boolean isAdapterForType(Object type) {
+ return type == IDifferenceGroupProvider.class;
+ }
+
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider#getGroups(org.eclipse.emf.compare.Comparison)
*/
- public Iterable<? extends IDifferenceGroup> getGroups(Comparison comparison) {
- final List<Diff> diffs = comparison.getDifferences();
-
- final IDifferenceGroup additions = new BasicDifferenceGroupImpl(comparison, diffs,
- ofKind(DifferenceKind.ADD), "Additions");
- final IDifferenceGroup deletions = new BasicDifferenceGroupImpl(comparison, diffs,
- ofKind(DifferenceKind.DELETE), "Deletions");
- final IDifferenceGroup changes = new BasicDifferenceGroupImpl(comparison, diffs,
- ofKind(DifferenceKind.CHANGE), "Changes");
- final IDifferenceGroup moves = new BasicDifferenceGroupImpl(comparison, diffs,
- ofKind(DifferenceKind.MOVE), "Moves");
-
- return ImmutableList.of(additions, deletions, changes, moves);
+ public Collection<? extends IDifferenceGroup> getGroups(Comparison comparison) {
+ if (differenceGroups == null || !comparison.equals(comp)) {
+ this.comp = comparison;
+ final IDifferenceGroup additions = new BasicDifferenceGroupImpl(comparison,
+ ofKind(DifferenceKind.ADD), "Additions");
+ final IDifferenceGroup deletions = new BasicDifferenceGroupImpl(comparison,
+ ofKind(DifferenceKind.DELETE), "Deletions");
+ final IDifferenceGroup changes = new BasicDifferenceGroupImpl(comparison,
+ ofKind(DifferenceKind.CHANGE), "Changes");
+ final IDifferenceGroup moves = new BasicDifferenceGroupImpl(comparison,
+ ofKind(DifferenceKind.MOVE), "Moves");
+ Collection<IDifferenceGroup> groups = Lists.newArrayList();
+ if (!additions.getGroupTree().isEmpty()) {
+ groups.add(additions);
+ }
+ if (!deletions.getGroupTree().isEmpty()) {
+ groups.add(deletions);
+ }
+ if (!changes.getGroupTree().isEmpty()) {
+ groups.add(changes);
+ }
+ if (!moves.getGroupTree().isEmpty()) {
+ groups.add(moves);
+ }
+ differenceGroups = ImmutableList.copyOf(groups);
+ }
+ return differenceGroups;
}
/**
@@ -104,5 +135,4 @@ public class KindGroupProvider implements IDifferenceGroupProvider {
public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
return true;
}
-
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/ThreeWayComparisonGroupProvider.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/ThreeWayComparisonGroupProvider.java
index 58a34e7fa..d8683f6c6 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/ThreeWayComparisonGroupProvider.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/ThreeWayComparisonGroupProvider.java
@@ -11,6 +11,12 @@
package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl;
import static com.google.common.base.Predicates.and;
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Iterables.size;
+import static com.google.common.collect.Iterators.concat;
+import static com.google.common.collect.Iterators.filter;
+import static com.google.common.collect.Iterators.transform;
+import static com.google.common.collect.Lists.newArrayList;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasConflict;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasState;
@@ -18,15 +24,24 @@ import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasState;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+import com.google.common.collect.Sets.SetView;
+import com.google.common.collect.UnmodifiableIterator;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.ConflictKind;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceSource;
import org.eclipse.emf.compare.DifferenceState;
+import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.ReferenceChange;
+import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
import org.eclipse.emf.compare.provider.utils.IStyledString;
import org.eclipse.emf.compare.provider.utils.IStyledString.IComposedStyledString;
@@ -35,6 +50,8 @@ import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.Basic
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.tree.TreeNode;
/**
* This implementation of a {@link IDifferenceGroupProvider} will be used to group the differences by their
@@ -43,7 +60,7 @@ import org.eclipse.emf.compare.scope.IComparisonScope;
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
* @since 3.0
*/
-public class ThreeWayComparisonGroupProvider implements IDifferenceGroupProvider {
+public class ThreeWayComparisonGroupProvider extends AdapterImpl implements IDifferenceGroupProvider {
/** A human-readable label for this group provider. This will be displayed in the EMF Compare UI. */
private String label;
@@ -51,24 +68,42 @@ public class ThreeWayComparisonGroupProvider implements IDifferenceGroupProvider
/** The initial activation state of the group provider. */
private boolean activeByDefault;
+ /** The groups provided by this provider. */
+ private ImmutableList<IDifferenceGroup> differenceGroups;
+
+ /** The comparison object. */
+ private Comparison comp;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.notify.impl.AdapterImpl#isAdapterForType(java.lang.Object)
+ */
+ @Override
+ public boolean isAdapterForType(Object type) {
+ return type == IDifferenceGroupProvider.class;
+ }
+
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider#getGroups(org.eclipse.emf.compare.Comparison)
*/
- public Iterable<? extends IDifferenceGroup> getGroups(Comparison comparison) {
- final List<Diff> diffs = comparison.getDifferences();
-
- final IDifferenceGroup conflicts = new ConflictsGroupImpl(comparison, diffs, hasConflict(
- ConflictKind.REAL, ConflictKind.PSEUDO), "Conflicts");
- final IDifferenceGroup leftSide = new BasicDifferenceGroupImpl(comparison, diffs, Predicates.and(
- fromSide(DifferenceSource.LEFT), Predicates.not(hasConflict(ConflictKind.REAL,
- ConflictKind.PSEUDO))), "Left side");
- final IDifferenceGroup rightSide = new BasicDifferenceGroupImpl(comparison, diffs, Predicates.and(
- fromSide(DifferenceSource.RIGHT), Predicates.not(hasConflict(ConflictKind.REAL,
- ConflictKind.PSEUDO))), "Right side");
-
- return ImmutableList.of(conflicts, leftSide, rightSide);
+ public Collection<? extends IDifferenceGroup> getGroups(Comparison comparison) {
+ if (differenceGroups == null || !comparison.equals(comp)) {
+ this.comp = comparison;
+ final IDifferenceGroup conflicts = new ConflictsGroupImpl(comparison, hasConflict(
+ ConflictKind.REAL, ConflictKind.PSEUDO), "Conflicts");
+ final IDifferenceGroup leftSide = new BasicDifferenceGroupImpl(comparison, Predicates.and(
+ fromSide(DifferenceSource.LEFT), Predicates.not(hasConflict(ConflictKind.REAL,
+ ConflictKind.PSEUDO))), "Left side");
+ final IDifferenceGroup rightSide = new BasicDifferenceGroupImpl(comparison, Predicates.and(
+ fromSide(DifferenceSource.RIGHT), Predicates.not(hasConflict(ConflictKind.REAL,
+ ConflictKind.PSEUDO))), "Right side");
+
+ differenceGroups = ImmutableList.of(conflicts, leftSide, rightSide);
+ }
+ return differenceGroups;
}
/**
@@ -125,7 +160,7 @@ public class ThreeWayComparisonGroupProvider implements IDifferenceGroupProvider
*
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
*/
- class ConflictsGroupImpl extends BasicDifferenceGroupImpl {
+ public static class ConflictsGroupImpl extends BasicDifferenceGroupImpl {
/**
* {@inheritDoc}.
@@ -133,9 +168,8 @@ public class ThreeWayComparisonGroupProvider implements IDifferenceGroupProvider
* @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.BasicDifferenceGroupImpl#BasicDifferenceGroupImpl(org.eclipse.emf.compare.Comparison,
* java.lang.Iterable, com.google.common.base.Predicate, java.lang.String)
*/
- public ConflictsGroupImpl(Comparison comparison, Iterable<? extends Diff> unfiltered,
- Predicate<? super Diff> filter, String name) {
- super(comparison, unfiltered, filter, name);
+ public ConflictsGroupImpl(Comparison comparison, Predicate<? super Diff> filter, String name) {
+ super(comparison, filter, name);
}
/**
@@ -146,10 +180,14 @@ public class ThreeWayComparisonGroupProvider implements IDifferenceGroupProvider
@Override
public IComposedStyledString getStyledName() {
final IStyledString.IComposedStyledString ret = new ComposedStyledString(getName());
- int unresolvedRealDiffs = Iterables.size(Iterables.filter(getDifferences(), and(
- hasState(DifferenceState.UNRESOLVED), hasConflict(ConflictKind.REAL))));
- int unresolvedPseudoDiffs = Iterables.size(Iterables.filter(getDifferences(), and(
- hasState(DifferenceState.UNRESOLVED), hasConflict(ConflictKind.PSEUDO))));
+ Iterator<EObject> eAllContents = concat(transform(getGroupTree().iterator(), E_ALL_CONTENTS));
+ Iterator<EObject> eAllData = transform(eAllContents, TREE_NODE_DATA);
+ UnmodifiableIterator<Diff> eAllDiffData = filter(eAllData, Diff.class);
+ Collection<Diff> diffs = Sets.newHashSet(eAllDiffData);
+ int unresolvedRealDiffs = size(filter(diffs, and(hasState(DifferenceState.UNRESOLVED),
+ hasConflict(ConflictKind.REAL))));
+ int unresolvedPseudoDiffs = size(filter(diffs, and(hasState(DifferenceState.UNRESOLVED),
+ hasConflict(ConflictKind.PSEUDO))));
ret.append(" [" + unresolvedRealDiffs + " real and " + unresolvedPseudoDiffs
+ " pseudo unresolved difference", Style.DECORATIONS_STYLER);
if (unresolvedRealDiffs + unresolvedPseudoDiffs > 1) {
@@ -158,6 +196,139 @@ public class ThreeWayComparisonGroupProvider implements IDifferenceGroupProvider
ret.append("]", Style.DECORATIONS_STYLER);
return ret;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.BasicDifferenceGroupImpl#getGroupTree()
+ */
+ @Override
+ public List<? extends TreeNode> getGroupTree() {
+ if (children == null) {
+ children = newArrayList();
+ for (Conflict conflict : comparison.getConflicts()) {
+ TreeNode buildSubTree = buildSubTree(conflict);
+ if (buildSubTree != null) {
+ children.add(buildSubTree);
+ }
+ }
+ }
+ return children;
+ }
+
+ /**
+ * Build sub tree for the given Conflict.
+ *
+ * @param conflict
+ * the given Conflict.
+ * @return the sub tree for the given Conflict.
+ */
+ protected TreeNode buildSubTree(Conflict conflict) {
+ TreeNode ret = wrap(conflict);
+
+ for (Match match : comparison.getMatches()) {
+ buildSubTree(ret, conflict, match);
+ }
+
+ return ret;
+
+ }
+
+ /**
+ * Build sub tree for the given Match.
+ *
+ * @param parentNode
+ * the parent node of the given match.
+ * @param conflict
+ * the conflict of the tree.
+ * @param match
+ * the given match.
+ */
+ protected void buildSubTree(TreeNode parentNode, Conflict conflict, Match match) {
+
+ SetView<Diff> setView = Sets.intersection(Sets.newHashSet(match.getDifferences()), Sets
+ .newHashSet(conflict.getDifferences()));
+ for (Diff diff : setView) {
+ if (!isParentPseudoConflictFromOtherSide(diff, parentNode.getData())) {
+ TreeNode wrap = wrap(diff);
+ parentNode.getChildren().add(wrap);
+ if (isContainment(diff)) {
+ final Match diffMatch = diff.getMatch().getComparison().getMatch(
+ ((ReferenceChange)diff).getValue());
+ buildSubTree(wrap, conflict, diffMatch);
+ }
+ }
+ }
+ for (Match subMatch : match.getSubmatches()) {
+ if (!isMatchOfConflictContainmentDiff(conflict, subMatch)) {
+ buildSubTree(parentNode, conflict, subMatch);
+ }
+ }
+
+ }
+
+ /**
+ * Checks if the parent of the given diff is a pseudo conflict with a different side than the given
+ * diff.
+ *
+ * @param diff
+ * the given diff.
+ * @param parent
+ * the parent of the given duff.
+ * @return true if the parent of the given diff is a pseudo conflict with a different side than the
+ * given diff, false otherwise.
+ */
+ private boolean isParentPseudoConflictFromOtherSide(Diff diff, EObject parent) {
+ boolean ret = false;
+ if (parent instanceof Diff) {
+ Conflict conflict = ((Diff)parent).getConflict();
+ if (conflict != null) {
+ if (ConflictKind.PSEUDO == conflict.getKind()) {
+ ret = !fromSide(((Diff)parent).getSource()).apply(diff);
+ }
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * Checks if the given match is a match of one of the containment diffs of the given Conflict.
+ *
+ * @param conflict
+ * the given conflict.
+ * @param subMatch
+ * the given match.
+ * @return true, if the given match is a match of one of the containment diffs of the given Conflict,
+ * false otherwise.
+ */
+ protected boolean isMatchOfConflictContainmentDiff(Conflict conflict, Match subMatch) {
+ if (subMatch != null) {
+ for (Diff diff : conflict.getDifferences()) {
+ if (isContainment(diff)) {
+ final Match realMatch = diff.getMatch().getComparison().getMatch(
+ ((ReferenceChange)diff).getValue());
+ if (subMatch.equals(realMatch)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks whether the given diff corresponds to a containment change. This holds true for differences
+ * on containment references' values, but also for resource attachment changes.
+ *
+ * @param diff
+ * The diff to consider.
+ * @return <code>true</code> if the given {@code diff} is to be considered a containment change,
+ * <code>false</code> otherwise.
+ */
+ private boolean isContainment(Diff diff) {
+ return diff instanceof ReferenceChange && ((ReferenceChange)diff).getReference().isContainment()
+ || diff instanceof ResourceAttachmentChange;
+ }
}
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/provider/GroupItemProviderAdapter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/provider/GroupItemProviderAdapter.java
new file mode 100644
index 000000000..13770c70c
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/provider/GroupItemProviderAdapter.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.provider;
+
+import java.util.Collection;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.compare.ComparePackage;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
+import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
+import org.eclipse.emf.compare.provider.utils.IStyledString.IComposedStyledString;
+import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
+import org.eclipse.emf.edit.provider.IItemColorProvider;
+import org.eclipse.emf.edit.provider.IItemFontProvider;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.edit.provider.IItemPropertySource;
+import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
+import org.eclipse.emf.edit.provider.ItemProviderAdapter;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class GroupItemProviderAdapter extends ItemProviderAdapter implements IEditingDomainItemProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource, IItemColorProvider, IItemFontProvider, IItemStyledLabelProvider, IItemDescriptionProvider {
+
+ /** The comparsion object used by this group. */
+ private Comparison comparison;
+
+ /** The group for which we want the item provider. */
+ private IDifferenceGroup group;
+
+ /**
+ * Constructor.
+ */
+ public GroupItemProviderAdapter(AdapterFactory adapterFactory, Comparison comparison,
+ IDifferenceGroup group) {
+ super(adapterFactory);
+ this.comparison = comparison;
+ this.group = group;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemDescriptionProvider#getDescription(java.lang.Object)
+ */
+ public String getDescription(Object object) {
+ return group.getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getImage(java.lang.Object)
+ */
+ @Override
+ public Object getImage(Object object) {
+ return group.getImage();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getText(java.lang.Object)
+ */
+ @Override
+ public String getText(Object object) {
+ return group.getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object)
+ */
+ public IComposedStyledString getStyledText(Object object) {
+ return group.getStyledName();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildrenFeatures(java.lang.Object)
+ */
+ @Override
+ public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) {
+ if (childrenFeatures == null) {
+ super.getChildrenFeatures(object);
+ childrenFeatures.add(ComparePackage.Literals.COMPARISON__MATCHED_RESOURCES);
+ childrenFeatures.add(ComparePackage.Literals.COMPARISON__MATCHES);
+ }
+ return childrenFeatures;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getValue(org.eclipse.emf.ecore.EObject,
+ * org.eclipse.emf.ecore.EStructuralFeature)
+ */
+ @Override
+ protected Object getValue(EObject eObject, EStructuralFeature eStructuralFeature) {
+ return super.getValue(eObject, eStructuralFeature);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getParent(java.lang.Object)
+ */
+ @Override
+ public Object getParent(Object object) {
+ return comparison;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#hasChildren(java.lang.Object)
+ */
+ @Override
+ public boolean hasChildren(Object object) {
+ return !group.getGroupTree().isEmpty();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
+ */
+ @Override
+ public Collection<?> getChildren(Object object) {
+ return group.getGroupTree();
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/provider/TreeItemProviderAdapterFactorySpec.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/provider/TreeItemProviderAdapterFactorySpec.java
new file mode 100644
index 000000000..33868fbe2
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/provider/TreeItemProviderAdapterFactorySpec.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.provider;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.compare.internal.adapterfactory.RankedAdapterFactory;
+import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
+import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
+import org.eclipse.emf.edit.tree.provider.TreeItemProviderAdapterFactory;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class TreeItemProviderAdapterFactorySpec extends TreeItemProviderAdapterFactory implements RankedAdapterFactory {
+
+ /** The ranking of this adapter factory. */
+ private int ranking;
+
+ /**
+ * Constructor.
+ */
+ public TreeItemProviderAdapterFactorySpec() {
+ super();
+ supportedTypes.add(IItemStyledLabelProvider.class);
+ supportedTypes.add(IItemDescriptionProvider.class);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.tree.provider.TreeItemProviderAdapterFactory#createTreeNodeAdapter()
+ */
+ @Override
+ public Adapter createTreeNodeAdapter() {
+ return new TreeNodeItemProviderSpec(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.internal.adapterfactory.RankedAdapterFactory#getRanking()
+ */
+ public int getRanking() {
+ return ranking;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.internal.adapterfactory.RankedAdapterFactory#setRanking(int)
+ */
+ public void setRanking(int ranking) {
+ this.ranking = ranking;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/provider/TreeNodeItemProviderSpec.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/provider/TreeNodeItemProviderSpec.java
new file mode 100644
index 000000000..f5577ff43
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/provider/TreeNodeItemProviderSpec.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.provider;
+
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Lists.newArrayList;
+
+import com.google.common.collect.Maps;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.provider.AdapterFactoryUtil;
+import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
+import org.eclipse.emf.compare.provider.utils.IStyledString.IComposedStyledString;
+import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup;
+import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
+import org.eclipse.emf.edit.tree.TreeNode;
+import org.eclipse.emf.edit.tree.provider.TreeNodeItemProvider;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class TreeNodeItemProviderSpec extends TreeNodeItemProvider implements IItemStyledLabelProvider {
+
+ /***/
+ private final Map<IDifferenceGroup, GroupItemProviderAdapter> fGroupAdapters = Maps.newHashMap();
+
+ /**
+ * This constructs an instance from a factory.
+ *
+ * @param adapterFactory
+ * the given factory
+ */
+ public TreeNodeItemProviderSpec(AdapterFactory adapterFactory) {
+ super(adapterFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.tree.provider.TreeNodeItemProvider#getParent(java.lang.Object)
+ */
+ @Override
+ public Object getParent(Object object) {
+ Object parent = null;
+ TreeNode treeNode = (TreeNode)object;
+ TreeNode superParent = (TreeNode)super.getParent(object);
+ if (superParent != null && superParent.getData() instanceof Comparison) {
+ EObject parentData = superParent.getData();
+ GroupItemProviderAdapter comparisonGroupItemProvider = (GroupItemProviderAdapter)adapterFactory
+ .adapt(parentData, IEditingDomainItemProvider.class);
+ Collection<?> children = comparisonGroupItemProvider.getChildren(parentData);
+ if (children.size() > 1) {
+ for (Notifier child : filter(children, Notifier.class)) {
+ IDifferenceGroup parentGroup = (IDifferenceGroup)EcoreUtil.getAdapter(child.eAdapters(),
+ IDifferenceGroup.class);
+ IDifferenceGroup group = (IDifferenceGroup)EcoreUtil.getAdapter(treeNode.getData()
+ .eAdapters(), IDifferenceGroup.class);
+ if (parentGroup == group) {
+ parent = child;
+ }
+ }
+ } else {
+ parent = superParent;
+ }
+ }
+ return parent;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
+ */
+ @Override
+ public Collection<?> getChildren(Object object) {
+ TreeNode treeNode = (TreeNode)object;
+ EObject data = treeNode.getData();
+ if (data instanceof Comparison) {
+ IDifferenceGroupProvider groupProvider = (IDifferenceGroupProvider)EcoreUtil.getAdapter(treeNode
+ .eAdapters(), IDifferenceGroupProvider.class);
+ Comparison comparison = (Comparison)data;
+ Collection<? extends IDifferenceGroup> groups = groupProvider.getGroups(comparison);
+ if (groups.size() > 1) {
+ List<GroupItemProviderAdapter> children = newArrayList();
+ for (IDifferenceGroup differenceGroup : groups) {
+ if (!fGroupAdapters.containsKey(differenceGroup)) {
+ fGroupAdapters.put(differenceGroup, new GroupItemProviderAdapter(adapterFactory,
+ comparison, differenceGroup));
+ }
+ children.add(fGroupAdapters.get(differenceGroup));
+ }
+ return children;
+ } else {
+ return groups.iterator().next().getGroupTree();
+ }
+ } else {
+ return super.getChildren(object);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object)
+ */
+ public IComposedStyledString getStyledText(Object object) {
+ TreeNode treeNode = (TreeNode)object;
+ EObject data = treeNode.getData();
+ return (IComposedStyledString)AdapterFactoryUtil.getStyledText(getRootAdapterFactory(), data);
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestComparisonItemProviderSpec.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestComparisonItemProviderSpec.java
index 1ba8f54cf..a51c1e9c1 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestComparisonItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestComparisonItemProviderSpec.java
@@ -1,54 +1,54 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.tests.edit;
-
-import static com.google.common.collect.Iterables.filter;
-import static com.google.common.collect.Iterables.size;
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.util.Collection;
-
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.MatchResource;
-import org.eclipse.emf.compare.provider.ComparisonItemProvider;
-import org.eclipse.emf.compare.provider.spec.ComparisonItemProviderSpec;
-import org.eclipse.emf.compare.tests.edit.data.ecore.a1.EcoreA1InputData;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class TestComparisonItemProviderSpec extends AbstractTestCompareItemProviderAdapter {
-
- private ComparisonItemProvider itemProvider;
-
- @Override
- @Before
- public void before() throws IOException {
- super.before();
- itemProvider = (ComparisonItemProviderSpec)compareItemProviderAdapterFactory
- .createComparisonAdapter();
- }
-
- @Test
- public void testGetChildren_EcoreA1() throws IOException {
- Comparison comparison = getComparison(new EcoreA1InputData());
-
- Collection<?> children = itemProvider.getChildren(comparison);
-
- assertEquals(2, children.size());
- assertEquals(1, size(filter(children, Match.class)));
- assertEquals(1, size(filter(children, MatchResource.class)));
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.edit;
+
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Iterables.size;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.MatchResource;
+import org.eclipse.emf.compare.provider.ComparisonItemProvider;
+import org.eclipse.emf.compare.provider.spec.ComparisonItemProviderSpec;
+import org.eclipse.emf.compare.tests.edit.data.ecore.a1.EcoreA1InputData;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class TestComparisonItemProviderSpec extends AbstractTestCompareItemProviderAdapter {
+
+ private ComparisonItemProvider itemProvider;
+
+ @Override
+ @Before
+ public void before() throws IOException {
+ super.before();
+ itemProvider = (ComparisonItemProviderSpec)compareItemProviderAdapterFactory
+ .createComparisonAdapter();
+ }
+
+ @Test
+ public void testGetChildren_EcoreA1() throws IOException {
+ Comparison comparison = getComparison(new EcoreA1InputData());
+
+ Collection<?> children = itemProvider.getChildren(comparison);
+
+ assertEquals(7, children.size());
+ assertEquals(1, size(filter(children, Match.class)));
+ assertEquals(1, size(filter(children, MatchResource.class)));
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestMatchItemProviderSpec.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestMatchItemProviderSpec.java
index d351bcf21..8a1363e8a 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestMatchItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestMatchItemProviderSpec.java
@@ -46,9 +46,9 @@ public class TestMatchItemProviderSpec extends AbstractTestCompareItemProviderAd
Match ePackageMatch = getEcoreA1_EPackageMatch();
Collection<?> ePackageMatchChildren = itemProvider.getChildren(ePackageMatch);
- assertEquals(18, ePackageMatchChildren.size());
+ assertEquals(22, ePackageMatchChildren.size());
assertEquals(4, size(filter(ePackageMatchChildren, Diff.class)));
- assertEquals(14, size(filter(ePackageMatchChildren, Match.class)));
+ assertEquals(18, size(filter(ePackageMatchChildren, Match.class)));
}
static Match getEcoreA1_EPackageMatch() throws IOException {
@@ -64,13 +64,13 @@ public class TestMatchItemProviderSpec extends AbstractTestCompareItemProviderAd
Match ePackageMatch = getEcoreA1_EPackageMatch();
Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
- Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
- "AudioVisualItem");
+ Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", //$NON-NLS-1$
+ "AudioVisualItem"); //$NON-NLS-1$
Collection<?> audioVisualItem_MatchChildren = itemProvider.getChildren(audioVisualItem_Match);
- assertEquals(4, audioVisualItem_MatchChildren.size());
+ assertEquals(5, audioVisualItem_MatchChildren.size());
assertEquals(2, size(filter(audioVisualItem_MatchChildren, Diff.class)));
- assertEquals(2, size(filter(audioVisualItem_MatchChildren, Match.class)));
+ assertEquals(3, size(filter(audioVisualItem_MatchChildren, Match.class)));
}
@Test
@@ -78,11 +78,11 @@ public class TestMatchItemProviderSpec extends AbstractTestCompareItemProviderAd
Match ePackageMatch = getEcoreA1_EPackageMatch();
Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
- Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
- "AudioVisualItem");
+ Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", //$NON-NLS-1$
+ "AudioVisualItem"); //$NON-NLS-1$
Collection<?> audioVisualItem_MatchChildren = itemProvider.getChildren(audioVisualItem_Match);
- Match audioVisualItem_legnth_Match = getMatchWithFeatureValue(audioVisualItem_MatchChildren, "name",
- "length");
+ Match audioVisualItem_legnth_Match = getMatchWithFeatureValue(audioVisualItem_MatchChildren, "name", //$NON-NLS-1$
+ "length"); //$NON-NLS-1$
Collection<?> audioVisualItem_legnth_MatchChildren = itemProvider
.getChildren(audioVisualItem_legnth_Match);
@@ -96,12 +96,12 @@ public class TestMatchItemProviderSpec extends AbstractTestCompareItemProviderAd
Match ePackageMatch = getEcoreA1_EPackageMatch();
Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
- Match book_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Book");
+ Match book_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Book"); //$NON-NLS-1$ //$NON-NLS-2$
Collection<?> book_MatchChildren = itemProvider.getChildren(book_Match);
- assertEquals(6, book_MatchChildren.size());
+ assertEquals(8, book_MatchChildren.size());
assertEquals(3, size(filter(book_MatchChildren, Diff.class)));
- assertEquals(3, size(filter(book_MatchChildren, Match.class)));
+ assertEquals(5, size(filter(book_MatchChildren, Match.class)));
}
@Test
@@ -109,12 +109,12 @@ public class TestMatchItemProviderSpec extends AbstractTestCompareItemProviderAd
Match ePackageMatch = getEcoreA1_EPackageMatch();
Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
- Match bookCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "BookCategory");
+ Match bookCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "BookCategory"); //$NON-NLS-1$ //$NON-NLS-2$
Collection<?> bookCategory_MatchChildren = itemProvider.getChildren(bookCategory_Match);
- assertEquals(7, bookCategory_MatchChildren.size());
+ assertEquals(11, bookCategory_MatchChildren.size());
assertEquals(4, size(filter(bookCategory_MatchChildren, Diff.class)));
- assertEquals(3, size(filter(bookCategory_MatchChildren, Match.class)));
+ assertEquals(7, size(filter(bookCategory_MatchChildren, Match.class)));
}
@Test
@@ -122,7 +122,7 @@ public class TestMatchItemProviderSpec extends AbstractTestCompareItemProviderAd
Match ePackageMatch = getEcoreA1_EPackageMatch();
Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
- Match borrowable_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Borrowable");
+ Match borrowable_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Borrowable"); //$NON-NLS-1$ //$NON-NLS-2$
Collection<?> borrowable_MatchChildren = itemProvider.getChildren(borrowable_Match);
assertEquals(3, borrowable_MatchChildren.size());
@@ -135,11 +135,11 @@ public class TestMatchItemProviderSpec extends AbstractTestCompareItemProviderAd
Match ePackageMatch = getEcoreA1_EPackageMatch();
Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
- Match person_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Person");
+ Match person_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Person"); //$NON-NLS-1$ //$NON-NLS-2$
Collection<?> person_MatchChildren = itemProvider.getChildren(person_Match);
- assertEquals(3, person_MatchChildren.size());
+ assertEquals(6, person_MatchChildren.size());
assertEquals(3, size(filter(person_MatchChildren, Diff.class)));
- assertEquals(0, size(filter(person_MatchChildren, Match.class)));
+ assertEquals(3, size(filter(person_MatchChildren, Match.class)));
}
}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestReferenceChangeItemProviderSpec.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestReferenceChangeItemProviderSpec.java
index 2d32db3c3..603ee6dce 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestReferenceChangeItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestReferenceChangeItemProviderSpec.java
@@ -11,20 +11,15 @@
package org.eclipse.emf.compare.tests.edit;
import static com.google.common.collect.Iterables.filter;
-import static com.google.common.collect.Iterables.get;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.Collection;
-import java.util.Iterator;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.compare.AttributeChange;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ReferenceChange;
import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EcorePackage;
import org.junit.Test;
/**
@@ -38,27 +33,18 @@ public class TestReferenceChangeItemProviderSpec extends AbstractTestCompareItem
Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch).getChildren(
ePackageMatch);
- Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
- "AudioVisualItem");
+ Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", //$NON-NLS-1$
+ "AudioVisualItem"); //$NON-NLS-1$
Collection<?> audioVisualItem_MatchChildren = adaptAsITreeItemContentProvider(audioVisualItem_Match)
.getChildren(audioVisualItem_Match);
ReferenceChange titleReferenceChange = getReferenceChangeWithFeatureValue(
- audioVisualItem_MatchChildren, "name", "title");
+ audioVisualItem_MatchChildren, "name", "title"); //$NON-NLS-1$ //$NON-NLS-2$
Collection<?> titleReferenceChange_Children = adaptAsITreeItemContentProvider(titleReferenceChange)
.getChildren(titleReferenceChange);
- assertEquals(1, titleReferenceChange_Children.size());
- Object child = get(titleReferenceChange_Children, 0);
- assertTrue(child instanceof ReferenceChange);
- assertEquals(EcorePackage.Literals.ETYPED_ELEMENT__ETYPE, ((ReferenceChange)child).getReference());
-
- ReferenceChange titledItemReferenceChange = getReferenceChangeWithFeatureValue(
- audioVisualItem_MatchChildren, "name", "TitledItem");
- Collection<?> titledItemReferenceChange_Children = adaptAsITreeItemContentProvider(
- titledItemReferenceChange).getChildren(titledItemReferenceChange);
- assertEquals(0, titledItemReferenceChange_Children.size());
+ assertEquals(0, titleReferenceChange_Children.size());
}
@Test
@@ -67,36 +53,17 @@ public class TestReferenceChangeItemProviderSpec extends AbstractTestCompareItem
Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch).getChildren(
ePackageMatch);
- Match book_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Book");
- Collection<?> book_MatchChildren = adaptAsITreeItemContentProvider(book_Match).getChildren(book_Match);
+ Match book_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Book"); //$NON-NLS-1$ //$NON-NLS-2$
+ Collection<?> book_MatchChildren = adaptAsITreeItemContentProvider(book_Match)
+ .getChildren(book_Match);
ReferenceChange subtitleReferenceChange = getReferenceChangeWithFeatureValue(book_MatchChildren,
- "name", "subtitle");
+ "name", "subtitle"); //$NON-NLS-1$ //$NON-NLS-2$
Collection<?> subtitleReferenceChange_Children = adaptAsITreeItemContentProvider(
subtitleReferenceChange).getChildren(subtitleReferenceChange);
- assertEquals(1, subtitleReferenceChange_Children.size());
- Notifier child = (Notifier)get(subtitleReferenceChange_Children, 0);
- assertTrue(child instanceof ReferenceChange);
- assertEquals(EcorePackage.Literals.ETYPED_ELEMENT__ETYPE, ((ReferenceChange)child).getReference());
- assertTrue(adaptAsITreeItemContentProvider(child).getChildren(child).isEmpty());
-
- ReferenceChange titleReferenceChange = getReferenceChangeWithFeatureValue(book_MatchChildren, "name",
- "title");
- Collection<?> titleReferenceChange_Children = adaptAsITreeItemContentProvider(titleReferenceChange)
- .getChildren(titleReferenceChange);
- assertEquals(1, titleReferenceChange_Children.size());
- child = (Notifier)get(titleReferenceChange_Children, 0);
- assertTrue(child instanceof ReferenceChange);
- assertEquals(EcorePackage.Literals.ETYPED_ELEMENT__ETYPE, ((ReferenceChange)child).getReference());
- assertTrue(adaptAsITreeItemContentProvider(child).getChildren(child).isEmpty());
-
- ReferenceChange titledItemReferenceChange = getReferenceChangeWithFeatureValue(book_MatchChildren,
- "name", "TitledItem");
- Collection<?> titledItemReferenceChange_Children = adaptAsITreeItemContentProvider(
- titledItemReferenceChange).getChildren(titledItemReferenceChange);
- assertEquals(0, titledItemReferenceChange_Children.size());
+ assertEquals(0, subtitleReferenceChange_Children.size());
}
@Test
@@ -105,8 +72,8 @@ public class TestReferenceChangeItemProviderSpec extends AbstractTestCompareItem
Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch).getChildren(
ePackageMatch);
- Match borrowableCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
- "Borrowable");
+ Match borrowableCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", //$NON-NLS-1$
+ "Borrowable"); //$NON-NLS-1$
Collection<?> borrowable_MatchChildren = adaptAsITreeItemContentProvider(borrowableCategory_Match)
.getChildren(borrowableCategory_Match);
@@ -119,18 +86,18 @@ public class TestReferenceChangeItemProviderSpec extends AbstractTestCompareItem
Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch).getChildren(
ePackageMatch);
- Match bookCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "BookCategory");
+ Match bookCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "BookCategory"); //$NON-NLS-1$ //$NON-NLS-2$
Collection<?> bookCategory_MatchChildren = adaptAsITreeItemContentProvider(bookCategory_Match)
.getChildren(bookCategory_Match);
ReferenceChange dictionaryReferenceChange = getReferenceChangeWithFeatureValue(
- bookCategory_MatchChildren, "name", "Dictionary");
+ bookCategory_MatchChildren, "name", "Dictionary"); //$NON-NLS-1$ //$NON-NLS-2$
ReferenceChange encyclopediaReferenceChange = getReferenceChangeWithFeatureValue(
- bookCategory_MatchChildren, "name", "Encyclopedia");
+ bookCategory_MatchChildren, "name", "Encyclopedia"); //$NON-NLS-1$ //$NON-NLS-2$
ReferenceChange mangaReferenceChange = getReferenceChangeWithFeatureValue(bookCategory_MatchChildren,
- "name", "Manga");
+ "name", "Manga"); //$NON-NLS-1$ //$NON-NLS-2$
ReferenceChange manhwaReferenceChange = getReferenceChangeWithFeatureValue(
- bookCategory_MatchChildren, "name", "Manhwa");
+ bookCategory_MatchChildren, "name", "Manhwa"); //$NON-NLS-1$ //$NON-NLS-2$
assertTrue(adaptAsITreeItemContentProvider(dictionaryReferenceChange).getChildren(
dictionaryReferenceChange).isEmpty());
@@ -152,28 +119,14 @@ public class TestReferenceChangeItemProviderSpec extends AbstractTestCompareItem
Collection<?> magazineChildren = null;
for (ReferenceChange referenceChange : filter(ePackage_MatchChildren, ReferenceChange.class)) {
EClass eClass = (EClass)referenceChange.getValue();
- if ("Magazine".equals(eClass.getName())
- && "CirculatingItem".equals(eClass.getESuperTypes().get(0).getName())) {
+ if ("Magazine".equals(eClass.getName()) //$NON-NLS-1$
+ && "CirculatingItem".equals(eClass.getESuperTypes().get(0).getName())) { //$NON-NLS-1$
magazineChildren = adaptAsITreeItemContentProvider(referenceChange).getChildren(
referenceChange);
- assertEquals(3, magazineChildren.size());
+ assertEquals(0, magazineChildren.size());
break;
}
}
- ReferenceChange magazineSuperTypeChange = getReferenceChangeWithFeatureValue(magazineChildren,
- "name", "CirculatingItem");
- assertTrue(adaptAsITreeItemContentProvider(magazineSuperTypeChange).getChildren(
- magazineSuperTypeChange).isEmpty());
-
- ReferenceChange magazineSFChange1 = getReferenceChangeWithFeatureValue(magazineChildren, "name",
- "pages");
- assertEquals(1, adaptAsITreeItemContentProvider(magazineSFChange1).getChildren(magazineSFChange1)
- .size());
-
- ReferenceChange magazineSFChange2 = getReferenceChangeWithFeatureValue(magazineChildren, "name",
- "title");
- assertEquals(1, adaptAsITreeItemContentProvider(magazineSFChange2).getChildren(magazineSFChange2)
- .size());
}
@Test
@@ -186,18 +139,14 @@ public class TestReferenceChangeItemProviderSpec extends AbstractTestCompareItem
Collection<?> magazineChildren = null;
for (ReferenceChange referenceChange : filter(ePackage_MatchChildren, ReferenceChange.class)) {
EClass eClass = (EClass)referenceChange.getValue();
- if ("Magazine".equals(eClass.getName())
- && "Periodical".equals(eClass.getESuperTypes().get(0).getName())) {
+ if ("Magazine".equals(eClass.getName()) //$NON-NLS-1$
+ && "Periodical".equals(eClass.getESuperTypes().get(0).getName())) { //$NON-NLS-1$
magazineChildren = adaptAsITreeItemContentProvider(referenceChange).getChildren(
referenceChange);
- assertEquals(1, magazineChildren.size());
+ assertEquals(0, magazineChildren.size());
break;
}
}
- ReferenceChange magazineSuperTypeChange = getReferenceChangeWithFeatureValue(magazineChildren,
- "name", "Periodical");
- assertTrue(adaptAsITreeItemContentProvider(magazineSuperTypeChange).getChildren(
- magazineSuperTypeChange).isEmpty());
}
@Test
@@ -207,28 +156,11 @@ public class TestReferenceChangeItemProviderSpec extends AbstractTestCompareItem
Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch).getChildren(
ePackageMatch);
ReferenceChange periodical_ReferenceChange = getReferenceChangeWithFeatureValue(
- ePackage_MatchChildren, "name", "Periodical");
+ ePackage_MatchChildren, "name", "Periodical"); //$NON-NLS-1$ //$NON-NLS-2$
Collection<?> periodical_ReferenceChangeChildren = adaptAsITreeItemContentProvider(
periodical_ReferenceChange).getChildren(periodical_ReferenceChange);
- assertEquals(5, periodical_ReferenceChangeChildren.size());
-
- ReferenceChange issuesPerYearChange = getReferenceChangeWithFeatureValue(
- periodical_ReferenceChangeChildren, "name", "issuesPerYear");
-
- ReferenceChange itemChange = getReferenceChangeWithFeatureValue(periodical_ReferenceChangeChildren,
- "name", "Item");
- ReferenceChange titledItemChange = getReferenceChangeWithFeatureValue(
- periodical_ReferenceChangeChildren, "name", "TitledItem");
-
- Collection<?> issuesPerYearChildren = adaptAsITreeItemContentProvider(issuesPerYearChange)
- .getChildren(issuesPerYearChange);
- assertEquals(1, issuesPerYearChildren.size());
- ReferenceChange issuePerYearChild = (ReferenceChange)issuesPerYearChildren.iterator().next();
- assertEquals(EcorePackage.Literals.ETYPED_ELEMENT__ETYPE, issuePerYearChild.getReference());
-
- assertTrue(adaptAsITreeItemContentProvider(itemChange).getChildren(itemChange).isEmpty());
- assertTrue(adaptAsITreeItemContentProvider(titledItemChange).getChildren(titledItemChange).isEmpty());
+ assertEquals(0, periodical_ReferenceChangeChildren.size());
}
@Test
@@ -237,38 +169,17 @@ public class TestReferenceChangeItemProviderSpec extends AbstractTestCompareItem
Collection<?> ePackage_MatchChildren = adaptAsITreeItemContentProvider(ePackageMatch).getChildren(
ePackageMatch);
- Match person_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Person");
+ Match person_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Person"); //$NON-NLS-1$ //$NON-NLS-2$
Collection<?> person_MatchChildren = adaptAsITreeItemContentProvider(person_Match).getChildren(
person_Match);
- assertEquals(3, person_MatchChildren.size());
+ assertEquals(6, person_MatchChildren.size());
ReferenceChange issuesPerYearChange = getReferenceChangeWithFeatureValue(person_MatchChildren,
- "name", "firstName");
+ "name", "firstName"); //$NON-NLS-1$ //$NON-NLS-2$
Collection<?> firstNameChildren = adaptAsITreeItemContentProvider(issuesPerYearChange).getChildren(
issuesPerYearChange);
- assertEquals(1, firstNameChildren.size());
- ReferenceChange firstNameChild = (ReferenceChange)firstNameChildren.iterator().next();
- assertEquals(EcorePackage.Literals.ETYPED_ELEMENT__ETYPE, firstNameChild.getReference());
-
- ReferenceChange fullNameChange = getReferenceChangeWithFeatureValue(person_MatchChildren, "name",
- "fullName");
- Collection<?> fullNameChildren = adaptAsITreeItemContentProvider(fullNameChange).getChildren(
- fullNameChange);
- assertEquals(1, fullNameChildren.size());
- ReferenceChange fullNameChild = (ReferenceChange)fullNameChildren.iterator().next();
- assertEquals(EcorePackage.Literals.ETYPED_ELEMENT__ETYPE, fullNameChild.getReference());
-
- ReferenceChange lastNameChange = getReferenceChangeWithFeatureValue(person_MatchChildren, "name",
- "lastName");
- Collection<?> lastNameChildren = adaptAsITreeItemContentProvider(lastNameChange).getChildren(
- lastNameChange);
- assertEquals(2, lastNameChildren.size());
- Iterator<?> lastNameiterator = lastNameChildren.iterator();
- ReferenceChange lastName1stChild = (ReferenceChange)lastNameiterator.next();
- AttributeChange lastName2ndChild = (AttributeChange)lastNameiterator.next();
- assertEquals(EcorePackage.Literals.ETYPED_ELEMENT__ETYPE, lastName1stChild.getReference());
- assertEquals(EcorePackage.Literals.ENAMED_ELEMENT__NAME, lastName2ndChild.getAttribute());
+ assertEquals(0, firstNameChildren.size());
}
@Test
@@ -279,17 +190,9 @@ public class TestReferenceChangeItemProviderSpec extends AbstractTestCompareItem
ePackageMatch);
ReferenceChange titledItem_ReferenceChange = getReferenceChangeWithFeatureValue(
- ePackage_MatchChildren, "name", "TitledItem");
+ ePackage_MatchChildren, "name", "TitledItem"); //$NON-NLS-1$ //$NON-NLS-2$
Collection<?> titledItem_ReferenceChangeChildren = adaptAsITreeItemContentProvider(
titledItem_ReferenceChange).getChildren(titledItem_ReferenceChange);
- assertEquals(1, titledItem_ReferenceChangeChildren.size());
-
- ReferenceChange title_Change = (ReferenceChange)titledItem_ReferenceChangeChildren.iterator().next();
- Collection<?> title_ChangeChildren = adaptAsITreeItemContentProvider(title_Change).getChildren(
- title_Change);
- assertEquals(1, title_ChangeChildren.size());
-
- ReferenceChange eType_Change = (ReferenceChange)title_ChangeChildren.iterator().next();
- assertTrue(adaptAsITreeItemContentProvider(eType_Change).getChildren(eType_Change).isEmpty());
+ assertEquals(0, titledItem_ReferenceChangeChildren.size());
}
}
diff --git a/plugins/org.eclipse.emf.compare.uml2.rcp.ui/src/org/eclipse/emf/compare/uml2/rcp/ui/internal/structuremergeviewer/filters/UMLRefinedElementsFilter.java b/plugins/org.eclipse.emf.compare.uml2.rcp.ui/src/org/eclipse/emf/compare/uml2/rcp/ui/internal/structuremergeviewer/filters/UMLRefinedElementsFilter.java
index 316b43697..eb18d1e89 100644
--- a/plugins/org.eclipse.emf.compare.uml2.rcp.ui/src/org/eclipse/emf/compare/uml2/rcp/ui/internal/structuremergeviewer/filters/UMLRefinedElementsFilter.java
+++ b/plugins/org.eclipse.emf.compare.uml2.rcp.ui/src/org/eclipse/emf/compare/uml2/rcp/ui/internal/structuremergeviewer/filters/UMLRefinedElementsFilter.java
@@ -22,6 +22,7 @@ import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.compare.uml2.internal.UMLDiff;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.edit.tree.TreeNode;
/**
* A filter used by default that to filtered out refined UML differences.
@@ -34,11 +35,14 @@ public class UMLRefinedElementsFilter extends AbstractDifferenceFilter {
/**
* The predicate use by this filter when it is selected.
*/
- private static final Predicate<? super EObject> predicateWhenSelected = new Predicate<EObject>() {
+ private static final Predicate<? super EObject> PREDICATE_WHEN_SELECTED = new Predicate<EObject>() {
public boolean apply(EObject input) {
- if (input instanceof Diff) {
- Diff diff = (Diff)input;
- return Iterables.any(diff.getRefines(), instanceOf(UMLDiff.class));
+ if (input instanceof TreeNode) {
+ EObject data = ((TreeNode)input).getData();
+ if (data instanceof Diff) {
+ Diff diff = (Diff)data;
+ return Iterables.any(diff.getRefines(), instanceOf(UMLDiff.class));
+ }
}
return false;
}
@@ -47,11 +51,16 @@ public class UMLRefinedElementsFilter extends AbstractDifferenceFilter {
/**
* The predicate use by this filter when it is unselected.
*/
- private static final Predicate<? super EObject> predicateWhenUnselected = new Predicate<EObject>() {
+ private static final Predicate<? super EObject> PREDICATE_WHEN_UNSELECTED = new Predicate<EObject>() {
public boolean apply(EObject input) {
- EPackage p = input.eClass().getEPackage();
- if (p != null) {
- return p.getNsURI().startsWith("http://www.eclipse.org/emf/compare/uml2"); //$NON-NLS-1$
+ if (input instanceof TreeNode) {
+ EObject data = ((TreeNode)input).getData();
+ if (data != null) {
+ EPackage p = data.eClass().getEPackage();
+ if (p != null) {
+ return p.getNsURI().startsWith("http://www.eclipse.org/emf/compare/uml2"); //$NON-NLS-1$
+ }
+ }
}
return false;
}
@@ -82,7 +91,7 @@ public class UMLRefinedElementsFilter extends AbstractDifferenceFilter {
*/
@Override
public Predicate<? super EObject> getPredicateWhenSelected() {
- return predicateWhenSelected;
+ return PREDICATE_WHEN_SELECTED;
}
/**
@@ -92,6 +101,6 @@ public class UMLRefinedElementsFilter extends AbstractDifferenceFilter {
*/
@Override
public Predicate<? super EObject> getPredicateWhenUnselected() {
- return predicateWhenUnselected;
+ return PREDICATE_WHEN_UNSELECTED;
}
}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java
index cea6e8865..f11bbc6d1 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java
@@ -1,1097 +1,1097 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.utils;
-
-import static com.google.common.base.Predicates.and;
-
-import com.google.common.base.Predicate;
-
-import java.util.Arrays;
-import java.util.Iterator;
-
-import org.eclipse.emf.compare.AttributeChange;
-import org.eclipse.emf.compare.ConflictKind;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceKind;
-import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.DifferenceState;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.ReferenceChange;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.ENamedElement;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.EcorePackage;
-
-/**
- * This class will provide a number of Predicates that can be used to retrieve particular {@link Diff}s from
- * an iterable.
- *
- * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
- */
-public final class EMFComparePredicates {
- /**
- * This class does not need to be instantiated.
- */
- private EMFComparePredicates() {
- // Hides default constructor
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the modification of a single-valued
- * reference going by the given {@code referenceName} on an EObject which name matches
- * {@code qualifiedName}. This can be used both on three-way and two-way Diffs : if three-way, we'll
- * consider that the {@code fromQualifiedName} can be either one of the right or origin values, and the
- * {@code toQualifiedName} to be either left or right. on two-way diffs however, {@code fromQualifiedName}
- * can only be the right value, and {@code toQualifiedName} will be the left one.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present a ReferenceChange.
- * @param referenceName
- * Name of the single-valued reference on which we expect a change.
- * @param fromQualifiedName
- * The original value of this reference.
- * @param toQualifiedName
- * The value to which this reference has been changed.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> changedReference(final String qualifiedName,
- final String referenceName, final String fromQualifiedName, final String toQualifiedName) {
- final Predicate<? super Diff> valuesMatch = new ReferenceValuesMatch(referenceName,
- fromQualifiedName, toQualifiedName);
- return and(ofKind(DifferenceKind.CHANGE), onEObject(qualifiedName), valuesMatch);
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the addition of a value in a
- * multi-valued attribute going by {@code attributeName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present an AttributeChange.
- * @param attributeName
- * Name of the multi-valued attribute on which we expect a change.
- * @param addedValue
- * The value we expect to have been added to this attribute.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> addedToAttribute(final String qualifiedName,
- final String attributeName, final Object addedValue) {
- // This is only meant for multi-valued attributes
- return and(ofKind(DifferenceKind.ADD), onEObject(qualifiedName), attributeValueMatch(attributeName,
- addedValue, true));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the addition of a value in a
- * multi-valued reference going by {@code referenceName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present a ReferenceChange.
- * @param referenceName
- * Name of the multi-valued reference on which we expect a change.
- * @param addedQualifiedName
- * Qualified name of the EObject which we expect to have been added to this reference.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> addedToReference(final String qualifiedName,
- final String referenceName, final String addedQualifiedName) {
- // This is only meant for multi-valued references
- return and(ofKind(DifferenceKind.ADD), onEObject(qualifiedName), referenceValueMatch(referenceName,
- addedQualifiedName, true));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the addition of a value in a
- * multi-valued reference going by {@code referenceName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present a ReferenceChange.
- * @param referenceName
- * Name of the multi-valued reference on which we expect a change.
- * @param addedQualifiedName
- * Qualified name of the EObject which we expect to have been added to this reference.
- * @param featureDelegateForAddedName
- * The optional feature to define the name of the objects which we expect to have been added to
- * this reference. May be null.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> addedToReference(final String qualifiedName,
- final String referenceName, final String addedQualifiedName,
- final EStructuralFeature featureDelegateForAddedName) {
- // This is only meant for multi-valued references
- return and(ofKind(DifferenceKind.ADD), onEObject(qualifiedName), referenceValueMatch(referenceName,
- addedQualifiedName, true, featureDelegateForAddedName));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the moving of a value within a
- * multi-valued attribute going by {@code attributeName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present an AttributeChange.
- * @param attributeName
- * Name of the multi-valued attribute on which we expect a change.
- * @param removedValue
- * Value which we expect to have been moved within this attribute.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> movedInAttribute(final String qualifiedName,
- final String attributeName, final Object removedValue) {
- // This is only meant for multi-valued attributes
- return and(ofKind(DifferenceKind.MOVE), onEObject(qualifiedName), attributeValueMatch(attributeName,
- removedValue, true));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the moving of a value within a
- * multi-valued reference going by {@code referenceName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present a ReferenceChange.
- * @param referenceName
- * Name of the multi-valued reference on which we expect a change.
- * @param removedQualifiedName
- * Qualified name of the EObject which we expect to have been moved within this reference.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> movedInReference(final String qualifiedName,
- final String referenceName, final String removedQualifiedName) {
- // This is only meant for multi-valued references
- return and(ofKind(DifferenceKind.MOVE), onEObject(qualifiedName), referenceValueMatch(referenceName,
- removedQualifiedName, true));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the deletion of a value from a
- * multi-valued attribute going by {@code attributeName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present an AttributeChange.
- * @param attributeName
- * Name of the multi-valued attribute on which we expect a change.
- * @param removedValue
- * Value which we expect to have been removed from this attribute.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> removedFromAttribute(final String qualifiedName,
- final String attributeName, final Object removedValue) {
- // This is only meant for multi-valued attributes
- return and(ofKind(DifferenceKind.DELETE), onEObject(qualifiedName), attributeValueMatch(
- attributeName, removedValue, true));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the deletion of a value from a
- * multi-valued reference going by {@code referenceName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present a ReferenceChange.
- * @param referenceName
- * Name of the multi-valued reference on which we expect a change.
- * @param removedQualifiedName
- * Qualified name of the EObject which we expect to have been removed from this reference.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> removedFromReference(final String qualifiedName,
- final String referenceName, final String removedQualifiedName) {
- // This is only meant for multi-valued references
- return and(ofKind(DifferenceKind.DELETE), onEObject(qualifiedName), referenceValueMatch(
- referenceName, removedQualifiedName, true));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the deletion of a value from a
- * multi-valued reference going by {@code referenceName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present a ReferenceChange.
- * @param referenceName
- * Name of the multi-valued reference on which we expect a change.
- * @param removedQualifiedName
- * Qualified name of the EObject which we expect to have been removed from this reference.
- * @param featureDelegateForRemovedName
- * The optional feature to define the name of the objects which we expect to have been removed
- * from this reference. May be null.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> removedFromReference(final String qualifiedName,
- final String referenceName, final String removedQualifiedName,
- final EStructuralFeature featureDelegateForRemovedName) {
- // This is only meant for multi-valued references
- return and(ofKind(DifferenceKind.DELETE), onEObject(qualifiedName), referenceValueMatch(
- referenceName, removedQualifiedName, true, featureDelegateForRemovedName));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the modification of a single-valued
- * attribute going by the given {@code attributeName} on an EObject which name matches
- * {@code qualifiedName}. This can be used both on three-way and two-way Diffs : if three-way, we'll
- * consider that the {@code fromValue} can be either one of the right or origin values, and the
- * {@code toValue} to be either left or right. on two-way diffs however, {@code fromValue} can only be the
- * right value, and {@code toValue} will be the left one.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present an AttributeChange.
- * @param attributeName
- * Name of the single-valued attribute on which we expect a change.
- * @param fromValue
- * The original value of this attribute.
- * @param toValue
- * The value to which this attribute has been changed.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> changedAttribute(final String qualifiedName,
- final String attributeName, final Object fromValue, final Object toValue) {
- final Predicate<? super Diff> valuesMatch = new AttributeValuesMatch(attributeName, fromValue,
- toValue);
- return and(ofKind(DifferenceKind.CHANGE), onEObject(qualifiedName), valuesMatch);
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the addition of an EObject matching
- * the given qualified name. Namely, it will check that that Diff is a ReferenceChange, that one of its
- * Match sides correspond to the given qualified name's ancestors, and that its value correspond to the
- * given qualified name's last segment.
- * <p>
- * For example, {@code added("extlibrary.BookCategory.Encyclopedia")} will check that an EObject named
- * "Encyclopedia" has been added under the container "extlibrary.BookCategory". Note that
- * {@code added("emf.compare.Match")} will <b>not</b> match a difference on the EObject
- * "org.eclipse.emf.compare.Match". The qualified name must be absolute.
- * </p>
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a
- * String.
- * </p>
- *
- * @param qualifiedName
- * The qualified name of the EObject we expect to have been added.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> added(final String qualifiedName) {
- final int parentEndIndex = qualifiedName.lastIndexOf('.');
- if (parentEndIndex >= 0) {
- final String ancestors = qualifiedName.substring(0, parentEndIndex);
- final String objectName = qualifiedName.substring(parentEndIndex + 1);
- return and(ofKind(DifferenceKind.ADD), onEObject(ancestors), valueNameMatches(objectName));
- }
- return and(valueNameMatches(qualifiedName), ofKind(DifferenceKind.ADD));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the move of an EObject matching the
- * given qualified name. Namely, it will check that that Diff is a ReferenceChange, that one of its Match
- * sides correspond to the given qualified name's ancestors, and that its value correspond to the given
- * qualified name's last segment.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a
- * String.
- * </p>
- *
- * @param qualifiedName
- * The qualified name of the EObject we expect to have been moved.
- * @param referenceName
- * Name of the reference in which we expect a child to have been added.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> moved(final String qualifiedName, final String referenceName) {
- final int parentEndIndex = qualifiedName.lastIndexOf('.');
- if (parentEndIndex >= 0) {
- final String ancestors = qualifiedName.substring(0, parentEndIndex);
- final String objectName = qualifiedName.substring(parentEndIndex + 1);
- return and(ofKind(DifferenceKind.MOVE), onEObject(ancestors), onFeature(referenceName),
- valueNameMatches(objectName));
- }
- return and(ofKind(DifferenceKind.MOVE), valueNameMatches(qualifiedName), onFeature(referenceName));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the removal of an EObject matching
- * the given qualified name. Namely, it will check that that Diff is a ReferenceChange, that one of its
- * Match sides correspond to the given qualified name's ancestors, and that its value correspond to the
- * given qualified name's last segment.
- * <p>
- * For example, {@code removed("extlibrary.BookCategory.Encyclopedia")} will check that an EObject named
- * "Encyclopedia" has been removed from the container "extlibrary.BookCategory". Note that
- * {@code removed("emf.compare.Match")} will <b>not</b> match a difference on the EObject
- * "org.eclipse.emf.compare.Match". The qualified name must be absolute.
- * </p>
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a
- * String.
- * </p>
- *
- * @param qualifiedName
- * The qualified name of the EObject we expect to have been removed.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> removed(final String qualifiedName) {
- final int parentEndIndex = qualifiedName.lastIndexOf('.');
- if (parentEndIndex >= 0) {
- final String ancestors = qualifiedName.substring(0, parentEndIndex);
- final String objectName = qualifiedName.substring(parentEndIndex + 1);
- return and(ofKind(DifferenceKind.DELETE), onEObject(ancestors), valueNameMatches(objectName));
- }
- return and(valueNameMatches(qualifiedName), ofKind(DifferenceKind.DELETE));
- }
-
- /**
- * This can be used to check that a given Diff correspond to either an {@link AttributeChange} or a
- * {@link ReferenceChange}, and that the corresponding reference or attribute matches the given
- * {@code featureName}.
- *
- * @param featureName
- * Name of the feature on which we expect a change.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> onFeature(final String featureName) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- final EStructuralFeature affectedFeature;
- if (input instanceof AttributeChange) {
- affectedFeature = ((AttributeChange)input).getAttribute();
- } else if (input instanceof ReferenceChange) {
- affectedFeature = ((ReferenceChange)input).getReference();
- } else {
- return false;
- }
- return featureName.equals(affectedFeature.getName());
- }
- };
- }
-
- /**
- * This can be used to check that a given Diff originates from the given {@code source} side.
- *
- * @param source
- * The side from which we expect this diff to originate.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> fromSide(final DifferenceSource source) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- return input != null && input.getSource() == source;
- }
- };
- }
-
- /**
- * This can be used in order to check that a Diff has been detected on the given EObject.
- *
- * @param eObject
- * The EObject which we expect the diff to concern.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> onEObject(final EObject eObject) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- if (input == null) {
- return false;
- }
-
- final Match match = input.getMatch();
- return match.getLeft() == eObject || match.getRight() == eObject
- || match.getOrigin() == eObject;
- }
- };
- }
-
- /**
- * This can be used in order to check whether a Diff has been detected on an EObject matching the given
- * qualified name.
- * <p>
- * For this to work, we expect the EObjects to have a feature named "name" returning a String.
- * </p>
- *
- * @param qualifiedName
- * The qualified name of the EObject we expect that diff to concern.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> onEObject(final String qualifiedName) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- if (input == null) {
- return false;
- }
-
- final Match match = input.getMatch();
- return match(match.getLeft(), qualifiedName, null)
- || match(match.getRight(), qualifiedName, null)
- || match(match.getOrigin(), qualifiedName, null);
- }
- };
- }
-
- /**
- * This can be used in order to check whether a Diff has been detected on an EObject matching the given
- * qualified name or the qualified name under the given feature.
- * <p>
- * For this to work, we expect the EObjects to have a feature named "name" returning a String or to have
- * the given feature (String or EObject with a feature named "name").
- * </p>
- *
- * @param qualifiedName
- * The qualified name of the EObject we expect that diff to concern.
- * @param featureDelegate
- * The optional feature to define the name of the objects. May be null.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> onEObject(final String qualifiedName,
- final EStructuralFeature featureDelegate) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- if (input == null) {
- return false;
- }
-
- final Match match = input.getMatch();
- return match(match.getLeft(), qualifiedName, featureDelegate)
- || match(match.getRight(), qualifiedName, featureDelegate)
- || match(match.getOrigin(), qualifiedName, featureDelegate);
- }
- };
- }
-
- /**
- * This predicate can be used to check whether a particular diff is of the given {@code kind}. This is
- * mainly used to differentiate additions from deletions.
- *
- * @param kind
- * The kind we expect this diff to have.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> ofKind(final DifferenceKind kind) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- return input != null && input.getKind() == kind;
- }
- };
- }
-
- /**
- * This predicate can be used in order to check that a particular Diff describes either a
- * {@link ReferenceChange} or {@link AttributeChange} for the given {@code expectedValue}.
- * <p>
- * For example, this could be used to check that the given value has indeed been added to a reference or
- * attribute, though such checks are more easily performed through {@link #addedIn(EObject, EObject)} or
- * {@link #removedFrom(EObject, EObject)}.
- * </p>
- *
- * @param expectedValue
- * The value which we expect to have changed and detected through a Diff.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> valueIs(final Object expectedValue) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- final Object value;
- if (input instanceof ReferenceChange) {
- value = ((ReferenceChange)input).getValue();
- } else if (input instanceof AttributeChange) {
- value = ((AttributeChange)input).getValue();
- } else {
- return false;
- }
-
- return value == expectedValue || (value != null && value.equals(expectedValue));
- }
- };
- }
-
- /**
- * This predicate can be used to check whether a given Diff describes an AttributeChange with the given
- * {@code attributeName} and which changed value corresponds to the given {@code expectedValue}.
- *
- * @param attributeName
- * The name of the attribute for which we seek an AttributeChange.
- * @param expectedValue
- * The value we expect to correspond to this AttributeChange.
- * @param multiValued
- * Tells us to check for either multi- or single-valued reference changes.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> attributeValueMatch(final String attributeName,
- final Object expectedValue, final boolean multiValued) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- if (input instanceof AttributeChange
- && ((AttributeChange)input).getAttribute().getName().equals(attributeName)
- && ((AttributeChange)input).getAttribute().isMany() == multiValued) {
- final Object value = ((AttributeChange)input).getValue();
- return input.getMatch().getComparison().getEqualityHelper().matchingAttributeValues(
- value, expectedValue);
- }
- return false;
- }
- };
- }
-
- /**
- * This predicate can be used to check whether a given Diff describes a ReferenceChange with the given
- * {@code referenceName} and which changed value corresponds to the given {@code qualifiedName}.
- * <p>
- * For this to work, we expect the EObject to have a feature named "name" returning a String for us to try
- * and match it.
- * </p>
- *
- * @param referenceName
- * The reference for which we seek a ReferenceChange.
- * @param qualifiedName
- * The qualified name of the EObject on which we detected a change.
- * @param multiValued
- * Tells us to check for either multi- or single-valued reference changes.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> referenceValueMatch(final String referenceName,
- final String qualifiedName, final boolean multiValued) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- if (input instanceof ReferenceChange
- && ((ReferenceChange)input).getReference().getName().equals(referenceName)
- && ((ReferenceChange)input).getReference().isMany() == multiValued) {
- final EObject value = ((ReferenceChange)input).getValue();
- return qualifiedName != null && match(value, qualifiedName, null);
- }
- return false;
- }
- };
- }
-
- /**
- * This predicate can be used to check whether a given Diff describes a ReferenceChange with the given
- * {@code referenceName} and which changed value corresponds to the given {@code qualifiedName} or the
- * qualified name under the given {@code featureDelegate}.
- * <p>
- * For this to work, we expect the EObject to have a feature named "name" returning a String or to have
- * the given feature (String or EObject with a feature named "name") for us to try and match it.
- * </p>
- *
- * @param referenceName
- * The reference for which we seek a ReferenceChange.
- * @param qualifiedName
- * The qualified name of the EObject on which we detected a change.
- * @param multiValued
- * Tells us to check for either multi- or single-valued reference changes.
- * @param featureDelegate
- * The optional feature to define the name of the objects. May be null.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> referenceValueMatch(final String referenceName,
- final String qualifiedName, final boolean multiValued, final EStructuralFeature featureDelegate) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- if (input instanceof ReferenceChange
- && ((ReferenceChange)input).getReference().getName().equals(referenceName)
- && ((ReferenceChange)input).getReference().isMany() == multiValued) {
- final EObject value = ((ReferenceChange)input).getValue();
- return qualifiedName != null && match(value, qualifiedName, featureDelegate);
- }
- return false;
- }
- };
- }
-
- /**
- * This can be used to check whether a given Diff describes either a {@link ReferenceChange} on an EObject
- * which name is {@code expectedName}.
- * <p>
- * For this to work, we expect the EObject to have a feature named "name" returning a String for us to try
- * and match it.
- * </p>
- *
- * @param expectedName
- * The name of the EObject which we expect as a changed reference value.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> valueNameMatches(final String expectedName) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- final EObject value;
- if (input instanceof ReferenceChange) {
- value = ((ReferenceChange)input).getValue();
- } else {
- return false;
- }
- return internalMatch(value, expectedName, null);
- }
- };
- }
-
- /**
- * This can be used to check whether a given Diff describes either a {@link ReferenceChange} on an EObject
- * which name is {@code expectedName} or which the given feature provides the {@code expectedName}.
- * <p>
- * For this to work, we expect the EObject to have a feature named "name" returning a String or to have
- * the given feature (String or EObject with a feature named "name") for us to try and match it.
- * </p>
- *
- * @param expectedName
- * The name of the EObject which we expect as a changed reference value.
- * @param featureDelegate
- * The optional feature to define the name of the objects. May be null.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> valueNameMatches(final String expectedName,
- final EStructuralFeature featureDelegate) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- final EObject value;
- if (input instanceof ReferenceChange) {
- value = ((ReferenceChange)input).getValue();
- } else {
- return false;
- }
- return internalMatch(value, expectedName, featureDelegate);
- }
- };
- }
-
- /**
- * This can be used to check whether a given Diff has a conflict of one of the given type.
- *
- * @param kinds
- * Type(s) of the conflict(s) we seek.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> hasConflict(final ConflictKind... kinds) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- return input != null && input.getConflict() != null
- && Arrays.asList(kinds).contains(input.getConflict().getKind());
- }
- };
- }
-
- /**
- * This can be used to check whether a given Diff is in (one of) the given state(s).
- *
- * @param states
- * State(s) in which we need a Diff to be.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> hasState(final DifferenceState... states) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- return input != null && Arrays.asList(states).contains(input.getState());
- }
- };
- }
-
- /**
- * This can be used to check whether a givan diff is a containment reference change.
- *
- * @return The created predicate.
- */
- public static Predicate<? super Diff> containmentReferenceChange() {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- return input instanceof ReferenceChange
- && ((ReferenceChange)input).getReference().isContainment();
- }
- };
- }
-
- /**
- * This will be used to check that a given {@link EObject} corresponds to the given {@code qualifiedName}.
- * <p>
- * For example, {@code match("extlibrary.BookCategory.Encyclopedia")} will return {@code true} for an
- * EObject named "Encyclopedia" under the container "extlibrary.BookCategory". Note, however that
- * {@code match("emf.compare.Match")} will <b>not</b> match the EObject "org.eclipse.emf.compare.Match".
- * The qualified name must be absolute.
- * </p>
- * <p>
- * For this to work, we expect the EObject to have a feature named "name" returning a String or to have
- * the given feature (String or EObject with a feature named "name") for us to try and match it. See also
- * {@link #getNameFeature(EObject)}.
- * </p>
- *
- * @param eObject
- * The EObject which qualified name we are to check.
- * @param qualifiedName
- * The expected, <b>absolute</b> qualified name of the given {@code eObject}.
- * @param featureDelegate
- * The optional feature to define the name of the objects. May be null.
- * @return {@code true} if the given {@code eObject} matches the given {@code qualifiedName},
- * {@code false} if not, or if we could not determine the "name" feature of that EObject.
- * @see #getNameFeature(EObject)
- */
- private static boolean match(EObject eObject, String qualifiedName, EStructuralFeature featureDelegate) {
- if (eObject == null || qualifiedName == null || qualifiedName.length() == 0) {
- return false;
- }
- final String[] names = qualifiedName.split("\\."); //$NON-NLS-1$
-
- int current = names.length - 1;
- boolean matches = internalMatch(eObject, names[current--], featureDelegate);
- if (matches) {
- EObject container = eObject.eContainer();
- while (matches && container != null && current >= 0) {
- matches = internalMatch(container, names[current--], featureDelegate);
- container = container.eContainer();
- }
- // This qualified name does not match if there was still a container "above"
- // "emf.compare.Match" does not match the EObject "org.eclipse.emf.compare.Match"
- matches = matches && container == null;
- }
-
- return matches;
- }
-
- /**
- * This will be used to check whether a given Object matches the given {@code qualifiedName}, considering
- * {@code null} as legal values. Namely, this will return {@code true} in the following cases :
- * <ul>
- * <li>both {@code eObject} and {@code qualifiedName} are {@code null}</li>
- * <li>eObject is an instance of {@link EObject} and its qualified name matches the given
- * {@code qualifiedName} according to the semantics of {@link #match(EObject, String)}</li>
- * </ul>
- *
- * @param eObject
- * The Object which qualified name we are to check. May be {@code null}.
- * @param qualifiedName
- * The expected, <b>absolute</b> qualified name of the given {@code eObject}. May be
- * {@code null}.
- * @return {@code true} if the given {@code eObject} matches the given {@code qualifiedName},
- * {@code false} if not, or if we could not determine the "name" feature of that EObject.
- * @see #match(EObject, String)
- */
- private static boolean matchAllowingNull(Object eObject, String qualifiedName) {
- if (eObject == null) {
- return qualifiedName == null;
- }
- return qualifiedName != null && eObject instanceof EObject
- && match((EObject)eObject, qualifiedName, null);
- }
-
- /**
- * Checks that the given {@code eObject}'s name is equal to {@code name}.
- * <p>
- * For this to work, we expect the EObject to have a feature named "name" returning a String or to have
- * the given feature (String or EObject with a feature named "name") for us to try and match it. See also
- * {@link #getNameFeature(EObject)}.
- * </p>
- *
- * @param eObject
- * the EObject which name we are to check.
- * @param name
- * The expected name of {@code eObject}.
- * @param featureDelegate
- * The optional feature to define the name of the objects. May be null.
- * @return {@code true} if the given {@code eObject}'s name is equal to the given {@code name},
- * {@code false} if not, or if we could not determine the "name" feature of that EObject.
- * @see #getNameFeature(EObject)
- */
- private static boolean internalMatch(EObject eObject, String name, EStructuralFeature featureDelegate) {
- final EStructuralFeature nameFeature = getNameFeature(eObject);
- boolean match = false;
- if (nameFeature != null) {
- final Object featureValue = eObject.eGet(nameFeature);
- if (featureValue instanceof String) {
- match = featureValue.equals(name);
- }
- } else if (featureDelegate != null && !featureDelegate.isMany()) {
- final Object featureValue = eObject.eGet(featureDelegate, false);
- if (featureValue instanceof String) {
- match = featureValue.equals(name);
- } else if (featureValue instanceof EObject) {
- match = internalMatch((EObject)featureValue, name, null);
- }
- }
- return match;
- }
-
- /**
- * Tries and determine the "name" feature of the given EObject. By default, we only consider
- * {@link ENamedElement#name} or a feature of the given {@code eObject}'s EClass which would be named
- * "name".
- *
- * @param eObject
- * The EObject for which we are trying to determine a name.
- * @return The name feature of the given EObject if we could find one, {@code null} otherwise.
- */
- private static EStructuralFeature getNameFeature(EObject eObject) {
- if (eObject instanceof ENamedElement) {
- return EcorePackage.eINSTANCE.getENamedElement_Name();
- }
- EStructuralFeature nameFeature = null;
- final Iterator<EStructuralFeature> features = eObject.eClass().getEAllStructuralFeatures().iterator();
- while (nameFeature == null && features.hasNext()) {
- final EStructuralFeature feature = features.next();
- if ("name".equals(feature.getName())) { //$NON-NLS-1$
- nameFeature = feature;
- }
- }
- return nameFeature;
- }
-
- /**
- * This particular predicate will be used to check that a given Diff corresponds to a ReferenceChange on a
- * given reference, with known "original" and "changed" values.
- *
- * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
- */
- private static final class ReferenceValuesMatch implements Predicate<Diff> {
- /** Name of the reference we expect to have been changed. */
- private final String referenceName;
-
- /** Qualified name of the expected original value of this reference. */
- private final String fromQualifiedName;
-
- /** Qualified name of the value to which this reference is expected to have changed. */
- private final String toQualifiedName;
-
- /**
- * Instantiates this predicate given the values it is meant to match.
- *
- * @param referenceName
- * Name of the single-valued reference on which we expect a change.
- * @param fromQualifiedName
- * The original value of this reference.
- * @param toQualifiedName
- * The value to which this reference has been changed.
- */
- public ReferenceValuesMatch(String referenceName, String fromQualifiedName, String toQualifiedName) {
- this.referenceName = referenceName;
- this.fromQualifiedName = fromQualifiedName;
- this.toQualifiedName = toQualifiedName;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see com.google.common.base.Predicate#apply(java.lang.Object)
- */
- public boolean apply(Diff input) {
- // Note that this is not meant for many-valued references
- if (input instanceof ReferenceChange
- && ((ReferenceChange)input).getReference().getName().equals(referenceName)
- && !((ReferenceChange)input).getReference().isMany()) {
- final EReference reference = ((ReferenceChange)input).getReference();
- final Match match = input.getMatch();
- final Object leftValue;
- if (match.getLeft() != null) {
- leftValue = match.getLeft().eGet(reference);
- } else {
- leftValue = null;
- }
- final Object rightValue;
- if (match.getRight() != null) {
- rightValue = match.getRight().eGet(reference);
- } else {
- rightValue = null;
- }
- final Object originValue;
- if (match.getOrigin() != null) {
- originValue = match.getOrigin().eGet(reference);
- } else {
- originValue = null;
- }
-
- // "from" is either right or origin
- boolean applies = false;
- if (matchAllowingNull(originValue, fromQualifiedName)) {
- // "from" is origin, "to" can be either left or right
- applies = matchAllowingNull(leftValue, toQualifiedName)
- || matchAllowingNull(rightValue, toQualifiedName);
- } else if (matchAllowingNull(rightValue, fromQualifiedName)) {
- // "from" is right, "to" can only be left
- applies = matchAllowingNull(leftValue, toQualifiedName);
- }
- return applies;
- }
- return false;
- }
- }
-
- /**
- * This particular predicate will be used to check that a given Diff corresponds to an AttributeChange on
- * a given attribute, with known "original" and "changed" values.
- *
- * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
- */
- private static final class AttributeValuesMatch implements Predicate<Diff> {
- /** Name of the attribute we expect to have been changed. */
- private final String attributeName;
-
- /** The expected original value of this attribute. */
- private final Object fromValue;
-
- /** The value to which this attribute is expected to have changed. */
- private final Object toValue;
-
- /**
- * Instantiates this predicate given the values it is meant to match.
- *
- * @param attributeName
- * Name of the single-valued attribute on which we expect a change.
- * @param fromValue
- * The original value of this attribute.
- * @param toValue
- * The value to which this attribute has been changed.
- */
- public AttributeValuesMatch(String attributeName, Object fromValue, Object toValue) {
- this.attributeName = attributeName;
- this.fromValue = fromValue;
- this.toValue = toValue;
- }
-
- /**
- * Checks whether the two given Objects match : they are either both {@code null}, the same instance,
- * or their "equals" returns {@code true}. If neither is {@code true}, we assume that these two
- * Objects don't match.
- * <p>
- * Do note that "unset" values are in fact set to the empty String instead of {@code null}. We will
- * thus consider {@code null} equal to the empty String here.
- * </p>
- *
- * @param attributeValue
- * The reference value, first of the two Objects to compare.
- * @param expectedValue
- * The expected value, second of the two Objects to compare.
- * @return {@code true} if these two Objects are equal, {@code false} otherwise.
- */
- private static boolean equalAttributeValues(Object attributeValue, Object expectedValue) {
- // Using == to handle the "null" case
- boolean equal = expectedValue == attributeValue || expectedValue != null
- && expectedValue.equals(attributeValue);
- // Consider that null is equal to the empty string (unset attributes)
- if (!equal) {
- equal = "".equals(attributeValue) && expectedValue == null || "".equals(expectedValue) //$NON-NLS-1$ //$NON-NLS-2$
- && attributeValue == null;
- }
- return equal;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see com.google.common.base.Predicate#apply(java.lang.Object)
- */
- public boolean apply(Diff input) {
- // Note that this is not meant for multi-valued attributes
- if (input instanceof AttributeChange
- && ((AttributeChange)input).getAttribute().getName().equals(attributeName)
- && !((AttributeChange)input).getAttribute().isMany()) {
- final EAttribute attribute = ((AttributeChange)input).getAttribute();
- final Match match = input.getMatch();
-
- final Object leftValue;
- if (match.getLeft() != null) {
- leftValue = match.getLeft().eGet(attribute);
- } else {
- leftValue = attribute.getDefaultValue();
- }
-
- final Object rightValue;
- if (match.getRight() != null) {
- rightValue = match.getRight().eGet(attribute);
- } else {
- rightValue = attribute.getDefaultValue();
- }
-
- final Object originValue;
- if (match.getOrigin() != null) {
- originValue = match.getOrigin().eGet(attribute);
- } else {
- originValue = attribute.getDefaultValue();
- }
-
- final Object actualFrom;
- if (fromValue == null) {
- actualFrom = attribute.getDefaultValue();
- } else {
- actualFrom = fromValue;
- }
- final Object actualTo;
- if (toValue == null) {
- actualTo = attribute.getDefaultValue();
- } else {
- actualTo = toValue;
- }
-
- // "from" is either right or origin
- boolean applies = false;
- if (equalAttributeValues(actualFrom, originValue)) {
- // "from" is origin, "to" can be either left or right
- applies = equalAttributeValues(actualTo, leftValue)
- || equalAttributeValues(actualTo, rightValue);
- } else if (equalAttributeValues(actualFrom, rightValue)) {
- // "from" is right, "to" can only be left
- applies = equalAttributeValues(actualTo, leftValue);
- }
- return applies;
- }
- return false;
- }
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.utils;
+
+import static com.google.common.base.Predicates.and;
+
+import com.google.common.base.Predicate;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.eclipse.emf.compare.AttributeChange;
+import org.eclipse.emf.compare.ConflictKind;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceKind;
+import org.eclipse.emf.compare.DifferenceSource;
+import org.eclipse.emf.compare.DifferenceState;
+import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.ReferenceChange;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
+
+/**
+ * This class will provide a number of Predicates that can be used to retrieve particular {@link Diff}s from
+ * an iterable.
+ *
+ * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
+ */
+public final class EMFComparePredicates {
+ /**
+ * This class does not need to be instantiated.
+ */
+ private EMFComparePredicates() {
+ // Hides default constructor
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the modification of a single-valued
+ * reference going by the given {@code referenceName} on an EObject which name matches
+ * {@code qualifiedName}. This can be used both on three-way and two-way Diffs : if three-way, we'll
+ * consider that the {@code fromQualifiedName} can be either one of the right or origin values, and the
+ * {@code toQualifiedName} to be either left or right. on two-way diffs however, {@code fromQualifiedName}
+ * can only be the right value, and {@code toQualifiedName} will be the left one.
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
+ * for us to compare it with the given qualified name.
+ * </p>
+ *
+ * @param qualifiedName
+ * Qualified name of the EObject which we expect to present a ReferenceChange.
+ * @param referenceName
+ * Name of the single-valued reference on which we expect a change.
+ * @param fromQualifiedName
+ * The original value of this reference.
+ * @param toQualifiedName
+ * The value to which this reference has been changed.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> changedReference(final String qualifiedName,
+ final String referenceName, final String fromQualifiedName, final String toQualifiedName) {
+ final Predicate<? super Diff> valuesMatch = new ReferenceValuesMatch(referenceName,
+ fromQualifiedName, toQualifiedName);
+ return and(ofKind(DifferenceKind.CHANGE), onEObject(qualifiedName), valuesMatch);
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the addition of a value in a
+ * multi-valued attribute going by {@code attributeName} on an EObject which name matches
+ * {@code qualifiedName}.
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
+ * for us to compare it with the given qualified name.
+ * </p>
+ *
+ * @param qualifiedName
+ * Qualified name of the EObject which we expect to present an AttributeChange.
+ * @param attributeName
+ * Name of the multi-valued attribute on which we expect a change.
+ * @param addedValue
+ * The value we expect to have been added to this attribute.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> addedToAttribute(final String qualifiedName,
+ final String attributeName, final Object addedValue) {
+ // This is only meant for multi-valued attributes
+ return and(ofKind(DifferenceKind.ADD), onEObject(qualifiedName), attributeValueMatch(attributeName,
+ addedValue, true));
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the addition of a value in a
+ * multi-valued reference going by {@code referenceName} on an EObject which name matches
+ * {@code qualifiedName}.
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
+ * for us to compare it with the given qualified name.
+ * </p>
+ *
+ * @param qualifiedName
+ * Qualified name of the EObject which we expect to present a ReferenceChange.
+ * @param referenceName
+ * Name of the multi-valued reference on which we expect a change.
+ * @param addedQualifiedName
+ * Qualified name of the EObject which we expect to have been added to this reference.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> addedToReference(final String qualifiedName,
+ final String referenceName, final String addedQualifiedName) {
+ // This is only meant for multi-valued references
+ return and(ofKind(DifferenceKind.ADD), onEObject(qualifiedName), referenceValueMatch(referenceName,
+ addedQualifiedName, true));
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the addition of a value in a
+ * multi-valued reference going by {@code referenceName} on an EObject which name matches
+ * {@code qualifiedName}.
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
+ * for us to compare it with the given qualified name.
+ * </p>
+ *
+ * @param qualifiedName
+ * Qualified name of the EObject which we expect to present a ReferenceChange.
+ * @param referenceName
+ * Name of the multi-valued reference on which we expect a change.
+ * @param addedQualifiedName
+ * Qualified name of the EObject which we expect to have been added to this reference.
+ * @param featureDelegateForAddedName
+ * The optional feature to define the name of the objects which we expect to have been added to
+ * this reference. May be null.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> addedToReference(final String qualifiedName,
+ final String referenceName, final String addedQualifiedName,
+ final EStructuralFeature featureDelegateForAddedName) {
+ // This is only meant for multi-valued references
+ return and(ofKind(DifferenceKind.ADD), onEObject(qualifiedName), referenceValueMatch(referenceName,
+ addedQualifiedName, true, featureDelegateForAddedName));
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the moving of a value within a
+ * multi-valued attribute going by {@code attributeName} on an EObject which name matches
+ * {@code qualifiedName}.
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
+ * for us to compare it with the given qualified name.
+ * </p>
+ *
+ * @param qualifiedName
+ * Qualified name of the EObject which we expect to present an AttributeChange.
+ * @param attributeName
+ * Name of the multi-valued attribute on which we expect a change.
+ * @param removedValue
+ * Value which we expect to have been moved within this attribute.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> movedInAttribute(final String qualifiedName,
+ final String attributeName, final Object removedValue) {
+ // This is only meant for multi-valued attributes
+ return and(ofKind(DifferenceKind.MOVE), onEObject(qualifiedName), attributeValueMatch(attributeName,
+ removedValue, true));
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the moving of a value within a
+ * multi-valued reference going by {@code referenceName} on an EObject which name matches
+ * {@code qualifiedName}.
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
+ * for us to compare it with the given qualified name.
+ * </p>
+ *
+ * @param qualifiedName
+ * Qualified name of the EObject which we expect to present a ReferenceChange.
+ * @param referenceName
+ * Name of the multi-valued reference on which we expect a change.
+ * @param removedQualifiedName
+ * Qualified name of the EObject which we expect to have been moved within this reference.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> movedInReference(final String qualifiedName,
+ final String referenceName, final String removedQualifiedName) {
+ // This is only meant for multi-valued references
+ return and(ofKind(DifferenceKind.MOVE), onEObject(qualifiedName), referenceValueMatch(referenceName,
+ removedQualifiedName, true));
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the deletion of a value from a
+ * multi-valued attribute going by {@code attributeName} on an EObject which name matches
+ * {@code qualifiedName}.
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
+ * for us to compare it with the given qualified name.
+ * </p>
+ *
+ * @param qualifiedName
+ * Qualified name of the EObject which we expect to present an AttributeChange.
+ * @param attributeName
+ * Name of the multi-valued attribute on which we expect a change.
+ * @param removedValue
+ * Value which we expect to have been removed from this attribute.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> removedFromAttribute(final String qualifiedName,
+ final String attributeName, final Object removedValue) {
+ // This is only meant for multi-valued attributes
+ return and(ofKind(DifferenceKind.DELETE), onEObject(qualifiedName), attributeValueMatch(
+ attributeName, removedValue, true));
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the deletion of a value from a
+ * multi-valued reference going by {@code referenceName} on an EObject which name matches
+ * {@code qualifiedName}.
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
+ * for us to compare it with the given qualified name.
+ * </p>
+ *
+ * @param qualifiedName
+ * Qualified name of the EObject which we expect to present a ReferenceChange.
+ * @param referenceName
+ * Name of the multi-valued reference on which we expect a change.
+ * @param removedQualifiedName
+ * Qualified name of the EObject which we expect to have been removed from this reference.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> removedFromReference(final String qualifiedName,
+ final String referenceName, final String removedQualifiedName) {
+ // This is only meant for multi-valued references
+ return and(ofKind(DifferenceKind.DELETE), onEObject(qualifiedName), referenceValueMatch(
+ referenceName, removedQualifiedName, true));
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the deletion of a value from a
+ * multi-valued reference going by {@code referenceName} on an EObject which name matches
+ * {@code qualifiedName}.
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
+ * for us to compare it with the given qualified name.
+ * </p>
+ *
+ * @param qualifiedName
+ * Qualified name of the EObject which we expect to present a ReferenceChange.
+ * @param referenceName
+ * Name of the multi-valued reference on which we expect a change.
+ * @param removedQualifiedName
+ * Qualified name of the EObject which we expect to have been removed from this reference.
+ * @param featureDelegateForRemovedName
+ * The optional feature to define the name of the objects which we expect to have been removed
+ * from this reference. May be null.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> removedFromReference(final String qualifiedName,
+ final String referenceName, final String removedQualifiedName,
+ final EStructuralFeature featureDelegateForRemovedName) {
+ // This is only meant for multi-valued references
+ return and(ofKind(DifferenceKind.DELETE), onEObject(qualifiedName), referenceValueMatch(
+ referenceName, removedQualifiedName, true, featureDelegateForRemovedName));
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the modification of a single-valued
+ * attribute going by the given {@code attributeName} on an EObject which name matches
+ * {@code qualifiedName}. This can be used both on three-way and two-way Diffs : if three-way, we'll
+ * consider that the {@code fromValue} can be either one of the right or origin values, and the
+ * {@code toValue} to be either left or right. on two-way diffs however, {@code fromValue} can only be the
+ * right value, and {@code toValue} will be the left one.
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
+ * for us to compare it with the given qualified name.
+ * </p>
+ *
+ * @param qualifiedName
+ * Qualified name of the EObject which we expect to present an AttributeChange.
+ * @param attributeName
+ * Name of the single-valued attribute on which we expect a change.
+ * @param fromValue
+ * The original value of this attribute.
+ * @param toValue
+ * The value to which this attribute has been changed.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> changedAttribute(final String qualifiedName,
+ final String attributeName, final Object fromValue, final Object toValue) {
+ final Predicate<? super Diff> valuesMatch = new AttributeValuesMatch(attributeName, fromValue,
+ toValue);
+ return and(ofKind(DifferenceKind.CHANGE), onEObject(qualifiedName), valuesMatch);
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the addition of an EObject matching
+ * the given qualified name. Namely, it will check that that Diff is a ReferenceChange, that one of its
+ * Match sides correspond to the given qualified name's ancestors, and that its value correspond to the
+ * given qualified name's last segment.
+ * <p>
+ * For example, {@code added("extlibrary.BookCategory.Encyclopedia")} will check that an EObject named
+ * "Encyclopedia" has been added under the container "extlibrary.BookCategory". Note that
+ * {@code added("emf.compare.Match")} will <b>not</b> match a difference on the EObject
+ * "org.eclipse.emf.compare.Match". The qualified name must be absolute.
+ * </p>
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a
+ * String.
+ * </p>
+ *
+ * @param qualifiedName
+ * The qualified name of the EObject we expect to have been added.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> added(final String qualifiedName) {
+ final int parentEndIndex = qualifiedName.lastIndexOf('.');
+ if (parentEndIndex >= 0) {
+ final String ancestors = qualifiedName.substring(0, parentEndIndex);
+ final String objectName = qualifiedName.substring(parentEndIndex + 1);
+ return and(ofKind(DifferenceKind.ADD), onEObject(ancestors), valueNameMatches(objectName));
+ }
+ return and(valueNameMatches(qualifiedName), ofKind(DifferenceKind.ADD));
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the move of an EObject matching the
+ * given qualified name. Namely, it will check that that Diff is a ReferenceChange, that one of its Match
+ * sides correspond to the given qualified name's ancestors, and that its value correspond to the given
+ * qualified name's last segment.
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a
+ * String.
+ * </p>
+ *
+ * @param qualifiedName
+ * The qualified name of the EObject we expect to have been moved.
+ * @param referenceName
+ * Name of the reference in which we expect a child to have been added.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> moved(final String qualifiedName, final String referenceName) {
+ final int parentEndIndex = qualifiedName.lastIndexOf('.');
+ if (parentEndIndex >= 0) {
+ final String ancestors = qualifiedName.substring(0, parentEndIndex);
+ final String objectName = qualifiedName.substring(parentEndIndex + 1);
+ return and(ofKind(DifferenceKind.MOVE), onEObject(ancestors), onFeature(referenceName),
+ valueNameMatches(objectName));
+ }
+ return and(ofKind(DifferenceKind.MOVE), valueNameMatches(qualifiedName), onFeature(referenceName));
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff represents the removal of an EObject matching
+ * the given qualified name. Namely, it will check that that Diff is a ReferenceChange, that one of its
+ * Match sides correspond to the given qualified name's ancestors, and that its value correspond to the
+ * given qualified name's last segment.
+ * <p>
+ * For example, {@code removed("extlibrary.BookCategory.Encyclopedia")} will check that an EObject named
+ * "Encyclopedia" has been removed from the container "extlibrary.BookCategory". Note that
+ * {@code removed("emf.compare.Match")} will <b>not</b> match a difference on the EObject
+ * "org.eclipse.emf.compare.Match". The qualified name must be absolute.
+ * </p>
+ * <p>
+ * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a
+ * String.
+ * </p>
+ *
+ * @param qualifiedName
+ * The qualified name of the EObject we expect to have been removed.
+ * @return The created predicate.
+ */
+ @SuppressWarnings("unchecked")
+ public static Predicate<? super Diff> removed(final String qualifiedName) {
+ final int parentEndIndex = qualifiedName.lastIndexOf('.');
+ if (parentEndIndex >= 0) {
+ final String ancestors = qualifiedName.substring(0, parentEndIndex);
+ final String objectName = qualifiedName.substring(parentEndIndex + 1);
+ return and(ofKind(DifferenceKind.DELETE), onEObject(ancestors), valueNameMatches(objectName));
+ }
+ return and(valueNameMatches(qualifiedName), ofKind(DifferenceKind.DELETE));
+ }
+
+ /**
+ * This can be used to check that a given Diff correspond to either an {@link AttributeChange} or a
+ * {@link ReferenceChange}, and that the corresponding reference or attribute matches the given
+ * {@code featureName}.
+ *
+ * @param featureName
+ * Name of the feature on which we expect a change.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> onFeature(final String featureName) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ final EStructuralFeature affectedFeature;
+ if (input instanceof AttributeChange) {
+ affectedFeature = ((AttributeChange)input).getAttribute();
+ } else if (input instanceof ReferenceChange) {
+ affectedFeature = ((ReferenceChange)input).getReference();
+ } else {
+ return false;
+ }
+ return featureName.equals(affectedFeature.getName());
+ }
+ };
+ }
+
+ /**
+ * This can be used to check that a given Diff originates from the given {@code source} side.
+ *
+ * @param source
+ * The side from which we expect this diff to originate.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> fromSide(final DifferenceSource source) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ return input != null && input.getSource() == source;
+ }
+ };
+ }
+
+ /**
+ * This can be used in order to check that a Diff has been detected on the given EObject.
+ *
+ * @param eObject
+ * The EObject which we expect the diff to concern.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> onEObject(final EObject eObject) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ if (input == null) {
+ return false;
+ }
+
+ final Match match = input.getMatch();
+ return match.getLeft() == eObject || match.getRight() == eObject
+ || match.getOrigin() == eObject;
+ }
+ };
+ }
+
+ /**
+ * This can be used in order to check whether a Diff has been detected on an EObject matching the given
+ * qualified name.
+ * <p>
+ * For this to work, we expect the EObjects to have a feature named "name" returning a String.
+ * </p>
+ *
+ * @param qualifiedName
+ * The qualified name of the EObject we expect that diff to concern.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> onEObject(final String qualifiedName) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ if (input == null) {
+ return false;
+ }
+
+ final Match match = input.getMatch();
+ return match(match.getLeft(), qualifiedName, null)
+ || match(match.getRight(), qualifiedName, null)
+ || match(match.getOrigin(), qualifiedName, null);
+ }
+ };
+ }
+
+ /**
+ * This can be used in order to check whether a Diff has been detected on an EObject matching the given
+ * qualified name or the qualified name under the given feature.
+ * <p>
+ * For this to work, we expect the EObjects to have a feature named "name" returning a String or to have
+ * the given feature (String or EObject with a feature named "name").
+ * </p>
+ *
+ * @param qualifiedName
+ * The qualified name of the EObject we expect that diff to concern.
+ * @param featureDelegate
+ * The optional feature to define the name of the objects. May be null.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> onEObject(final String qualifiedName,
+ final EStructuralFeature featureDelegate) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ if (input == null) {
+ return false;
+ }
+
+ final Match match = input.getMatch();
+ return match(match.getLeft(), qualifiedName, featureDelegate)
+ || match(match.getRight(), qualifiedName, featureDelegate)
+ || match(match.getOrigin(), qualifiedName, featureDelegate);
+ }
+ };
+ }
+
+ /**
+ * This predicate can be used to check whether a particular diff is of the given {@code kind}. This is
+ * mainly used to differentiate additions from deletions.
+ *
+ * @param kind
+ * The kind we expect this diff to have.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> ofKind(final DifferenceKind kind) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ return input != null && input.getKind() == kind;
+ }
+ };
+ }
+
+ /**
+ * This predicate can be used in order to check that a particular Diff describes either a
+ * {@link ReferenceChange} or {@link AttributeChange} for the given {@code expectedValue}.
+ * <p>
+ * For example, this could be used to check that the given value has indeed been added to a reference or
+ * attribute, though such checks are more easily performed through {@link #addedIn(EObject, EObject)} or
+ * {@link #removedFrom(EObject, EObject)}.
+ * </p>
+ *
+ * @param expectedValue
+ * The value which we expect to have changed and detected through a Diff.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> valueIs(final Object expectedValue) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ final Object value;
+ if (input instanceof ReferenceChange) {
+ value = ((ReferenceChange)input).getValue();
+ } else if (input instanceof AttributeChange) {
+ value = ((AttributeChange)input).getValue();
+ } else {
+ return false;
+ }
+
+ return value == expectedValue || (value != null && value.equals(expectedValue));
+ }
+ };
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff describes an AttributeChange with the given
+ * {@code attributeName} and which changed value corresponds to the given {@code expectedValue}.
+ *
+ * @param attributeName
+ * The name of the attribute for which we seek an AttributeChange.
+ * @param expectedValue
+ * The value we expect to correspond to this AttributeChange.
+ * @param multiValued
+ * Tells us to check for either multi- or single-valued reference changes.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> attributeValueMatch(final String attributeName,
+ final Object expectedValue, final boolean multiValued) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ if (input instanceof AttributeChange
+ && ((AttributeChange)input).getAttribute().getName().equals(attributeName)
+ && ((AttributeChange)input).getAttribute().isMany() == multiValued) {
+ final Object value = ((AttributeChange)input).getValue();
+ return input.getMatch().getComparison().getEqualityHelper().matchingAttributeValues(
+ value, expectedValue);
+ }
+ return false;
+ }
+ };
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff describes a ReferenceChange with the given
+ * {@code referenceName} and which changed value corresponds to the given {@code qualifiedName}.
+ * <p>
+ * For this to work, we expect the EObject to have a feature named "name" returning a String for us to try
+ * and match it.
+ * </p>
+ *
+ * @param referenceName
+ * The reference for which we seek a ReferenceChange.
+ * @param qualifiedName
+ * The qualified name of the EObject on which we detected a change.
+ * @param multiValued
+ * Tells us to check for either multi- or single-valued reference changes.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> referenceValueMatch(final String referenceName,
+ final String qualifiedName, final boolean multiValued) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ if (input instanceof ReferenceChange
+ && ((ReferenceChange)input).getReference().getName().equals(referenceName)
+ && ((ReferenceChange)input).getReference().isMany() == multiValued) {
+ final EObject value = ((ReferenceChange)input).getValue();
+ return qualifiedName != null && match(value, qualifiedName, null);
+ }
+ return false;
+ }
+ };
+ }
+
+ /**
+ * This predicate can be used to check whether a given Diff describes a ReferenceChange with the given
+ * {@code referenceName} and which changed value corresponds to the given {@code qualifiedName} or the
+ * qualified name under the given {@code featureDelegate}.
+ * <p>
+ * For this to work, we expect the EObject to have a feature named "name" returning a String or to have
+ * the given feature (String or EObject with a feature named "name") for us to try and match it.
+ * </p>
+ *
+ * @param referenceName
+ * The reference for which we seek a ReferenceChange.
+ * @param qualifiedName
+ * The qualified name of the EObject on which we detected a change.
+ * @param multiValued
+ * Tells us to check for either multi- or single-valued reference changes.
+ * @param featureDelegate
+ * The optional feature to define the name of the objects. May be null.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> referenceValueMatch(final String referenceName,
+ final String qualifiedName, final boolean multiValued, final EStructuralFeature featureDelegate) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ if (input instanceof ReferenceChange
+ && ((ReferenceChange)input).getReference().getName().equals(referenceName)
+ && ((ReferenceChange)input).getReference().isMany() == multiValued) {
+ final EObject value = ((ReferenceChange)input).getValue();
+ return qualifiedName != null && match(value, qualifiedName, featureDelegate);
+ }
+ return false;
+ }
+ };
+ }
+
+ /**
+ * This can be used to check whether a given Diff describes either a {@link ReferenceChange} on an EObject
+ * which name is {@code expectedName}.
+ * <p>
+ * For this to work, we expect the EObject to have a feature named "name" returning a String for us to try
+ * and match it.
+ * </p>
+ *
+ * @param expectedName
+ * The name of the EObject which we expect as a changed reference value.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> valueNameMatches(final String expectedName) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ final EObject value;
+ if (input instanceof ReferenceChange) {
+ value = ((ReferenceChange)input).getValue();
+ } else {
+ return false;
+ }
+ return internalMatch(value, expectedName, null);
+ }
+ };
+ }
+
+ /**
+ * This can be used to check whether a given Diff describes either a {@link ReferenceChange} on an EObject
+ * which name is {@code expectedName} or which the given feature provides the {@code expectedName}.
+ * <p>
+ * For this to work, we expect the EObject to have a feature named "name" returning a String or to have
+ * the given feature (String or EObject with a feature named "name") for us to try and match it.
+ * </p>
+ *
+ * @param expectedName
+ * The name of the EObject which we expect as a changed reference value.
+ * @param featureDelegate
+ * The optional feature to define the name of the objects. May be null.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> valueNameMatches(final String expectedName,
+ final EStructuralFeature featureDelegate) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ final EObject value;
+ if (input instanceof ReferenceChange) {
+ value = ((ReferenceChange)input).getValue();
+ } else {
+ return false;
+ }
+ return internalMatch(value, expectedName, featureDelegate);
+ }
+ };
+ }
+
+ /**
+ * This can be used to check whether a given Diff has a conflict of one of the given type.
+ *
+ * @param kinds
+ * Type(s) of the conflict(s) we seek.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> hasConflict(final ConflictKind... kinds) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ return input != null && input.getConflict() != null
+ && Arrays.asList(kinds).contains(input.getConflict().getKind());
+ }
+ };
+ }
+
+ /**
+ * This can be used to check whether a given Diff is in (one of) the given state(s).
+ *
+ * @param states
+ * State(s) in which we need a Diff to be.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> hasState(final DifferenceState... states) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ return input != null && Arrays.asList(states).contains(input.getState());
+ }
+ };
+ }
+
+ /**
+ * This can be used to check whether a givan diff is a containment reference change.
+ *
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> containmentReferenceChange() {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ return input instanceof ReferenceChange
+ && ((ReferenceChange)input).getReference().isContainment();
+ }
+ };
+ }
+
+ /**
+ * This will be used to check that a given {@link EObject} corresponds to the given {@code qualifiedName}.
+ * <p>
+ * For example, {@code match("extlibrary.BookCategory.Encyclopedia")} will return {@code true} for an
+ * EObject named "Encyclopedia" under the container "extlibrary.BookCategory". Note, however that
+ * {@code match("emf.compare.Match")} will <b>not</b> match the EObject "org.eclipse.emf.compare.Match".
+ * The qualified name must be absolute.
+ * </p>
+ * <p>
+ * For this to work, we expect the EObject to have a feature named "name" returning a String or to have
+ * the given feature (String or EObject with a feature named "name") for us to try and match it. See also
+ * {@link #getNameFeature(EObject)}.
+ * </p>
+ *
+ * @param eObject
+ * The EObject which qualified name we are to check.
+ * @param qualifiedName
+ * The expected, <b>absolute</b> qualified name of the given {@code eObject}.
+ * @param featureDelegate
+ * The optional feature to define the name of the objects. May be null.
+ * @return {@code true} if the given {@code eObject} matches the given {@code qualifiedName},
+ * {@code false} if not, or if we could not determine the "name" feature of that EObject.
+ * @see #getNameFeature(EObject)
+ */
+ private static boolean match(EObject eObject, String qualifiedName, EStructuralFeature featureDelegate) {
+ if (eObject == null || qualifiedName == null || qualifiedName.length() == 0) {
+ return false;
+ }
+ final String[] names = qualifiedName.split("\\."); //$NON-NLS-1$
+
+ int current = names.length - 1;
+ boolean matches = internalMatch(eObject, names[current--], featureDelegate);
+ if (matches) {
+ EObject container = eObject.eContainer();
+ while (matches && container != null && current >= 0) {
+ matches = internalMatch(container, names[current--], featureDelegate);
+ container = container.eContainer();
+ }
+ // This qualified name does not match if there was still a container "above"
+ // "emf.compare.Match" does not match the EObject "org.eclipse.emf.compare.Match"
+ matches = matches && container == null;
+ }
+
+ return matches;
+ }
+
+ /**
+ * This will be used to check whether a given Object matches the given {@code qualifiedName}, considering
+ * {@code null} as legal values. Namely, this will return {@code true} in the following cases :
+ * <ul>
+ * <li>both {@code eObject} and {@code qualifiedName} are {@code null}</li>
+ * <li>eObject is an instance of {@link EObject} and its qualified name matches the given
+ * {@code qualifiedName} according to the semantics of {@link #match(EObject, String)}</li>
+ * </ul>
+ *
+ * @param eObject
+ * The Object which qualified name we are to check. May be {@code null}.
+ * @param qualifiedName
+ * The expected, <b>absolute</b> qualified name of the given {@code eObject}. May be
+ * {@code null}.
+ * @return {@code true} if the given {@code eObject} matches the given {@code qualifiedName},
+ * {@code false} if not, or if we could not determine the "name" feature of that EObject.
+ * @see #match(EObject, String)
+ */
+ private static boolean matchAllowingNull(Object eObject, String qualifiedName) {
+ if (eObject == null) {
+ return qualifiedName == null;
+ }
+ return qualifiedName != null && eObject instanceof EObject
+ && match((EObject)eObject, qualifiedName, null);
+ }
+
+ /**
+ * Checks that the given {@code eObject}'s name is equal to {@code name}.
+ * <p>
+ * For this to work, we expect the EObject to have a feature named "name" returning a String or to have
+ * the given feature (String or EObject with a feature named "name") for us to try and match it. See also
+ * {@link #getNameFeature(EObject)}.
+ * </p>
+ *
+ * @param eObject
+ * the EObject which name we are to check.
+ * @param name
+ * The expected name of {@code eObject}.
+ * @param featureDelegate
+ * The optional feature to define the name of the objects. May be null.
+ * @return {@code true} if the given {@code eObject}'s name is equal to the given {@code name},
+ * {@code false} if not, or if we could not determine the "name" feature of that EObject.
+ * @see #getNameFeature(EObject)
+ */
+ private static boolean internalMatch(EObject eObject, String name, EStructuralFeature featureDelegate) {
+ final EStructuralFeature nameFeature = getNameFeature(eObject);
+ boolean match = false;
+ if (nameFeature != null) {
+ final Object featureValue = eObject.eGet(nameFeature);
+ if (featureValue instanceof String) {
+ match = featureValue.equals(name);
+ }
+ } else if (featureDelegate != null && !featureDelegate.isMany()) {
+ final Object featureValue = eObject.eGet(featureDelegate, false);
+ if (featureValue instanceof String) {
+ match = featureValue.equals(name);
+ } else if (featureValue instanceof EObject) {
+ match = internalMatch((EObject)featureValue, name, null);
+ }
+ }
+ return match;
+ }
+
+ /**
+ * Tries and determine the "name" feature of the given EObject. By default, we only consider
+ * {@link ENamedElement#name} or a feature of the given {@code eObject}'s EClass which would be named
+ * "name".
+ *
+ * @param eObject
+ * The EObject for which we are trying to determine a name.
+ * @return The name feature of the given EObject if we could find one, {@code null} otherwise.
+ */
+ private static EStructuralFeature getNameFeature(EObject eObject) {
+ if (eObject instanceof ENamedElement) {
+ return EcorePackage.eINSTANCE.getENamedElement_Name();
+ }
+ EStructuralFeature nameFeature = null;
+ final Iterator<EStructuralFeature> features = eObject.eClass().getEAllStructuralFeatures().iterator();
+ while (nameFeature == null && features.hasNext()) {
+ final EStructuralFeature feature = features.next();
+ if ("name".equals(feature.getName())) { //$NON-NLS-1$
+ nameFeature = feature;
+ }
+ }
+ return nameFeature;
+ }
+
+ /**
+ * This particular predicate will be used to check that a given Diff corresponds to a ReferenceChange on a
+ * given reference, with known "original" and "changed" values.
+ *
+ * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
+ */
+ private static final class ReferenceValuesMatch implements Predicate<Diff> {
+ /** Name of the reference we expect to have been changed. */
+ private final String referenceName;
+
+ /** Qualified name of the expected original value of this reference. */
+ private final String fromQualifiedName;
+
+ /** Qualified name of the value to which this reference is expected to have changed. */
+ private final String toQualifiedName;
+
+ /**
+ * Instantiates this predicate given the values it is meant to match.
+ *
+ * @param referenceName
+ * Name of the single-valued reference on which we expect a change.
+ * @param fromQualifiedName
+ * The original value of this reference.
+ * @param toQualifiedName
+ * The value to which this reference has been changed.
+ */
+ public ReferenceValuesMatch(String referenceName, String fromQualifiedName, String toQualifiedName) {
+ this.referenceName = referenceName;
+ this.fromQualifiedName = fromQualifiedName;
+ this.toQualifiedName = toQualifiedName;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see com.google.common.base.Predicate#apply(java.lang.Object)
+ */
+ public boolean apply(Diff input) {
+ // Note that this is not meant for many-valued references
+ if (input instanceof ReferenceChange
+ && ((ReferenceChange)input).getReference().getName().equals(referenceName)
+ && !((ReferenceChange)input).getReference().isMany()) {
+ final EReference reference = ((ReferenceChange)input).getReference();
+ final Match match = input.getMatch();
+ final Object leftValue;
+ if (match.getLeft() != null) {
+ leftValue = match.getLeft().eGet(reference);
+ } else {
+ leftValue = null;
+ }
+ final Object rightValue;
+ if (match.getRight() != null) {
+ rightValue = match.getRight().eGet(reference);
+ } else {
+ rightValue = null;
+ }
+ final Object originValue;
+ if (match.getOrigin() != null) {
+ originValue = match.getOrigin().eGet(reference);
+ } else {
+ originValue = null;
+ }
+
+ // "from" is either right or origin
+ boolean applies = false;
+ if (matchAllowingNull(originValue, fromQualifiedName)) {
+ // "from" is origin, "to" can be either left or right
+ applies = matchAllowingNull(leftValue, toQualifiedName)
+ || matchAllowingNull(rightValue, toQualifiedName);
+ } else if (matchAllowingNull(rightValue, fromQualifiedName)) {
+ // "from" is right, "to" can only be left
+ applies = matchAllowingNull(leftValue, toQualifiedName);
+ }
+ return applies;
+ }
+ return false;
+ }
+ }
+
+ /**
+ * This particular predicate will be used to check that a given Diff corresponds to an AttributeChange on
+ * a given attribute, with known "original" and "changed" values.
+ *
+ * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
+ */
+ private static final class AttributeValuesMatch implements Predicate<Diff> {
+ /** Name of the attribute we expect to have been changed. */
+ private final String attributeName;
+
+ /** The expected original value of this attribute. */
+ private final Object fromValue;
+
+ /** The value to which this attribute is expected to have changed. */
+ private final Object toValue;
+
+ /**
+ * Instantiates this predicate given the values it is meant to match.
+ *
+ * @param attributeName
+ * Name of the single-valued attribute on which we expect a change.
+ * @param fromValue
+ * The original value of this attribute.
+ * @param toValue
+ * The value to which this attribute has been changed.
+ */
+ public AttributeValuesMatch(String attributeName, Object fromValue, Object toValue) {
+ this.attributeName = attributeName;
+ this.fromValue = fromValue;
+ this.toValue = toValue;
+ }
+
+ /**
+ * Checks whether the two given Objects match : they are either both {@code null}, the same instance,
+ * or their "equals" returns {@code true}. If neither is {@code true}, we assume that these two
+ * Objects don't match.
+ * <p>
+ * Do note that "unset" values are in fact set to the empty String instead of {@code null}. We will
+ * thus consider {@code null} equal to the empty String here.
+ * </p>
+ *
+ * @param attributeValue
+ * The reference value, first of the two Objects to compare.
+ * @param expectedValue
+ * The expected value, second of the two Objects to compare.
+ * @return {@code true} if these two Objects are equal, {@code false} otherwise.
+ */
+ private static boolean equalAttributeValues(Object attributeValue, Object expectedValue) {
+ // Using == to handle the "null" case
+ boolean equal = expectedValue == attributeValue || expectedValue != null
+ && expectedValue.equals(attributeValue);
+ // Consider that null is equal to the empty string (unset attributes)
+ if (!equal) {
+ equal = "".equals(attributeValue) && expectedValue == null || "".equals(expectedValue) //$NON-NLS-1$ //$NON-NLS-2$
+ && attributeValue == null;
+ }
+ return equal;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see com.google.common.base.Predicate#apply(java.lang.Object)
+ */
+ public boolean apply(Diff input) {
+ // Note that this is not meant for multi-valued attributes
+ if (input instanceof AttributeChange
+ && ((AttributeChange)input).getAttribute().getName().equals(attributeName)
+ && !((AttributeChange)input).getAttribute().isMany()) {
+ final EAttribute attribute = ((AttributeChange)input).getAttribute();
+ final Match match = input.getMatch();
+
+ final Object leftValue;
+ if (match.getLeft() != null) {
+ leftValue = match.getLeft().eGet(attribute);
+ } else {
+ leftValue = attribute.getDefaultValue();
+ }
+
+ final Object rightValue;
+ if (match.getRight() != null) {
+ rightValue = match.getRight().eGet(attribute);
+ } else {
+ rightValue = attribute.getDefaultValue();
+ }
+
+ final Object originValue;
+ if (match.getOrigin() != null) {
+ originValue = match.getOrigin().eGet(attribute);
+ } else {
+ originValue = attribute.getDefaultValue();
+ }
+
+ final Object actualFrom;
+ if (fromValue == null) {
+ actualFrom = attribute.getDefaultValue();
+ } else {
+ actualFrom = fromValue;
+ }
+ final Object actualTo;
+ if (toValue == null) {
+ actualTo = attribute.getDefaultValue();
+ } else {
+ actualTo = toValue;
+ }
+
+ // "from" is either right or origin
+ boolean applies = false;
+ if (equalAttributeValues(actualFrom, originValue)) {
+ // "from" is origin, "to" can be either left or right
+ applies = equalAttributeValues(actualTo, leftValue)
+ || equalAttributeValues(actualTo, rightValue);
+ } else if (equalAttributeValues(actualFrom, rightValue)) {
+ // "from" is right, "to" can only be left
+ applies = equalAttributeValues(actualTo, leftValue);
+ }
+ return applies;
+ }
+ return false;
+ }
+ }
+
+}

Back to the top