Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikaël Barbero2013-10-02 10:06:01 -0400
committerMikaël Barbero2013-10-03 05:09:54 -0400
commit35f30158008b2a1505077f69bbf0221ab79f7015 (patch)
tree427257504b1703ce11b4425ceb17263b7b606730 /plugins/org.eclipse.emf.compare.ide.ui/src
parent121830947f4ef4e39031fa82b71a444b58b62b7c (diff)
downloadorg.eclipse.emf.compare-35f30158008b2a1505077f69bbf0221ab79f7015.tar.gz
org.eclipse.emf.compare-35f30158008b2a1505077f69bbf0221ab79f7015.tar.xz
org.eclipse.emf.compare-35f30158008b2a1505077f69bbf0221ab79f7015.zip
Introduce IEMFCompareConfiguration.
This avoids implementing property change listeners everywhere. Change-Id: Ie48052e7f9a18d8ce1fe3b2237649de032e15787
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/configuration/EMFCompareConfiguration.java245
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/EMFCompareContentMergeViewer.java355
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/table/TableContentMergeViewer.java61
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/TreeContentMergeViewer.java40
4 files changed, 455 insertions, 246 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/configuration/EMFCompareConfiguration.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/configuration/EMFCompareConfiguration.java
new file mode 100644
index 000000000..dd5aeb6f1
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/configuration/EMFCompareConfiguration.java
@@ -0,0 +1,245 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.internal.configuration;
+
+import static com.google.common.base.Predicates.alwaysFalse;
+import static com.google.common.collect.Sets.newLinkedHashSet;
+
+import com.google.common.base.Predicate;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.domain.ICompareEditingDomain;
+import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration;
+import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
+import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+
+/**
+ * A wrapping compare configuration.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class EMFCompareConfiguration implements IEMFCompareConfiguration, IPropertyChangeListener {
+
+ /** The compare configuration. */
+ private final CompareConfiguration compareConfiguration;
+
+ /** The active group provider. */
+ private IDifferenceGroupProvider selectedDifferenceGroupProvider;
+
+ /** The list of active filters. */
+ private Set<IDifferenceFilter> selectedDifferenceFilters;
+
+ /** The aggregated viewer predicate. */
+ private Predicate<? super EObject> aggregatedViewerPredicate;
+
+ /** The editing domain. */
+ private ICompareEditingDomain editingDomain;
+
+ /** The comparison. */
+ private Comparison comparison;
+
+ /** The adapter factory. */
+ private AdapterFactory adapterFactory;
+
+ /**
+ * Creates a new object wrapping the given {@link CompareConfiguration}.
+ *
+ * @param cc
+ * the {@link CompareConfiguration} to wrap.
+ */
+ public EMFCompareConfiguration(CompareConfiguration cc) {
+ this.compareConfiguration = cc;
+
+ editingDomainChange(null, (ICompareEditingDomain)cc.getProperty(EMFCompareConstants.EDITING_DOMAIN));
+ selectedDifferenceGroupProviderChange(null, (IDifferenceGroupProvider)cc
+ .getProperty(EMFCompareConstants.SELECTED_GROUP));
+ selectedDifferenceFiltersChange(null, (Set<IDifferenceFilter>)cc
+ .getProperty(EMFCompareConstants.SELECTED_FILTERS));
+ aggregatedViewerPredicateChange(null, (Predicate<? super EObject>)cc
+ .getProperty(EMFCompareConstants.AGGREGATED_VIEWER_PREDICATE));
+ adapterFactoryChange(null, (AdapterFactory)cc
+ .getProperty(EMFCompareConstants.COMPOSED_ADAPTER_FACTORY));
+ comparisonChange(null, (Comparison)cc.getProperty(EMFCompareConstants.COMPARE_RESULT));
+
+ compareConfiguration.addPropertyChangeListener(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#getEditingDomain()
+ */
+ public ICompareEditingDomain getEditingDomain() {
+ return editingDomain;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#getSelectedGroup()
+ */
+ public IDifferenceGroupProvider getSelectedGroup() {
+ return selectedDifferenceGroupProvider;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#getSelectedFilters()
+ */
+ public Collection<IDifferenceFilter> getSelectedFilters() {
+ return selectedDifferenceFilters;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#getAggregatedPredicate()
+ */
+ public Predicate<? super EObject> getAggregatedPredicate() {
+ return aggregatedViewerPredicate;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#getComparison()
+ */
+ public Comparison getComparison() {
+ return comparison;
+ }
+
+ /**
+ * @param property
+ */
+ public void adapterFactoryChange(AdapterFactory oldValue, AdapterFactory newValue) {
+ adapterFactory = newValue;
+ }
+
+ public AdapterFactory getAdapterFactory() {
+ return adapterFactory;
+ }
+
+ /**
+ * @param property
+ */
+ public void aggregatedViewerPredicateChange(Predicate<? super EObject> oldValue,
+ Predicate<? super EObject> newValue) {
+ if (newValue != null) {
+ aggregatedViewerPredicate = newValue;
+ } else {
+ aggregatedViewerPredicate = alwaysFalse();
+ }
+
+ }
+
+ /**
+ * @param object
+ * @param property
+ */
+ public void selectedDifferenceFiltersChange(Set<IDifferenceFilter> oldValue,
+ Set<IDifferenceFilter> newValue) {
+ if (newValue != null) {
+ this.selectedDifferenceFilters = newValue;
+ } else {
+ this.selectedDifferenceFilters = newLinkedHashSet();
+ }
+ }
+
+ /**
+ * @param object
+ * @param property
+ */
+ public void selectedDifferenceGroupProviderChange(IDifferenceGroupProvider oldValue,
+ IDifferenceGroupProvider newValue) {
+ if (newValue != null) {
+ selectedDifferenceGroupProvider = newValue;
+ } else {
+ selectedDifferenceGroupProvider = IDifferenceGroupProvider.EMPTY;
+ }
+ }
+
+ /**
+ * @param oldValue
+ * @param newValue
+ */
+ public void editingDomainChange(ICompareEditingDomain oldValue, ICompareEditingDomain newValue) {
+ editingDomain = newValue;
+ }
+
+ /**
+ * @param object
+ * @param property
+ */
+ public void comparisonChange(Comparison oldValue, Comparison newValue) {
+ comparison = newValue;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
+ */
+ @SuppressWarnings("unchecked")
+ public void propertyChange(PropertyChangeEvent event) {
+ if (EMFCompareConstants.EDITING_DOMAIN.equals(event.getProperty())) {
+ ICompareEditingDomain oldValue = (ICompareEditingDomain)event.getOldValue();
+ ICompareEditingDomain newValue = (ICompareEditingDomain)event.getNewValue();
+ editingDomainChange(oldValue, newValue);
+ } else if (EMFCompareConstants.SELECTED_GROUP.equals(event.getProperty())) {
+ IDifferenceGroupProvider oldValue = (IDifferenceGroupProvider)event.getOldValue();
+ IDifferenceGroupProvider newValue = (IDifferenceGroupProvider)event.getNewValue();
+ selectedDifferenceGroupProviderChange(oldValue, newValue);
+ } else if (EMFCompareConstants.SELECTED_FILTERS.equals(event.getProperty())) {
+ Set<IDifferenceFilter> oldValue = (Set<IDifferenceFilter>)event.getOldValue();
+ Set<IDifferenceFilter> newValue = (Set<IDifferenceFilter>)event.getNewValue();
+ selectedDifferenceFiltersChange(oldValue, newValue);
+ } else if (EMFCompareConstants.AGGREGATED_VIEWER_PREDICATE.equals(event.getProperty())) {
+ Predicate<? super EObject> oldValue = (Predicate<? super EObject>)event.getOldValue();
+ Predicate<? super EObject> newValue = (Predicate<? super EObject>)event.getNewValue();
+ aggregatedViewerPredicateChange(oldValue, newValue);
+ } else if (EMFCompareConstants.COMPARE_RESULT.equals(event.getProperty())) {
+ Comparison oldValue = (Comparison)event.getOldValue();
+ Comparison newValue = (Comparison)event.getNewValue();
+ comparisonChange(oldValue, newValue);
+ } else if (EMFCompareConstants.COMPOSED_ADAPTER_FACTORY.equals(event.getProperty())) {
+ AdapterFactory oldValue = (AdapterFactory)event.getOldValue();
+ AdapterFactory newValue = (AdapterFactory)event.getNewValue();
+ adapterFactoryChange(oldValue, newValue);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#dispose()
+ */
+ public void dispose() {
+ compareConfiguration.removePropertyChangeListener(this);
+
+ editingDomainChange(editingDomain, null);
+ selectedDifferenceGroupProviderChange(selectedDifferenceGroupProvider, null);
+ selectedDifferenceFiltersChange(selectedDifferenceFilters, null);
+ aggregatedViewerPredicateChange(aggregatedViewerPredicate, null);
+ adapterFactoryChange(adapterFactory, null);
+ comparisonChange(comparison, null);
+
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/EMFCompareContentMergeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/EMFCompareContentMergeViewer.java
index f5d36ed86..78fd1bc2a 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/EMFCompareContentMergeViewer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/EMFCompareContentMergeViewer.java
@@ -15,12 +15,12 @@ import static com.google.common.collect.Iterables.filter;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
-import java.util.Collection;
import java.util.EventObject;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.compare.CompareConfiguration;
@@ -30,18 +30,19 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStackListener;
-import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceSource;
import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.domain.ICompareEditingDomain;
+import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.DynamicObject;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.EMFCompareColor;
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.util.SWTUtil;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
-import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration;
import org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.ICompareAccessor;
import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.ICompareColor;
import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.IMergeViewer;
@@ -49,19 +50,15 @@ import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.IMergeViewer.MergeVie
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.structuremergeviewer.filters.impl.CascadingDifferencesFilter;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
import org.eclipse.emf.compare.utils.EMFComparePredicates;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.emf.edit.ui.view.ExtendedPropertySheetPage;
import org.eclipse.jface.action.ToolBarManager;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -88,7 +85,110 @@ import org.eclipse.ui.views.properties.PropertySheet;
/**
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
*/
-public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer implements ISelectionChangedListener, ICompareColor.Provider, IAdaptable, IPropertyChangeListener, CommandStackListener {
+public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer implements ISelectionChangedListener, ICompareColor.Provider, IAdaptable, CommandStackListener {
+
+ /**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+ private final class EMFCompareContentMergerViewerConfiguration extends EMFCompareConfiguration {
+
+ /**
+ * @param cc
+ */
+ private EMFCompareContentMergerViewerConfiguration(CompareConfiguration cc) {
+ super(cc);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration#editingDomainChange(org.eclipse.emf.compare.domain.ICompareEditingDomain,
+ * org.eclipse.emf.compare.domain.ICompareEditingDomain)
+ */
+ @Override
+ public void editingDomainChange(ICompareEditingDomain oldValue, ICompareEditingDomain newValue) {
+ super.editingDomainChange(oldValue, newValue);
+ if (newValue != oldValue) {
+ if (oldValue != null) {
+ oldValue.getCommandStack().removeCommandStackListener(EMFCompareContentMergeViewer.this);
+ }
+
+ if (newValue != null) {
+ newValue.getCommandStack().addCommandStackListener(EMFCompareContentMergeViewer.this);
+ setLeftDirty(newValue.getCommandStack().isLeftSaveNeeded());
+ setRightDirty(newValue.getCommandStack().isRightSaveNeeded());
+ }
+ if (undoAction != null) {
+ undoAction.setEditingDomain(newValue);
+ }
+ if (redoAction != null) {
+ redoAction.setEditingDomain(newValue);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration#aggregatedViewerPredicateChange(com.google.common.base.Predicate,
+ * com.google.common.base.Predicate)
+ */
+ @Override
+ public void aggregatedViewerPredicateChange(Predicate<? super EObject> oldValue,
+ Predicate<? super EObject> newValue) {
+ super.aggregatedViewerPredicateChange(oldValue, newValue);
+ if (oldValue != newValue) {
+ redrawCenterControl();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration#selectedDifferenceFiltersChange(java.util.Set,
+ * java.util.Set)
+ */
+ @Override
+ public void selectedDifferenceFiltersChange(Set<IDifferenceFilter> oldValue,
+ Set<IDifferenceFilter> newValue) {
+ super.selectedDifferenceFiltersChange(oldValue, newValue);
+ if (oldValue != newValue) {
+ redrawCenterControl();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration#selectedDifferenceGroupProviderChange(org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider,
+ * org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider)
+ */
+ @Override
+ public void selectedDifferenceGroupProviderChange(IDifferenceGroupProvider oldValue,
+ IDifferenceGroupProvider newValue) {
+ super.selectedDifferenceGroupProviderChange(oldValue, newValue);
+ if (oldValue != newValue) {
+ redrawCenterControl();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration#adapterFactoryChange(org.eclipse.emf.common.notify.AdapterFactory,
+ * org.eclipse.emf.common.notify.AdapterFactory)
+ */
+ @Override
+ public void adapterFactoryChange(AdapterFactory oldValue, AdapterFactory newValue) {
+ super.adapterFactoryChange(oldValue, newValue);
+ if (oldValue != null) {
+ fAdapterFactoryContentProvider.dispose();
+ }
+ if (newValue != oldValue) {
+ fAdapterFactoryContentProvider = new AdapterFactoryContentProvider(newValue);
+ }
+ }
+ }
private static final String HANDLER_SERVICE = "fHandlerService";
@@ -113,17 +213,9 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
private RedoAction redoAction;
- /** The active group provider. */
- private IDifferenceGroupProvider selectedGroup;
+ private final IEMFCompareConfiguration emfCompareConfiguration;
- /** The list of active filters. */
- private Collection<IDifferenceFilter> selectedFilters;
-
- /** The compare configuration object. */
- private CompareConfiguration configuration;
-
- /** The AdapterFactoryContentProvider useful to fill in the property sheet page. */
- private final AdapterFactoryContentProvider fAdapterFactoryContentProvider;
+ private AdapterFactoryContentProvider fAdapterFactoryContentProvider;
/**
* @param style
@@ -132,82 +224,9 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
*/
protected EMFCompareContentMergeViewer(int style, ResourceBundle bundle, CompareConfiguration cc) {
super(style, bundle, cc);
- fDynamicObject = new DynamicObject(this);
-
- editingDomainChange(null, getEditingDomain());
- setSelectedGroup((IDifferenceGroupProvider)cc.getProperty(EMFCompareConstants.SELECTED_GROUP));
- setSelectedFilters((Collection<IDifferenceFilter>)cc
- .getProperty(EMFCompareConstants.SELECTED_FILTERS));
- configuration = cc;
- configuration.addPropertyChangeListener(this);
- ComposedAdapterFactory adapterFactory = (ComposedAdapterFactory)configuration
- .getProperty(EMFCompareConstants.COMPOSED_ADAPTER_FACTORY);
- fAdapterFactoryContentProvider = new AdapterFactoryContentProvider(adapterFactory);
- }
-
- public void propertyChange(PropertyChangeEvent event) {
- if (EMFCompareConstants.EDITING_DOMAIN.equals(event.getProperty())) {
- editingDomainChange((ICompareEditingDomain)event.getOldValue(), (ICompareEditingDomain)event
- .getNewValue());
- } else if (EMFCompareConstants.SELECTED_FILTERS.equals(event.getProperty())) {
- Object newValue = event.getNewValue();
- if (newValue != null) {
- setSelectedFilters((Collection<IDifferenceFilter>)newValue);
-
- fLeft.setSelectedFilters((Collection<IDifferenceFilter>)newValue);
- fRight.setSelectedFilters((Collection<IDifferenceFilter>)newValue);
- fAncestor.setSelectedFilters((Collection<IDifferenceFilter>)newValue);
-
- IDifferenceGroupProvider group = getSelectedGroup();
- if (group != null) {
- if (fLeft.getSelectedGroup() == null) {
- fLeft.setSelectedGroup(group);
- }
- if (fRight.getSelectedGroup() == null) {
- fRight.setSelectedGroup(group);
- }
- if (fAncestor.getSelectedGroup() == null) {
- fAncestor.setSelectedGroup(group);
- }
- }
- fLeft.refresh();
- fRight.refresh();
- fAncestor.refresh();
- getCenterControl().redraw();
- }
- } else if (EMFCompareConstants.SELECTED_GROUP.equals(event.getProperty())) {
- Object newValue = event.getNewValue();
- if (newValue != null) {
- setSelectedGroup((IDifferenceGroupProvider)newValue);
-
- fLeft.setSelectedGroup((IDifferenceGroupProvider)newValue);
- fRight.setSelectedGroup((IDifferenceGroupProvider)newValue);
- fAncestor.setSelectedGroup((IDifferenceGroupProvider)newValue);
- }
- }
- }
- /**
- * @param oldValue
- * @param newValue
- */
- protected void editingDomainChange(ICompareEditingDomain oldValue, ICompareEditingDomain newValue) {
- if (oldValue != null) {
- oldValue.getCommandStack().removeCommandStackListener(this);
- }
- if (newValue != oldValue) {
- if (newValue != null) {
- newValue.getCommandStack().addCommandStackListener(this);
- setLeftDirty(newValue.getCommandStack().isLeftSaveNeeded());
- setRightDirty(newValue.getCommandStack().isRightSaveNeeded());
- }
- if (undoAction != null) {
- undoAction.setEditingDomain(newValue);
- }
- if (redoAction != null) {
- redoAction.setEditingDomain(newValue);
- }
- }
+ fDynamicObject = new DynamicObject(this);
+ emfCompareConfiguration = new EMFCompareContentMergerViewerConfiguration(cc);
}
/**
@@ -220,35 +239,6 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
}
/**
- * @return the fEditingDomain
- */
- protected final ICompareEditingDomain getEditingDomain() {
- return (ICompareEditingDomain)getCompareConfiguration().getProperty(
- EMFCompareConstants.EDITING_DOMAIN);
- }
-
- /**
- * @return the fComparison
- */
- protected final Comparison getComparison() {
- return (Comparison)getCompareConfiguration().getProperty(EMFCompareConstants.COMPARE_RESULT);
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * Overriden to enhance visibility.
- * </p>
- *
- * @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#isThreeWay()
- */
- @Override
- public boolean isThreeWay() {
- // enhances visibility
- return super.isThreeWay();
- }
-
- /**
* {@inheritDoc}
*
* @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#updateContent(java.lang.Object,
@@ -276,7 +266,7 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
ISelection leftSelection = createSelectionOrEmpty(leftInitialItem);
fLeft.setSelection(leftSelection, true); // others will synchronize on this one :)
- getCenterControl().redraw();
+ redrawCenterControl();
}
private ISelection createSelectionOrEmpty(final Object o) {
@@ -335,8 +325,8 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
"toolbar:org.eclipse.emf.compare.contentmergeviewer.toolbar");
}
- undoAction = new UndoAction(getEditingDomain());
- redoAction = new RedoAction(getEditingDomain());
+ undoAction = new UndoAction(getEMFCompareConfiguration().getEditingDomain());
+ redoAction = new RedoAction(getEMFCompareConfiguration().getEditingDomain());
getHandlerService().setGlobalActionHandler(ActionFactory.UNDO.getId(), undoAction);
getHandlerService().setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
@@ -350,9 +340,10 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
if (redoAction != null) {
redoAction.update();
}
- if (getEditingDomain() != null) {
- setLeftDirty(getEditingDomain().getCommandStack().isLeftSaveNeeded());
- setRightDirty(getEditingDomain().getCommandStack().isRightSaveNeeded());
+ if (getEMFCompareConfiguration().getEditingDomain() != null) {
+ setLeftDirty(getEMFCompareConfiguration().getEditingDomain().getCommandStack().isLeftSaveNeeded());
+ setRightDirty(getEMFCompareConfiguration().getEditingDomain().getCommandStack()
+ .isRightSaveNeeded());
}
SWTUtil.safeAsyncExec(new Runnable() {
@@ -363,6 +354,13 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
}
/**
+ * @return the emfCompareConfiguration
+ */
+ protected final IEMFCompareConfiguration getEMFCompareConfiguration() {
+ return emfCompareConfiguration;
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#copy(boolean)
@@ -371,29 +369,28 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
protected void copy(final boolean leftToRight) {
final List<Diff> differences;
- if (getComparison().isThreeWay()) {
- differences = ImmutableList.copyOf(filter(getComparison().getDifferences(),
- new Predicate<Diff>() {
- public boolean apply(Diff diff) {
- final boolean unresolved = diff.getState() == DifferenceState.UNRESOLVED;
- final boolean nonConflictual = diff.getConflict() == null;
- final boolean fromLeftToRight = leftToRight
- && diff.getSource() == DifferenceSource.LEFT;
- final boolean fromRightToLeft = !leftToRight
- && diff.getSource() == DifferenceSource.RIGHT;
- return unresolved && nonConflictual && (fromLeftToRight || fromRightToLeft);
- }
- }));
+ if (getEMFCompareConfiguration().getComparison().isThreeWay()) {
+ differences = ImmutableList.copyOf(filter(getEMFCompareConfiguration().getComparison()
+ .getDifferences(), new Predicate<Diff>() {
+ public boolean apply(Diff diff) {
+ final boolean unresolved = diff.getState() == DifferenceState.UNRESOLVED;
+ final boolean nonConflictual = diff.getConflict() == null;
+ final boolean fromLeftToRight = leftToRight && diff.getSource() == DifferenceSource.LEFT;
+ final boolean fromRightToLeft = !leftToRight
+ && diff.getSource() == DifferenceSource.RIGHT;
+ return unresolved && nonConflictual && (fromLeftToRight || fromRightToLeft);
+ }
+ }));
} else {
- differences = ImmutableList.copyOf(filter(getComparison().getDifferences(), EMFComparePredicates
- .hasState(DifferenceState.UNRESOLVED)));
+ differences = ImmutableList.copyOf(filter(getEMFCompareConfiguration().getComparison()
+ .getDifferences(), EMFComparePredicates.hasState(DifferenceState.UNRESOLVED)));
}
if (differences.size() > 0) {
- final Command copyCommand = getEditingDomain().createCopyCommand(differences, leftToRight,
- EMFCompareRCPPlugin.getDefault().getMergerRegistry());
+ final Command copyCommand = getEMFCompareConfiguration().getEditingDomain().createCopyCommand(
+ differences, leftToRight, EMFCompareRCPPlugin.getDefault().getMergerRegistry());
- getEditingDomain().getCommandStack().execute(copyCommand);
+ getEMFCompareConfiguration().getEditingDomain().getCommandStack().execute(copyCommand);
refresh();
}
}
@@ -605,11 +602,11 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
*/
private void manageReadOnly(EObject selectedObject, MergeViewerSide side) {
if (MergeViewerSide.LEFT == side) {
- if (!configuration.isLeftEditable()) {
+ if (!getCompareConfiguration().isLeftEditable()) {
setToReadOnly(selectedObject);
}
} else if (MergeViewerSide.RIGHT == side) {
- if (!configuration.isRightEditable()) {
+ if (!getCompareConfiguration().isRightEditable()) {
setToReadOnly(selectedObject);
}
} else if (MergeViewerSide.ANCESTOR == side) {
@@ -665,68 +662,14 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
*/
@Override
protected void handleDispose(DisposeEvent event) {
- getCompareConfiguration().removePropertyChangeListener(this);
- editingDomainChange(getEditingDomain(), null);
+ getEMFCompareConfiguration().dispose();
super.handleDispose(event);
}
- /**
- * Checks the state of the filter sub diff elements.
- *
- * @return true, if the filter sub diff is active, false otherwise.
- */
- @SuppressWarnings("unchecked")
- protected boolean isSubDiffFilterActive() {
- Object property = getCompareConfiguration().getProperty(EMFCompareConstants.SELECTED_FILTERS);
- final Collection<IDifferenceFilter> filters;
- if (property == null) {
- return false;
- } else {
- filters = (Collection<IDifferenceFilter>)property;
- for (IDifferenceFilter iDifferenceFilter : filters) {
- if (iDifferenceFilter instanceof CascadingDifferencesFilter) {
- return true;
- }
- }
+ protected final void redrawCenterControl() {
+ if (getCenterControl() != null) {
+ getCenterControl().redraw();
}
- return false;
- }
-
- /**
- * Returns the active group.
- *
- * @return the selected group provider.
- */
- public IDifferenceGroupProvider getSelectedGroup() {
- return selectedGroup;
- }
-
- /**
- * Set the selected group.
- *
- * @param group
- * the group provider to set.
- */
- public void setSelectedGroup(IDifferenceGroupProvider group) {
- this.selectedGroup = group;
- }
-
- /**
- * Returns the active filters.
- *
- * @return the selectedFilters.
- */
- public Collection<IDifferenceFilter> getSelectedFilters() {
- return selectedFilters;
}
- /**
- * Set the list of selected filters.
- *
- * @param selectedFilters
- * the selectedFilters to set
- */
- public void setSelectedFilters(Collection<IDifferenceFilter> selectedFilters) {
- this.selectedFilters = selectedFilters;
- }
}
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 a33708263..72789cedd 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
@@ -10,23 +10,32 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.table;
+import static com.google.common.base.Predicates.equalTo;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
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;
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;
@@ -141,7 +150,7 @@ public class TableContentMergeViewer extends EMFCompareContentMergeViewer {
*/
@Override
protected AbstractMergeViewer createMergeViewer(Composite parent, final MergeViewerSide side) {
- TableMergeViewer ret = new TableMergeViewer(parent, side, this);
+ TableMergeViewer ret = new TableMergeViewer(parent, side, this, getEMFCompareConfiguration());
ret.getStructuredViewer().getTable().getVerticalBar().setVisible(false);
ret.setContentProvider(new ArrayContentProvider() {
@@ -243,10 +252,6 @@ public class TableContentMergeViewer extends EMFCompareContentMergeViewer {
return ret;
}
- protected void redrawCenterControl() {
- getCenterControl().redraw();
- }
-
/**
* {@inheritDoc}
*
@@ -267,25 +272,34 @@ public class TableContentMergeViewer extends EMFCompareContentMergeViewer {
TableItem[] leftItems = leftTable.getItems();
TableItem[] rightItems = rightTable.getItems();
- TableItem[] selection = leftTable.getSelection();
+ final ImmutableSet<TableItem> selection = ImmutableSet.copyOf(leftTable.getSelection());
for (TableItem leftItem : leftItems) {
- final boolean selected;
- if (selection.length > 0) {
- selected = leftItem == selection[0];
- } else {
- selected = false;
- }
+ final boolean selected = Iterables.any(selection, equalTo(leftItem));
+ IMergeViewerItem leftData = (IMergeViewerItem)leftItem.getData();
final Diff leftDiff = ((IMergeViewerItem)leftItem.getData()).getDiff();
-
+ boolean doPaint = true;
if (leftDiff != null) {
- TableItem rightItem = findRightTableItemFromLeftDiff(rightItems, leftDiff);
-
- if (rightItem != null) {
- Color strokeColor = getCompareColor().getStrokeColor(leftDiff, isThreeWay(), false,
- selected);
- g.setForeground(strokeColor);
- drawCenterLine(g, leftClientArea, rightClientArea, leftItem, rightItem);
+ 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) {
+ TableItem rightItem = findRightTableItemFromLeftDiff(rightItems, leftDiff, leftData);
+
+ if (rightItem != null) {
+ Color strokeColor = getCompareColor().getStrokeColor(leftDiff, isThreeWay(), false,
+ selected);
+ g.setForeground(strokeColor);
+ drawCenterLine(g, leftClientArea, rightClientArea, leftItem, rightItem);
+ }
}
}
}
@@ -335,13 +349,18 @@ public class TableContentMergeViewer extends EMFCompareContentMergeViewer {
}
}
- private TableItem findRightTableItemFromLeftDiff(TableItem[] rightItems, Diff leftDiff) {
+ private TableItem findRightTableItemFromLeftDiff(TableItem[] rightItems, Diff leftDiff,
+ IMergeViewerItem rightData) {
TableItem ret = null;
for (int i = 0; i < rightItems.length && ret == null; i++) {
TableItem rightItem = rightItems[i];
final Diff rightDiff = ((IMergeViewerItem)rightItem.getData()).getDiff();
if (leftDiff == rightDiff) {
ret = rightItem;
+ } else if (rightData.getAncestor() == rightData.getAncestor()
+ && rightData.getRight() == rightData.getRight()
+ && rightData.getLeft() == rightData.getLeft()) {
+ ret = rightItem;
}
}
return ret;
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 57efc91a0..7781e36f8 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
@@ -183,7 +183,8 @@ public class TreeContentMergeViewer extends EMFCompareContentMergeViewer {
*/
@Override
protected AbstractMergeViewer createMergeViewer(final Composite parent, final MergeViewerSide side) {
- final TreeMergeViewer mergeTreeViewer = new TreeMergeViewer(parent, side, this);
+ final TreeMergeViewer mergeTreeViewer = new TreeMergeViewer(parent, side, this,
+ getEMFCompareConfiguration());
IContentProvider contentProvider = new AdapterFactoryContentProvider(fAdapterFactory) {
/**
* {@inheritDoc}
@@ -207,7 +208,8 @@ public class TreeContentMergeViewer extends EMFCompareContentMergeViewer {
public Object[] getChildren(Object object) {
if (object instanceof IMergeViewerItem.Container) {
IMergeViewerItem[] children = ((IMergeViewerItem.Container)object).getChildren(
- getSelectedGroup(), getSelectedFilters());
+ getEMFCompareConfiguration().getSelectedGroup(), getEMFCompareConfiguration()
+ .getAggregatedPredicate());
return children;
}
@@ -222,8 +224,8 @@ public class TreeContentMergeViewer extends EMFCompareContentMergeViewer {
@Override
public boolean hasChildren(Object object) {
if (object instanceof IMergeViewerItem.Container) {
- return ((IMergeViewerItem.Container)object).hasChildren(getSelectedGroup(),
- getSelectedFilters());
+ return ((IMergeViewerItem.Container)object).hasChildren(getEMFCompareConfiguration()
+ .getSelectedGroup(), getEMFCompareConfiguration().getAggregatedPredicate());
}
return super.hasChildren(object);
}
@@ -324,10 +326,6 @@ public class TreeContentMergeViewer extends EMFCompareContentMergeViewer {
return mergeTreeViewer;
}
- protected void redrawCenterControl() {
- getCenterControl().redraw();
- }
-
/**
* {@inheritDoc}
*
@@ -356,8 +354,8 @@ public class TreeContentMergeViewer extends EMFCompareContentMergeViewer {
final Diff leftDiff = leftData.getDiff();
boolean doPaint = true;
if (leftDiff != null) {
- for (IDifferenceFilter filter : getSelectedFilters()) {
- TreeNode treeNode = MergeViewerUtil.getTreeNode(getComparison(), getSelectedGroup(),
+ for (IDifferenceFilter filter : getEMFCompareConfiguration().getSelectedFilters()) {
+ TreeNode treeNode = MergeViewerUtil.getTreeNode(getEMFCompareConfiguration().getComparison(), getEMFCompareConfiguration().getSelectedGroup(),
leftDiff);
if (filter.getPredicateWhenSelected().apply(treeNode)
&& !DiffUtil.isPrimeRefining(treeNode.getData())) {
@@ -532,26 +530,30 @@ public class TreeContentMergeViewer extends EMFCompareContentMergeViewer {
}
if (parent instanceof EObject) {
- Match match = getComparison().getMatch((EObject)parent);
+ Match match = getEMFCompareConfiguration().getComparison().getMatch((EObject)parent);
if (match != null) {
for (ReferenceChange referenceChange : filter(filter(match.getDifferences(),
ReferenceChange.class), EMFComparePredicates.ofKind(DifferenceKind.MOVE))) {
if (getLeftMergeViewer() == mergeTreeViewer) {
- EObject eContainer = getComparison().getMatch(referenceChange.getValue())
- .getRight().eContainer(); // XXX: use itemProvider.getParent().
- Match match2 = getComparison().getMatch(eContainer);
+ EObject eContainer = getEMFCompareConfiguration().getComparison().getMatch(
+ referenceChange.getValue()).getRight().eContainer(); // XXX: use
+ // itemProvider.getParent().
+ Match match2 = getEMFCompareConfiguration().getComparison().getMatch(eContainer);
if (match2.getLeft() != parent) {
IMergeViewerItem.Container container = new MergeViewerItem.Container(
- getComparison(), null, match2, MergeViewerSide.RIGHT, fAdapterFactory);
+ getEMFCompareConfiguration().getComparison(), null, match2,
+ MergeViewerSide.RIGHT, fAdapterFactory);
toBeExpanded.add(container);
}
} else if (getRightMergeViewer() == mergeTreeViewer) {
- EObject eContainer = getComparison().getMatch(referenceChange.getValue())
- .getLeft().eContainer(); // XXX: use itemProvider.getParent().
- Match match2 = getComparison().getMatch(eContainer);
+ EObject eContainer = getEMFCompareConfiguration().getComparison().getMatch(
+ referenceChange.getValue()).getLeft().eContainer(); // XXX: use
+ // itemProvider.getParent().
+ Match match2 = getEMFCompareConfiguration().getComparison().getMatch(eContainer);
if (match2.getRight() != parent) {
IMergeViewerItem.Container container = new MergeViewerItem.Container(
- getComparison(), null, match2, MergeViewerSide.LEFT, fAdapterFactory);
+ getEMFCompareConfiguration().getComparison(), null, match2,
+ MergeViewerSide.LEFT, fAdapterFactory);
toBeExpanded.add(container);
}
}

Back to the top