Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikaël Barbero2013-10-02 08:43:19 -0400
committerGerrit Code Review @ Eclipse.org2013-10-03 08:04:48 -0400
commitdf454c2a36084c805510b5f7ae3ed1694ab62b10 (patch)
tree25f8c5b0da57a171a4956926cbbc65c99f4ca2f1 /plugins/org.eclipse.emf.compare.ide.ui/src
parente7d42794195d6c67101a026d624a32616df554ed (diff)
downloadorg.eclipse.emf.compare-df454c2a36084c805510b5f7ae3ed1694ab62b10.tar.gz
org.eclipse.emf.compare-df454c2a36084c805510b5f7ae3ed1694ab62b10.tar.xz
org.eclipse.emf.compare-df454c2a36084c805510b5f7ae3ed1694ab62b10.zip
Factorized out filtering code.
It is now the exact same code that is used in SMV and CMV. The only difference in CMV is that it also display prime refining differences. Change-Id: If66fbb319aadf5037fd18ef35ac90d6c14b3d2d2
Diffstat (limited to 'plugins/org.eclipse.emf.compare.ide.ui/src')
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/table/TableContentMergeViewer.java21
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/TreeContentMergeViewer.java19
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java27
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java24
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java1
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/util/EMFCompareUIActionUtil.java2
6 files changed, 37 insertions, 57 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/table/TableContentMergeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/table/TableContentMergeViewer.java
index 72789cedd..b405aa2c0 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/table/TableContentMergeViewer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/table/TableContentMergeViewer.java
@@ -20,14 +20,12 @@ import java.util.ResourceBundle;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer;
-import org.eclipse.emf.compare.internal.utils.DiffUtil;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
import org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.ICompareAccessor;
import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.IMergeViewer.MergeViewerSide;
import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.impl.AbstractMergeViewer;
import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.impl.TableMergeViewer;
import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.item.IMergeViewerItem;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
import org.eclipse.emf.compare.rcp.ui.internal.util.MergeViewerUtil;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
@@ -35,7 +33,6 @@ import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IItemFontProvider;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
-import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
@@ -280,23 +277,13 @@ public class TableContentMergeViewer extends EMFCompareContentMergeViewer {
final Diff leftDiff = ((IMergeViewerItem)leftItem.getData()).getDiff();
boolean doPaint = true;
if (leftDiff != null) {
- for (IDifferenceFilter filter : getEMFCompareConfiguration().getSelectedFilters()) {
- TreeNode treeNode = MergeViewerUtil.getTreeNode(getEMFCompareConfiguration()
- .getComparison(), getEMFCompareConfiguration().getSelectedGroup(), leftDiff);
- if (filter.getPredicateWhenSelected().apply(treeNode)
- && !DiffUtil.isPrimeRefining(treeNode.getData())) {
- doPaint = false;
- break;
- }
- }
- }
- if (doPaint) {
- if (leftDiff != null) {
+ if (MergeViewerUtil.isVisibleInMergeViewer(leftDiff, getEMFCompareConfiguration()
+ .getSelectedGroup(), getEMFCompareConfiguration().getAggregatedPredicate())) {
TableItem rightItem = findRightTableItemFromLeftDiff(rightItems, leftDiff, leftData);
if (rightItem != null) {
- Color strokeColor = getCompareColor().getStrokeColor(leftDiff, isThreeWay(), false,
- selected);
+ final Color strokeColor = getCompareColor().getStrokeColor(leftDiff, isThreeWay(),
+ false, selected);
g.setForeground(strokeColor);
drawCenterLine(g, leftClientArea, rightClientArea, leftItem, rightItem);
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/TreeContentMergeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/TreeContentMergeViewer.java
index 7781e36f8..8af40406b 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/TreeContentMergeViewer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/TreeContentMergeViewer.java
@@ -27,7 +27,6 @@ import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ReferenceChange;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.EMFCompareContentMergeViewer;
-import org.eclipse.emf.compare.internal.utils.DiffUtil;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
import org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.ICompareAccessor;
import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.IMergeViewer.MergeViewerSide;
@@ -35,7 +34,6 @@ import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.impl.AbstractMergeVie
import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.impl.TreeMergeViewer;
import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.item.IMergeViewerItem;
import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.item.impl.MergeViewerItem;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
import org.eclipse.emf.compare.rcp.ui.internal.util.MergeViewerUtil;
import org.eclipse.emf.compare.utils.EMFComparePredicates;
import org.eclipse.emf.ecore.EObject;
@@ -44,7 +42,6 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
-import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.action.ActionContributionItem;
@@ -112,6 +109,7 @@ public class TreeContentMergeViewer extends EMFCompareContentMergeViewer {
*/
public TreeContentMergeViewer(Composite parent, CompareConfiguration config) {
super(SWT.NONE, ResourceBundle.getBundle(BUNDLE_NAME), config);
+
fAdapterFactory = new ComposedAdapterFactory(EMFCompareRCPPlugin.getDefault()
.getAdapterFactoryRegistry());
fAdapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
@@ -352,20 +350,9 @@ public class TreeContentMergeViewer extends EMFCompareContentMergeViewer {
final boolean selected = Iterables.any(selection, equalTo(leftItem));
IMergeViewerItem leftData = (IMergeViewerItem)leftItem.getData();
final Diff leftDiff = leftData.getDiff();
- boolean doPaint = true;
if (leftDiff != null) {
- for (IDifferenceFilter filter : getEMFCompareConfiguration().getSelectedFilters()) {
- TreeNode treeNode = MergeViewerUtil.getTreeNode(getEMFCompareConfiguration().getComparison(), getEMFCompareConfiguration().getSelectedGroup(),
- leftDiff);
- if (filter.getPredicateWhenSelected().apply(treeNode)
- && !DiffUtil.isPrimeRefining(treeNode.getData())) {
- doPaint = false;
- break;
- }
- }
- }
- if (doPaint) {
- if (leftDiff != null) {
+ if (MergeViewerUtil.isVisibleInMergeViewer(leftDiff, getEMFCompareConfiguration()
+ .getSelectedGroup(), getEMFCompareConfiguration().getAggregatedPredicate())) {
TreeItem rightItem = findRightTreeItemFromLeftDiff(rightItems, leftDiff, leftData);
if (rightItem != null) {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java
index 25e2982ae..40f1d284b 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java
@@ -10,7 +10,11 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer;
+import static com.google.common.collect.Iterables.filter;
+
+import com.google.common.base.Predicate;
import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -334,10 +338,10 @@ public class EMFCompareDiffTreeRuler extends Canvas {
*/
private void handlePaintEvent(PaintEvent e) {
annotationsData.clear();
- Collection<IDifferenceFilter> filters = (Collection<IDifferenceFilter>)fConfiguration
- .getProperty(EMFCompareConstants.SELECTED_FILTERS);
- Collection<? extends Diff> filteredRequires = filteredDiffs(requires, filters);
- Collection<? extends Diff> filteredUnmergeables = filteredDiffs(unmergeables, filters);
+ Predicate<? super EObject> predicate = (Predicate<? super EObject>)fConfiguration
+ .getProperty(EMFCompareConstants.AGGREGATED_VIEWER_PREDICATE);
+ Collection<? extends Diff> filteredRequires = filteredDiffs(requires, predicate);
+ Collection<? extends Diff> filteredUnmergeables = filteredDiffs(unmergeables, predicate);
for (Diff diff : filteredRequires) {
for (TreeItem item : diffItems.get(diff)) {
createAnnotation(e, diff, item, requiredDiffFillColor, requiredDiffBorderColor);
@@ -638,19 +642,10 @@ public class EMFCompareDiffTreeRuler extends Canvas {
* @return A filtered list of diffs.
*/
protected Collection<? extends Diff> filteredDiffs(Collection<? extends Diff> unfilteredDiffs,
- Collection<IDifferenceFilter> filters) {
+ Predicate<? super EObject> filters) {
if (filters != null) {
- List<Diff> filteredDiffs = Lists.newArrayList(unfilteredDiffs);
- for (IDifferenceFilter filter : filters) {
- for (Diff unfilteredDiff : unfilteredDiffs) {
- if (filter.getPredicateWhenSelected().apply(unfilteredDiff)) {
- filteredDiffs.remove(unfilteredDiff);
- }
- }
- }
- return filteredDiffs;
+ return ImmutableList.copyOf(filter(unfilteredDiffs, filters));
}
- return unfilteredDiffs;
-
+ return ImmutableList.of();
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java
index 8a32c897e..0e1c17077 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java
@@ -11,6 +11,7 @@
package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer;
import static com.google.common.collect.Sets.newHashSet;
+import static com.google.common.collect.Sets.newLinkedHashSet;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
@@ -25,7 +26,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
-import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
@@ -468,21 +468,26 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
final Object property = getCompareConfiguration().getProperty(EMFCompareConstants.SELECTED_FILTERS);
final Collection<IDifferenceFilter> selectedFilters;
if (property == null) {
- selectedFilters = new HashSet<IDifferenceFilter>();
+ selectedFilters = newLinkedHashSet();
} else {
- selectedFilters = new HashSet<IDifferenceFilter>((Collection<IDifferenceFilter>)property);
+ selectedFilters = newLinkedHashSet((Collection<IDifferenceFilter>)property);
}
switch (event.getAction()) {
- case ACTIVATE:
+ case SELECTED:
selectedFilters.add(event.getFilter());
break;
- case DEACTIVATE:
+ case DESELECTED:
selectedFilters.remove(event.getFilter());
break;
default:
throw new IllegalStateException();
}
+
getCompareConfiguration().setProperty(EMFCompareConstants.SELECTED_FILTERS, selectedFilters);
+ getCompareConfiguration().setProperty(EMFCompareConstants.AGGREGATED_VIEWER_PREDICATE,
+ event.getAggregatedPredicate());
+
+ refreshTitle();
}
@Subscribe
@@ -495,6 +500,8 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
}
eAdapters.add(differenceGroupProvider);
getCompareConfiguration().setProperty(EMFCompareConstants.SELECTED_GROUP, differenceGroupProvider);
+
+ refreshTitle();
}
public void configurationPropertyChanged() {
@@ -607,6 +614,11 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
return;
}
+ refreshTitle();
+ refresh(root);
+ }
+
+ protected void refreshTitle() {
if (fParent != null) {
ITreeContentProvider contentProvider = (ITreeContentProvider)getContentProvider();
int displayedDiff = getMatchCount(contentProvider, contentProvider.getElements(getRoot()));
@@ -617,8 +629,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
fParent.setTitleArgument(computedDiff + " differences – " + filteredDiff
+ " differences filtered from view");
}
-
- refresh(root);
}
private int getMatchCount(ITreeContentProvider cp, Object[] elements) {
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 e5e2bca83..c53e9ec5c 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
@@ -537,6 +537,7 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
if (getCompareConfiguration() != null) {
getCompareConfiguration().setProperty(EMFCompareConstants.COMPARE_RESULT, null);
getCompareConfiguration().setProperty(EMFCompareConstants.SELECTED_FILTERS, null);
+ getCompareConfiguration().setProperty(EMFCompareConstants.AGGREGATED_VIEWER_PREDICATE, null);
getCompareConfiguration().setProperty(EMFCompareConstants.SELECTED_GROUP, null);
getCompareConfiguration().setProperty(EMFCompareConstants.MERGE_WAY, null);
getCompareConfiguration().setProperty(EMFCompareConstants.SMV_SELECTION, null);
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/util/EMFCompareUIActionUtil.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/util/EMFCompareUIActionUtil.java
index 475bc6d6d..bb1e80602 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/util/EMFCompareUIActionUtil.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/util/EMFCompareUIActionUtil.java
@@ -67,7 +67,7 @@ public final class EMFCompareUIActionUtil {
public static boolean isCascadingDifferencesFilterActive(CompareConfiguration configuration) {
Object property = configuration.getProperty(EMFCompareConstants.SELECTED_FILTERS);
final Collection<IDifferenceFilter> selectedFilters;
- if (property != null) {
+ if (property instanceof Collection<?>) {
selectedFilters = (Collection<IDifferenceFilter>)property;
for (IDifferenceFilter iDifferenceFilter : selectedFilters) {
if (iDifferenceFilter instanceof CascadingDifferencesFilter) {

Back to the top