Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikaël Barbero2013-10-13 07:12:58 -0400
committerMikaël Barbero2013-10-18 13:47:52 -0400
commit6bb3738a89c001e0258e7f77ec90d0e458b9a099 (patch)
tree90961e201639dadcbf8acbe4e38fdb15f8004f3e /plugins/org.eclipse.emf.compare.ide.ui/src
parent6b470fbb97e266ef2aae8b0a91fc96d49db01671 (diff)
downloadorg.eclipse.emf.compare-6bb3738a89c001e0258e7f77ec90d0e458b9a099.tar.gz
org.eclipse.emf.compare-6bb3738a89c001e0258e7f77ec90d0e458b9a099.tar.xz
org.eclipse.emf.compare-6bb3738a89c001e0258e7f77ec90d0e458b9a099.zip
Minimize the number of events to dispatch.
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/logical/ComparisonScopeBuilder.java91
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractStructuredViewerWrapper.java1
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java95
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java132
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java461
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/JFaceUtil.java45
6 files changed, 358 insertions, 467 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ComparisonScopeBuilder.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ComparisonScopeBuilder.java
index c0b693fba..50b332ad7 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ComparisonScopeBuilder.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ComparisonScopeBuilder.java
@@ -17,10 +17,14 @@ import static org.eclipse.emf.compare.ide.utils.ResourceUtil.createURIFor;
import com.google.common.base.Predicate;
import com.google.common.collect.Sets;
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
+import org.eclipse.compare.ICompareContainer;
import org.eclipse.compare.ITypedElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IStorage;
@@ -29,6 +33,8 @@ import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.ide.internal.utils.NotLoadingResourceSet;
import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages;
+import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
+import org.eclipse.emf.compare.ide.ui.internal.util.PlatformElementUtil;
import org.eclipse.emf.compare.ide.ui.logical.IModelMinimizer;
import org.eclipse.emf.compare.ide.ui.logical.IModelResolver;
import org.eclipse.emf.compare.ide.ui.logical.IStorageProviderAccessor;
@@ -39,6 +45,11 @@ import org.eclipse.emf.compare.scope.FilterComparisonScope;
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.team.core.subscribers.Subscriber;
+import org.eclipse.team.core.subscribers.SubscriberMergeContext;
+import org.eclipse.team.internal.ui.mapping.ModelCompareEditorInput;
+import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
+import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant;
/**
* This will be used by EMF Compare in order to construct its comparison scope given a "starting point".
@@ -132,6 +143,86 @@ public final class ComparisonScopeBuilder {
}
/**
+ * Constructs the comparison scope corresponding to the given typed elements.
+ *
+ * @param left
+ * Left of the compared elements.
+ * @param right
+ * Right of the compared elements.
+ * @param origin
+ * Common ancestor of the <code>left</code> and <code>right</code> compared elements.
+ * @param monitor
+ * Monitor to report progress on.
+ * @return The created comparison scope.
+ */
+ public static IComparisonScope create(ICompareContainer container, ITypedElement left,
+ ITypedElement right, ITypedElement origin, IProgressMonitor monitor) {
+ IStorageProviderAccessor storageAccessor = null;
+ Subscriber subscriber = getSubscriber(container);
+ if (subscriber != null) {
+ storageAccessor = new SubscriberStorageAccessor(subscriber);
+ }
+ IStorage leftStorage = PlatformElementUtil.findFile(left);
+ if (leftStorage == null) {
+ leftStorage = StreamAccessorStorage.fromTypedElement(left);
+ }
+ IModelResolver resolver = EMFCompareIDEUIPlugin.getDefault().getModelResolverRegistry()
+ .getBestResolverFor(leftStorage);
+ final ComparisonScopeBuilder scopeBuilder = new ComparisonScopeBuilder(resolver,
+ new IdenticalResourceMinimizer(), storageAccessor);
+ return scopeBuilder.build(left, right, origin, monitor);
+ }
+
+ /**
+ * Team left us with absolutely no way to determine whether our supplied input is the result of a
+ * synchronization or not.
+ * <p>
+ * In order to properly resolve the logical model of the resource currently being compared we need to know
+ * what "other" resources were part of its logical model, and we need to know the revisions of these
+ * resources we are to load. All of this has already been computed by Team, but it would not let us know.
+ * This method uses discouraged means to get around this "black box" locking from Team.
+ * </p>
+ * <p>
+ * The basic need here is to retrieve the Subscriber from this point. We have a lot of accessible
+ * variables, the two most important being the CompareConfiguration and ICompareInput... I could find no
+ * way around the privileged access to the private ModelCompareEditorInput.participant field. There does
+ * not seem to be any adapter (or Platform.getAdapterManager().getAdapter(...)) that would allow for this,
+ * so I'm taking the long way 'round.
+ * </p>
+ *
+ * @return The subscriber used for this comparison if any could be found, <code>null</code> otherwise.
+ */
+ @SuppressWarnings("restriction")
+ private static Subscriber getSubscriber(ICompareContainer container) {
+ if (container instanceof ModelCompareEditorInput) {
+ final ModelCompareEditorInput modelInput = (ModelCompareEditorInput)container;
+ ISynchronizeParticipant participant = null;
+ try {
+ final Field field = ModelCompareEditorInput.class.getDeclaredField("participant"); //$NON-NLS-1$
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ field.setAccessible(true);
+ return null;
+ }
+ });
+ participant = (ISynchronizeParticipant)field.get(modelInput);
+ } catch (NoSuchFieldException e) {
+ // Swallow this, this private field was there at least from 3.5 to 4.3
+ } catch (IllegalArgumentException e) {
+ // Cannot happen
+ } catch (IllegalAccessException e) {
+ // "Should" not happen, but ignore it anyway
+ }
+ if (participant instanceof ModelSynchronizeParticipant
+ && ((ModelSynchronizeParticipant)participant).getContext() instanceof SubscriberMergeContext) {
+ return ((SubscriberMergeContext)((ModelSynchronizeParticipant)participant).getContext())
+ .getSubscriber();
+ }
+ }
+ return null;
+ }
+
+ /**
* Creates the synchronization model for the given three elements (left, right, and the common ancestor of
* the two). Since this comparison may concern either local or remote resources, all I/O operations should
* go through the given storage accessor.
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractStructuredViewerWrapper.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractStructuredViewerWrapper.java
index 35ef8cae5..647c6a27d 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractStructuredViewerWrapper.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractStructuredViewerWrapper.java
@@ -427,6 +427,7 @@ public abstract class AbstractStructuredViewerWrapper<C extends Control, V exten
*/
@Override
protected void handleInvalidSelection(ISelection invalidSelection, ISelection newSelection) {
+ throw new UnsupportedOperationException();
}
/**
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 5fc300171..fe3466598 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
@@ -20,7 +20,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
-import com.google.common.eventbus.Subscribe;
import java.util.Collection;
import java.util.LinkedList;
@@ -35,16 +34,10 @@ import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.internal.utils.DiffUtil;
-import org.eclipse.emf.compare.rcp.ui.internal.configuration.IMergePreviewModeChange;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilterChange;
-import org.eclipse.emf.compare.rcp.ui.internal.util.SWTUtil;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
@@ -124,13 +117,6 @@ public class EMFCompareDiffTreeRuler extends Canvas {
/** The last cursor used. */
private Cursor lastCursor;
- /** The selected diff in the Treeviewer associated with this Treeruler. */
- private Diff selectedDiff;
-
- private Predicate<? super EObject> differencePredicate;
-
- private MergeMode mergePreviewMode;
-
private final EMFCompareConfiguration compareConfiguration;
/**
@@ -153,7 +139,6 @@ public class EMFCompareDiffTreeRuler extends Canvas {
fWidth = width;
fTreeViewer = treeViewer;
this.compareConfiguration = config;
- compareConfiguration.getEventBus().register(this);
requiredDiffFillColor = JFaceResources.getColorRegistry().get(
EMFCompareDiffTreeViewer.REQUIRED_DIFF_COLOR);
@@ -218,83 +203,21 @@ public class EMFCompareDiffTreeRuler extends Canvas {
}
/**
- * Compute consequences (required and unmergeable differences) when selection changed occurs.
- *
- * @param event
- * the SelectionChangedEvent event.
- */
- public void selectionChanged(SelectionChangedEvent event) {
- clearAllData();
- ISelection selection = event.getSelection();
- if (selection instanceof IStructuredSelection) {
- Object element = ((IStructuredSelection)selection).getFirstElement();
- if (element instanceof Adapter) {
- Object target = ((Adapter)element).getTarget();
- if (target instanceof TreeNode) {
- EObject data = ((TreeNode)target).getData();
- if (data instanceof Diff) {
- selectedDiff = (Diff)data;
- computeConsequences();
- }
- }
- }
- }
- }
-
- /**
* Compute consequences (required and unmergeable differences).
*/
- public void computeConsequences() {
+ public void computeConsequences(Object object) {
clearAllData();
- if (selectedDiff != null) {
- boolean leftToRigh = getMergePreviewMode().isLeftToRight(compareConfiguration.isLeftEditable(),
+ if (object instanceof Diff) {
+ Diff diff = (Diff)object;
+ MergeMode mergePreviewMode = compareConfiguration.getMergePreviewMode();
+ boolean leftToRigh = mergePreviewMode.isLeftToRight(compareConfiguration.isLeftEditable(),
compareConfiguration.isRightEditable());
- requires = DiffUtil.getRequires(selectedDiff, leftToRigh);
- unmergeables = DiffUtil.getUnmergeables(selectedDiff, leftToRigh);
+ requires = DiffUtil.getRequires(diff, leftToRigh);
+ unmergeables = DiffUtil.getUnmergeables(diff, leftToRigh);
associateTreeItems(Lists.newLinkedList(Iterables.concat(requires, unmergeables)));
}
}
- @Subscribe
- public void handleDifferenceFilterChange(IDifferenceFilterChange event) {
- differencePredicate = event.getPredicate();
- SWTUtil.safeAsyncExec(new Runnable() {
- public void run() {
- ((EMFCompareDiffTreeViewer)fTreeViewer).createChildrenSilently(fTreeViewer.getTree());
- computeConsequences();
- redraw();
- }
- });
- }
-
- /**
- * @return the differencePredicate
- */
- public Predicate<? super EObject> getDifferencePredicate() {
- if (differencePredicate == null) {
- differencePredicate = compareConfiguration.getStructureMergeViewerFilter()
- .getAggregatedPredicate();
- }
- return differencePredicate;
- }
-
- @Subscribe
- public void handleMergePreviewModeChange(IMergePreviewModeChange event) {
- mergePreviewMode = event.getNewValue();
- computeConsequences();
- redraw();
- }
-
- /**
- * @return the mergePreviewMode
- */
- public MergeMode getMergePreviewMode() {
- if (mergePreviewMode == null) {
- mergePreviewMode = compareConfiguration.getMergePreviewMode();
- }
- return mergePreviewMode;
- }
-
/**
* Maps tree items with the given list of diffs.
*
@@ -349,7 +272,6 @@ public class EMFCompareDiffTreeRuler extends Canvas {
* Handles the dispose event on this control.
*/
public void handleDispose() {
- compareConfiguration.getEventBus().unregister(this);
removeMouseTrackListener(mouseTrackListener);
removeMouseMoveListener(mouseMoveListener);
removeMouseListener(mouseClickListener);
@@ -364,7 +286,8 @@ public class EMFCompareDiffTreeRuler extends Canvas {
*/
private void handlePaintEvent(PaintEvent e) {
annotationsData.clear();
- Predicate<? super EObject> predicate = differencePredicate;
+ Predicate<? super EObject> predicate = compareConfiguration.getStructureMergeViewerFilter()
+ .getAggregatedPredicate();
Collection<? extends Diff> filteredRequires = filteredDiffs(requires, predicate);
Collection<? extends Diff> filteredUnmergeables = filteredDiffs(unmergeables, predicate);
for (Diff diff : filteredRequires) {
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 757af17d7..8c0d9e6d0 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
@@ -10,42 +10,27 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer;
-import static com.google.common.collect.Sets.newHashSet;
-
import com.google.common.base.Predicate;
-import com.google.common.eventbus.Subscribe;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Set;
-import org.eclipse.compare.CompareViewerSwitchingPane;
import org.eclipse.compare.structuremergeviewer.DiffTreeViewer;
import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceSource;
import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
-import org.eclipse.emf.compare.ide.ui.internal.util.JFaceUtil;
import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.internal.utils.DiffUtil;
-import org.eclipse.emf.compare.rcp.ui.internal.configuration.IComparisonAndScopeChange;
-import org.eclipse.emf.compare.rcp.ui.internal.configuration.IMergePreviewModeChange;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilterChange;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProviderChange;
-import org.eclipse.emf.compare.rcp.ui.internal.util.SWTUtil;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
@@ -77,31 +62,15 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
private final Color unmergeableDiffColor;
- private final CompareViewerSwitchingPane fParent;
-
private Listener fEraseItemListener;
- private AdapterFactory adapterFactory;
-
- private ISelectionChangedListener selectionChangeListener;
-
/**
* @param parent
* @param adapterFactory
* @param configuration
*/
- public EMFCompareDiffTreeViewer(Composite parent, final AdapterFactory adapterFactory,
- EMFCompareConfiguration configuration) {
+ public EMFCompareDiffTreeViewer(Composite parent, EMFCompareConfiguration configuration) {
super(parent, configuration);
- this.adapterFactory = adapterFactory;
-
- getCompareConfiguration().getEventBus().register(this);
-
- if (parent.getParent() instanceof CompareViewerSwitchingPane) {
- fParent = (CompareViewerSwitchingPane)parent.getParent();
- } else {
- fParent = null;
- }
fEraseItemListener = new Listener() {
public void handleEvent(Event event) {
@@ -110,13 +79,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
};
getControl().addListener(SWT.EraseItem, fEraseItemListener);
- selectionChangeListener = new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- getControl().redraw();
- }
- };
- addSelectionChangedListener(selectionChangeListener);
-
JFaceResources.getColorRegistry().put(REQUIRED_DIFF_COLOR, new RGB(215, 255, 200));
JFaceResources.getColorRegistry().put(REQUIRED_DIFF_BORDER_COLOR, new RGB(195, 235, 180));
JFaceResources.getColorRegistry().put(UNMERGEABLE_DIFF_COLOR, new RGB(255, 205, 180));
@@ -139,35 +101,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
}
};
- @Subscribe
- public void selectedDifferenceFiltersChange(IDifferenceFilterChange event) {
- SWTUtil.safeAsyncExec(new Runnable() {
- public void run() {
- getTree().redraw();
- refreshTitle();
- }
- });
- }
-
- @Subscribe
- public void handleDifferenceGroupProviderChange(IDifferenceGroupProviderChange event) {
- SWTUtil.safeAsyncExec(new Runnable() {
- public void run() {
- refreshTitle();
- }
- });
- }
-
- @Subscribe
- public void mergePreviewModeChange(IMergePreviewModeChange event) {
- SWTUtil.safeRedraw(getTree(), true);
- }
-
- @Subscribe
- public void comparisonChange(IComparisonAndScopeChange event) {
- SWTUtil.safeRefresh(this, true);
- }
-
/**
* {@inheritDoc}
*
@@ -178,7 +111,11 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
return null;
}
- public void createChildrenSilently(Object o) {
+ public void createChildrenSilently() {
+ createChildrenSilently(getTree());
+ }
+
+ private void createChildrenSilently(Object o) {
if (o instanceof Tree) {
createChildren((Widget)o);
for (TreeItem item : ((Tree)o).getItems()) {
@@ -192,11 +129,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
}
}
- @Override
- public void initialSelection() {
- super.initialSelection();
- }
-
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.AbstractTreeViewer#isExpandable(java.lang.Object)
@@ -210,56 +142,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
return super.isExpandable(parent);
}
- public void refreshAfterDiff(Object root) {
- if (getControl().isDisposed()) {
- return;
- }
-
- refresh(root);
- }
-
- protected void refreshTitle() {
- if (fParent != null) {
- ITreeContentProvider contentProvider = (ITreeContentProvider)getContentProvider();
- int displayedDiff = getMatchCount(contentProvider, contentProvider.getElements(getRoot()));
- Comparison comparison = getCompareConfiguration().getComparison();
- int computedDiff = comparison.getDifferences().size();
- int filteredDiff = computedDiff - displayedDiff;
- fParent.setTitleArgument(computedDiff + " differences – " + filteredDiff
- + " differences filtered from view");
- }
- }
-
- private int getMatchCount(ITreeContentProvider cp, Object[] elements) {
- Set<Diff> diffs = newHashSet();
- getMatchCount(cp, elements, diffs);
- return diffs.size();
- }
-
- /**
- * @param cp
- * @param children
- * @param diffs
- * @return
- */
- private void getMatchCount(ITreeContentProvider cp, Object[] elements, Set<Diff> diffs) {
- for (int j = 0; j < elements.length; j++) {
- Object element = elements[j];
- if (!JFaceUtil.isFiltered(this, element, null) && element instanceof Adapter) {
- Notifier target = ((Adapter)element).getTarget();
- if (target instanceof TreeNode) {
- TreeNode treeNode = (TreeNode)target;
- EObject data = treeNode.getData();
- if (data instanceof Diff) {
- diffs.add((Diff)data);
- }
- }
- }
- Object[] children = cp.getChildren(element);
- getMatchCount(cp, children, diffs);
- }
- }
-
/**
* {@inheritDoc}
*
@@ -268,8 +150,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
@Override
protected void handleDispose(DisposeEvent event) {
getControl().removeListener(SWT.EraseItem, fEraseItemListener);
- removeSelectionChangedListener(selectionChangeListener);
- getCompareConfiguration().getEventBus().unregister(this);
super.handleDispose(event);
}
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 fd2f346a7..a0e6a6ce2 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
@@ -10,13 +10,17 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer;
+import static com.google.common.base.Predicates.notNull;
+import static com.google.common.collect.Iterables.addAll;
import static com.google.common.collect.Iterables.getFirst;
+import static com.google.common.collect.Iterables.transform;
+import static com.google.common.collect.Lists.newArrayList;
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
import com.google.common.eventbus.Subscribe;
-import java.lang.reflect.Field;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.Collection;
import java.util.EventObject;
import java.util.Iterator;
@@ -24,12 +28,12 @@ import java.util.List;
import org.eclipse.compare.CompareUI;
import org.eclipse.compare.CompareViewerPane;
+import org.eclipse.compare.CompareViewerSwitchingPane;
import org.eclipse.compare.INavigatable;
import org.eclipse.compare.ITypedElement;
import org.eclipse.compare.internal.CompareHandlerService;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
-import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -40,30 +44,28 @@ import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.command.CommandStackListener;
import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.ui.dialogs.DiagnosticDialog;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.command.ICompareCopyCommand;
import org.eclipse.emf.compare.domain.ICompareEditingDomain;
import org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain;
-import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.RedoAction;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.UndoAction;
import org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonScopeInput;
import org.eclipse.emf.compare.ide.ui.internal.logical.ComparisonScopeBuilder;
-import org.eclipse.emf.compare.ide.ui.internal.logical.IdenticalResourceMinimizer;
-import org.eclipse.emf.compare.ide.ui.internal.logical.StreamAccessorStorage;
-import org.eclipse.emf.compare.ide.ui.internal.logical.SubscriberStorageAccessor;
import org.eclipse.emf.compare.ide.ui.internal.util.ExceptionUtil;
-import org.eclipse.emf.compare.ide.ui.internal.util.PlatformElementUtil;
-import org.eclipse.emf.compare.ide.ui.logical.IModelResolver;
-import org.eclipse.emf.compare.ide.ui.logical.IStorageProviderAccessor;
+import org.eclipse.emf.compare.ide.ui.internal.util.JFaceUtil;
import org.eclipse.emf.compare.internal.utils.ComparisonUtil;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.ICompareEditingDomainChange;
import org.eclipse.emf.compare.rcp.ui.internal.configuration.IMergePreviewModeChange;
+import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilterChange;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.StructureMergeViewerFilter;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProviderChange;
@@ -74,14 +76,15 @@ import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
-import org.eclipse.emf.edit.provider.IDisposable;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
import org.eclipse.emf.edit.tree.TreeFactory;
import org.eclipse.emf.edit.tree.TreeNode;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeViewerListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -93,11 +96,6 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.team.core.subscribers.Subscriber;
-import org.eclipse.team.core.subscribers.SubscriberMergeContext;
-import org.eclipse.team.internal.ui.mapping.ModelCompareEditorInput;
-import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
-import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant;
import org.eclipse.ui.actions.ActionFactory;
/**
@@ -138,6 +136,19 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
*/
private boolean resourcesShouldBeUnload;
+ private ISelectionChangedListener selectionChangeListener;
+
+ private final Job inputChangedTask = new Job("Compute Model Differences") {
+ @Override
+ public IStatus run(IProgressMonitor monitor) {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, "Computing Model Differences", 100);
+ compareInputChanged((ICompareInput)getInput(), subMonitor.newChild(100));
+ return Status.OK_STATUS;
+ }
+ };
+
+ private CompareToolBar toolBar;
+
/**
* Constructor.
*
@@ -149,7 +160,25 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
public EMFCompareStructureMergeViewer(Composite parent, EMFCompareConfiguration config) {
super(parent, config);
- config.getEventBus().register(this);
+ StructureMergeViewerFilter structureMergeViewerFilter = getCompareConfiguration()
+ .getStructureMergeViewerFilter();
+ getViewer().addFilter(structureMergeViewerFilter);
+
+ StructureMergeViewerGrouper structureMergeViewerGrouper = getCompareConfiguration()
+ .getStructureMergeViewerGrouper();
+ structureMergeViewerGrouper.install(getViewer());
+
+ toolBar = new CompareToolBar(structureMergeViewerGrouper, structureMergeViewerFilter,
+ getCompareConfiguration());
+ getViewer().addSelectionChangedListener(toolBar);
+ toolBar.initToolbar(CompareViewerPane.getToolBarManager(parent), getViewer());
+
+ selectionChangeListener = new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ handleSelectionChangedEvent(event);
+ }
+ };
+ addSelectionChangedListener(selectionChangeListener);
fHandlerService = CompareHandlerService.createFor(getCompareConfiguration().getContainer(),
getControl().getShell());
@@ -160,7 +189,11 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
setContentProvider(new EMFCompareStructureMergeViewerContentProvider(getCompareConfiguration()
.getAdapterFactory()));
+ undoAction = new UndoAction(null);
+ redoAction = new RedoAction(null);
+
inputChangedTask.setPriority(Job.LONG);
+ config.getEventBus().register(this);
}
/**
@@ -200,8 +233,7 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
control.setLayout(layout);
control.setLayoutData(data);
- final TreeViewer treeViewer = new EMFCompareDiffTreeViewer(control, fAdapterFactory,
- getCompareConfiguration());
+ final TreeViewer treeViewer = new EMFCompareDiffTreeViewer(control, getCompareConfiguration());
INavigatable nav = new Navigatable(fAdapterFactory, treeViewer);
control.setData(INavigatable.NAVIGATOR_PROPERTY, nav);
control.setData(CompareUI.COMPARE_VIEWER_TITLE, "Model differences");
@@ -233,82 +265,81 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
fHandlerService = CompareHandlerService.createFor(getCompareConfiguration().getContainer(),
treeViewer.getControl().getShell());
- StructureMergeViewerFilter structureMergeViewerFilter = getCompareConfiguration()
- .getStructureMergeViewerFilter();
- structureMergeViewerFilter.install(treeViewer);
-
- StructureMergeViewerGrouper structureMergeViewerGrouper = getCompareConfiguration()
- .getStructureMergeViewerGrouper();
- structureMergeViewerGrouper.install(treeViewer);
-
- toolBar = new CompareToolBar(structureMergeViewerGrouper, structureMergeViewerFilter,
- getCompareConfiguration());
- treeViewer.addSelectionChangedListener(toolBar);
- toolBar.initToolbar(CompareViewerPane.getToolBarManager(parent), treeViewer);
-
return ControlAndViewer.create(control, treeViewer);
}
@Subscribe
- public void handleGroupProviderSelectionChange(IDifferenceGroupProviderChange event) {
- differenceGroupProvider = event.getDifferenceGroupProvider();
+ public void handleEditingDomainChange(ICompareEditingDomainChange event) {
+ editingDomainChange(event.getOldValue(), event.getNewValue());
+ }
- Adapter root = (Adapter)getViewer().getInput();
- if (root != null) {
- TreeNode target = (TreeNode)root.getTarget();
- registerDifferenceGroupProvider(target, differenceGroupProvider);
- }
+ protected void editingDomainChange(ICompareEditingDomain oldValue, ICompareEditingDomain newValue) {
+ if (newValue != oldValue) {
+ if (oldValue != null) {
+ oldValue.getCommandStack().removeCommandStackListener(this);
+ }
- SWTUtil.safeAsyncExec(new Runnable() {
- public void run() {
- ((EMFCompareDiffTreeViewer)getViewer()).createChildrenSilently(getViewer().getTree());
- treeRuler.computeConsequences();
- treeRuler.redraw();
+ if (newValue != null) {
+ newValue.getCommandStack().addCommandStackListener(this);
+ // setLeftDirty(newValue.getCommandStack().isLeftSaveNeeded());
+ // setRightDirty(newValue.getCommandStack().isRightSaveNeeded());
}
- });
+
+ undoAction.setEditingDomain(newValue);
+ redoAction.setEditingDomain(newValue);
+ }
}
- /**
- * @return the differenceGroupProvider
- */
- public IDifferenceGroupProvider getSelectedDifferenceGroupProvider() {
- if (differenceGroupProvider == null) {
- differenceGroupProvider = getCompareConfiguration().getStructureMergeViewerGrouper()
- .getProvider();
+ private void refreshTitle() {
+ Composite parent = getControl().getParent();
+ if (parent instanceof CompareViewerSwitchingPane) {
+ int displayedDiff = JFaceUtil.filterVisibleElement(getViewer(), IS_DIFF).size();
+ Comparison comparison = getCompareConfiguration().getComparison();
+ if (comparison != null) {
+ int computedDiff = comparison.getDifferences().size();
+ int filteredDiff = computedDiff - displayedDiff;
+ ((CompareViewerSwitchingPane)parent).setTitleArgument(computedDiff + " differences – "
+ + filteredDiff + " differences filtered from view");
+ }
}
- return differenceGroupProvider;
}
- protected void registerDifferenceGroupProvider(TreeNode treeNode,
- IDifferenceGroupProvider differenceGroupProvider) {
- List<Adapter> eAdapters = treeNode.eAdapters();
- IDifferenceGroupProvider oldDifferenceGroupProvider = (IDifferenceGroupProvider)EcoreUtil.getAdapter(
- eAdapters, IDifferenceGroupProvider.class);
- if (oldDifferenceGroupProvider != null) {
- eAdapters.remove(oldDifferenceGroupProvider);
+ private static final Predicate<? super Object> IS_DIFF = new Predicate<Object>() {
+ public boolean apply(Object object) {
+ return getDataOfTreeNodeOfAdapter(object) instanceof Diff;
}
- eAdapters.add(differenceGroupProvider);
+ };
- treeRuler.computeConsequences();
- SWTUtil.safeRedraw(treeRuler, true);
+ private static EObject getDataOfTreeNodeOfAdapter(Object object) {
+ EObject data = null;
+ if (object instanceof Adapter) {
+ Notifier target = ((Adapter)object).getTarget();
+ if (target instanceof TreeNode) {
+ data = ((TreeNode)target).getData();
+ }
+ }
+ return data;
}
+ private static final Function<Object, EObject> ADAPTER__TARGET__DATA = new Function<Object, EObject>() {
+ public EObject apply(Object object) {
+ return getDataOfTreeNodeOfAdapter(object);
+ }
+ };
+
@Subscribe
public void mergePreviewModeChange(IMergePreviewModeChange event) {
- treeRuler.computeConsequences();
- treeRuler.redraw();
+ redrawFromSelection(getSelection());
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.Viewer#fireSelectionChanged(SelectionChangedEvent)
- */
- @Override
- protected void fireSelectionChanged(SelectionChangedEvent event) {
- super.fireSelectionChanged(event);
- treeRuler.selectionChanged(event);
- treeRuler.redraw();
+ @Subscribe
+ public void handleDifferenceFilterChange(IDifferenceFilterChange event) {
+ SWTUtil.safeRefresh(this, true);
+ }
+
+ @Subscribe
+ public void handleDifferenceGroupProviderChange(IDifferenceGroupProviderChange event) {
+ SWTUtil.safeRefresh(this, true);
}
/**
@@ -351,6 +382,7 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
ICompareInput ci = (ICompareInput)input;
ci.removeCompareInputChangeListener(fCompareInputChangeListener);
}
+ removeSelectionChangedListener(selectionChangeListener);
getViewer().removeSelectionChangedListener(toolBar);
compareInputChanged((ICompareInput)null);
treeRuler.handleDispose();
@@ -376,19 +408,13 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
if (mostRecentCommand instanceof ICompareCopyCommand) {
Collection<?> affectedObjects = mostRecentCommand.getAffectedObjects();
- SWTUtil.safeAsyncExec(new Runnable() {
- public void run() {
- treeRuler.computeConsequences();
- ((EMFCompareDiffTreeViewer)getViewer()).createChildrenSilently(getViewer().getTree());
- treeRuler.redraw();
- }
- });
if (!affectedObjects.isEmpty()) {
// MUST NOT call a setSelection with a list, o.e.compare does not handle it (cf
// org.eclipse.compare.CompareEditorInput#getElement(ISelection))
Object first = getFirst(affectedObjects, null);
if (first instanceof EObject) {
- IDifferenceGroupProvider groupProvider = getSelectedDifferenceGroupProvider();
+ IDifferenceGroupProvider groupProvider = getCompareConfiguration()
+ .getStructureMergeViewerGrouper().getProvider();
Iterable<TreeNode> treeNodes = groupProvider.getTreeNodes((EObject)first);
TreeNode treeNode = getFirst(treeNodes, null);
if (treeNode != null) {
@@ -409,19 +435,6 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
}
- private Job inputChangedTask = new Job("Compute Model Differences") {
- @Override
- public IStatus run(IProgressMonitor monitor) {
- SubMonitor subMonitor = SubMonitor.convert(monitor, "Computing Model Differences", 100);
- compareInputChanged((ICompareInput)getInput(), subMonitor.newChild(100));
- return Status.OK_STATUS;
- }
- };
-
- private CompareToolBar toolBar;
-
- private IDifferenceGroupProvider differenceGroupProvider;
-
/**
* Triggered by fCompareInputChangeListener and {@link #inputChanged(Object, Object)}.
*/
@@ -438,16 +451,10 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
}
void compareInputChanged(CompareInputAdapter input, IProgressMonitor monitor) {
- ICompareEditingDomain editingDomain = getCompareConfiguration().getEditingDomain();
- editingDomain.getCommandStack().addCommandStackListener(this);
-
compareInputChanged(null, (Comparison)input.getComparisonObject());
}
void compareInputChanged(ComparisonScopeInput input, IProgressMonitor monitor) {
- ICompareEditingDomain editingDomain = getCompareConfiguration().getEditingDomain();
- editingDomain.getCommandStack().addCommandStackListener(this);
-
EMFCompare comparator = getCompareConfiguration().getEMFComparator();
IComparisonScope comparisonScope = input.getComparisonScope();
@@ -466,8 +473,13 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
// this will set to the EMPTY difference group provider, but necessary to avoid NPE while setting
// input.
- treeNode.eAdapters().add(getSelectedDifferenceGroupProvider());
+ IDifferenceGroupProvider groupProvider = getCompareConfiguration()
+ .getStructureMergeViewerGrouper().getProvider();
+ treeNode.eAdapters().add(groupProvider);
+ // must set the input now in a synchronous mean. It will be used in the #setComparisonAndScope
+ // afterwards during the initialization of StructureMergeViewerFilter and
+ // StructureMergeViewerGrouper.
SWTUtil.safeSyncExec(new Runnable() {
public void run() {
getViewer().setInput(input);
@@ -478,15 +490,18 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
SWTUtil.safeAsyncExec(new Runnable() {
public void run() {
- ((EMFCompareDiffTreeViewer)getViewer()).createChildrenSilently(getViewer().getTree());
- ((EMFCompareDiffTreeViewer)getViewer()).initialSelection();
- }
- });
+ // the tree has now a proper group provider and its input, so we can create the child
+ // silently.
+ ((EMFCompareDiffTreeViewer)getViewer()).createChildrenSilently();
- ICompareEditingDomain editingDomain = getCompareConfiguration().getEditingDomain();
+ // title is not initialized as the comparison was set after the refresh caused by the
+ // initialization of the viewer filters and the groupe providers.
+ refreshTitle();
- undoAction = new UndoAction(editingDomain);
- redoAction = new RedoAction(editingDomain);
+ // XXX: fixme!!
+ // ((EMFCompareDiffTreeViewer)getViewer()).initialSelection();
+ }
+ });
SWTUtil.safeAsyncExec(new Runnable() {
public void run() {
@@ -520,7 +535,8 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
IComparisonScope scope = null;
try {
- scope = buildComparisonScope(left, right, origin, subMonitor.newChild(85));
+ scope = ComparisonScopeBuilder.create(getCompareConfiguration().getContainer(), left,
+ right, origin, subMonitor.newChild(85));
} catch (Exception e) {
ExceptionUtil.handleException(e, getCompareConfiguration(), true);
return;
@@ -538,79 +554,64 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
final ResourceSet rightResourceSet = (ResourceSet)scope.getRight();
final ResourceSet originResourceSet = (ResourceSet)scope.getOrigin();
- if (getCompareConfiguration() != null) {
- ICompareEditingDomain editingDomain = getCompareConfiguration().getEditingDomain();
- if (editingDomain != null) {
- editingDomain.getCommandStack().removeCommandStackListener(this);
- if (editingDomain instanceof IDisposable) {
- ((IDisposable)editingDomain).dispose();
- }
- }
-
- editingDomain = EMFCompareEditingDomain.create(leftResourceSet, rightResourceSet,
- originResourceSet);
- editingDomain.getCommandStack().addCommandStackListener(this);
- getCompareConfiguration().setEditingDomain(editingDomain);
- }
+ ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(leftResourceSet,
+ rightResourceSet, originResourceSet);
+ getCompareConfiguration().setEditingDomain(editingDomain);
compareInputChanged(scope, compareResult);
}
} else {
- ResourceSet leftResourceSet = null;
- ResourceSet rightResourceSet = null;
- ResourceSet originResourceSet = null;
-
- if (getCompareConfiguration().getComparison() != null) {
- Comparison comparison = getCompareConfiguration().getComparison();
- Iterator<Match> matchIt = comparison.getMatches().iterator();
- if (comparison.isThreeWay()) {
- while (matchIt.hasNext()
- && (leftResourceSet == null || rightResourceSet == null || originResourceSet == null)) {
- Match match = matchIt.next();
- if (leftResourceSet == null) {
- leftResourceSet = getResourceSet(match.getLeft());
- }
- if (rightResourceSet == null) {
- rightResourceSet = getResourceSet(match.getRight());
- }
- if (originResourceSet == null) {
- originResourceSet = getResourceSet(match.getOrigin());
- }
+ compareInputChangedToNull();
+ }
+ }
+
+ private void compareInputChangedToNull() {
+ ResourceSet leftResourceSet = null;
+ ResourceSet rightResourceSet = null;
+ ResourceSet originResourceSet = null;
+
+ if (getCompareConfiguration().getComparison() != null) {
+ Comparison comparison = getCompareConfiguration().getComparison();
+ Iterator<Match> matchIt = comparison.getMatches().iterator();
+ if (comparison.isThreeWay()) {
+ while (matchIt.hasNext()
+ && (leftResourceSet == null || rightResourceSet == null || originResourceSet == null)) {
+ Match match = matchIt.next();
+ if (leftResourceSet == null) {
+ leftResourceSet = getResourceSet(match.getLeft());
}
- } else {
- while (matchIt.hasNext() && (leftResourceSet == null || rightResourceSet == null)) {
- Match match = matchIt.next();
- if (leftResourceSet == null) {
- leftResourceSet = getResourceSet(match.getLeft());
- }
- if (rightResourceSet == null) {
- rightResourceSet = getResourceSet(match.getRight());
- }
+ if (rightResourceSet == null) {
+ rightResourceSet = getResourceSet(match.getRight());
+ }
+ if (originResourceSet == null) {
+ originResourceSet = getResourceSet(match.getOrigin());
}
}
- }
-
- ICompareEditingDomain editingDomain = getCompareConfiguration().getEditingDomain();
- if (editingDomain != null) {
- editingDomain.getCommandStack().removeCommandStackListener(this);
- getCompareConfiguration().setEditingDomain(null);
- if (editingDomain instanceof IDisposable) {
- ((IDisposable)editingDomain).dispose();
+ } else {
+ while (matchIt.hasNext() && (leftResourceSet == null || rightResourceSet == null)) {
+ Match match = matchIt.next();
+ if (leftResourceSet == null) {
+ leftResourceSet = getResourceSet(match.getLeft());
+ }
+ if (rightResourceSet == null) {
+ rightResourceSet = getResourceSet(match.getRight());
+ }
}
- editingDomain = null;
}
+ }
- if (resourcesShouldBeUnload) {
- unload(leftResourceSet);
- unload(rightResourceSet);
- unload(originResourceSet);
- }
+ editingDomainChange(getCompareConfiguration().getEditingDomain(), null);
- if (getCompareConfiguration() != null) {
- getCompareConfiguration().dispose();
- }
- getViewer().setInput(null);
+ if (resourcesShouldBeUnload) {
+ unload(leftResourceSet);
+ unload(rightResourceSet);
+ unload(originResourceSet);
}
+
+ if (getCompareConfiguration() != null) {
+ getCompareConfiguration().dispose();
+ }
+ getViewer().setInput(null);
}
private void reportErrors(final Comparison comparison) {
@@ -624,86 +625,6 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
}
}
- /**
- * Constructs the comparison scope corresponding to the given typed elements.
- *
- * @param left
- * Left of the compared elements.
- * @param right
- * Right of the compared elements.
- * @param origin
- * Common ancestor of the <code>left</code> and <code>right</code> compared elements.
- * @param monitor
- * Monitor to report progress on.
- * @return The created comparison scope.
- */
- private IComparisonScope buildComparisonScope(ITypedElement left, ITypedElement right,
- ITypedElement origin, IProgressMonitor monitor) {
- IStorageProviderAccessor storageAccessor = null;
- if (getSubscriber() != null) {
- storageAccessor = new SubscriberStorageAccessor(getSubscriber());
- }
- IStorage leftStorage = PlatformElementUtil.findFile(left);
- if (leftStorage == null) {
- leftStorage = StreamAccessorStorage.fromTypedElement(left);
- }
- IModelResolver resolver = EMFCompareIDEUIPlugin.getDefault().getModelResolverRegistry()
- .getBestResolverFor(leftStorage);
- final ComparisonScopeBuilder scopeBuilder = new ComparisonScopeBuilder(resolver,
- new IdenticalResourceMinimizer(), storageAccessor);
- return scopeBuilder.build(left, right, origin, monitor);
- }
-
- /**
- * Team left us with absolutely no way to determine whether our supplied input is the result of a
- * synchronization or not.
- * <p>
- * In order to properly resolve the logical model of the resource currently being compared we need to know
- * what "other" resources were part of its logical model, and we need to know the revisions of these
- * resources we are to load. All of this has already been computed by Team, but it would not let us know.
- * This method uses discouraged means to get around this "black box" locking from Team.
- * </p>
- * <p>
- * The basic need here is to retrieve the Subscriber from this point. We have a lot of accessible
- * variables, the two most important being the CompareConfiguration and ICompareInput... I could find no
- * way around the privileged access to the private ModelCompareEditorInput.participant field. There does
- * not seem to be any adapter (or Platform.getAdapterManager().getAdapter(...)) that would allow for this,
- * so I'm taking the long way 'round.
- * </p>
- *
- * @return The subscriber used for this comparison if any could be found, <code>null</code> otherwise.
- */
- @SuppressWarnings("restriction")
- private Subscriber getSubscriber() {
- if (getCompareConfiguration().getContainer() instanceof ModelCompareEditorInput) {
- final ModelCompareEditorInput modelInput = (ModelCompareEditorInput)getCompareConfiguration()
- .getContainer();
- ISynchronizeParticipant participant = null;
- try {
- final Field field = ModelCompareEditorInput.class.getDeclaredField("participant"); //$NON-NLS-1$
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- public Object run() {
- field.setAccessible(true);
- return null;
- }
- });
- participant = (ISynchronizeParticipant)field.get(modelInput);
- } catch (NoSuchFieldException e) {
- // Swallow this, this private field was there at least from 3.5 to 4.3
- } catch (IllegalArgumentException e) {
- // Cannot happen
- } catch (IllegalAccessException e) {
- // "Should" not happen, but ignore it anyway
- }
- if (participant instanceof ModelSynchronizeParticipant
- && ((ModelSynchronizeParticipant)participant).getContext() instanceof SubscriberMergeContext) {
- return ((SubscriberMergeContext)((ModelSynchronizeParticipant)participant).getContext())
- .getSubscriber();
- }
- }
- return null;
- }
-
private static void unload(ResourceSet resourceSet) {
if (resourceSet != null) {
for (Resource resource : resourceSet.getResources()) {
@@ -730,7 +651,37 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
*/
@Override
protected void internalRefresh(Object element) {
- getViewer().refresh();
+ SWTUtil.safeSyncExec(new Runnable() {
+ public void run() {
+ getViewer().refresh();
+ refreshTitle();
+
+ ((EMFCompareDiffTreeViewer)getViewer()).createChildrenSilently();
+ redrawFromSelection(getSelection());
+ }
+ });
+ }
+
+ private void handleSelectionChangedEvent(SelectionChangedEvent event) {
+ redrawFromSelection(event.getSelection());
+ }
+
+ protected void redrawFromSelection(ISelection selection) {
+ EObject eObject = getFirst(getSelectedComparisonObject(selection), null);
+ if (eObject != null) {
+ treeRuler.computeConsequences(eObject);
+ getControl().redraw();
+ }
+ }
+ private static List<EObject> getSelectedComparisonObject(ISelection selection) {
+ List<EObject> ret = newArrayList();
+ if (selection instanceof IStructuredSelection) {
+ List<?> selectedObjects = ((IStructuredSelection)selection).toList();
+ Iterable<EObject> data = transform(selectedObjects, ADAPTER__TARGET__DATA);
+ Iterable<EObject> notNullData = Iterables.filter(data, notNull());
+ addAll(ret, notNullData);
+ }
+ return ret;
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/JFaceUtil.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/JFaceUtil.java
index 0acb9c46a..a2ef7c31e 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/JFaceUtil.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/JFaceUtil.java
@@ -10,7 +10,18 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.util;
+import static com.google.common.collect.Iterables.addAll;
+import static com.google.common.collect.Sets.newHashSet;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+import java.util.Arrays;
+import java.util.Set;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerFilter;
/**
@@ -37,4 +48,38 @@ public class JFaceUtil {
}
return false;
}
+
+ /**
+ * Return the set of visible elements from the given viewer filtered by the given predicate.
+ *
+ * @param treeViewer
+ * @param predicate
+ * @return
+ */
+ public static Set<?> filterVisibleElement(TreeViewer treeViewer, Predicate<? super Object> predicate) {
+ Set<Object> acc = newHashSet();
+ ITreeContentProvider contentProvider = (ITreeContentProvider)treeViewer.getContentProvider();
+ Object[] elements = contentProvider.getElements(treeViewer.getInput());
+ getMatchCount(treeViewer, elements, null, predicate, acc);
+ return acc;
+ }
+
+ /**
+ * @param cp
+ * @param children
+ * @param diffs
+ * @return
+ */
+ private static void getMatchCount(TreeViewer treeViewer, Object[] elements, Object parent,
+ Predicate<? super Object> predicate, Set<Object> acc) {
+ final ITreeContentProvider cp = (ITreeContentProvider)treeViewer.getContentProvider();
+ addAll(acc, Iterables.filter(Arrays.asList(elements), predicate));
+ for (Object element : elements) {
+ if (!isFiltered(treeViewer, element, parent) && predicate.apply(element)) {
+ acc.add(element);
+ }
+ Object[] children = cp.getChildren(element);
+ getMatchCount(treeViewer, children, element, predicate, acc);
+ }
+ }
}

Back to the top