Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Richard2013-02-19 14:07:09 +0000
committerAxel Richard2013-03-07 10:25:33 +0000
commit9da022449f18180a7c5d3b28d9076ea96d7ae7d2 (patch)
treecbed02ae15a135f3fb67d12ddaac523a04753ef2 /plugins
parent7877561fd43eaf3780115a75e9e2a567cebcd20f (diff)
downloadorg.eclipse.emf.compare-9da022449f18180a7c5d3b28d9076ea96d7ae7d2.tar.gz
org.eclipse.emf.compare-9da022449f18180a7c5d3b28d9076ea96d7ae7d2.tar.xz
org.eclipse.emf.compare-9da022449f18180a7c5d3b28d9076ea96d7ae7d2.zip
[401659] New filters and trees under groups
Display the tree structure of the model below each group. Add new filters : * Identical elements : hide elements with no differences * Pseudo conflicts elements : on a 3-way comparison, hide elements that has been made on both side. * Pseudo delete conflicts elements : on a 3-way comparison, hide deleted elements that has been made on both side. * Sub diff elements : hide differences under differences. * Uml refined elements : hide all uml elements refined by another diff. * Diagram (Gmf) refined elements : hide all gmf elements refined by another diff. Remove filters : Addes, Removes, Changed, Moved Remove Group : By Metaclass Bug: 401659 Change-Id: I97f4bcf6a2f4dc4fadec42a55c6b8adec574f536
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.ide.ui/plugin.xml8
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/structuremergeviewer/filters/GMFRefinedElementsFilter.java74
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchItemProviderSpec.java132
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ReferenceChangeItemProviderSpec.java3
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ResourceAttachmentChangeItemProviderSpec.java4
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewerContentProvider.java344
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/plugin.xml33
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/mergeviewer/CompareColorImpl.java560
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/mergeviewer/TableMergeViewer.java3
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/actions/FilterAction.java3
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/AbstractDifferenceFilter.java (renamed from plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/AddedElementsFilter.java)65
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/ChangedElementsFilter.java114
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/EmptyMatchedResourcesFilter.java123
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/IDifferenceFilter.java17
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/IdenticalElementsFilter.java62
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/MovedElementsFilter.java115
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/PseudoConflictsFilter.java71
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/PseudoDeleteConflictsFilter.java83
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/RemovedElementsFilter.java115
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/StructureMergeViewerFilter.java34
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/SubDiffElementsFilter.java64
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/groups/MetamodelGroupProvider.java159
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/AbstractTestCompareItemProviderAdapter.java248
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestMatchItemProviderSpec.java290
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/TestReferenceChangeItemProviderSpec.java590
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.ide.ui/plugin.xml8
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.ide.ui/src/org/eclipse/emf/compare/uml2/ide/ui/structuremergeviewer/filters/UMLRefinedElementsFilter.java97
28 files changed, 1825 insertions, 1596 deletions
diff --git a/plugins/org.eclipse.emf.compare.diagram.ide.ui/plugin.xml b/plugins/org.eclipse.emf.compare.diagram.ide.ui/plugin.xml
index 84c1defd5..c870dff40 100644
--- a/plugins/org.eclipse.emf.compare.diagram.ide.ui/plugin.xml
+++ b/plugins/org.eclipse.emf.compare.diagram.ide.ui/plugin.xml
@@ -35,5 +35,13 @@
ranking="40">
</factory>
</extension>
+ <extension
+ point="org.eclipse.emf.compare.rcp.ui.filters">
+ <filter
+ activeByDefault="true"
+ class="org.eclipse.emf.compare.diagram.ide.ui.structuremergeviewer.filters.GMFRefinedElementsFilter"
+ label="Diagram Refined elements">
+ </filter>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/structuremergeviewer/filters/GMFRefinedElementsFilter.java b/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/structuremergeviewer/filters/GMFRefinedElementsFilter.java
new file mode 100644
index 000000000..8f56df68a
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/structuremergeviewer/filters/GMFRefinedElementsFilter.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.diagram.ide.ui.structuremergeviewer.filters;
+
+import static com.google.common.base.Predicates.instanceOf;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.diagram.internal.extensions.DiagramDiff;
+import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.AbstractDifferenceFilter;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * A filter used by default that filtered out refined GMF differences.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+public class GMFRefinedElementsFilter extends AbstractDifferenceFilter {
+
+ /**
+ * The predicate use by this filter when it is selected.
+ */
+ private static final Predicate<? super EObject> predicateWhenSelected = new Predicate<EObject>() {
+ public boolean apply(EObject input) {
+ if (input instanceof Diff) {
+ Diff diff = (Diff)input;
+ return Iterables.any(diff.getRefines(), instanceOf(DiagramDiff.class));
+ }
+ return false;
+ }
+ };
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#isEnabled(org.eclipse.emf.compare.scope.IComparisonScope,
+ * org.eclipse.emf.compare.Comparison)
+ */
+ @Override
+ public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
+ if (scope != null) {
+ for (String nsURI : scope.getNsURIs()) {
+ if (nsURI.startsWith("http://www\\.eclipse\\.org/gmf/")) { //$NON-NLS-1$
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicateWhenSelected()
+ */
+ @Override
+ public Predicate<? super EObject> getPredicateWhenSelected() {
+ return predicateWhenSelected;
+ }
+
+}
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 a84e27173..863dc33a1 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
@@ -27,8 +27,6 @@ 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;
@@ -39,7 +37,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.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
/**
* Specialized {@link MatchItemProvider} returning nice output for {@link #getText(Object)} and
@@ -49,18 +46,25 @@ import org.eclipse.emf.ecore.EReference;
*/
public class MatchItemProviderSpec extends MatchItemProvider implements IItemStyledLabelProvider {
+ /**
+ * A predicate to know if the given {@link ReferenceChange} is a reference of type containment.
+ */
private static final Predicate<ReferenceChange> CONTAINMENT_REFERENCE_CHANGE = new Predicate<ReferenceChange>() {
public boolean apply(ReferenceChange input) {
return input.getReference().isContainment();
}
};
+ /**
+ * A function returning the {@link ReferenceChange#getValue()} of the given {@link ReferenceChange}.
+ */
private static final Function<ReferenceChange, EObject> VALUE = new Function<ReferenceChange, EObject>() {
public EObject apply(ReferenceChange input) {
return input.getValue();
}
};
+ /** A provider to compose images. */
private final OverlayImageProvider overlayProvider;
/**
@@ -139,19 +143,55 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty
return ImmutableList.copyOf(filteredChildren);
}
- Iterable<?> getChildrenIterable(Match match) {
+ /**
+ * 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),
- matchWithNoChildren(), emptyMatch(), PSEUDO_CONFLICT_DIFF, REFINED_DIFF,
- PSEUDO_DELETE_CONFLICT, instanceOf(ResourceAttachmentChange.class)));
+ emptyMatch(), instanceOf(ResourceAttachmentChange.class)));
Iterable<?> filteredChildren = filter(super.getChildren(match), childrenFilter);
return filteredChildren;
}
- private ImmutableSet<EObject> containmentReferencesValues(Match match) {
+ /**
+ * 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<ReferenceChange> containmentReferenceChanges = filter(filter(differences,
ReferenceChange.class), CONTAINMENT_REFERENCE_CHANGE);
@@ -160,8 +200,18 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty
return containementDifferenceValues;
}
- private static Predicate<? super Object> matchOfContainmentDiff(
- final ImmutableSet<EObject> 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;
@@ -178,24 +228,34 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty
};
}
+ /**
+ * 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.getChildrenIterable(match));
+ 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);
+ final Match match = (Match)input;
return match.getLeft() == null && match.getRight() == null && match.getOrigin() == null;
}
return false;
@@ -203,55 +263,6 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty
};
}
- static final Predicate<? super Object> REFINED_DIFF = new Predicate<Object>() {
- public boolean apply(Object input) {
- boolean ret = false;
- if (input instanceof Diff) {
- Diff diff = (Diff)input;
- ret = !diff.getRefines().isEmpty();
- }
- return ret;
- }
- };
-
- private static final Predicate<? super Object> PSEUDO_CONFLICT_DIFF = new Predicate<Object>() {
- public boolean apply(Object 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;
- }
- }
- return ret;
- }
- };
-
- private static final Predicate<? super Object> PSEUDO_DELETE_CONFLICT = new Predicate<Object>() {
- public boolean apply(Object input) {
- boolean ret = false;
- if (input instanceof ReferenceChange) {
- ReferenceChange referenceChange = (ReferenceChange)input;
- Conflict conflict = referenceChange.getConflict();
- if (conflict != null) {
- EReference eReference = referenceChange.getReference();
- EObject value = referenceChange.getValue();
- Iterable<ReferenceChange> conflictualReferenceChanges = filter(conflict.getDifferences(),
- ReferenceChange.class);
- for (ReferenceChange conflictualReferenceChange : conflictualReferenceChanges) {
- if (conflictualReferenceChange != referenceChange
- && conflictualReferenceChange.getReference() == eReference
- && conflictualReferenceChange.getValue() == value) {
- ret = true;
- }
- }
- }
- }
- return ret;
- }
- };
-
/**
* {@inheritDoc}
*
@@ -267,6 +278,7 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object)
+ * @since 3.0
*/
public IStyledString.IComposedStyledString getStyledText(Object object) {
return new ComposedStyledString(getText(object));
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 8285deb85..4ba41b2e6 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
@@ -176,8 +176,7 @@ public class ReferenceChangeItemProviderSpec extends ReferenceChangeItemProvider
}
}
- return ImmutableList.copyOf(filter(filter(ret, not(instanceOf(ResourceAttachmentChange.class))),
- not(MatchItemProviderSpec.REFINED_DIFF)));
+ return ImmutableList.copyOf(filter(ret, not(instanceOf(ResourceAttachmentChange.class))));
}
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 932dd79dc..5b501a2ad 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,8 +10,6 @@
*******************************************************************************/
package org.eclipse.emf.compare.provider.spec;
-import static com.google.common.base.Predicates.not;
-import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Lists.newArrayList;
import com.google.common.collect.ImmutableCollection;
@@ -88,7 +86,7 @@ public class ResourceAttachmentChangeItemProviderSpec extends ResourceAttachment
ret.addAll(children);
}
- return ImmutableList.copyOf(filter(ret, not(MatchItemProviderSpec.REFINED_DIFF)));
+ return ImmutableList.copyOf(ret);
}
private Collection<?> getChildren(Match matchOfValue) {
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 4a2ee21eb..1941ecaf6 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
@@ -142,7 +142,7 @@ public class EMFCompareStructureMergeViewer extends DiffTreeViewer implements Co
setLabelProvider(new DelegatingStyledCellLabelProvider(
new EMFCompareStructureMergeViewerLabelProvider(fAdapterFactory, this)));
setContentProvider(new EMFCompareStructureMergeViewerContentProvider(fAdapterFactory,
- structureMergeViewerGrouper));
+ structureMergeViewerGrouper, structureMergeViewerFilter));
if (parent instanceof CompareViewerSwitchingPane) {
fParent = (CompareViewerSwitchingPane)parent;
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 562b32a00..b17c0cdab 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Obeo.
+ * 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
@@ -10,38 +10,76 @@
*******************************************************************************/
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.Iterables;
import com.google.common.collect.Lists;
+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.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.structuremergeviewer.filters.StructureMergeViewerFilter;
import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.DifferenceGroup;
import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.StructureMergeViewerGrouper;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
+import org.eclipse.swt.graphics.Image;
+/**
+ * Specialized AdapterFactoryContentProvider for the emf compare structure merge viewer.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryContentProvider {
+ /** The viewer grouper associated with this content provider. */
private final StructureMergeViewerGrouper fViewerGrouper;
- EMFCompareStructureMergeViewerContentProvider(AdapterFactory adapterFactory,
- StructureMergeViewerGrouper structureMergeViewerGrouper) {
+ /** The viewer filter associated with this content provider. */
+ private final StructureMergeViewerFilter fViewerFilter;
+
+ /**
+ * 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.
+ */
+ public EMFCompareStructureMergeViewerContentProvider(AdapterFactory adapterFactory,
+ StructureMergeViewerGrouper structureMergeViewerGrouper,
+ StructureMergeViewerFilter structureMergeViewerFilter) {
super(adapterFactory);
this.fViewerGrouper = structureMergeViewerGrouper;
+ this.fViewerFilter = structureMergeViewerFilter;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider#getParent(Object object)
+ */
@Override
public Object getParent(Object element) {
- final Object ret;
+ Object ret;
if (element instanceof Adapter) {
ret = getAdapterFactory().adapt(super.getParent(((Adapter)element).getTarget()),
ICompareInput.class);
@@ -53,6 +91,11 @@ class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryConten
return ret;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider#hasChildren(Object object)
+ */
@Override
public final boolean hasChildren(Object element) {
final boolean ret;
@@ -74,6 +117,11 @@ class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryConten
return ret;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider#getChildren(Object object)
+ */
@Override
public final Object[] getChildren(Object element) {
final Object[] ret;
@@ -88,20 +136,39 @@ class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryConten
ret = toArray(compareInputs, ICompareInput.class);
}
} else if (element instanceof DifferenceGroup) {
- Iterable<? extends Diff> differences = ((DifferenceGroup)element).getDifferences();
- Iterable<ICompareInput> compareInputs = adapt(differences, getAdapterFactory(),
+ final Comparison target = ((DifferenceGroup)element).getComparison();
+ Iterable<ICompareInput> compareInputs = adapt(super.getChildren(target), getAdapterFactory(),
ICompareInput.class);
- ret = toArray(compareInputs, ICompareInput.class);
+ Iterable<FilteredEDiffNode> filteredCompareInputs = filteredEDiffNodes(filter(compareInputs,
+ AbstractEDiffNode.class), (DifferenceGroup)element);
+ ret = toArray(filteredCompareInputs, FilteredEDiffNode.class);
} else if (element instanceof Adapter) {
- Iterable<ICompareInput> compareInputs = adapt(super.getChildren(((Adapter)element).getTarget()),
- getAdapterFactory(), ICompareInput.class);
- ret = toArray(compareInputs, ICompareInput.class);
+ final Iterable<Object> children;
+ if (element instanceof FilteredEDiffNode) {
+ children = filteredElements(super.getChildren(((Adapter)element).getTarget()),
+ ((FilteredEDiffNode)element).getDifferenceGroup());
+ } else {
+ children = Lists.newArrayList(super.getChildren(((Adapter)element).getTarget()));
+ }
+ Iterable<ICompareInput> compareInputs = adapt(children, getAdapterFactory(), ICompareInput.class);
+ if (element instanceof FilteredEDiffNode) {
+ Iterable<FilteredEDiffNode> filteredCompareInputs = filteredEDiffNodes(filter(compareInputs,
+ AbstractEDiffNode.class), ((FilteredEDiffNode)element).getDifferenceGroup());
+ ret = toArray(filteredCompareInputs, FilteredEDiffNode.class);
+ } else {
+ ret = toArray(compareInputs, ICompareInput.class);
+ }
} else {
ret = new Object[0];
}
return ret;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider#getElements(Object object)
+ */
@Override
public Object[] getElements(Object element) {
return getChildren(element);
@@ -116,9 +183,9 @@ class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryConten
* @param iterable
* the iterable to transform.
* @param adapterFactory
- * the {@link AdapterFactory} used to adapt elements
+ * the {@link AdapterFactory} used to adapt elements.
* @param type
- * the target type of adapted elements
+ * 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,
@@ -131,7 +198,260 @@ class EMFCompareStructureMergeViewerContentProvider extends AdapterFactoryConten
return filter(transform(iterable, adaptFunction), type);
}
+ /**
+ * Adapts each elements of the the given <code>array</code> to the given <code>type</code> by using the
+ * given <code>adapterFactory</code>.
+ *
+ * @param <T>
+ * the type of returned elements.
+ * @param iterable
+ * the array to transform.
+ * @param adapterFactory
+ * the {@link AdapterFactory} used to adapt elements.
+ * @param type
+ * 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) {
return adapt(Lists.newArrayList(iterable), adapterFactory, type);
}
+
+ /**
+ * Filter out each element of the given <code>array</code> that should not be contained under the given
+ * {@link DifferenceGroup}.
+ *
+ * @param unfiltered
+ * the array to filter.
+ * @param diffGroup
+ * the given {@link DifferenceGroup}.
+ * @return an iterable of elements that should be contained under the given {@link DifferenceGroup}.
+ */
+ private Iterable<Object> filteredElements(Object[] unfiltered, final DifferenceGroup diffGroup) {
+ final Predicate<? super Object> isPartOfTree = new Predicate<Object>() {
+ public boolean apply(Object input) {
+ return isPartOfGroup(input, diffGroup);
+ }
+ };
+ return filter(Lists.newArrayList(unfiltered), isPartOfTree);
+ }
+
+ /**
+ * Returns whether this object should be contained under the given {@link DifferenceGroup}.
+ *
+ * @param object
+ * the object to filter.
+ * @param diffGroup
+ * the given {@link DifferenceGroup}.
+ * @return true if the object should be contained under the given {@link DifferenceGroup}, false
+ * otherwise.
+ */
+ private boolean isPartOfGroup(Object object, final DifferenceGroup diffGroup) {
+ final Predicate<? super EObject> isPartOfTree = new Predicate<EObject>() {
+ public boolean apply(EObject input) {
+ return Iterables.contains(filter(diffGroup.getDifferences(), not(or(fViewerFilter
+ .getPredicates()))), 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()) {
+ ret = Iterables.any(((Diff)object).getMatch().getComparison().getMatch(
+ ((ReferenceChange)object).getValue()).getAllDifferences(), isPartOfTree);
+ }
+ } else {
+ ret = true;
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * Creates an iterable of {@link FilteredEDiffNode} from an iterable of {@link AbstractEDiffNode} and a
+ * {@link DifferenceGroup}.
+ *
+ * @param iterable
+ * the iterable of {@link AbstractEDiffNode} to transform.
+ * @param diffGroup
+ * the {@link DifferenceGroup} to associate with the FilteredEDiffNodes.
+ * @return an iterable of {@link FilteredEDiffNode}.
+ */
+ private Iterable<FilteredEDiffNode> filteredEDiffNodes(Iterable<AbstractEDiffNode> iterable,
+ final DifferenceGroup diffGroup) {
+ Function<AbstractEDiffNode, FilteredEDiffNode> adaptFunction = new Function<AbstractEDiffNode, FilteredEDiffNode>() {
+ public FilteredEDiffNode apply(AbstractEDiffNode input) {
+ return new FilteredEDiffNode(input, diffGroup);
+ }
+ };
+ return transform(iterable, adaptFunction);
+ }
+
+ /**
+ * AbstractEDiffNodes that know the DifferenceGroup in which they are. 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>
+ */
+ private class FilteredEDiffNode implements ICompareInput, Adapter {
+
+ /** The AbstractEDiffNode wrapped. */
+ private AbstractEDiffNode fDelegate;
+
+ /** The DifferenceGroup associated with the node. */
+ private DifferenceGroup differenceGroup;
+
+ /**
+ * This constructs an instance that wraps this {@link AbstractEDiffNode} contained in the given
+ * {@link DifferenceGroup}.
+ *
+ * @param delegate
+ * the given AbstractEDiffNode.
+ * @param diffGroup
+ * the given DifferenceGroup.
+ */
+ public FilteredEDiffNode(AbstractEDiffNode delegate, DifferenceGroup diffGroup) {
+ fDelegate = delegate;
+ differenceGroup = diffGroup;
+ }
+
+ /**
+ * Returns the backing delegate instance that methods are forwarded to.
+ *
+ * @return the wrapped AbstractEDiffNode.
+ */
+ private AbstractEDiffNode delegate() {
+ return fDelegate;
+ }
+
+ /**
+ * Returns the {@link DifferenceGroup} associated with the wrapped {@link AbstractEDiffNode}.
+ *
+ * @return the difference group.
+ */
+ public DifferenceGroup getDifferenceGroup() {
+ return differenceGroup;
+ }
+
+ /**
+ * {@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);
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/plugin.xml b/plugins/org.eclipse.emf.compare.rcp.ui/plugin.xml
index b76137a6a..82aac02d4 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/plugin.xml
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/plugin.xml
@@ -24,11 +24,6 @@
</group>
<group
activeByDefault="false"
- class="org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.MetamodelGroupProvider"
- label="By Metaclass">
- </group>
- <group
- activeByDefault="false"
class="org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.ThreeWayComparisonGroupProvider"
label="By Side">
</group>
@@ -36,29 +31,29 @@
<extension
point="org.eclipse.emf.compare.rcp.ui.filters">
<filter
- activeByDefault="false"
- class="org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.ChangedElementsFilter"
- label="Changed elements">
+ activeByDefault="true"
+ class="org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.EmptyMatchedResourcesFilter"
+ label="Empty resource mappings">
</filter>
<filter
- activeByDefault="false"
- class="org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.AddedElementsFilter"
- label="Added elements">
+ activeByDefault="true"
+ class="org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.PseudoConflictsFilter"
+ label="Pseudo conflicts differences">
</filter>
<filter
- activeByDefault="false"
- class="org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.RemovedElementsFilter"
- label="Removed elements">
+ activeByDefault="true"
+ class="org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.PseudoDeleteConflictsFilter"
+ label="Pseudo delete conflicts differences">
</filter>
<filter
- activeByDefault="false"
- class="org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.MovedElementsFilter"
- label="Moved elements">
+ activeByDefault="true"
+ class="org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IdenticalElementsFilter"
+ label="Identical elements">
</filter>
<filter
activeByDefault="true"
- class="org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.EmptyMatchedResourcesFilter"
- label="Empty Resource Mappings">
+ class="org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.SubDiffElementsFilter"
+ label="Sub diff elements">
</filter>
</extension>
</plugin>
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/mergeviewer/CompareColorImpl.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/mergeviewer/CompareColorImpl.java
index 642d7d1cc..35c78c76e 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/mergeviewer/CompareColorImpl.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/mergeviewer/CompareColorImpl.java
@@ -1,280 +1,280 @@
-/*******************************************************************************
- * 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.rcp.ui.mergeviewer;
-
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
-
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.resource.ColorRegistry;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * Default implementation that use a cache to store created Color and that is listening to a preference store
- * for color configuration.
- *
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class CompareColorImpl implements RemovalListener<RGB, Color>, ICompareColor {
-
- /**
- *
- */
- private static final int MAX_CACHE_SIZE = 16;
-
- /**
- *
- */
- private static final int MED_RGB_COMPONENT = 128;
-
- /**
- *
- */
- private static final int MAX_RGB_COMPONENT = 255;
-
- /**
- *
- */
- private static final double INTERPOLATION_SCALE_1 = 0.6;
-
- /**
- *
- */
- private static final double INTERPOLATION_SCALE_2 = 0.97;
-
- public static final String INCOMING_COLOR = "INCOMING_COLOR"; //$NON-NLS-1$
-
- public static final String OUTGOING_COLOR = "OUTGOING_COLOR"; //$NON-NLS-1$
-
- public static final String CONFLICTING_COLOR = "CONFLICTING_COLOR"; //$NON-NLS-1$
-
- public static final String RESOLVED_COLOR = "RESOLVED_COLOR"; //$NON-NLS-1$
-
- private RGB fIncomingSelected;
-
- private RGB fIncoming;
-
- private RGB fIncomingFill;
-
- private RGB fConflictSelected;
-
- private RGB fConflict;
-
- private RGB fConflictFill;
-
- private RGB fOutgoingSelected;
-
- private RGB fOutgoing;
-
- private RGB fOutgoingFill;
-
- private RGB fResolved;
-
- private final LoadingCache<RGB, Color> fColors;
-
- private final IPreferenceStore fPreferenceStore;
-
- private final IPropertyChangeListener fPreferenceChangeListener;
-
- private final boolean fLeftIsLocal;
-
- private Display fDisplay;
-
- public CompareColorImpl(Display display, boolean leftIsLocal, IPreferenceStore preferenceStore) {
- this.fDisplay = display;
- this.fPreferenceStore = preferenceStore;
- this.fColors = CacheBuilder.newBuilder().maximumSize(MAX_CACHE_SIZE).removalListener(this).build(
- new CacheLoader<RGB, Color>() {
- @Override
- public Color load(RGB rgb) throws Exception {
- return new Color(fDisplay, rgb);
- }
- });
-
- this.fPreferenceChangeListener = new IPropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent event) {
- handlePropertyChangeEvent(event);
- }
- };
-
- if (fPreferenceStore != null) {
- fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener);
- }
-
- fLeftIsLocal = leftIsLocal;
- updateColors();
- }
-
- public void onRemoval(RemovalNotification<RGB, Color> notification) {
- Color color = notification.getValue();
- if (!color.isDisposed()) {
- color.dispose();
- }
- }
-
- protected final void handlePropertyChangeEvent(PropertyChangeEvent event) {
- String key = event.getProperty();
-
- if (key.equals(INCOMING_COLOR) || key.equals(OUTGOING_COLOR) || key.equals(CONFLICTING_COLOR)
- || key.equals(RESOLVED_COLOR)) {
- updateColors();
- }
- }
-
- private Color getColor(RGB rgb) {
- if (rgb == null) {
- return null;
- }
- Color c = fColors.getUnchecked(rgb);
- return c;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.ICompareColor#getFillColor(org.eclipse.emf.compare.Diff,
- * boolean, boolean, boolean)
- */
- public Color getFillColor(Diff diff, boolean isThreeWay, boolean isIgnoreAncestor, boolean selected) {
- return getColor(getFillRGB(diff, isThreeWay, isIgnoreAncestor, selected));
- }
-
- private RGB getFillRGB(Diff diff, boolean isThreeWay, boolean isIgnoreAncestor, boolean selected) {
- RGB selectedFill = getBackground();
- if (isThreeWay && !isIgnoreAncestor) {
- boolean requiredConflictForWayOfMerge = false;
-
- if (diff.getConflict() == null && !requiredConflictForWayOfMerge) {
- switch (diff.getSource()) {
- case RIGHT:
- if (fLeftIsLocal) {
- return selected ? selectedFill : fIncomingFill;
- }
- return selected ? selectedFill : fOutgoingFill;
- case LEFT:
- if (fLeftIsLocal) {
- return selected ? selectedFill : fOutgoingFill;
- }
- return selected ? selectedFill : fIncomingFill;
- }
- } else {
- return selected ? selectedFill : fConflictFill;
- }
- return selected ? selectedFill : fConflictFill;
- }
- return selected ? selectedFill : fOutgoingFill;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.ICompareColor#getStrokeColor(org.eclipse.emf.compare.Diff,
- * boolean, boolean, boolean)
- */
- public Color getStrokeColor(Diff diff, boolean isThreeWay, boolean isIgnoreAncestor, boolean selected) {
- return getColor(getStrokeRGB(diff, isThreeWay, isIgnoreAncestor, selected));
- }
-
- private RGB getStrokeRGB(Diff diff, boolean isThreeWay, boolean isIgnoreAncestor, boolean selected) {
- if (isThreeWay && !isIgnoreAncestor) {
- boolean requiredConflictForWayOfMerge = false;
-
- if (diff.getConflict() == null && !requiredConflictForWayOfMerge) {
- switch (diff.getSource()) {
- case RIGHT:
- if (fLeftIsLocal) {
- return selected ? fIncomingSelected : fIncoming;
- }
- return selected ? fOutgoingSelected : fOutgoing;
- case LEFT:
- if (fLeftIsLocal) {
- return selected ? fOutgoingSelected : fOutgoing;
- }
- return selected ? fIncomingSelected : fIncoming;
- }
- } else {
- return selected ? fConflictSelected : fConflict;
- }
- return selected ? fConflictSelected : fConflict;
- }
- return selected ? fOutgoingSelected : fOutgoing;
- }
-
- private RGB getBackground() {
- return fDisplay.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB();
- }
-
- private void updateColors() {
- ColorRegistry registry = JFaceResources.getColorRegistry();
-
- RGB bg = getBackground();
- fIncomingSelected = registry.getRGB(INCOMING_COLOR);
- if (fIncomingSelected == null) {
- fIncomingSelected = new RGB(0, 0, MAX_RGB_COMPONENT); // BLUE
- }
- fIncoming = interpolate(fIncomingSelected, bg, INTERPOLATION_SCALE_1);
- fIncomingFill = interpolate(fIncomingSelected, bg, INTERPOLATION_SCALE_2);
-
- fOutgoingSelected = registry.getRGB(OUTGOING_COLOR);
- if (fOutgoingSelected == null) {
- fOutgoingSelected = new RGB(0, 0, 0); // BLACK
- }
- fOutgoing = interpolate(fOutgoingSelected, bg, INTERPOLATION_SCALE_1);
- fOutgoingFill = interpolate(fOutgoingSelected, bg, INTERPOLATION_SCALE_2);
-
- fConflictSelected = registry.getRGB(CONFLICTING_COLOR);
- if (fConflictSelected == null) {
- fConflictSelected = new RGB(MAX_RGB_COMPONENT, 0, 0); // RED
- }
- fConflict = interpolate(fConflictSelected, bg, INTERPOLATION_SCALE_1);
- fConflictFill = interpolate(fConflictSelected, bg, INTERPOLATION_SCALE_2);
-
- fResolved = registry.getRGB(RESOLVED_COLOR);
- if (fResolved == null) {
- fResolved = new RGB(0, MAX_RGB_COMPONENT, 0); // GREEN
- }
- }
-
- private static RGB interpolate(RGB fg, RGB bg, double scale) {
- if (fg != null && bg != null) {
- return new RGB((int)((1.0 - scale) * fg.red + scale * bg.red),
- (int)((1.0 - scale) * fg.green + scale * bg.green), (int)((1.0 - scale) * fg.blue + scale
- * bg.blue));
- }
- if (fg != null) {
- return fg;
- }
- if (bg != null) {
- return bg;
- }
- return new RGB(MED_RGB_COMPONENT, MED_RGB_COMPONENT, MED_RGB_COMPONENT); // a gray
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.ICompareColor#dispose()
- */
- public void dispose() {
- fColors.invalidateAll();
- fPreferenceStore.removePropertyChangeListener(fPreferenceChangeListener);
- }
-}
+/*******************************************************************************
+ * 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.rcp.ui.mergeviewer;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.cache.RemovalListener;
+import com.google.common.cache.RemovalNotification;
+
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.ColorRegistry;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Default implementation that use a cache to store created Color and that is listening to a preference store
+ * for color configuration.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class CompareColorImpl implements RemovalListener<RGB, Color>, ICompareColor {
+
+ /**
+ *
+ */
+ private static final int MAX_CACHE_SIZE = 16;
+
+ /**
+ *
+ */
+ private static final int MED_RGB_COMPONENT = 128;
+
+ /**
+ *
+ */
+ private static final int MAX_RGB_COMPONENT = 255;
+
+ /**
+ *
+ */
+ private static final double INTERPOLATION_SCALE_1 = 0.6;
+
+ /**
+ *
+ */
+ private static final double INTERPOLATION_SCALE_2 = 0.97;
+
+ public static final String INCOMING_COLOR = "INCOMING_COLOR"; //$NON-NLS-1$
+
+ public static final String OUTGOING_COLOR = "OUTGOING_COLOR"; //$NON-NLS-1$
+
+ public static final String CONFLICTING_COLOR = "CONFLICTING_COLOR"; //$NON-NLS-1$
+
+ public static final String RESOLVED_COLOR = "RESOLVED_COLOR"; //$NON-NLS-1$
+
+ private RGB fIncomingSelected;
+
+ private RGB fIncoming;
+
+ private RGB fIncomingFill;
+
+ private RGB fConflictSelected;
+
+ private RGB fConflict;
+
+ private RGB fConflictFill;
+
+ private RGB fOutgoingSelected;
+
+ private RGB fOutgoing;
+
+ private RGB fOutgoingFill;
+
+ private RGB fResolved;
+
+ private final LoadingCache<RGB, Color> fColors;
+
+ private final IPreferenceStore fPreferenceStore;
+
+ private final IPropertyChangeListener fPreferenceChangeListener;
+
+ private final boolean fLeftIsLocal;
+
+ private Display fDisplay;
+
+ public CompareColorImpl(Display display, boolean leftIsLocal, IPreferenceStore preferenceStore) {
+ this.fDisplay = display;
+ this.fPreferenceStore = preferenceStore;
+ this.fColors = CacheBuilder.newBuilder().maximumSize(MAX_CACHE_SIZE).removalListener(this).build(
+ new CacheLoader<RGB, Color>() {
+ @Override
+ public Color load(RGB rgb) throws Exception {
+ return new Color(fDisplay, rgb);
+ }
+ });
+
+ this.fPreferenceChangeListener = new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ handlePropertyChangeEvent(event);
+ }
+ };
+
+ if (fPreferenceStore != null) {
+ fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener);
+ }
+
+ fLeftIsLocal = leftIsLocal;
+ updateColors();
+ }
+
+ public void onRemoval(RemovalNotification<RGB, Color> notification) {
+ Color color = notification.getValue();
+ if (!color.isDisposed()) {
+ color.dispose();
+ }
+ }
+
+ protected final void handlePropertyChangeEvent(PropertyChangeEvent event) {
+ String key = event.getProperty();
+
+ if (key.equals(INCOMING_COLOR) || key.equals(OUTGOING_COLOR) || key.equals(CONFLICTING_COLOR)
+ || key.equals(RESOLVED_COLOR)) {
+ updateColors();
+ }
+ }
+
+ private Color getColor(RGB rgb) {
+ if (rgb == null) {
+ return null;
+ }
+ Color c = fColors.getUnchecked(rgb);
+ return c;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.ICompareColor#getFillColor(org.eclipse.emf.compare.Diff,
+ * boolean, boolean, boolean)
+ */
+ public Color getFillColor(Diff diff, boolean isThreeWay, boolean isIgnoreAncestor, boolean selected) {
+ return getColor(getFillRGB(diff, isThreeWay, isIgnoreAncestor, selected));
+ }
+
+ private RGB getFillRGB(Diff diff, boolean isThreeWay, boolean isIgnoreAncestor, boolean selected) {
+ RGB selectedFill = getBackground();
+ if (isThreeWay && !isIgnoreAncestor) {
+ boolean requiredConflictForWayOfMerge = false;
+
+ if (diff.getConflict() == null && !requiredConflictForWayOfMerge) {
+ switch (diff.getSource()) {
+ case RIGHT:
+ if (fLeftIsLocal) {
+ return selected ? selectedFill : fIncomingFill;
+ }
+ return selected ? selectedFill : fOutgoingFill;
+ case LEFT:
+ if (fLeftIsLocal) {
+ return selected ? selectedFill : fOutgoingFill;
+ }
+ return selected ? selectedFill : fIncomingFill;
+ }
+ } else {
+ return selected ? selectedFill : fConflictFill;
+ }
+ return selected ? selectedFill : fConflictFill;
+ }
+ return selected ? selectedFill : fOutgoingFill;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.ICompareColor#getStrokeColor(org.eclipse.emf.compare.Diff,
+ * boolean, boolean, boolean)
+ */
+ public Color getStrokeColor(Diff diff, boolean isThreeWay, boolean isIgnoreAncestor, boolean selected) {
+ return getColor(getStrokeRGB(diff, isThreeWay, isIgnoreAncestor, selected));
+ }
+
+ private RGB getStrokeRGB(Diff diff, boolean isThreeWay, boolean isIgnoreAncestor, boolean selected) {
+ if (isThreeWay && !isIgnoreAncestor) {
+ boolean requiredConflictForWayOfMerge = false;
+
+ if (diff.getConflict() == null && !requiredConflictForWayOfMerge) {
+ switch (diff.getSource()) {
+ case RIGHT:
+ if (fLeftIsLocal) {
+ return selected ? fIncomingSelected : fIncoming;
+ }
+ return selected ? fOutgoingSelected : fOutgoing;
+ case LEFT:
+ if (fLeftIsLocal) {
+ return selected ? fOutgoingSelected : fOutgoing;
+ }
+ return selected ? fIncomingSelected : fIncoming;
+ }
+ } else {
+ return selected ? fConflictSelected : fConflict;
+ }
+ return selected ? fConflictSelected : fConflict;
+ }
+ return selected ? fOutgoingSelected : fOutgoing;
+ }
+
+ private RGB getBackground() {
+ return fDisplay.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB();
+ }
+
+ private void updateColors() {
+ ColorRegistry registry = JFaceResources.getColorRegistry();
+
+ RGB bg = getBackground();
+ fIncomingSelected = registry.getRGB(INCOMING_COLOR);
+ if (fIncomingSelected == null) {
+ fIncomingSelected = new RGB(0, 0, MAX_RGB_COMPONENT); // BLUE
+ }
+ fIncoming = interpolate(fIncomingSelected, bg, INTERPOLATION_SCALE_1);
+ fIncomingFill = interpolate(fIncomingSelected, bg, INTERPOLATION_SCALE_2);
+
+ fOutgoingSelected = registry.getRGB(OUTGOING_COLOR);
+ if (fOutgoingSelected == null) {
+ fOutgoingSelected = new RGB(0, 0, 0); // BLACK
+ }
+ fOutgoing = interpolate(fOutgoingSelected, bg, INTERPOLATION_SCALE_1);
+ fOutgoingFill = interpolate(fOutgoingSelected, bg, INTERPOLATION_SCALE_2);
+
+ fConflictSelected = registry.getRGB(CONFLICTING_COLOR);
+ if (fConflictSelected == null) {
+ fConflictSelected = new RGB(MAX_RGB_COMPONENT, 0, 0); // RED
+ }
+ fConflict = interpolate(fConflictSelected, bg, INTERPOLATION_SCALE_1);
+ fConflictFill = interpolate(fConflictSelected, bg, INTERPOLATION_SCALE_2);
+
+ fResolved = registry.getRGB(RESOLVED_COLOR);
+ if (fResolved == null) {
+ fResolved = new RGB(0, MAX_RGB_COMPONENT, 0); // GREEN
+ }
+ }
+
+ private static RGB interpolate(RGB fg, RGB bg, double scale) {
+ if (fg != null && bg != null) {
+ return new RGB((int)((1.0 - scale) * fg.red + scale * bg.red),
+ (int)((1.0 - scale) * fg.green + scale * bg.green), (int)((1.0 - scale) * fg.blue + scale
+ * bg.blue));
+ }
+ if (fg != null) {
+ return fg;
+ }
+ if (bg != null) {
+ return bg;
+ }
+ return new RGB(MED_RGB_COMPONENT, MED_RGB_COMPONENT, MED_RGB_COMPONENT); // a gray
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.ICompareColor#dispose()
+ */
+ public void dispose() {
+ fColors.invalidateAll();
+ fPreferenceStore.removePropertyChangeListener(fPreferenceChangeListener);
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/mergeviewer/TableMergeViewer.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/mergeviewer/TableMergeViewer.java
index 0b3cdaa94..061aada39 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/mergeviewer/TableMergeViewer.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/mergeviewer/TableMergeViewer.java
@@ -153,7 +153,8 @@ public class TableMergeViewer extends StructuredMergeViewer {
private void paintItemDiffBox(Event event, Diff diff, Rectangle bounds) {
event.detail &= ~SWT.HOT;
- if (diff.getState() == DifferenceState.DISCARDED || diff.getState() == DifferenceState.MERGED) {
+ if (diff != null
+ && (diff.getState() == DifferenceState.DISCARDED || diff.getState() == DifferenceState.MERGED)) {
return;
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/actions/FilterAction.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/actions/FilterAction.java
index 4cb6e0f30..39b6d26d1 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/actions/FilterAction.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/actions/FilterAction.java
@@ -45,7 +45,8 @@ public class FilterAction extends Action {
* @param filter
* The filter associated with this action.
*/
- public FilterAction(String text, StructureMergeViewerFilter structureMergeViewerFilter, IDifferenceFilter filter) {
+ public FilterAction(String text, StructureMergeViewerFilter structureMergeViewerFilter,
+ IDifferenceFilter filter) {
super(text, IAction.AS_CHECK_BOX);
this.structureMergeViewerFilter = structureMergeViewerFilter;
this.filter = filter;
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/AddedElementsFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/AbstractDifferenceFilter.java
index b8c8995fc..d9679edf4 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/AddedElementsFilter.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/AbstractDifferenceFilter.java
@@ -1,48 +1,47 @@
-/*******************************************************************************
- * 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.structuremergeviewer.filters;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
-
import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.EObject;
/**
- * A filter used by default that filtered out added elements.
+ * An abstract filter implementation.
*
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
* @since 3.0
*/
-public class AddedElementsFilter implements IDifferenceFilter {
+public abstract class AbstractDifferenceFilter implements IDifferenceFilter {
/** A human-readable label for this filter. This will be displayed in the EMF Compare UI. */
- private String label;
+ protected String label;
/** The initial activation state of the filter. */
- private boolean activeByDefault;
-
- /** The predicate activate through this filter. */
- private Predicate<? super EObject> predicate;
+ protected boolean activeByDefault;
/**
* Constructs the filter with the appropriate predicate.
*/
- public AddedElementsFilter() {
+ public AbstractDifferenceFilter() {
super();
- setPredicate();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicateWhenSelected()
+ */
+ public abstract Predicate<? super EObject> getPredicateWhenSelected();
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicateWhenUnselected()
+ */
+ public Predicate<? super EObject> getPredicateWhenUnselected() {
+ return Predicates.alwaysFalse();
}
/**
@@ -91,24 +90,4 @@ public class AddedElementsFilter implements IDifferenceFilter {
return true;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicate()
- */
- public Predicate<? super EObject> getPredicate() {
- return predicate;
- }
-
- /**
- * Set the predicate that will be activate through this filter.
- */
- private void setPredicate() {
- final Predicate<? super EObject> actualPredicate = new Predicate<EObject>() {
- public boolean apply(EObject input) {
- return input instanceof Diff && ofKind(DifferenceKind.ADD).apply((Diff)input);
- }
- };
- predicate = actualPredicate;
- }
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/ChangedElementsFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/ChangedElementsFilter.java
deleted file mode 100644
index dfa072d6a..000000000
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/ChangedElementsFilter.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*******************************************************************************
- * 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.structuremergeviewer.filters;
-
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
-
-import com.google.common.base.Predicate;
-
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceKind;
-import org.eclipse.emf.compare.scope.IComparisonScope;
-import org.eclipse.emf.ecore.EObject;
-
-/**
- * A filter used by default that filtered out changed elements.
- *
- * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
- * @since 3.0
- */
-public class ChangedElementsFilter implements IDifferenceFilter {
-
- /** A human-readable label for this filter. This will be displayed in the EMF Compare UI. */
- private String label;
-
- /** The initial activation state of the filter. */
- private boolean activeByDefault;
-
- /** The Predicate activate through this action. */
- private Predicate<? super EObject> predicate;
-
- /**
- * Constructs the filter with the appropriate predicate.
- */
- public ChangedElementsFilter() {
- super();
- setPredicate();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getLabel()
- */
- public String getLabel() {
- return label;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#setLabel(java.lang.String)
- */
- public void setLabel(String label) {
- this.label = label;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#defaultSelected()
- */
- public boolean defaultSelected() {
- return activeByDefault;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#setDefaultSelected(boolean)
- */
- public void setDefaultSelected(boolean activeByDefault) {
- this.activeByDefault = activeByDefault;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#isEnabled(org.eclipse.emf.compare.scope.IComparisonScope,
- * org.eclipse.emf.compare.Comparison)
- */
- public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicate()
- */
- public Predicate<? super EObject> getPredicate() {
- return predicate;
- }
-
- /**
- * Set the predicate that will be activate through this filter.
- */
- private void setPredicate() {
- final Predicate<? super EObject> actualPredicate = new Predicate<EObject>() {
- public boolean apply(EObject input) {
- return input instanceof Diff && ofKind(DifferenceKind.CHANGE).apply((Diff)input);
- }
- };
- predicate = actualPredicate;
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/EmptyMatchedResourcesFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/EmptyMatchedResourcesFilter.java
index 355242e52..0fd965382 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/EmptyMatchedResourcesFilter.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/EmptyMatchedResourcesFilter.java
@@ -16,11 +16,9 @@ import static com.google.common.collect.Iterables.isEmpty;
import com.google.common.base.Predicate;
import org.eclipse.emf.common.util.EList;
-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.scope.IComparisonScope;
import org.eclipse.emf.ecore.EObject;
/**
@@ -29,107 +27,42 @@ import org.eclipse.emf.ecore.EObject;
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
* @since 3.0
*/
-public class EmptyMatchedResourcesFilter implements IDifferenceFilter {
-
- /** A human-readable label for this filter. This will be displayed in the EMF Compare UI. */
- private String label;
-
- /** The initial activation state of the filter. */
- private boolean activeByDefault;
-
- /** The Predicate activate through this action. */
- private Predicate<? super EObject> predicate;
-
- /**
- * Constructs the filter with the appropriate predicate.
- */
- public EmptyMatchedResourcesFilter() {
- super();
- setPredicate();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getLabel()
- */
- public String getLabel() {
- return label;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#setLabel(java.lang.String)
- */
- public void setLabel(String label) {
- this.label = label;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#defaultSelected()
- */
- public boolean defaultSelected() {
- return activeByDefault;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#setDefaultSelected(boolean)
- */
- public void setDefaultSelected(boolean activeByDefault) {
- this.activeByDefault = activeByDefault;
- }
+public class EmptyMatchedResourcesFilter extends AbstractDifferenceFilter {
/**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#isEnabled(org.eclipse.emf.compare.scope.IComparisonScope,
- * org.eclipse.emf.compare.Comparison)
+ * The predicate use by this filter when it is selected.
*/
- public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
- return true;
- }
+ 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)) {
+ for (ResourceAttachmentChange rac : resourceAttachmentchanges) {
+ final String diffResourceURI = rac.getResourceURI();
+ if (!diffResourceURI.equals(((MatchResource)input).getLeftURI())
+ && !diffResourceURI.equals(((MatchResource)input).getRightURI())
+ && !diffResourceURI.equals(((MatchResource)input).getOriginURI())) {
+ return true;
+ }
+ }
+ } else {
+ return true;
+ }
+ }
+ return false;
+ }
+ };
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicate()
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicateWhenSelected()
*/
- public Predicate<? super EObject> getPredicate() {
- return predicate;
- }
-
- /**
- * Set the predicate that will be activate through this filter.
- */
- private void setPredicate() {
- final Predicate<? super EObject> actualPredicate = 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)) {
- for (ResourceAttachmentChange rac : resourceAttachmentchanges) {
- final String diffResourceURI = rac.getResourceURI();
- if (!diffResourceURI.equals(((MatchResource)input).getLeftURI())
- && !diffResourceURI.equals(((MatchResource)input).getRightURI())
- && !diffResourceURI.equals(((MatchResource)input).getOriginURI())) {
- return true;
- }
- }
- } else {
- return true;
- }
- }
- return false;
- }
- };
- predicate = actualPredicate;
+ @Override
+ public Predicate<? super EObject> getPredicateWhenSelected() {
+ return predicateWhenSelected;
}
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/IDifferenceFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/IDifferenceFilter.java
index 496e94b7a..8658a707d 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/IDifferenceFilter.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/IDifferenceFilter.java
@@ -35,11 +35,22 @@ import org.eclipse.emf.ecore.EObject;
public interface IDifferenceFilter {
/**
- * The predicate that will filter out objects in the structural differences view.
+ * Returns the predicate that will filter out objects in the structural differences view when this filter
+ * will be selected.
*
- * @return The predicate that will filter out objects in the structural differences view.
+ * @return the predicate that will filter out objects in the structural differences view when this filter
+ * will be selected.
*/
- Predicate<? super EObject> getPredicate();
+ Predicate<? super EObject> getPredicateWhenSelected();
+
+ /**
+ * Returns the predicate that will filter out objects in the structural differences view when this filter
+ * will be unselected.
+ *
+ * @return the predicate that will filter out objects in the structural differences view when this filter
+ * will be unselected.
+ */
+ Predicate<? super EObject> getPredicateWhenUnselected();
/**
* A human-readable label for this filter. 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/structuremergeviewer/filters/IdenticalElementsFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/IdenticalElementsFilter.java
new file mode 100644
index 000000000..44e23e834
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/IdenticalElementsFilter.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.structuremergeviewer.filters;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.provider.spec.MatchItemProviderSpec;
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * A filter used by default that filtered out identical elements.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+public class IdenticalElementsFilter extends AbstractDifferenceFilter {
+
+ /**
+ * The predicate use by this filter when it is selected.
+ */
+ 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)));
+ }
+ }
+ return Iterables.isEmpty(match.getAllDifferences());
+ }
+ return false;
+ }
+ };
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicateWhenSelected()
+ */
+ @Override
+ public Predicate<? super EObject> getPredicateWhenSelected() {
+ return predicateWhenSelected;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/MovedElementsFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/MovedElementsFilter.java
deleted file mode 100644
index ad9eed0ae..000000000
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/MovedElementsFilter.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * 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.structuremergeviewer.filters;
-
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
-
-import com.google.common.base.Predicate;
-
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceKind;
-import org.eclipse.emf.compare.scope.IComparisonScope;
-import org.eclipse.emf.ecore.EObject;
-
-/**
- * A filter used by default that filtered out moved elements.
- *
- * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
- * @since 3.0
- */
-public class MovedElementsFilter implements IDifferenceFilter {
-
- /** A human-readable label for this filter. This will be displayed in the EMF Compare UI. */
- private String label;
-
- /** The initial activation state of the filter. */
- private boolean activeByDefault;
-
- /** The Predicate activate through this action. */
- private Predicate<? super EObject> predicate;
-
- /**
- * Constructs the filter with the appropriate predicate.
- */
- public MovedElementsFilter() {
- super();
- setPredicate();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getLabel()
- */
- public String getLabel() {
- return label;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#setLabel(java.lang.String)
- */
- public void setLabel(String label) {
- this.label = label;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#defaultSelected()
- */
- public boolean defaultSelected() {
- return activeByDefault;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#setDefaultSelected(boolean)
- */
- public void setDefaultSelected(boolean activeByDefault) {
- this.activeByDefault = activeByDefault;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#isEnabled(org.eclipse.emf.compare.scope.IComparisonScope,
- * org.eclipse.emf.compare.Comparison)
- */
- public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicate()
- */
- public Predicate<? super EObject> getPredicate() {
- return predicate;
- }
-
- /**
- * Set the predicate that will be activate through this filter.
- */
- private void setPredicate() {
- final Predicate<? super EObject> actualPredicate = new Predicate<EObject>() {
- public boolean apply(EObject input) {
- return input instanceof Diff && ofKind(DifferenceKind.MOVE).apply((Diff)input);
- }
- };
- predicate = actualPredicate;
- }
-
-}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/PseudoConflictsFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/PseudoConflictsFilter.java
new file mode 100644
index 000000000..47d3dcc9a
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/PseudoConflictsFilter.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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.structuremergeviewer.filters;
+
+import com.google.common.base.Predicate;
+
+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.scope.IComparisonScope;
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * A filter used by default that filtered out pseudo conflicts differences.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+public class PseudoConflictsFilter extends AbstractDifferenceFilter {
+
+ /**
+ * The predicate use by this filter when it is selected.
+ */
+ 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;
+ }
+ }
+ return ret;
+ }
+ };
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#isEnabled(org.eclipse.emf.compare.scope.IComparisonScope,
+ * org.eclipse.emf.compare.Comparison)
+ */
+ @Override
+ public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
+ if (comparison != null && comparison.isThreeWay()) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicateWhenSelected()
+ */
+ @Override
+ public Predicate<? super EObject> getPredicateWhenSelected() {
+ return predicateWhenSelected;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/PseudoDeleteConflictsFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/PseudoDeleteConflictsFilter.java
new file mode 100644
index 000000000..b673de658
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/PseudoDeleteConflictsFilter.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * 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.structuremergeviewer.filters;
+
+import static com.google.common.collect.Iterables.filter;
+
+import com.google.common.base.Predicate;
+
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Conflict;
+import org.eclipse.emf.compare.ReferenceChange;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+
+/**
+ * A filter used by default that filtered out pseudo delete conflicts differences.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+public class PseudoDeleteConflictsFilter extends AbstractDifferenceFilter {
+
+ /**
+ * The predicate use by this filter when it is selected.
+ */
+ private static final Predicate<? super EObject> predicateWhenSelected = new Predicate<EObject>() {
+ public boolean apply(EObject input) {
+ boolean ret = false;
+ if (input instanceof ReferenceChange) {
+ ReferenceChange referenceChange = (ReferenceChange)input;
+ Conflict conflict = referenceChange.getConflict();
+ if (conflict != null) {
+ EReference eReference = referenceChange.getReference();
+ EObject value = referenceChange.getValue();
+ Iterable<ReferenceChange> conflictualReferenceChanges = filter(conflict.getDifferences(),
+ ReferenceChange.class);
+ for (ReferenceChange conflictualReferenceChange : conflictualReferenceChanges) {
+ if (conflictualReferenceChange != referenceChange
+ && conflictualReferenceChange.getReference() == eReference
+ && conflictualReferenceChange.getValue() == value) {
+ ret = true;
+ }
+ }
+ }
+ }
+ return ret;
+ }
+ };
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#isEnabled(org.eclipse.emf.compare.scope.IComparisonScope,
+ * org.eclipse.emf.compare.Comparison)
+ */
+ @Override
+ public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
+ if (comparison != null && comparison.isThreeWay()) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicateWhenSelected()
+ */
+ @Override
+ public Predicate<? super EObject> getPredicateWhenSelected() {
+ return predicateWhenSelected;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/RemovedElementsFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/RemovedElementsFilter.java
deleted file mode 100644
index 2bf51be43..000000000
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/RemovedElementsFilter.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * 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.structuremergeviewer.filters;
-
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
-
-import com.google.common.base.Predicate;
-
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceKind;
-import org.eclipse.emf.compare.scope.IComparisonScope;
-import org.eclipse.emf.ecore.EObject;
-
-/**
- * A filter used by default that filtered out removed elements.
- *
- * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
- * @since 3.0
- */
-public class RemovedElementsFilter implements IDifferenceFilter {
-
- /** A human-readable label for this filter. This will be displayed in the EMF Compare UI. */
- private String label;
-
- /** The initial activation state of the filter. */
- private boolean activeByDefault;
-
- /** The Predicate activate through this action. */
- private Predicate<? super EObject> predicate;
-
- /**
- * Constructs the filter with the appropriate predicate.
- */
- public RemovedElementsFilter() {
- super();
- setPredicate();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getLabel()
- */
- public String getLabel() {
- return label;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#setLabel(java.lang.String)
- */
- public void setLabel(String label) {
- this.label = label;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#defaultSelected()
- */
- public boolean defaultSelected() {
- return activeByDefault;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#setDefaultSelected(boolean)
- */
- public void setDefaultSelected(boolean activeByDefault) {
- this.activeByDefault = activeByDefault;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#isEnabled(org.eclipse.emf.compare.scope.IComparisonScope,
- * org.eclipse.emf.compare.Comparison)
- */
- public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicate()
- */
- public Predicate<? super EObject> getPredicate() {
- return predicate;
- }
-
- /**
- * Set the predicate that will be activate through this filter.
- */
- private void setPredicate() {
- final Predicate<? super EObject> actualPredicate = new Predicate<EObject>() {
- public boolean apply(EObject input) {
- return input instanceof Diff && ofKind(DifferenceKind.DELETE).apply((Diff)input);
- }
- };
- predicate = actualPredicate;
- }
-
-}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/StructureMergeViewerFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/StructureMergeViewerFilter.java
index e9b530f27..e77026141 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/StructureMergeViewerFilter.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/StructureMergeViewerFilter.java
@@ -14,6 +14,7 @@ import static com.google.common.base.Predicates.not;
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;
@@ -80,13 +81,13 @@ public class StructureMergeViewerFilter extends ViewerFilter {
*/
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (predicates.isEmpty()) {
+ if (getPredicates().isEmpty()) {
return true;
}
boolean result = false;
- final Predicate<? super EObject> predicate = Predicates.or(predicates);
+ final Predicate<? super EObject> predicate = Predicates.or(getPredicates());
- if (predicates.isEmpty()) {
+ if (getPredicates().isEmpty()) {
result = true;
} else if (element instanceof Adapter) {
Notifier notifier = ((Adapter)element).getTarget();
@@ -94,8 +95,12 @@ public class StructureMergeViewerFilter extends ViewerFilter {
final Diff diff = (Diff)notifier;
result = !predicate.apply(diff);
} else if (notifier instanceof Match) {
- final Iterator<Diff> differences = ((Match)notifier).getAllDifferences().iterator();
- result = Iterators.any(differences, not(predicate));
+ 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);
@@ -123,7 +128,8 @@ public class StructureMergeViewerFilter extends ViewerFilter {
* The given {@link IDifferenceFilter}.
*/
public void addFilter(IDifferenceFilter filter) {
- addPredicate(filter.getPredicate());
+ getPredicates().remove(filter.getPredicateWhenUnselected());
+ addPredicate(filter.getPredicateWhenSelected());
eventBus.post(new IDifferenceFilterSelectionChangeEvent.DefaultFilterSelectionChangeEvent(filter,
Action.ADD));
}
@@ -135,7 +141,8 @@ public class StructureMergeViewerFilter extends ViewerFilter {
* The given {@link IDifferenceFilter}.
*/
public void removeFilter(IDifferenceFilter filter) {
- removePredicate(filter.getPredicate());
+ getPredicates().add(filter.getPredicateWhenUnselected());
+ removePredicate(filter.getPredicateWhenSelected());
eventBus.post(new IDifferenceFilterSelectionChangeEvent.DefaultFilterSelectionChangeEvent(filter,
Action.REMOVE));
}
@@ -148,7 +155,7 @@ public class StructureMergeViewerFilter extends ViewerFilter {
* accepted.
*/
public void addPredicate(Predicate<? super EObject> predicate) {
- final boolean changed = predicates.add(predicate);
+ final boolean changed = getPredicates().add(predicate);
if (changed) {
refreshViewers();
}
@@ -162,7 +169,7 @@ public class StructureMergeViewerFilter extends ViewerFilter {
* of the accepted ones.
*/
public void removePredicate(Predicate<? super EObject> predicate) {
- final boolean changed = predicates.remove(predicate);
+ final boolean changed = getPredicates().remove(predicate);
if (changed) {
refreshViewers();
}
@@ -211,4 +218,13 @@ public class StructureMergeViewerFilter extends ViewerFilter {
viewers.remove(viewer);
}
+ /**
+ * Get the predicates associated with this viewer.
+ *
+ * @return the predicates
+ */
+ public Set<Predicate<? super EObject>> getPredicates() {
+ return predicates;
+ }
+
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/SubDiffElementsFilter.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/SubDiffElementsFilter.java
new file mode 100644
index 000000000..4dd539903
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/filters/SubDiffElementsFilter.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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.structuremergeviewer.filters;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableSet;
+
+import org.eclipse.emf.compare.Conflict;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.provider.spec.MatchItemProviderSpec;
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * A filter used by default that filtered out sub differences.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+public class SubDiffElementsFilter extends AbstractDifferenceFilter {
+
+ /**
+ * The predicate use by this filter when it is selected.
+ */
+ private static final Predicate<? super EObject> predicateWhenSelected = new Predicate<EObject>() {
+ public boolean apply(EObject input) {
+ boolean ret = false;
+ if (input instanceof Diff) {
+ final Diff diff = (Diff)input;
+ final Conflict conflict = diff.getConflict();
+ if (conflict == null) {
+ final EObject grandParent = diff.getMatch().eContainer();
+ if (grandParent instanceof Match) {
+ ImmutableSet<EObject> containementDifferenceValues = MatchItemProviderSpec
+ .containmentReferencesValues((Match)grandParent);
+ if (MatchItemProviderSpec.matchOfContainmentDiff(containementDifferenceValues).apply(
+ diff.getMatch())) {
+ ret = true;
+ }
+ }
+ }
+ }
+ return ret;
+ }
+ };
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicateWhenSelected()
+ */
+ @Override
+ public Predicate<? super EObject> getPredicateWhenSelected() {
+ return predicateWhenSelected;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/groups/MetamodelGroupProvider.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/groups/MetamodelGroupProvider.java
deleted file mode 100644
index 3c61cc0a7..000000000
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/structuremergeviewer/groups/MetamodelGroupProvider.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*******************************************************************************
- * 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.rcp.ui.structuremergeviewer.groups;
-
-import static com.google.common.base.Predicates.alwaysTrue;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.compare.AttributeChange;
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.ReferenceChange;
-import org.eclipse.emf.compare.scope.IComparisonScope;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-
-/**
- * This implementation of a {@link IDifferenceGroupProvider} will be used to group the differences by their
- * metamodel element : all diffs that apply to a Class, all diffs that apply on a reference...
- *
- * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
- * @since 3.0
- */
-public class MetamodelGroupProvider 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;
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.IDifferenceGroupProvider#getGroups(org.eclipse.emf.compare.Comparison)
- */
- public Iterable<? extends DifferenceGroup> getGroups(Comparison comparison) {
- final List<Diff> diffs = comparison.getDifferences();
-
- final Map<EClass, List<Diff>> diffByEClass = Maps.newLinkedHashMap();
- for (Diff candidate : diffs) {
- final EClass target;
- if (candidate instanceof ReferenceChange) {
- if (((ReferenceChange)candidate).getReference().isContainment()) {
- final EObject parentMatch = candidate.getMatch().eContainer();
- if (parentMatch instanceof Match) {
- target = findEClass((Match)parentMatch);
- } else {
- target = findEClass(candidate.getMatch());
- }
- } else {
- target = findEClass(candidate.getMatch());
- }
- } else if (candidate instanceof AttributeChange) {
- target = findEClass(candidate.getMatch());
- } else {
- // Ignore this possibility for now.
- continue;
- }
-
- List<Diff> diffsForEClass = diffByEClass.get(target);
- if (diffsForEClass == null) {
- diffsForEClass = Lists.newArrayList();
- diffByEClass.put(target, diffsForEClass);
- }
- diffsForEClass.add(candidate);
- }
-
- final List<DifferenceGroup> groups = Lists.newArrayList();
- for (Map.Entry<EClass, List<Diff>> entry : diffByEClass.entrySet()) {
- groups.add(new DefaultDifferenceGroup(comparison, entry.getValue(), alwaysTrue(), entry.getKey()
- .getName()));
- }
-
- return groups;
- }
-
- /**
- * Returns the appropriate {@link EClass} associated with the given {@link Match}.
- *
- * @param match
- * The given {@link Match}.
- * @return the appropriate {@link EClass} associated with the given {@link Match}.
- */
- private EClass findEClass(Match match) {
- final EClass eClass;
- if (match.getOrigin() != null) {
- eClass = match.getOrigin().eClass();
- } else if (match.getRight() != null) {
- eClass = match.getRight().eClass();
- } else {
- /*
- * All three sides null means that something went awry. Might as well throw the exception from
- * here.
- */
- eClass = match.getLeft().eClass();
- }
- return eClass;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.IDifferenceGroupProvider#getLabel()
- */
- public String getLabel() {
- return label;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.IDifferenceGroupProvider#setLabel(java.lang.String)
- */
- public void setLabel(String label) {
- this.label = label;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.IDifferenceGroupProvider#defaultSelected()
- */
- public boolean defaultSelected() {
- return activeByDefault;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.IDifferenceGroupProvider#setDefaultSelected(boolean)
- */
- public void setDefaultSelected(boolean activeByDefault) {
- this.activeByDefault = activeByDefault;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.IDifferenceGroupProvider#isEnabled(org
- * .eclipse.emf.compare.scope.IComparisonScope, org.eclipse.emf.compare.Comparison)
- */
- public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
- return true;
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/AbstractTestCompareItemProviderAdapter.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/AbstractTestCompareItemProviderAdapter.java
index 5addcdf05..fcc6d1eec 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/AbstractTestCompareItemProviderAdapter.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/edit/AbstractTestCompareItemProviderAdapter.java
@@ -1,124 +1,124 @@
-/*******************************************************************************
- * 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.find;
-import static com.google.common.collect.Lists.newArrayList;
-
-import com.google.common.base.Objects;
-import com.google.common.base.Predicate;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.EMFCompare;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.ReferenceChange;
-import org.eclipse.emf.compare.provider.CompareItemProviderAdapterFactory;
-import org.eclipse.emf.compare.provider.spec.CompareItemProviderAdapterFactorySpec;
-import org.eclipse.emf.compare.scope.IComparisonScope;
-import org.eclipse.emf.compare.tests.edit.data.ResourceScopeProvider;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
-import org.junit.Before;
-
-/**
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class AbstractTestCompareItemProviderAdapter {
-
- protected CompareItemProviderAdapterFactory compareItemProviderAdapterFactory;
-
- @Before
- public void before() throws IOException {
- compareItemProviderAdapterFactory = new CompareItemProviderAdapterFactorySpec();
- }
-
- /**
- * @return the comparison
- * @throws IOException
- */
- protected static Comparison getComparison(ResourceScopeProvider scopeProvider) throws IOException {
- IComparisonScope scope = EMFCompare.createDefaultScope(scopeProvider.getLeft(), scopeProvider
- .getRight(), scopeProvider.getOrigin());
- return EMFCompare.builder().build().compare(scope);
- }
-
- protected Match getMatchWithFeatureValue(Collection<?> c, final String featureName, final Object value) {
- Iterable<Match> matches = filter(c, Match.class);
- Predicate<Match> predicate = hasFeatureValue(featureName, value);
- return find(matches, predicate);
- }
-
- protected ReferenceChange getReferenceChangeWithFeatureValue(Collection<?> c, final String featureName,
- final Object value) {
- Iterable<ReferenceChange> matches = filter(c, ReferenceChange.class);
- Predicate<ReferenceChange> predicate = new Predicate<ReferenceChange>() {
- public boolean apply(ReferenceChange referenceChange) {
- EObject referenceChangeValue = referenceChange.getValue();
- if (referenceChangeValue != null) {
- return Objects.equal(eGet(referenceChangeValue, featureName), value);
- }
- return false;
- }
- };
- return find(matches, predicate);
- }
-
- protected Predicate<Match> hasFeatureValue(final String featureName, final Object value) {
- Predicate<Match> predicate = new Predicate<Match>() {
- public boolean apply(Match match) {
- final boolean ret;
- final EObject left = match.getLeft();
- final EObject right = match.getRight();
- final EObject origin = match.getOrigin();
- if (left != null) {
- ret = Objects.equal(value, eGet(left, featureName));
- } else if (right != null) {
- ret = Objects.equal(value, eGet(right, featureName));
- } else if (origin != null) {
- ret = Objects.equal(value, eGet(origin, featureName));
- } else {
- ret = false;
- }
- return ret;
- }
- };
- return predicate;
- }
-
- protected Object eGet(EObject eObject, String featureName) {
- EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(featureName);
- return eObject.eGet(eStructuralFeature);
- }
-
- protected List<Notifier> eAllChildren(Notifier notifier) {
- List<Notifier> ret = newArrayList();
- ITreeItemContentProvider contentProvider = adaptAsITreItemContentProvider(notifier);
- Iterable<Notifier> children = filter(contentProvider.getChildren(notifier), Notifier.class);
- for (Notifier child : children) {
- ret.add(child);
- ret.addAll(eAllChildren(child));
- }
- return ret;
- }
-
- protected ITreeItemContentProvider adaptAsITreItemContentProvider(Notifier notifier) {
- ITreeItemContentProvider contentProvider = (ITreeItemContentProvider)compareItemProviderAdapterFactory
- .adapt(notifier, ITreeItemContentProvider.class);
- return contentProvider;
- }
-}
+/*******************************************************************************
+ * 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.find;
+import static com.google.common.collect.Lists.newArrayList;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Predicate;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.ReferenceChange;
+import org.eclipse.emf.compare.provider.CompareItemProviderAdapterFactory;
+import org.eclipse.emf.compare.provider.spec.CompareItemProviderAdapterFactorySpec;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.compare.tests.edit.data.ResourceScopeProvider;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
+import org.junit.Before;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class AbstractTestCompareItemProviderAdapter {
+
+ protected CompareItemProviderAdapterFactory compareItemProviderAdapterFactory;
+
+ @Before
+ public void before() throws IOException {
+ compareItemProviderAdapterFactory = new CompareItemProviderAdapterFactorySpec();
+ }
+
+ /**
+ * @return the comparison
+ * @throws IOException
+ */
+ protected static Comparison getComparison(ResourceScopeProvider scopeProvider) throws IOException {
+ IComparisonScope scope = EMFCompare.createDefaultScope(scopeProvider.getLeft(), scopeProvider
+ .getRight(), scopeProvider.getOrigin());
+ return EMFCompare.builder().build().compare(scope);
+ }
+
+ protected Match getMatchWithFeatureValue(Collection<?> c, final String featureName, final Object value) {
+ Iterable<Match> matches = filter(c, Match.class);
+ Predicate<Match> predicate = hasFeatureValue(featureName, value);
+ return find(matches, predicate);
+ }
+
+ protected ReferenceChange getReferenceChangeWithFeatureValue(Collection<?> c, final String featureName,
+ final Object value) {
+ Iterable<ReferenceChange> matches = filter(c, ReferenceChange.class);
+ Predicate<ReferenceChange> predicate = new Predicate<ReferenceChange>() {
+ public boolean apply(ReferenceChange referenceChange) {
+ EObject referenceChangeValue = referenceChange.getValue();
+ if (referenceChangeValue != null) {
+ return Objects.equal(eGet(referenceChangeValue, featureName), value);
+ }
+ return false;
+ }
+ };
+ return find(matches, predicate);
+ }
+
+ protected Predicate<Match> hasFeatureValue(final String featureName, final Object value) {
+ Predicate<Match> predicate = new Predicate<Match>() {
+ public boolean apply(Match match) {
+ final boolean ret;
+ final EObject left = match.getLeft();
+ final EObject right = match.getRight();
+ final EObject origin = match.getOrigin();
+ if (left != null) {
+ ret = Objects.equal(value, eGet(left, featureName));
+ } else if (right != null) {
+ ret = Objects.equal(value, eGet(right, featureName));
+ } else if (origin != null) {
+ ret = Objects.equal(value, eGet(origin, featureName));
+ } else {
+ ret = false;
+ }
+ return ret;
+ }
+ };
+ return predicate;
+ }
+
+ protected Object eGet(EObject eObject, String featureName) {
+ EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(featureName);
+ return eObject.eGet(eStructuralFeature);
+ }
+
+ protected List<Notifier> eAllChildren(Notifier notifier) {
+ List<Notifier> ret = newArrayList();
+ ITreeItemContentProvider contentProvider = adaptAsITreItemContentProvider(notifier);
+ Iterable<Notifier> children = filter(contentProvider.getChildren(notifier), Notifier.class);
+ for (Notifier child : children) {
+ ret.add(child);
+ ret.addAll(eAllChildren(child));
+ }
+ return ret;
+ }
+
+ protected ITreeItemContentProvider adaptAsITreItemContentProvider(Notifier notifier) {
+ ITreeItemContentProvider contentProvider = (ITreeItemContentProvider)compareItemProviderAdapterFactory
+ .adapt(notifier, ITreeItemContentProvider.class);
+ return contentProvider;
+ }
+}
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 3f9507a72..d351bcf21 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
@@ -1,145 +1,145 @@
-/*******************************************************************************
- * 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 java.util.List;
-
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.provider.MatchItemProvider;
-import org.eclipse.emf.compare.provider.spec.MatchItemProviderSpec;
-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 TestMatchItemProviderSpec extends AbstractTestCompareItemProviderAdapter {
-
- private MatchItemProvider itemProvider;
-
- @Override
- @Before
- public void before() throws IOException {
- super.before();
- itemProvider = (MatchItemProviderSpec)compareItemProviderAdapterFactory.createMatchAdapter();
- }
-
- @Test
- public void testGetChildren_EcoreA1() throws IOException {
- Match ePackageMatch = getEcoreA1_EPackageMatch();
-
- Collection<?> ePackageMatchChildren = itemProvider.getChildren(ePackageMatch);
- assertEquals(9, ePackageMatchChildren.size());
- assertEquals(4, size(filter(ePackageMatchChildren, Diff.class)));
- assertEquals(5, size(filter(ePackageMatchChildren, Match.class)));
- }
-
- static Match getEcoreA1_EPackageMatch() throws IOException {
- Comparison comparison = getComparison(new EcoreA1InputData());
-
- List<Match> matches = comparison.getMatches();
- Match ePackageMatch = matches.get(0);
- return ePackageMatch;
- }
-
- @Test
- public void testGetChildren_AudioVisualItem() throws IOException {
- Match ePackageMatch = getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
- Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
- "AudioVisualItem");
- Collection<?> audioVisualItem_MatchChildren = itemProvider.getChildren(audioVisualItem_Match);
-
- assertEquals(3, audioVisualItem_MatchChildren.size());
- assertEquals(2, size(filter(audioVisualItem_MatchChildren, Diff.class)));
- assertEquals(1, size(filter(audioVisualItem_MatchChildren, Match.class)));
- }
-
- @Test
- public void testGetChildren_AudioVisualItem_lenght() throws IOException {
- Match ePackageMatch = getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
- Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
- "AudioVisualItem");
- Collection<?> audioVisualItem_MatchChildren = itemProvider.getChildren(audioVisualItem_Match);
- Match audioVisualItem_legnth_Match = getMatchWithFeatureValue(audioVisualItem_MatchChildren, "name",
- "length");
- Collection<?> audioVisualItem_legnth_MatchChildren = itemProvider
- .getChildren(audioVisualItem_legnth_Match);
-
- assertEquals(2, audioVisualItem_legnth_MatchChildren.size());
- assertEquals(2, size(filter(audioVisualItem_legnth_MatchChildren, Diff.class)));
- assertEquals(0, size(filter(audioVisualItem_legnth_MatchChildren, Match.class)));
- }
-
- @Test
- public void testGetChildren_Book() throws IOException {
- Match ePackageMatch = getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
- Match book_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Book");
- Collection<?> book_MatchChildren = itemProvider.getChildren(book_Match);
-
- assertEquals(3, book_MatchChildren.size());
- assertEquals(3, size(filter(book_MatchChildren, Diff.class)));
- assertEquals(0, size(filter(book_MatchChildren, Match.class)));
- }
-
- @Test
- public void testGetChildren_BookCategory() throws IOException {
- Match ePackageMatch = getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
- Match bookCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "BookCategory");
- Collection<?> bookCategory_MatchChildren = itemProvider.getChildren(bookCategory_Match);
-
- assertEquals(4, bookCategory_MatchChildren.size());
- assertEquals(4, size(filter(bookCategory_MatchChildren, Diff.class)));
- assertEquals(0, size(filter(bookCategory_MatchChildren, Match.class)));
- }
-
- @Test
- public void testGetChildren_Borrowable() throws IOException {
- Match ePackageMatch = getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
- Match borrowable_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Borrowable");
- Collection<?> borrowable_MatchChildren = itemProvider.getChildren(borrowable_Match);
-
- assertEquals(1, borrowable_MatchChildren.size());
- assertEquals(1, size(filter(borrowable_MatchChildren, Diff.class)));
- assertEquals(0, size(filter(borrowable_MatchChildren, Match.class)));
- }
-
- @Test
- public void testGetChildren_Person() throws IOException {
- Match ePackageMatch = getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
- Match person_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Person");
- Collection<?> person_MatchChildren = itemProvider.getChildren(person_Match);
-
- assertEquals(3, person_MatchChildren.size());
- assertEquals(3, size(filter(person_MatchChildren, Diff.class)));
- assertEquals(0, size(filter(person_MatchChildren, Match.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 java.util.List;
+
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.provider.MatchItemProvider;
+import org.eclipse.emf.compare.provider.spec.MatchItemProviderSpec;
+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 TestMatchItemProviderSpec extends AbstractTestCompareItemProviderAdapter {
+
+ private MatchItemProvider itemProvider;
+
+ @Override
+ @Before
+ public void before() throws IOException {
+ super.before();
+ itemProvider = (MatchItemProviderSpec)compareItemProviderAdapterFactory.createMatchAdapter();
+ }
+
+ @Test
+ public void testGetChildren_EcoreA1() throws IOException {
+ Match ePackageMatch = getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackageMatchChildren = itemProvider.getChildren(ePackageMatch);
+ assertEquals(18, ePackageMatchChildren.size());
+ assertEquals(4, size(filter(ePackageMatchChildren, Diff.class)));
+ assertEquals(14, size(filter(ePackageMatchChildren, Match.class)));
+ }
+
+ static Match getEcoreA1_EPackageMatch() throws IOException {
+ Comparison comparison = getComparison(new EcoreA1InputData());
+
+ List<Match> matches = comparison.getMatches();
+ Match ePackageMatch = matches.get(0);
+ return ePackageMatch;
+ }
+
+ @Test
+ public void testGetChildren_AudioVisualItem() throws IOException {
+ Match ePackageMatch = getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
+ Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
+ "AudioVisualItem");
+ Collection<?> audioVisualItem_MatchChildren = itemProvider.getChildren(audioVisualItem_Match);
+
+ assertEquals(4, audioVisualItem_MatchChildren.size());
+ assertEquals(2, size(filter(audioVisualItem_MatchChildren, Diff.class)));
+ assertEquals(2, size(filter(audioVisualItem_MatchChildren, Match.class)));
+ }
+
+ @Test
+ public void testGetChildren_AudioVisualItem_lenght() throws IOException {
+ Match ePackageMatch = getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
+ Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
+ "AudioVisualItem");
+ Collection<?> audioVisualItem_MatchChildren = itemProvider.getChildren(audioVisualItem_Match);
+ Match audioVisualItem_legnth_Match = getMatchWithFeatureValue(audioVisualItem_MatchChildren, "name",
+ "length");
+ Collection<?> audioVisualItem_legnth_MatchChildren = itemProvider
+ .getChildren(audioVisualItem_legnth_Match);
+
+ assertEquals(2, audioVisualItem_legnth_MatchChildren.size());
+ assertEquals(2, size(filter(audioVisualItem_legnth_MatchChildren, Diff.class)));
+ assertEquals(0, size(filter(audioVisualItem_legnth_MatchChildren, Match.class)));
+ }
+
+ @Test
+ public void testGetChildren_Book() throws IOException {
+ Match ePackageMatch = getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
+ Match book_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Book");
+ Collection<?> book_MatchChildren = itemProvider.getChildren(book_Match);
+
+ assertEquals(6, book_MatchChildren.size());
+ assertEquals(3, size(filter(book_MatchChildren, Diff.class)));
+ assertEquals(3, size(filter(book_MatchChildren, Match.class)));
+ }
+
+ @Test
+ public void testGetChildren_BookCategory() throws IOException {
+ Match ePackageMatch = getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
+ Match bookCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "BookCategory");
+ Collection<?> bookCategory_MatchChildren = itemProvider.getChildren(bookCategory_Match);
+
+ assertEquals(7, bookCategory_MatchChildren.size());
+ assertEquals(4, size(filter(bookCategory_MatchChildren, Diff.class)));
+ assertEquals(3, size(filter(bookCategory_MatchChildren, Match.class)));
+ }
+
+ @Test
+ public void testGetChildren_Borrowable() throws IOException {
+ Match ePackageMatch = getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
+ Match borrowable_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Borrowable");
+ Collection<?> borrowable_MatchChildren = itemProvider.getChildren(borrowable_Match);
+
+ assertEquals(3, borrowable_MatchChildren.size());
+ assertEquals(1, size(filter(borrowable_MatchChildren, Diff.class)));
+ assertEquals(2, size(filter(borrowable_MatchChildren, Match.class)));
+ }
+
+ @Test
+ public void testGetChildren_Person() throws IOException {
+ Match ePackageMatch = getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = itemProvider.getChildren(ePackageMatch);
+ Match person_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Person");
+ Collection<?> person_MatchChildren = itemProvider.getChildren(person_Match);
+
+ assertEquals(3, person_MatchChildren.size());
+ assertEquals(3, size(filter(person_MatchChildren, Diff.class)));
+ assertEquals(0, 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 0cda3ecfe..d219ef857 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
@@ -1,295 +1,295 @@
-/*******************************************************************************
- * 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.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;
-
-/**
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class TestReferenceChangeItemProviderSpec extends AbstractTestCompareItemProviderAdapter {
-
- @Test
- public void testGetChildren_AudioVisualItem() throws IOException {
- Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
- ePackageMatch);
- Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
- "AudioVisualItem");
- Collection<?> audioVisualItem_MatchChildren = adaptAsITreItemContentProvider(audioVisualItem_Match)
- .getChildren(audioVisualItem_Match);
-
- ReferenceChange titleReferenceChange = getReferenceChangeWithFeatureValue(
- audioVisualItem_MatchChildren, "name", "title");
-
- Collection<?> titleReferenceChange_Children = adaptAsITreItemContentProvider(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 = adaptAsITreItemContentProvider(
- titledItemReferenceChange).getChildren(titledItemReferenceChange);
- assertEquals(0, titledItemReferenceChange_Children.size());
- }
-
- @Test
- public void testGetChildren_Book() throws IOException {
- Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
- ePackageMatch);
- Match book_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Book");
- Collection<?> book_MatchChildren = adaptAsITreItemContentProvider(book_Match).getChildren(book_Match);
-
- ReferenceChange subtitleReferenceChange = getReferenceChangeWithFeatureValue(book_MatchChildren,
- "name", "subtitle");
-
- Collection<?> subtitleReferenceChange_Children = adaptAsITreItemContentProvider(
- 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(adaptAsITreItemContentProvider(child).getChildren(child).isEmpty());
-
- ReferenceChange titleReferenceChange = getReferenceChangeWithFeatureValue(book_MatchChildren, "name",
- "title");
- Collection<?> titleReferenceChange_Children = adaptAsITreItemContentProvider(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(adaptAsITreItemContentProvider(child).getChildren(child).isEmpty());
-
- ReferenceChange titledItemReferenceChange = getReferenceChangeWithFeatureValue(book_MatchChildren,
- "name", "TitledItem");
- Collection<?> titledItemReferenceChange_Children = adaptAsITreItemContentProvider(
- titledItemReferenceChange).getChildren(titledItemReferenceChange);
- assertEquals(0, titledItemReferenceChange_Children.size());
- }
-
- @Test
- public void testGetChildren_Borrowable() throws IOException {
- Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
- ePackageMatch);
- Match borrowableCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
- "Borrowable");
- Collection<?> borrowable_MatchChildren = adaptAsITreItemContentProvider(borrowableCategory_Match)
- .getChildren(borrowableCategory_Match);
-
- assertEquals(1, borrowable_MatchChildren.size());
- }
-
- @Test
- public void testGetChildren_BookCategory() throws IOException {
- Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
- ePackageMatch);
- Match bookCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "BookCategory");
- Collection<?> bookCategory_MatchChildren = adaptAsITreItemContentProvider(bookCategory_Match)
- .getChildren(bookCategory_Match);
-
- ReferenceChange dictionaryReferenceChange = getReferenceChangeWithFeatureValue(
- bookCategory_MatchChildren, "name", "Dictionary");
- ReferenceChange encyclopediaReferenceChange = getReferenceChangeWithFeatureValue(
- bookCategory_MatchChildren, "name", "Encyclopedia");
- ReferenceChange mangaReferenceChange = getReferenceChangeWithFeatureValue(bookCategory_MatchChildren,
- "name", "Manga");
- ReferenceChange manhwaReferenceChange = getReferenceChangeWithFeatureValue(
- bookCategory_MatchChildren, "name", "Manhwa");
-
- assertTrue(adaptAsITreItemContentProvider(dictionaryReferenceChange).getChildren(
- dictionaryReferenceChange).isEmpty());
- assertTrue(adaptAsITreItemContentProvider(encyclopediaReferenceChange).getChildren(
- encyclopediaReferenceChange).isEmpty());
- assertTrue(adaptAsITreItemContentProvider(mangaReferenceChange).getChildren(mangaReferenceChange)
- .isEmpty());
- assertTrue(adaptAsITreItemContentProvider(manhwaReferenceChange).getChildren(manhwaReferenceChange)
- .isEmpty());
- }
-
- @Test
- public void testGetChildren_Magazine1() throws IOException {
- Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
- ePackageMatch);
-
- 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())) {
- magazineChildren = adaptAsITreItemContentProvider(referenceChange).getChildren(
- referenceChange);
- assertEquals(3, magazineChildren.size());
- break;
- }
- }
- ReferenceChange magazineSuperTypeChange = getReferenceChangeWithFeatureValue(magazineChildren,
- "name", "CirculatingItem");
- assertTrue(adaptAsITreItemContentProvider(magazineSuperTypeChange).getChildren(
- magazineSuperTypeChange).isEmpty());
-
- ReferenceChange magazineSFChange1 = getReferenceChangeWithFeatureValue(magazineChildren, "name",
- "pages");
- assertEquals(1, adaptAsITreItemContentProvider(magazineSFChange1).getChildren(magazineSFChange1)
- .size());
-
- ReferenceChange magazineSFChange2 = getReferenceChangeWithFeatureValue(magazineChildren, "name",
- "title");
- assertEquals(1, adaptAsITreItemContentProvider(magazineSFChange2).getChildren(magazineSFChange2)
- .size());
- }
-
- @Test
- public void testGetChildren_Magazine2() throws IOException {
- Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
- ePackageMatch);
-
- 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())) {
- magazineChildren = adaptAsITreItemContentProvider(referenceChange).getChildren(
- referenceChange);
- assertEquals(1, magazineChildren.size());
- break;
- }
- }
- ReferenceChange magazineSuperTypeChange = getReferenceChangeWithFeatureValue(magazineChildren,
- "name", "Periodical");
- assertTrue(adaptAsITreItemContentProvider(magazineSuperTypeChange).getChildren(
- magazineSuperTypeChange).isEmpty());
- }
-
- @Test
- public void testGetChildren_Periodical() throws IOException {
- Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
- ePackageMatch);
- ReferenceChange periodical_ReferenceChange = getReferenceChangeWithFeatureValue(
- ePackage_MatchChildren, "name", "Periodical");
- Collection<?> periodical_ReferenceChangeChildren = adaptAsITreItemContentProvider(
- periodical_ReferenceChange).getChildren(periodical_ReferenceChange);
-
- assertEquals(3, 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 = adaptAsITreItemContentProvider(issuesPerYearChange)
- .getChildren(issuesPerYearChange);
- assertEquals(1, issuesPerYearChildren.size());
- ReferenceChange issuePerYearChild = (ReferenceChange)issuesPerYearChildren.iterator().next();
- assertEquals(EcorePackage.Literals.ETYPED_ELEMENT__ETYPE, issuePerYearChild.getReference());
-
- assertTrue(adaptAsITreItemContentProvider(itemChange).getChildren(itemChange).isEmpty());
- assertTrue(adaptAsITreItemContentProvider(titledItemChange).getChildren(titledItemChange).isEmpty());
- }
-
- @Test
- public void testGetChildren_Person() throws IOException {
- Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
- ePackageMatch);
- Match person_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Person");
- Collection<?> person_MatchChildren = adaptAsITreItemContentProvider(person_Match).getChildren(
- person_Match);
-
- assertEquals(3, person_MatchChildren.size());
-
- ReferenceChange issuesPerYearChange = getReferenceChangeWithFeatureValue(person_MatchChildren,
- "name", "firstName");
- Collection<?> firstNameChildren = adaptAsITreItemContentProvider(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 = adaptAsITreItemContentProvider(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 = adaptAsITreItemContentProvider(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());
- }
-
- @Test
- public void testGetChildren_TitledItem() throws IOException {
- Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
-
- Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
- ePackageMatch);
-
- ReferenceChange titledItem_ReferenceChange = getReferenceChangeWithFeatureValue(
- ePackage_MatchChildren, "name", "TitledItem");
- Collection<?> titledItem_ReferenceChangeChildren = adaptAsITreItemContentProvider(
- titledItem_ReferenceChange).getChildren(titledItem_ReferenceChange);
- assertEquals(1, titledItem_ReferenceChangeChildren.size());
-
- ReferenceChange title_Change = (ReferenceChange)titledItem_ReferenceChangeChildren.iterator().next();
- Collection<?> title_ChangeChildren = adaptAsITreItemContentProvider(title_Change).getChildren(
- title_Change);
- assertEquals(1, title_ChangeChildren.size());
-
- ReferenceChange eType_Change = (ReferenceChange)title_ChangeChildren.iterator().next();
- assertTrue(adaptAsITreItemContentProvider(eType_Change).getChildren(eType_Change).isEmpty());
- }
-}
+/*******************************************************************************
+ * 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.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;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class TestReferenceChangeItemProviderSpec extends AbstractTestCompareItemProviderAdapter {
+
+ @Test
+ public void testGetChildren_AudioVisualItem() throws IOException {
+ Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
+ ePackageMatch);
+ Match audioVisualItem_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
+ "AudioVisualItem");
+ Collection<?> audioVisualItem_MatchChildren = adaptAsITreItemContentProvider(audioVisualItem_Match)
+ .getChildren(audioVisualItem_Match);
+
+ ReferenceChange titleReferenceChange = getReferenceChangeWithFeatureValue(
+ audioVisualItem_MatchChildren, "name", "title");
+
+ Collection<?> titleReferenceChange_Children = adaptAsITreItemContentProvider(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 = adaptAsITreItemContentProvider(
+ titledItemReferenceChange).getChildren(titledItemReferenceChange);
+ assertEquals(0, titledItemReferenceChange_Children.size());
+ }
+
+ @Test
+ public void testGetChildren_Book() throws IOException {
+ Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
+ ePackageMatch);
+ Match book_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Book");
+ Collection<?> book_MatchChildren = adaptAsITreItemContentProvider(book_Match).getChildren(book_Match);
+
+ ReferenceChange subtitleReferenceChange = getReferenceChangeWithFeatureValue(book_MatchChildren,
+ "name", "subtitle");
+
+ Collection<?> subtitleReferenceChange_Children = adaptAsITreItemContentProvider(
+ 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(adaptAsITreItemContentProvider(child).getChildren(child).isEmpty());
+
+ ReferenceChange titleReferenceChange = getReferenceChangeWithFeatureValue(book_MatchChildren, "name",
+ "title");
+ Collection<?> titleReferenceChange_Children = adaptAsITreItemContentProvider(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(adaptAsITreItemContentProvider(child).getChildren(child).isEmpty());
+
+ ReferenceChange titledItemReferenceChange = getReferenceChangeWithFeatureValue(book_MatchChildren,
+ "name", "TitledItem");
+ Collection<?> titledItemReferenceChange_Children = adaptAsITreItemContentProvider(
+ titledItemReferenceChange).getChildren(titledItemReferenceChange);
+ assertEquals(0, titledItemReferenceChange_Children.size());
+ }
+
+ @Test
+ public void testGetChildren_Borrowable() throws IOException {
+ Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
+ ePackageMatch);
+ Match borrowableCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name",
+ "Borrowable");
+ Collection<?> borrowable_MatchChildren = adaptAsITreItemContentProvider(borrowableCategory_Match)
+ .getChildren(borrowableCategory_Match);
+
+ assertEquals(3, borrowable_MatchChildren.size());
+ }
+
+ @Test
+ public void testGetChildren_BookCategory() throws IOException {
+ Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
+ ePackageMatch);
+ Match bookCategory_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "BookCategory");
+ Collection<?> bookCategory_MatchChildren = adaptAsITreItemContentProvider(bookCategory_Match)
+ .getChildren(bookCategory_Match);
+
+ ReferenceChange dictionaryReferenceChange = getReferenceChangeWithFeatureValue(
+ bookCategory_MatchChildren, "name", "Dictionary");
+ ReferenceChange encyclopediaReferenceChange = getReferenceChangeWithFeatureValue(
+ bookCategory_MatchChildren, "name", "Encyclopedia");
+ ReferenceChange mangaReferenceChange = getReferenceChangeWithFeatureValue(bookCategory_MatchChildren,
+ "name", "Manga");
+ ReferenceChange manhwaReferenceChange = getReferenceChangeWithFeatureValue(
+ bookCategory_MatchChildren, "name", "Manhwa");
+
+ assertTrue(adaptAsITreItemContentProvider(dictionaryReferenceChange).getChildren(
+ dictionaryReferenceChange).isEmpty());
+ assertTrue(adaptAsITreItemContentProvider(encyclopediaReferenceChange).getChildren(
+ encyclopediaReferenceChange).isEmpty());
+ assertTrue(adaptAsITreItemContentProvider(mangaReferenceChange).getChildren(mangaReferenceChange)
+ .isEmpty());
+ assertTrue(adaptAsITreItemContentProvider(manhwaReferenceChange).getChildren(manhwaReferenceChange)
+ .isEmpty());
+ }
+
+ @Test
+ public void testGetChildren_Magazine1() throws IOException {
+ Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
+ ePackageMatch);
+
+ 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())) {
+ magazineChildren = adaptAsITreItemContentProvider(referenceChange).getChildren(
+ referenceChange);
+ assertEquals(3, magazineChildren.size());
+ break;
+ }
+ }
+ ReferenceChange magazineSuperTypeChange = getReferenceChangeWithFeatureValue(magazineChildren,
+ "name", "CirculatingItem");
+ assertTrue(adaptAsITreItemContentProvider(magazineSuperTypeChange).getChildren(
+ magazineSuperTypeChange).isEmpty());
+
+ ReferenceChange magazineSFChange1 = getReferenceChangeWithFeatureValue(magazineChildren, "name",
+ "pages");
+ assertEquals(1, adaptAsITreItemContentProvider(magazineSFChange1).getChildren(magazineSFChange1)
+ .size());
+
+ ReferenceChange magazineSFChange2 = getReferenceChangeWithFeatureValue(magazineChildren, "name",
+ "title");
+ assertEquals(1, adaptAsITreItemContentProvider(magazineSFChange2).getChildren(magazineSFChange2)
+ .size());
+ }
+
+ @Test
+ public void testGetChildren_Magazine2() throws IOException {
+ Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
+ ePackageMatch);
+
+ 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())) {
+ magazineChildren = adaptAsITreItemContentProvider(referenceChange).getChildren(
+ referenceChange);
+ assertEquals(1, magazineChildren.size());
+ break;
+ }
+ }
+ ReferenceChange magazineSuperTypeChange = getReferenceChangeWithFeatureValue(magazineChildren,
+ "name", "Periodical");
+ assertTrue(adaptAsITreItemContentProvider(magazineSuperTypeChange).getChildren(
+ magazineSuperTypeChange).isEmpty());
+ }
+
+ @Test
+ public void testGetChildren_Periodical() throws IOException {
+ Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
+ ePackageMatch);
+ ReferenceChange periodical_ReferenceChange = getReferenceChangeWithFeatureValue(
+ ePackage_MatchChildren, "name", "Periodical");
+ Collection<?> periodical_ReferenceChangeChildren = adaptAsITreItemContentProvider(
+ 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 = adaptAsITreItemContentProvider(issuesPerYearChange)
+ .getChildren(issuesPerYearChange);
+ assertEquals(1, issuesPerYearChildren.size());
+ ReferenceChange issuePerYearChild = (ReferenceChange)issuesPerYearChildren.iterator().next();
+ assertEquals(EcorePackage.Literals.ETYPED_ELEMENT__ETYPE, issuePerYearChild.getReference());
+
+ assertTrue(adaptAsITreItemContentProvider(itemChange).getChildren(itemChange).isEmpty());
+ assertTrue(adaptAsITreItemContentProvider(titledItemChange).getChildren(titledItemChange).isEmpty());
+ }
+
+ @Test
+ public void testGetChildren_Person() throws IOException {
+ Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
+ ePackageMatch);
+ Match person_Match = getMatchWithFeatureValue(ePackage_MatchChildren, "name", "Person");
+ Collection<?> person_MatchChildren = adaptAsITreItemContentProvider(person_Match).getChildren(
+ person_Match);
+
+ assertEquals(3, person_MatchChildren.size());
+
+ ReferenceChange issuesPerYearChange = getReferenceChangeWithFeatureValue(person_MatchChildren,
+ "name", "firstName");
+ Collection<?> firstNameChildren = adaptAsITreItemContentProvider(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 = adaptAsITreItemContentProvider(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 = adaptAsITreItemContentProvider(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());
+ }
+
+ @Test
+ public void testGetChildren_TitledItem() throws IOException {
+ Match ePackageMatch = TestMatchItemProviderSpec.getEcoreA1_EPackageMatch();
+
+ Collection<?> ePackage_MatchChildren = adaptAsITreItemContentProvider(ePackageMatch).getChildren(
+ ePackageMatch);
+
+ ReferenceChange titledItem_ReferenceChange = getReferenceChangeWithFeatureValue(
+ ePackage_MatchChildren, "name", "TitledItem");
+ Collection<?> titledItem_ReferenceChangeChildren = adaptAsITreItemContentProvider(
+ titledItem_ReferenceChange).getChildren(titledItem_ReferenceChange);
+ assertEquals(1, titledItem_ReferenceChangeChildren.size());
+
+ ReferenceChange title_Change = (ReferenceChange)titledItem_ReferenceChangeChildren.iterator().next();
+ Collection<?> title_ChangeChildren = adaptAsITreItemContentProvider(title_Change).getChildren(
+ title_Change);
+ assertEquals(1, title_ChangeChildren.size());
+
+ ReferenceChange eType_Change = (ReferenceChange)title_ChangeChildren.iterator().next();
+ assertTrue(adaptAsITreItemContentProvider(eType_Change).getChildren(eType_Change).isEmpty());
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.uml2.ide.ui/plugin.xml b/plugins/org.eclipse.emf.compare.uml2.ide.ui/plugin.xml
index 344b27f8c..af129b3ed 100644
--- a/plugins/org.eclipse.emf.compare.uml2.ide.ui/plugin.xml
+++ b/plugins/org.eclipse.emf.compare.uml2.ide.ui/plugin.xml
@@ -16,4 +16,12 @@
ranking="21">
</factory>
</extension>
+ <extension
+ point="org.eclipse.emf.compare.rcp.ui.filters">
+ <filter
+ activeByDefault="true"
+ class="org.eclipse.emf.compare.uml2.ide.ui.structuremergeviewer.filters.UMLRefinedElementsFilter"
+ label="UML refined elements">
+ </filter>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.emf.compare.uml2.ide.ui/src/org/eclipse/emf/compare/uml2/ide/ui/structuremergeviewer/filters/UMLRefinedElementsFilter.java b/plugins/org.eclipse.emf.compare.uml2.ide.ui/src/org/eclipse/emf/compare/uml2/ide/ui/structuremergeviewer/filters/UMLRefinedElementsFilter.java
new file mode 100644
index 000000000..108240cce
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.uml2.ide.ui/src/org/eclipse/emf/compare/uml2/ide/ui/structuremergeviewer/filters/UMLRefinedElementsFilter.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * 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.uml2.ide.ui.structuremergeviewer.filters;
+
+import static com.google.common.base.Predicates.instanceOf;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.AbstractDifferenceFilter;
+import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.compare.uml2.UMLDiff;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+
+/**
+ * A filter used by default that to filtered out refined UML differences.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+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>() {
+ public boolean apply(EObject input) {
+ if (input instanceof Diff) {
+ Diff diff = (Diff)input;
+ return Iterables.any(diff.getRefines(), instanceOf(UMLDiff.class));
+ }
+ return false;
+ }
+ };
+
+ /**
+ * The predicate use by this filter when it is unselected.
+ */
+ private static final Predicate<? super EObject> predicateWhenUnselected = 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$
+ }
+ return false;
+ }
+ };
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#isEnabled(org.eclipse.emf.compare.scope.IComparisonScope,
+ * org.eclipse.emf.compare.Comparison)
+ */
+ @Override
+ public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
+ if (scope != null) {
+ for (String nsURI : scope.getNsURIs()) {
+ if (nsURI.matches("http://www\\.eclipse\\.org/uml2/.*/UML")) { //$NON-NLS-1$
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicateWhenSelected()
+ */
+ @Override
+ public Predicate<? super EObject> getPredicateWhenSelected() {
+ return predicateWhenSelected;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicateWhenUnselected()
+ */
+ @Override
+ public Predicate<? super EObject> getPredicateWhenUnselected() {
+ return predicateWhenUnselected;
+ }
+}

Back to the top