Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikaël Barbero2013-10-11 04:48:51 -0400
committerMikaël Barbero2013-10-18 13:47:37 -0400
commit91adf6af0b935d3067dc86f2a6a5eb295e336d6d (patch)
tree7f4d737bc078ee82fbe597b8c4a536239c00a24b /plugins/org.eclipse.emf.compare.ide.ui/src
parent1eb0c8efe5a3709f013e179a13fb221f207738f3 (diff)
downloadorg.eclipse.emf.compare-91adf6af0b935d3067dc86f2a6a5eb295e336d6d.tar.gz
org.eclipse.emf.compare-91adf6af0b935d3067dc86f2a6a5eb295e336d6d.tar.xz
org.eclipse.emf.compare-91adf6af0b935d3067dc86f2a6a5eb295e336d6d.zip
Use eventbus for IEMFCompareConfiguration.
It simplifies event handling a lot. Change-Id: I622ecee5fa94ffb9a8f20bd1c5175cdf64e1054f
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.java327
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/EMFCompareContentMergeViewer.java199
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/table/TableContentMergeViewer.java5
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/text/EMFCompareTextMergeViewer.java28
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/TreeContentMergeViewer.java13
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/editor/ComparisonScopeEditorInput.java2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/CompareToolBar.java162
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java66
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java97
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java132
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/DropDownMergeMenuAction.java31
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/ExpandAllModelAction.java2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/ExceptionUtil.java1
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/SWTUtil.java35
14 files changed, 470 insertions, 630 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
index 8f3e0d66a..42a905895 100644
--- 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
@@ -10,15 +10,11 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.configuration;
-import static com.google.common.base.Predicates.alwaysFalse;
-
import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+import com.google.common.eventbus.EventBus;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.Collection;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.emf.common.notify.AdapterFactory;
@@ -27,12 +23,17 @@ import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.domain.ICompareEditingDomain;
import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
import org.eclipse.emf.compare.internal.merge.MergeMode;
+import org.eclipse.emf.compare.rcp.ui.EMFCompareRCPUIPlugin;
import org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration;
-import org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfigurationChangeListener;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.impl.CompareEditingDomainChange;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.impl.ComparisonAndScopeChange;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.impl.EMFComparatorChange;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.impl.MergePreviewModeChange;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
+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.StructureMergeViewerGrouper;
import org.eclipse.emf.compare.scope.IComparisonScope;
-import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
@@ -49,27 +50,16 @@ public class EMFCompareConfiguration extends ForwardingCompareConfiguration impl
private static final String ADAPTER_FACTORY = EMFCompareIDEUIPlugin.PLUGIN_ID + ".ADAPTER_FACTORY"; //$NON-NLS-1$
- private static final String SELECTED_DIFFERENCE_FILTERS = EMFCompareIDEUIPlugin.PLUGIN_ID
- + ".SELECTED_DIFFERENCE_FILTERS"; //$NON-NLS-1$
-
- private static final Set<IDifferenceFilter> SELECTED_DIFFERENCE_FILTERS__DEFAULT_VALUE = ImmutableSet
- .of();
-
- private static final String AGGREGATED_VIEWER_PREDICATE = EMFCompareIDEUIPlugin.PLUGIN_ID
- + ".AGGREGATED_VIEWER_PREDICATE"; //$NON-NLS-1$
-
- private static final Predicate<? super EObject> AGGREGATED_VIEWER_PREDICATE__DEFAULT_VALUE = alwaysFalse();
-
- private static final String SELECTED_DIFFERENCE_GROUP_PROVIDER = EMFCompareIDEUIPlugin.PLUGIN_ID
- + ".SELECTED_DIFFERENCE_GROUP_PROVIDER"; //$NON-NLS-1$
-
- private static final IDifferenceGroupProvider SELECTED_DIFFERENCE_GROUP_PROVIDER__DEFAULT_VALUE = IDifferenceGroupProvider.EMPTY;
-
private static final String PREVIEW_MERGE_MODE = EMFCompareIDEUIPlugin.PLUGIN_ID + ".PREVIEW_MERGE_MODE"; //$NON-NLS-1$
private static final String COMPARISON_SCOPE = EMFCompareIDEUIPlugin.PLUGIN_ID + ".COMPARISON_SCOPE"; //$NON-NLS-1$;
- private final List<IEMFCompareConfigurationChangeListener> listeners;
+ private static final String SMV_FILTERS = EMFCompareIDEUIPlugin.PLUGIN_ID + ".SMV_FILTERS"; //$NON-NLS-1$;
+
+ private static final String EVENT_BUS = EMFCompareIDEUIPlugin.PLUGIN_ID + ".EVENT_BUS"; //$NON-NLS-1$;
+
+ private static final String SMV_GROUP_PROVIDERS = EMFCompareIDEUIPlugin.PLUGIN_ID
+ + ".SMV_GROUP_PROVIDERS"; //$NON-NLS-1$;
private final PropertyChangeListener propertyChangeListener;
@@ -78,37 +68,43 @@ public class EMFCompareConfiguration extends ForwardingCompareConfiguration impl
public EMFCompareConfiguration(CompareConfiguration compareConfiguration) {
this.compareConfiguration = compareConfiguration;
setDefaultValues();
- listeners = new CopyOnWriteArrayList<IEMFCompareConfigurationChangeListener>();
propertyChangeListener = new PropertyChangeListener();
compareConfiguration.addPropertyChangeListener(propertyChangeListener);
}
- public void setDefaultValues() {
- if (compareConfiguration.getProperty(AGGREGATED_VIEWER_PREDICATE) == null) {
- compareConfiguration.setProperty(AGGREGATED_VIEWER_PREDICATE,
- AGGREGATED_VIEWER_PREDICATE__DEFAULT_VALUE);
+ private void setDefaultValues() {
+ if (isLeftEditable() && isRightEditable()) {
+ setProperty(PREVIEW_MERGE_MODE, MergeMode.RIGHT_TO_LEFT);
+ } else {
+ setProperty(PREVIEW_MERGE_MODE, MergeMode.ACCEPT);
}
- if (compareConfiguration.getProperty(SELECTED_DIFFERENCE_FILTERS) == null) {
- compareConfiguration.setProperty(SELECTED_DIFFERENCE_FILTERS,
- SELECTED_DIFFERENCE_FILTERS__DEFAULT_VALUE);
+ EventBus eventBus = new EventBus();
+ if (getProperty(SMV_FILTERS) == null) {
+ setProperty(SMV_FILTERS, new StructureMergeViewerFilter(eventBus));
}
- if (compareConfiguration.getProperty(SELECTED_DIFFERENCE_GROUP_PROVIDER) == null) {
- compareConfiguration.setProperty(SELECTED_DIFFERENCE_GROUP_PROVIDER,
- SELECTED_DIFFERENCE_GROUP_PROVIDER__DEFAULT_VALUE);
+ if (getProperty(SMV_GROUP_PROVIDERS) == null) {
+ setProperty(SMV_GROUP_PROVIDERS, new StructureMergeViewerGrouper(eventBus));
}
- if (compareConfiguration.isLeftEditable() && compareConfiguration.isRightEditable()) {
- compareConfiguration.setProperty(PREVIEW_MERGE_MODE, MergeMode.RIGHT_TO_LEFT);
- } else {
- compareConfiguration.setProperty(PREVIEW_MERGE_MODE, MergeMode.ACCEPT);
+ if (getProperty(EVENT_BUS) == null) {
+ setProperty(EVENT_BUS, eventBus);
}
}
/**
* {@inheritDoc}
*
+ * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#getEventBus()
+ */
+ public EventBus getEventBus() {
+ return (EventBus)getProperty(EVENT_BUS);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.eclipse.emf.compare.ide.ui.internal.configuration.ForwardingCompareConfiguration#delegate()
*/
@Override
@@ -127,228 +123,135 @@ public class EMFCompareConfiguration extends ForwardingCompareConfiguration impl
compareConfiguration.removePropertyChangeListener(propertyChangeListener);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#addChangeListener(org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfigurationChangeListener)
- */
- public void addChangeListener(IEMFCompareConfigurationChangeListener listener) {
- listeners.add(listener);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#removeChangeListener(org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfigurationChangeListener)
- */
- public void removeChangeListener(IEMFCompareConfigurationChangeListener listener) {
- listeners.remove(listener);
+ public boolean getBooleanProperty(String key, boolean dflt) {
+ final boolean ret;
+ Object value = getProperty(key);
+ if (value instanceof Boolean) {
+ ret = ((Boolean)value).booleanValue();
+ } else {
+ ret = dflt;
+ }
+ return ret;
}
public Comparison getComparison() {
return (Comparison)getProperty(COMPARE_RESULT);
}
- public void setComparison(Comparison comparison) {
- setProperty(COMPARE_RESULT, comparison);
- }
-
- public EMFCompare getComparator() {
+ public EMFCompare getEMFComparator() {
return (EMFCompare)getProperty(COMPARATOR);
}
- public void setComparator(EMFCompare comparator) {
- setProperty(COMPARATOR, comparator);
- }
-
public ICompareEditingDomain getEditingDomain() {
return (ICompareEditingDomain)getProperty(EDITING_DOMAIN);
}
- public void setEditingDomain(ICompareEditingDomain editingDomain) {
- setProperty(EDITING_DOMAIN, editingDomain);
+ public MergeMode getMergePreviewMode() {
+ return (MergeMode)getProperty(PREVIEW_MERGE_MODE);
}
- @SuppressWarnings("unchecked")
- public Set<IDifferenceFilter> getSelectedDifferenceFilters() {
- return (Set<IDifferenceFilter>)getProperty(SELECTED_DIFFERENCE_FILTERS);
+ public AdapterFactory getAdapterFactory() {
+ return (AdapterFactory)getProperty(ADAPTER_FACTORY);
}
- public void setSelectedDifferenceFilters(Set<IDifferenceFilter> differenceFilters) {
- Preconditions.checkNotNull(differenceFilters);
- setProperty(SELECTED_DIFFERENCE_FILTERS, differenceFilters);
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#getComparisonScope()
+ */
+ public IComparisonScope getComparisonScope() {
+ return (IComparisonScope)getProperty(COMPARISON_SCOPE);
}
- @SuppressWarnings("unchecked")
- public Predicate<? super EObject> getAggregatedViewerPredicate() {
- return (Predicate<? super EObject>)getProperty(AGGREGATED_VIEWER_PREDICATE);
+ public void setEMFComparator(EMFCompare newComparator) {
+ EMFCompare oldComparator = getEMFComparator();
+ setProperty(COMPARATOR, oldComparator);
+ getEventBus().post(new EMFComparatorChange(oldComparator, newComparator));
}
- public void setAggregatedViewerPredicate(Predicate<? super EObject> predicate) {
- Preconditions.checkNotNull(predicate);
- setProperty(AGGREGATED_VIEWER_PREDICATE, predicate);
+ public void setEditingDomain(ICompareEditingDomain newValue) {
+ ICompareEditingDomain oldValue = getEditingDomain();
+ setProperty(EDITING_DOMAIN, newValue);
+ getEventBus().post(new CompareEditingDomainChange(oldValue, newValue));
}
- public IDifferenceGroupProvider getSelectedDifferenceGroupProvider() {
- return (IDifferenceGroupProvider)getProperty(SELECTED_DIFFERENCE_GROUP_PROVIDER);
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#setComparisonAndScope(org.eclipse.emf.compare.scope.IComparisonScope,
+ * org.eclipse.emf.compare.Comparison)
+ */
+ public void setComparisonAndScope(Comparison newComparison, IComparisonScope newComparisonScope) {
+ Comparison oldComparison = getComparison();
+ IComparisonScope oldComparisonScope = getComparisonScope();
+ setProperty(COMPARE_RESULT, newComparison);
+ setProperty(COMPARISON_SCOPE, newComparisonScope);
+
+ initStructureMergeViewerFilter(newComparison, newComparisonScope);
+ initStructureMergeViewerGroupProvider(newComparison, newComparisonScope);
+
+ getEventBus().post(
+ new ComparisonAndScopeChange(oldComparison, newComparison, oldComparisonScope,
+ newComparisonScope));
}
- public void setSelectedDifferenceGroupProvider(IDifferenceGroupProvider groupProvider) {
- Preconditions.checkNotNull(groupProvider);
- setProperty(SELECTED_DIFFERENCE_GROUP_PROVIDER, groupProvider);
+ protected void initStructureMergeViewerGroupProvider(Comparison comparison,
+ IComparisonScope comparisonScope) {
+ EMFCompareRCPUIPlugin plugin = EMFCompareRCPUIPlugin.getDefault();
+ IDifferenceGroupProvider.Registry groupProviderRegistry = plugin.getDifferenceGroupProviderRegistry();
+ getStructureMergeViewerGrouper().setProvider(
+ groupProviderRegistry.getDefaultGroupProviders(comparisonScope, comparison));
}
- public MergeMode getMergePreviewMode() {
- return (MergeMode)getProperty(PREVIEW_MERGE_MODE);
+ protected void initStructureMergeViewerFilter(Comparison comparison, IComparisonScope comparisonScope) {
+ EMFCompareRCPUIPlugin plugin = EMFCompareRCPUIPlugin.getDefault();
+ IDifferenceFilter.Registry filterRegistry = plugin.getDifferenceFilterRegistry();
+ Collection<IDifferenceFilter> filters = filterRegistry.getFilters(comparisonScope, comparison);
+ Collection<IDifferenceFilter> selectedFilters = Lists.newArrayList();
+ Collection<IDifferenceFilter> unselectedFilters = Lists.newArrayList();
+ for (IDifferenceFilter filter : filters) {
+ if (filter.defaultSelected()) {
+ selectedFilters.add(filter);
+ } else {
+ unselectedFilters.add(filter);
+ }
+ }
+ getStructureMergeViewerFilter().init(selectedFilters, unselectedFilters);
}
public void setMergePreviewMode(MergeMode previewMergeMode) {
Preconditions.checkNotNull(previewMergeMode);
+ MergeMode oldValue = getMergePreviewMode();
setProperty(PREVIEW_MERGE_MODE, previewMergeMode);
- }
-
- public AdapterFactory getAdapterFactory() {
- return (AdapterFactory)getProperty(ADAPTER_FACTORY);
+ getEventBus().post(new MergePreviewModeChange(oldValue, previewMergeMode));
}
public void setAdapterFactory(AdapterFactory adapterFactory) {
setProperty(ADAPTER_FACTORY, adapterFactory);
}
- public boolean getBooleanProperty(String key, boolean dflt) {
- final boolean ret;
- Object value = getProperty(key);
- if (value instanceof Boolean) {
- ret = ((Boolean)value).booleanValue();
- } else {
- ret = dflt;
+ private class PropertyChangeListener implements IPropertyChangeListener {
+ public void propertyChange(PropertyChangeEvent event) {
+ fireChange(event.getProperty(), event.getOldValue(), event.getNewValue());
}
- return ret;
}
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#getComparisonScope()
+ * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#getStructureMergeViewerGrouper()
*/
- public IComparisonScope getComparisonScope() {
- return (IComparisonScope)getProperty(COMPARISON_SCOPE);
+ public StructureMergeViewerGrouper getStructureMergeViewerGrouper() {
+ return (StructureMergeViewerGrouper)getProperty(SMV_GROUP_PROVIDERS);
}
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#setComparisonScope(org.eclipse.emf.compare.scope.IComparisonScope)
+ * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration#getStructureMergeViewerFilter()
*/
- public void setComparisonScope(IComparisonScope comparisonScope) {
- setProperty(COMPARISON_SCOPE, comparisonScope);
- }
-
- private class PropertyChangeListener implements IPropertyChangeListener {
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent event) {
- String property = event.getProperty();
- if (EDITING_DOMAIN.equals(property)) {
- handleEditingDomainChange(event);
- } else if (SELECTED_DIFFERENCE_GROUP_PROVIDER.equals(property)) {
- handleSelectedDifferenceGroupProviderChanger(event);
- } else if (SELECTED_DIFFERENCE_FILTERS.equals(property)) {
- handleSelectedDifferenceFiltersChange(event);
- } else if (AGGREGATED_VIEWER_PREDICATE.equals(property)) {
- handleAggregatedViewerPredicateChange(event);
- } else if (COMPARE_RESULT.equals(property)) {
- handleComparisonChange(event);
- } else if (ADAPTER_FACTORY.equals(property)) {
- handleAdapterFactoryChange(event);
- } else if (COMPARATOR.equals(property)) {
- handleComparatorChange(event);
- } else if (PREVIEW_MERGE_MODE.equals(property)) {
- handlePreviewMergeModeChange(event);
- } else if (COMPARISON_SCOPE.equals(property)) {
- handleComparisonScopeChange(event);
- } else {
- fireChange(property, event.getOldValue(), event.getNewValue());
- }
- }
-
- protected void handleAdapterFactoryChange(PropertyChangeEvent event) {
- AdapterFactory oldValue = (AdapterFactory)event.getOldValue();
- AdapterFactory newValue = (AdapterFactory)event.getNewValue();
- for (IEMFCompareConfigurationChangeListener listener : listeners) {
- listener.adapterFactoryChange(oldValue, newValue);
- }
- }
-
- protected void handleComparisonChange(PropertyChangeEvent event) {
- Comparison oldValue = (Comparison)event.getOldValue();
- Comparison newValue = (Comparison)event.getNewValue();
- for (IEMFCompareConfigurationChangeListener listener : listeners) {
- listener.comparisonChange(oldValue, newValue);
- }
- }
-
- @SuppressWarnings("unchecked")
- protected void handleAggregatedViewerPredicateChange(PropertyChangeEvent event) {
- Predicate<? super EObject> oldValue = (Predicate<? super EObject>)event.getOldValue();
- Predicate<? super EObject> newValue = (Predicate<? super EObject>)event.getNewValue();
- for (IEMFCompareConfigurationChangeListener listener : listeners) {
- listener.aggregatedViewerPredicateChange(oldValue, newValue);
- }
- }
-
- @SuppressWarnings("unchecked")
- protected void handleSelectedDifferenceFiltersChange(PropertyChangeEvent event) {
- Set<IDifferenceFilter> oldValue = (Set<IDifferenceFilter>)event.getOldValue();
- Set<IDifferenceFilter> newValue = (Set<IDifferenceFilter>)event.getNewValue();
- for (IEMFCompareConfigurationChangeListener listener : listeners) {
- listener.selectedDifferenceFiltersChange(oldValue, newValue);
- }
- }
-
- protected void handleSelectedDifferenceGroupProviderChanger(PropertyChangeEvent event) {
- IDifferenceGroupProvider oldValue = (IDifferenceGroupProvider)event.getOldValue();
- IDifferenceGroupProvider newValue = (IDifferenceGroupProvider)event.getNewValue();
- for (IEMFCompareConfigurationChangeListener listener : listeners) {
- listener.selectedDifferenceGroupProviderChange(oldValue, newValue);
- }
- }
-
- protected void handleEditingDomainChange(PropertyChangeEvent event) {
- ICompareEditingDomain oldValue = (ICompareEditingDomain)event.getOldValue();
- ICompareEditingDomain newValue = (ICompareEditingDomain)event.getNewValue();
- for (IEMFCompareConfigurationChangeListener listener : listeners) {
- listener.editingDomainChange(oldValue, newValue);
- }
- }
-
- protected void handleComparatorChange(PropertyChangeEvent event) {
- EMFCompare oldValue = (EMFCompare)event.getOldValue();
- EMFCompare newValue = (EMFCompare)event.getNewValue();
- for (IEMFCompareConfigurationChangeListener listener : listeners) {
- listener.comparatorChange(oldValue, newValue);
- }
- }
-
- protected void handlePreviewMergeModeChange(PropertyChangeEvent event) {
- MergeMode oldValue = (MergeMode)event.getOldValue();
- MergeMode newValue = (MergeMode)event.getNewValue();
- for (IEMFCompareConfigurationChangeListener listener : listeners) {
- listener.mergePreviewModeChange(oldValue, newValue);
- }
- }
-
- protected void handleComparisonScopeChange(PropertyChangeEvent event) {
- IComparisonScope oldValue = (IComparisonScope)event.getOldValue();
- IComparisonScope newValue = (IComparisonScope)event.getNewValue();
- for (IEMFCompareConfigurationChangeListener listener : listeners) {
- listener.comparisonScopeChange(oldValue, newValue);
- }
- }
+ public StructureMergeViewerFilter getStructureMergeViewerFilter() {
+ return (StructureMergeViewerFilter)getProperty(SMV_FILTERS);
}
}
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 3a9a9ec6f..05faed21f 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
@@ -14,13 +14,13 @@ import static com.google.common.collect.Iterables.filter;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
+import com.google.common.eventbus.Subscribe;
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.contentmergeviewer.ContentMergeViewer;
@@ -39,17 +39,19 @@ import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.DynamicOb
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.configuration.EMFCompareConfigurationChangeListener;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.IAdapterFactoryChange;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.ICompareEditingDomainChange;
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;
import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.IMergeViewer.MergeViewerSide;
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.IDifferenceFilterChange;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
+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.compare.utils.EMFComparePredicates;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
@@ -85,97 +87,6 @@ import org.eclipse.ui.views.properties.PropertySheet;
*/
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 EMFCompareContentMergerViewerConfigurationListener extends EMFCompareConfigurationChangeListener {
-
- /**
- * {@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) {
- 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) {
- 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) {
- 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) {
- 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) {
- if (oldValue != null) {
- fAdapterFactoryContentProvider.dispose();
- }
- if (newValue != oldValue) {
- fAdapterFactoryContentProvider = new AdapterFactoryContentProvider(newValue);
- }
- }
- }
-
private static final String HANDLER_SERVICE = "fHandlerService";
/**
@@ -201,7 +112,9 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
private AdapterFactoryContentProvider fAdapterFactoryContentProvider;
- private final EMFCompareContentMergerViewerConfigurationListener configurationListener;
+ private Predicate<? super EObject> differenceFilterPredicate;
+
+ private IDifferenceGroupProvider differenceGroupProvider;
/**
* @param style
@@ -218,8 +131,87 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
.getAdapterFactory());
}
- configurationListener = new EMFCompareContentMergerViewerConfigurationListener();
- getCompareConfiguration().addChangeListener(configurationListener);
+ editingDomainChange(null, getCompareConfiguration().getEditingDomain());
+ getCompareConfiguration().getEventBus().register(this);
+ }
+
+ @Subscribe
+ public void handleAdapterFactoryChange(IAdapterFactoryChange event) {
+ AdapterFactory oldValue = event.getOldValue();
+ AdapterFactory newValue = event.getNewValue();
+ if (oldValue != null) {
+ fAdapterFactoryContentProvider.dispose();
+ }
+ if (newValue != oldValue) {
+ fAdapterFactoryContentProvider = new AdapterFactoryContentProvider(newValue);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration#editingDomainChange(org.eclipse.emf.compare.domain.ICompareEditingDomain,
+ * org.eclipse.emf.compare.domain.ICompareEditingDomain)
+ */
+ @Subscribe
+ public void handleEditingDomainChange(ICompareEditingDomainChange event) {
+ ICompareEditingDomain oldValue = event.getOldValue();
+ ICompareEditingDomain newValue = event.getNewValue();
+ editingDomainChange(oldValue, newValue);
+ }
+
+ protected void editingDomainChange(ICompareEditingDomain oldValue, ICompareEditingDomain newValue) {
+ if (newValue != oldValue) {
+ if (oldValue != null) {
+ oldValue.getCommandStack().removeCommandStackListener(this);
+ }
+
+ 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);
+ }
+ }
+ }
+
+ @Subscribe
+ public void handleDifferenceFiltersChange(IDifferenceFilterChange event) {
+ differenceFilterPredicate = event.getPredicate();
+ redrawCenterControl();
+ }
+
+ /**
+ * @return the differenceFilterPredicate
+ */
+ protected final Predicate<? super EObject> getDifferenceFilterPredicate() {
+ if (differenceFilterPredicate == null) {
+ differenceFilterPredicate = getCompareConfiguration().getStructureMergeViewerFilter()
+ .getAggregatedPredicate();
+ }
+ return differenceFilterPredicate;
+ }
+
+ @Subscribe
+ public void handleDifferenceGroupProviderChange(IDifferenceGroupProviderChange event) {
+ differenceGroupProvider = event.getDifferenceGroupProvider();
+ redrawCenterControl();
+ }
+
+ /**
+ * @return the differenceGroupProvider
+ */
+ protected final IDifferenceGroupProvider getDifferenceGroupProvider() {
+ if (differenceGroupProvider == null) {
+ differenceGroupProvider = getCompareConfiguration().getStructureMergeViewerGrouper()
+ .getProvider();
+ }
+ return differenceGroupProvider;
}
/**
@@ -332,11 +324,7 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
setRightDirty(getCompareConfiguration().getEditingDomain().getCommandStack().isRightSaveNeeded());
}
- SWTUtil.safeAsyncExec(new Runnable() {
- public void run() {
- refresh();
- }
- });
+ SWTUtil.safeRefresh(this, true);
}
/**
@@ -641,13 +629,14 @@ public abstract class EMFCompareContentMergeViewer extends ContentMergeViewer im
*/
@Override
protected void handleDispose(DisposeEvent event) {
- getCompareConfiguration().removeChangeListener(configurationListener);
+ editingDomainChange(getCompareConfiguration().getEditingDomain(), null);
+ getCompareConfiguration().getEventBus().unregister(this);
super.handleDispose(event);
}
protected final void redrawCenterControl() {
if (getCenterControl() != null) {
- getCenterControl().redraw();
+ SWTUtil.safeRedraw(getCenterControl(), true);
}
}
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 701f65233..757669136 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
@@ -277,9 +277,8 @@ public class TableContentMergeViewer extends EMFCompareContentMergeViewer {
final Diff leftDiff = ((IMergeViewerItem)leftItem.getData()).getDiff();
boolean doPaint = true;
if (leftDiff != null) {
- if (MergeViewerUtil.isVisibleInMergeViewer(leftDiff, getCompareConfiguration()
- .getSelectedDifferenceGroupProvider(), getCompareConfiguration()
- .getAggregatedViewerPredicate())) {
+ if (MergeViewerUtil.isVisibleInMergeViewer(leftDiff, getDifferenceGroupProvider(),
+ getDifferenceFilterPredicate())) {
TableItem rightItem = findRightTableItemFromLeftDiff(rightItems, leftDiff, leftData);
if (rightItem != null) {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/text/EMFCompareTextMergeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/text/EMFCompareTextMergeViewer.java
index 13cceb182..c10e9f611 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/text/EMFCompareTextMergeViewer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/text/EMFCompareTextMergeViewer.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.text;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableSet;
+import com.google.common.eventbus.Subscribe;
import com.google.common.io.ByteStreams;
import com.google.common.io.Closeables;
@@ -51,8 +52,8 @@ import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.DynamicOb
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.RedoAction;
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.UndoAction;
import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.CompareInputAdapter;
-import org.eclipse.emf.compare.ide.ui.internal.util.SWTUtil;
-import org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.ICompareEditingDomainChange;
+import org.eclipse.emf.compare.rcp.ui.internal.util.SWTUtil;
import org.eclipse.emf.compare.utils.IEqualityHelper;
import org.eclipse.emf.compare.utils.ReferenceUtil;
import org.eclipse.emf.ecore.EAttribute;
@@ -91,15 +92,6 @@ public class EMFCompareTextMergeViewer extends TextMergeViewer implements Comman
private final ScheduledExecutorService fExecutorService;
- private final ConfigurationChangeListener configurationChangeListener;
-
- private class ConfigurationChangeListener extends EMFCompareConfigurationChangeListener {
- @Override
- public void editingDomainChange(ICompareEditingDomain oldValue, ICompareEditingDomain newValue) {
- EMFCompareTextMergeViewer.this.editingDomainChange(oldValue, newValue);
- }
- }
-
/**
* @param parent
* @param configuration
@@ -113,8 +105,7 @@ public class EMFCompareTextMergeViewer extends TextMergeViewer implements Comman
editingDomainChange(null, configuration.getEditingDomain());
- configurationChangeListener = new ConfigurationChangeListener();
- configuration.addChangeListener(configurationChangeListener);
+ configuration.getEventBus().register(this);
}
/**
@@ -137,7 +128,14 @@ public class EMFCompareTextMergeViewer extends TextMergeViewer implements Comman
* @param oldValue
* @param newValue
*/
- protected void editingDomainChange(ICompareEditingDomain oldValue, ICompareEditingDomain newValue) {
+ @Subscribe
+ public void editingDomainChange(ICompareEditingDomainChange event) {
+ ICompareEditingDomain oldValue = event.getOldValue();
+ ICompareEditingDomain newValue = event.getNewValue();
+ editingDomainChange(oldValue, newValue);
+ }
+
+ public void editingDomainChange(ICompareEditingDomain oldValue, ICompareEditingDomain newValue) {
if (oldValue != null) {
oldValue.getCommandStack().removeCommandStackListener(this);
}
@@ -456,7 +454,7 @@ public class EMFCompareTextMergeViewer extends TextMergeViewer implements Comman
}
fExecutorService.shutdown();
- getCompareConfiguration().removeChangeListener(configurationChangeListener);
+ getCompareConfiguration().getEventBus().unregister(this);
editingDomainChange(getCompareConfiguration().getEditingDomain(), null);
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 ac5eb93ca..f34368937 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
@@ -207,8 +207,7 @@ public class TreeContentMergeViewer extends EMFCompareContentMergeViewer {
public Object[] getChildren(Object object) {
if (object instanceof IMergeViewerItem.Container) {
IMergeViewerItem[] children = ((IMergeViewerItem.Container)object).getChildren(
- getCompareConfiguration().getSelectedDifferenceGroupProvider(),
- getCompareConfiguration().getAggregatedViewerPredicate());
+ getDifferenceGroupProvider(), getDifferenceFilterPredicate());
return children;
}
@@ -223,9 +222,8 @@ public class TreeContentMergeViewer extends EMFCompareContentMergeViewer {
@Override
public boolean hasChildren(Object object) {
if (object instanceof IMergeViewerItem.Container) {
- return ((IMergeViewerItem.Container)object).hasChildren(getCompareConfiguration()
- .getSelectedDifferenceGroupProvider(), getCompareConfiguration()
- .getAggregatedViewerPredicate());
+ return ((IMergeViewerItem.Container)object).hasChildren(getDifferenceGroupProvider(),
+ getDifferenceFilterPredicate());
}
return super.hasChildren(object);
}
@@ -353,9 +351,8 @@ public class TreeContentMergeViewer extends EMFCompareContentMergeViewer {
IMergeViewerItem leftData = (IMergeViewerItem)leftItem.getData();
final Diff leftDiff = leftData.getDiff();
if (leftDiff != null) {
- if (MergeViewerUtil.isVisibleInMergeViewer(leftDiff, getCompareConfiguration()
- .getSelectedDifferenceGroupProvider(), getCompareConfiguration()
- .getAggregatedViewerPredicate())) {
+ if (MergeViewerUtil.isVisibleInMergeViewer(leftDiff, getDifferenceGroupProvider(),
+ getDifferenceFilterPredicate())) {
TreeItem rightItem = findRightTreeItemFromLeftDiff(rightItems, leftDiff, leftData);
if (rightItem != null) {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/editor/ComparisonScopeEditorInput.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/editor/ComparisonScopeEditorInput.java
index 282f51632..87e20457d 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/editor/ComparisonScopeEditorInput.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/editor/ComparisonScopeEditorInput.java
@@ -50,7 +50,7 @@ public class ComparisonScopeEditorInput extends AbstractEMFCompareEditorInput {
@Override
protected Object doPrepareInput(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
- getCompareConfiguration().setComparator(comparator);
+ getCompareConfiguration().setEMFComparator(comparator);
return new ComparisonScopeInput(scope, getAdapterFactory());
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/CompareToolBar.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/CompareToolBar.java
index 025f8bf25..9501178ae 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/CompareToolBar.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/CompareToolBar.java
@@ -14,12 +14,11 @@ import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Lists.newArrayListWithCapacity;
+import com.google.common.eventbus.Subscribe;
+
import java.util.EnumSet;
import java.util.List;
-import java.util.Set;
-import org.eclipse.emf.compare.Comparison;
-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.structuremergeviewer.actions.CollapseAllModelAction;
import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.DropDownMergeMenuAction;
@@ -29,22 +28,24 @@ import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.Merg
import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.SaveComparisonModelAction;
import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.SelectNextDiffAction;
import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.SelectPreviousDiffAction;
-import org.eclipse.emf.compare.ide.ui.internal.util.SWTUtil;
import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.merge.IMerger;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
-import org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener;
+import org.eclipse.emf.compare.rcp.ui.EMFCompareRCPUIPlugin;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.ICompareEditingDomainChange;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.IComparisonAndScopeChange;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.actions.FilterActionMenu;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.actions.GroupActionMenu;
-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.structuremergeviewer.filters.StructureMergeViewerFilter;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.impl.CascadingDifferencesFilter;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.StructureMergeViewerGrouper;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl.DefaultGroupProvider;
-import org.eclipse.emf.compare.scope.IComparisonScope;
+import org.eclipse.emf.compare.rcp.ui.internal.util.SWTUtil;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.menus.IMenuService;
import org.eclipse.ui.services.IServiceLocator;
@@ -52,44 +53,46 @@ import org.eclipse.ui.services.IServiceLocator;
/**
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
*/
-public class CompareToolBar {
+public class CompareToolBar implements ISelectionChangedListener {
private final GroupActionMenu groupActionMenu;
private final FilterActionMenu filterActionMenu;
- private final List<MergeAction> mergeActions = newArrayListWithCapacity(2);
-
- private final List<MergeAllNonConflictingAction> mergeAllNonConflictingActions = newArrayListWithCapacity(2);
+ private final List<MergeAction> mergeActions;
- private final CompareConfigurationListener configurationChangeListener;
+ private final List<MergeAllNonConflictingAction> mergeAllNonConflictingActions;
private final EMFCompareConfiguration compareConfiguration;
- private final AbstractTreeViewer viewer;
-
/**
*
*/
- public CompareToolBar(AbstractTreeViewer viewer, ToolBarManager toolbarManager,
- StructureMergeViewerGrouper viewerGrouper, StructureMergeViewerFilter viewerFilter,
+ public CompareToolBar(StructureMergeViewerGrouper viewerGrouper, StructureMergeViewerFilter viewerFilter,
EMFCompareConfiguration compareConfiguration) {
- this.viewer = viewer;
this.compareConfiguration = compareConfiguration;
+ mergeActions = newArrayListWithCapacity(2);
+ mergeAllNonConflictingActions = newArrayListWithCapacity(2);
+
+ groupActionMenu = new GroupActionMenu(viewerGrouper, EMFCompareRCPUIPlugin.getDefault()
+ .getDifferenceGroupProviderRegistry());
+
+ filterActionMenu = new FilterActionMenu(viewerFilter, EMFCompareRCPUIPlugin.getDefault()
+ .getDifferenceFilterRegistry());
+ }
+
+ public final void initToolbar(ToolBarManager toolbarManager, AbstractTreeViewer viewer) {
+ compareConfiguration.getEventBus().register(this);
+
// Add extension point contributions to the structure merge viewer toolbar
IServiceLocator workbench = PlatformUI.getWorkbench();
+
IMenuService menuService = (IMenuService)workbench.getService(IMenuService.class);
if (menuService != null) {
menuService.populateContributionManager(toolbarManager,
"toolbar:org.eclipse.emf.compare.structuremergeviewer.toolbar");
}
- configurationChangeListener = new CompareConfigurationListener();
- compareConfiguration.addChangeListener(configurationChangeListener);
-
- groupActionMenu = new GroupActionMenu(viewerGrouper, new DefaultGroupProvider());
- filterActionMenu = new FilterActionMenu(viewerFilter);
-
boolean leftEditable = compareConfiguration.isLeftEditable();
boolean rightEditable = compareConfiguration.isRightEditable();
@@ -102,10 +105,10 @@ public class CompareToolBar {
toolbarManager.add(new DropDownMergeMenuAction(compareConfiguration, modes));
for (MergeMode mode : modes) {
- toolbarManager.add(createMergeAction(mode));
+ toolbarManager.add(createMergeAction(mode, compareConfiguration));
}
for (MergeMode mode : modes) {
- toolbarManager.add(createMergeAllNonConflictingAction(mode));
+ toolbarManager.add(createMergeAllNonConflictingAction(mode, compareConfiguration));
}
toolbarManager.add(new Separator());
@@ -116,105 +119,80 @@ public class CompareToolBar {
toolbarManager.add(new CollapseAllModelAction(viewer));
toolbarManager.add(new Separator());
toolbarManager.add(groupActionMenu);
+ groupActionMenu.updateMenu(compareConfiguration.getComparisonScope(), compareConfiguration
+ .getComparison());
toolbarManager.add(filterActionMenu);
+ filterActionMenu.updateMenu(compareConfiguration.getComparisonScope(), compareConfiguration
+ .getComparison());
toolbarManager.add(new Separator());
toolbarManager.add(new SaveComparisonModelAction(compareConfiguration));
toolbarManager.update(true);
}
- private MergeAction createMergeAction(MergeMode mergeMode) {
- EMFCompareConfiguration cc = compareConfiguration;
+ private MergeAction createMergeAction(MergeMode mergeMode, EMFCompareConfiguration cc) {
IMerger.Registry mergerRegistry = EMFCompareRCPPlugin.getDefault().getMergerRegistry();
MergeAction mergeAction = new MergeAction(cc.getEditingDomain(), mergerRegistry, mergeMode, cc
.isLeftEditable(), cc.isRightEditable());
- viewer.addSelectionChangedListener(mergeAction);
mergeActions.add(mergeAction);
return mergeAction;
}
- private MergeAction createMergeAllNonConflictingAction(MergeMode mergeMode) {
- EMFCompareConfiguration cc = compareConfiguration;
+ private MergeAction createMergeAllNonConflictingAction(MergeMode mergeMode, EMFCompareConfiguration cc) {
IMerger.Registry mergerRegistry = EMFCompareRCPPlugin.getDefault().getMergerRegistry();
MergeAllNonConflictingAction mergeAction = new MergeAllNonConflictingAction(cc.getEditingDomain(), cc
.getComparison(), mergerRegistry, mergeMode, cc.isLeftEditable(), cc.isRightEditable());
- viewer.addSelectionChangedListener(mergeAction);
mergeAllNonConflictingActions.add(mergeAction);
return mergeAction;
}
public void dispose() {
- compareConfiguration.addChangeListener(configurationChangeListener);
+ compareConfiguration.getEventBus().unregister(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+ // forward event to merge actions
+
for (MergeAction mergeAction : mergeActions) {
- viewer.removeSelectionChangedListener(mergeAction);
+ mergeAction.selectionChanged(event);
}
for (MergeAllNonConflictingAction mergeAllNonConflictingAction : mergeAllNonConflictingActions) {
- viewer.removeSelectionChangedListener(mergeAllNonConflictingAction);
+ mergeAllNonConflictingAction.selectionChanged(event);
}
}
- private class CompareConfigurationListener extends EMFCompareConfigurationChangeListener {
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener#editingDomainChange(org.eclipse.emf.compare.domain.ICompareEditingDomain,
- * org.eclipse.emf.compare.domain.ICompareEditingDomain)
- */
- @Override
- public void editingDomainChange(ICompareEditingDomain oldValue, ICompareEditingDomain newValue) {
- for (MergeAction mergeAction : mergeActions) {
- mergeAction.setEditingDomain(newValue);
- }
+ @Subscribe
+ public void editingDomainChange(ICompareEditingDomainChange event) {
+ for (MergeAction mergeAction : mergeActions) {
+ mergeAction.setEditingDomain(event.getNewValue());
}
+ }
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener#selectedDifferenceFiltersChange(java.util.Set,
- * java.util.Set)
- */
- @Override
- public void selectedDifferenceFiltersChange(Set<IDifferenceFilter> oldValue,
- Set<IDifferenceFilter> newValue) {
- final boolean enabled = any(newValue, instanceOf(CascadingDifferencesFilter.class));
- for (MergeAction mergeAction : mergeActions) {
- mergeAction.setCascadingDifferencesFilterEnabled(enabled);
- }
+ @Subscribe
+ public void selectedDifferenceFiltersChange(IDifferenceFilterChange event) {
+ final boolean enabled = any(event.getSelectedDifferenceFilters(),
+ instanceOf(CascadingDifferencesFilter.class));
+ for (MergeAction mergeAction : mergeActions) {
+ mergeAction.setCascadingDifferencesFilterEnabled(enabled);
}
+ }
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener#comparisonChange(org.eclipse.emf.compare.Comparison,
- * org.eclipse.emf.compare.Comparison)
- */
- @Override
- public void comparisonChange(Comparison oldValue, final Comparison newValue) {
- SWTUtil.safeSyncExec(new Runnable() {
- public void run() {
- groupActionMenu.createActions(compareConfiguration.getComparisonScope(), newValue);
- filterActionMenu.createActions(compareConfiguration.getComparisonScope(), newValue);
- }
- });
- for (MergeAllNonConflictingAction mergeAction : mergeAllNonConflictingActions) {
- mergeAction.setComparison(newValue);
+ @Subscribe
+ public void comparisonAndScopeChange(final IComparisonAndScopeChange event) {
+ SWTUtil.safeAsyncExec(new Runnable() {
+ public void run() {
+ filterActionMenu.updateMenu(event.getNewScope(), event.getNewComparison());
+ groupActionMenu.updateMenu(event.getNewScope(), event.getNewComparison());
}
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener#comparisonScopeChange(org.eclipse.emf.compare.scope.IComparisonScope,
- * org.eclipse.emf.compare.scope.IComparisonScope)
- */
- @Override
- public void comparisonScopeChange(IComparisonScope oldValue, final IComparisonScope newValue) {
- SWTUtil.safeSyncExec(new Runnable() {
- public void run() {
- groupActionMenu.createActions(newValue, compareConfiguration.getComparison());
- filterActionMenu.createActions(newValue, compareConfiguration.getComparison());
- }
- });
+ });
+ for (MergeAllNonConflictingAction mergeAction : mergeAllNonConflictingActions) {
+ mergeAction.setComparison(event.getNewComparison());
}
}
+
}
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 daf15d86e..5fc300171 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,6 +20,7 @@ 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;
@@ -34,7 +35,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;
@@ -120,12 +124,15 @@ public class EMFCompareDiffTreeRuler extends Canvas {
/** The last cursor used. */
private Cursor lastCursor;
- /** The configuration for this control. */
- private EMFCompareConfiguration fConfiguration;
-
/** 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;
+
/**
* Constructor.
*
@@ -145,7 +152,8 @@ public class EMFCompareDiffTreeRuler extends Canvas {
super(parent, style);
fWidth = width;
fTreeViewer = treeViewer;
- fConfiguration = config;
+ this.compareConfiguration = config;
+ compareConfiguration.getEventBus().register(this);
requiredDiffFillColor = JFaceResources.getColorRegistry().get(
EMFCompareDiffTreeViewer.REQUIRED_DIFF_COLOR);
@@ -239,15 +247,54 @@ public class EMFCompareDiffTreeRuler extends Canvas {
public void computeConsequences() {
clearAllData();
if (selectedDiff != null) {
- MergeMode mergePreviewMode = fConfiguration.getMergePreviewMode();
- boolean leftToRigh = mergePreviewMode.isLeftToRight(fConfiguration.isLeftEditable(),
- fConfiguration.isRightEditable());
+ boolean leftToRigh = getMergePreviewMode().isLeftToRight(compareConfiguration.isLeftEditable(),
+ compareConfiguration.isRightEditable());
requires = DiffUtil.getRequires(selectedDiff, leftToRigh);
unmergeables = DiffUtil.getUnmergeables(selectedDiff, 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.
*
@@ -257,7 +304,7 @@ public class EMFCompareDiffTreeRuler extends Canvas {
private void associateTreeItems(List<Diff> diffs) {
Tree tree = fTreeViewer.getTree();
if (fTreeViewer instanceof EMFCompareDiffTreeViewer) {
- ((EMFCompareDiffTreeViewer)fTreeViewer).createChildrenSilently(tree);
+ // ((EMFCompareDiffTreeViewer)fTreeViewer).createChildrenSilently(tree);
}
for (TreeItem item : tree.getItems()) {
associateTreeItem(item, diffs);
@@ -302,6 +349,7 @@ 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);
@@ -316,7 +364,7 @@ public class EMFCompareDiffTreeRuler extends Canvas {
*/
private void handlePaintEvent(PaintEvent e) {
annotationsData.clear();
- Predicate<? super EObject> predicate = fConfiguration.getAggregatedViewerPredicate();
+ Predicate<? super EObject> predicate = differencePredicate;
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 368bd1fbc..553d226d1 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
@@ -13,6 +13,7 @@ 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;
@@ -32,16 +33,20 @@ import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfigura
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.EMFCompareConfigurationChangeListener;
-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.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.DelegatingStyledCellLabelProvider;
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;
@@ -81,6 +86,8 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
private AdapterFactory adapterFactory;
+ private ISelectionChangedListener selectionChangeListener;
+
/**
* @param parent
* @param adapterFactory
@@ -91,6 +98,8 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
super(parent, configuration);
this.adapterFactory = adapterFactory;
+ getCompareConfiguration().getEventBus().register(this);
+
setLabelProvider(new DelegatingStyledCellLabelProvider(
new EMFCompareStructureMergeViewerLabelProvider(adapterFactory, this)));
setContentProvider(new EMFCompareStructureMergeViewerContentProvider(adapterFactory));
@@ -103,11 +112,18 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
fEraseItemListener = new Listener() {
public void handleEvent(Event event) {
- EMFCompareDiffTreeViewer.this.handleEraseItemEvent(event);
+ handleEraseItemEvent(event);
}
};
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));
@@ -116,46 +132,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
requiredDiffColor = JFaceResources.getColorRegistry().get(REQUIRED_DIFF_COLOR);
unmergeableDiffColor = JFaceResources.getColorRegistry().get(UNMERGEABLE_DIFF_COLOR);
- configurationChangeListener = new EMFCompareConfigurationChangeListener() {
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener#selectedDifferenceFiltersChange(java.util.Set,
- * java.util.Set)
- */
- @Override
- public void selectedDifferenceFiltersChange(Set<IDifferenceFilter> oldValue,
- Set<IDifferenceFilter> newValue) {
- getTree().redraw();
- refreshTitle();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener#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) {
- refreshTitle();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener#mergePreviewModeChange(org.eclipse.emf.compare.internal.merge.MergeMode,
- * org.eclipse.emf.compare.internal.merge.MergeMode)
- */
- @Override
- public void mergePreviewModeChange(MergeMode oldValue, MergeMode newValue) {
- getTree().redraw();
- }
-
- };
- configuration.addChangeListener(configurationChangeListener);
setUseHashlookup(true);
}
@@ -170,7 +146,34 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
}
};
- private final EMFCompareConfigurationChangeListener configurationChangeListener;
+ @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}
@@ -233,7 +236,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
return;
}
- refreshTitle();
refresh(root);
}
@@ -287,7 +289,8 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
@Override
protected void handleDispose(DisposeEvent event) {
getControl().removeListener(SWT.EraseItem, fEraseItemListener);
- getCompareConfiguration().removeChangeListener(configurationChangeListener);
+ 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 72ff5fe3b..89611fbf9 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
@@ -11,10 +11,7 @@
package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer;
import static com.google.common.collect.Iterables.getFirst;
-import static com.google.common.collect.Sets.newLinkedHashSet;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableSet;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
@@ -25,7 +22,6 @@ import java.util.Collection;
import java.util.EventObject;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareUI;
@@ -65,21 +61,16 @@ 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.internal.util.SWTUtil;
import org.eclipse.emf.compare.ide.ui.logical.IModelResolver;
import org.eclipse.emf.compare.ide.ui.logical.IStorageProviderAccessor;
-import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.internal.utils.ComparisonUtil;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
-import org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener;
-import org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfigurationChangeListener;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilterSelectionChangeEvent;
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;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.StructureMergeViewerGrouper;
-import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl.DefaultGroupProvider;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.provider.TreeItemProviderAdapterFactorySpec;
+import org.eclipse.emf.compare.rcp.ui.internal.util.SWTUtil;
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
@@ -116,31 +107,6 @@ import org.eclipse.ui.actions.ActionFactory;
*/
public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implements CommandStackListener {
- /**
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
- private final class EMFCompareStructureMergeViewerConfigurationChangeListener extends EMFCompareConfigurationChangeListener {
- @Override
- public void mergePreviewModeChange(MergeMode oldValue, MergeMode newValue) {
- treeRuler.computeConsequences();
- treeRuler.redraw();
- }
-
- @Override
- public void selectedDifferenceGroupProviderChange(IDifferenceGroupProvider oldValue,
- IDifferenceGroupProvider newValue) {
- treeRuler.computeConsequences();
- treeRuler.redraw();
- }
-
- @Override
- public void aggregatedViewerPredicateChange(Predicate<? super EObject> oldValue,
- Predicate<? super EObject> newValue) {
- treeRuler.computeConsequences();
- treeRuler.redraw();
- }
- }
-
/** The width of the tree ruler. */
private static final int TREE_RULER_WIDTH = 17;
@@ -155,9 +121,6 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
/** The expand/collapse item listener. */
private ITreeViewerListener fWrappedTreeListener;
- /** The compare configuration property change listener. */
- private IEMFCompareConfigurationChangeListener fCompareConfigurationPropertyChangeListener;
-
/** The tree viewer. */
private EMFCompareDiffTreeViewer diffTreeViewer;
@@ -187,8 +150,7 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
public EMFCompareStructureMergeViewer(Composite parent, EMFCompareConfiguration config) {
super(parent, config);
- fCompareConfigurationPropertyChangeListener = new EMFCompareStructureMergeViewerConfigurationChangeListener();
- getCompareConfiguration().addChangeListener(fCompareConfigurationPropertyChangeListener);
+ config.getEventBus().register(this);
inputChangedTask.setPriority(Job.LONG);
}
@@ -257,49 +219,61 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
EventBus eventBus = new EventBus();
eventBus.register(this);
- StructureMergeViewerFilter structureMergeViewerFilter = new StructureMergeViewerFilter(eventBus);
+ StructureMergeViewerFilter structureMergeViewerFilter = getCompareConfiguration()
+ .getStructureMergeViewerFilter();
structureMergeViewerFilter.install(diffTreeViewer);
- StructureMergeViewerGrouper structureMergeViewerGrouper = new StructureMergeViewerGrouper(eventBus);
+ StructureMergeViewerGrouper structureMergeViewerGrouper = getCompareConfiguration()
+ .getStructureMergeViewerGrouper();
structureMergeViewerGrouper.install(diffTreeViewer);
- toolBar = new CompareToolBar(diffTreeViewer, CompareViewerPane.getToolBarManager(parent),
- structureMergeViewerGrouper, structureMergeViewerFilter, getCompareConfiguration());
+ toolBar = new CompareToolBar(structureMergeViewerGrouper, structureMergeViewerFilter,
+ getCompareConfiguration());
+ diffTreeViewer.addSelectionChangedListener(toolBar);
+ toolBar.initToolbar(CompareViewerPane.getToolBarManager(parent), diffTreeViewer);
return control;
}
@Subscribe
- public void recordFilterSelectionChange(IDifferenceFilterSelectionChangeEvent event) {
- final Set<IDifferenceFilter> property = getCompareConfiguration().getSelectedDifferenceFilters();
-
- final Set<IDifferenceFilter> selectedFilters = newLinkedHashSet(property);
- switch (event.getAction()) {
- case SELECTED:
- selectedFilters.add(event.getFilter());
- break;
- case DESELECTED:
- selectedFilters.remove(event.getFilter());
- break;
- default:
- throw new IllegalStateException();
+ public void handleGroupProviderSelectionChange(IDifferenceGroupProviderChange event) {
+ differenceGroupProvider = event.getDifferenceGroupProvider();
+
+ Adapter root = (Adapter)diffTreeViewer.getRoot();
+ if (root != null) {
+ TreeNode target = (TreeNode)root.getTarget();
+ registerDifferenceGroupProvider(target, differenceGroupProvider);
}
- getCompareConfiguration().setSelectedDifferenceFilters(ImmutableSet.copyOf(selectedFilters));
- getCompareConfiguration().setAggregatedViewerPredicate(event.getAggregatedPredicate());
+ SWTUtil.safeAsyncExec(new Runnable() {
+ public void run() {
+ ((EMFCompareDiffTreeViewer)diffTreeViewer).createChildrenSilently(diffTreeViewer.getTree());
+ treeRuler.computeConsequences();
+ treeRuler.redraw();
+ }
+ });
}
- @Subscribe
- public void recordGroupProviderSelectionChange(IDifferenceGroupProvider differenceGroupProvider) {
- List<Adapter> eAdapters = ((Adapter)diffTreeViewer.getRoot()).getTarget().eAdapters();
+ /**
+ * @return the differenceGroupProvider
+ */
+ public IDifferenceGroupProvider getSelectedDifferenceGroupProvider() {
+ if (differenceGroupProvider == null) {
+ differenceGroupProvider = getCompareConfiguration().getStructureMergeViewerGrouper()
+ .getProvider();
+ }
+ 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);
}
eAdapters.add(differenceGroupProvider);
-
- getCompareConfiguration().setSelectedDifferenceGroupProvider(differenceGroupProvider);
}
/**
@@ -326,8 +300,8 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
old.removeCompareInputChangeListener(fCompareInputChangeListener);
}
if (input instanceof ICompareInput) {
- getViewer().setInput(input); // set input of EMFCompareDiffTreeViewer (useful for next/previous
- // diff buttons)
+ // getViewer().setInput(input); // set input of EMFCompareDiffTreeViewer (useful for next/previous
+ // diff buttons)
ICompareInput ci = (ICompareInput)input;
ci.addCompareInputChangeListener(fCompareInputChangeListener);
@@ -349,13 +323,14 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
if (fHandlerService != null) {
fHandlerService.dispose();
}
- getCompareConfiguration().removeChangeListener(fCompareConfigurationPropertyChangeListener);
+ getCompareConfiguration().getEventBus().unregister(this);
diffTreeViewer.removeTreeListener(fWrappedTreeListener);
Object input = getInput();
if (input instanceof ICompareInput) {
ICompareInput ci = (ICompareInput)input;
ci.removeCompareInputChangeListener(fCompareInputChangeListener);
}
+ diffTreeViewer.removeSelectionChangedListener(toolBar);
compareInputChanged((ICompareInput)null);
treeRuler.handleDispose();
fAdapterFactory.dispose();
@@ -383,6 +358,7 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
SWTUtil.safeAsyncExec(new Runnable() {
public void run() {
treeRuler.computeConsequences();
+ diffTreeViewer.createChildrenSilently(diffTreeViewer.getTree());
treeRuler.redraw();
}
});
@@ -391,8 +367,7 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
// org.eclipse.compare.CompareEditorInput#getElement(ISelection))
Object first = getFirst(affectedObjects, null);
if (first instanceof EObject) {
- IDifferenceGroupProvider groupProvider = getCompareConfiguration()
- .getSelectedDifferenceGroupProvider();
+ IDifferenceGroupProvider groupProvider = getSelectedDifferenceGroupProvider();
Iterable<TreeNode> treeNodes = groupProvider.getTreeNodes((EObject)first);
TreeNode treeNode = getFirst(treeNodes, null);
if (treeNode != null) {
@@ -424,6 +399,8 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
private CompareToolBar toolBar;
+ private IDifferenceGroupProvider differenceGroupProvider;
+
/**
* Triggered by fCompareInputChangeListener and {@link #inputChanged(Object, Object)}.
*/
@@ -450,7 +427,7 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
ICompareEditingDomain editingDomain = getCompareConfiguration().getEditingDomain();
editingDomain.getCommandStack().addCommandStackListener(this);
- EMFCompare comparator = getCompareConfiguration().getComparator();
+ EMFCompare comparator = getCompareConfiguration().getEMFComparator();
IComparisonScope comparisonScope = input.getComparisonScope();
Comparison comparison = comparator.compare(comparisonScope, BasicMonitor.toMonitor(monitor));
@@ -462,24 +439,18 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
void compareInputChanged(final IComparisonScope scope, final Comparison comparison) {
if (!getControl().isDisposed()) { // guard against disposal
- IDifferenceGroupProvider selectedGroup = getCompareConfiguration()
- .getSelectedDifferenceGroupProvider();
final TreeNode treeNode = TreeFactory.eINSTANCE.createTreeNode();
treeNode.setData(comparison);
- if (selectedGroup == IDifferenceGroupProvider.EMPTY) {
- selectedGroup = new DefaultGroupProvider();
- }
- treeNode.eAdapters().add(selectedGroup);
+ getCompareConfiguration().setComparisonAndScope(comparison, scope);
+ registerDifferenceGroupProvider(treeNode, getSelectedDifferenceGroupProvider());
diffTreeViewer.setRoot(fAdapterFactory.adapt(treeNode, ICompareInput.class));
- getCompareConfiguration().setComparison(comparison);
- getCompareConfiguration().setComparisonScope(scope);
SWTUtil.safeAsyncExec(new Runnable() {
public void run() {
// Mandatory for the EMFCompareDiffTreeRuler, all TreeItems must have been created
- diffTreeViewer.createChildrenSilently(diffTreeViewer.getTree());
diffTreeViewer.refreshAfterDiff(diffTreeViewer.getRoot());
+ diffTreeViewer.createChildrenSilently(diffTreeViewer.getTree());
diffTreeViewer.initialSelection();
}
});
@@ -500,7 +471,6 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
});
}
});
-
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/DropDownMergeMenuAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/DropDownMergeMenuAction.java
index 45e3268ff..e36a927a9 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/DropDownMergeMenuAction.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/DropDownMergeMenuAction.java
@@ -12,6 +12,8 @@ package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions;
import static com.google.common.collect.Lists.newArrayList;
+import com.google.common.eventbus.Subscribe;
+
import java.util.EnumSet;
import java.util.List;
@@ -19,7 +21,7 @@ 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.configuration.EMFCompareConfiguration;
import org.eclipse.emf.compare.internal.merge.MergeMode;
-import org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.IMergePreviewModeChange;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
@@ -45,8 +47,6 @@ public class DropDownMergeMenuAction extends Action implements IMenuCreator {
/** The accept menu item. */
private final List<Action> actions;
- private final EMFCompareConfigurationChangeListener changeListener;
-
/**
* Constructor.
*
@@ -57,20 +57,18 @@ public class DropDownMergeMenuAction extends Action implements IMenuCreator {
this.configuration = configuration;
actions = newArrayList();
- changeListener = new EMFCompareConfigurationChangeListener() {
- @Override
- public void mergePreviewModeChange(MergeMode oldValue, MergeMode newValue) {
- updateMenu(newValue);
- }
- };
- configuration.addChangeListener(changeListener);
-
for (MergeMode mergePreviewMode : previewModes) {
actions.add(new DropDownAction(configuration, mergePreviewMode));
}
- updateMenu(configuration.getMergePreviewMode());
+ setToolTipTextAndImage(this, configuration.getMergePreviewMode());
setMenuCreator(this);
+ configuration.getEventBus().register(this);
+ }
+
+ @Subscribe
+ public void mergePreviewModeChange(IMergePreviewModeChange event) {
+ setToolTipTextAndImage(this, event.getNewValue());
}
/**
@@ -94,7 +92,7 @@ public class DropDownMergeMenuAction extends Action implements IMenuCreator {
fMenu.dispose();
fMenu = null;
}
- configuration.removeChangeListener(changeListener);
+ configuration.getEventBus().unregister(this);
}
/**
@@ -136,13 +134,6 @@ public class DropDownMergeMenuAction extends Action implements IMenuCreator {
item.fill(parent, -1);
}
- /**
- * Update the icon and tooltip of the dropdown menu.
- */
- protected void updateMenu(MergeMode mergeWay) {
- setToolTipTextAndImage(this, mergeWay);
- }
-
static void setToolTipTextAndImage(IAction action, MergeMode mergeMode) {
switch (mergeMode) {
case LEFT_TO_RIGHT:
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/ExpandAllModelAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/ExpandAllModelAction.java
index 309cfc7fa..dd5dc8216 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/ExpandAllModelAction.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/ExpandAllModelAction.java
@@ -37,7 +37,5 @@ public class ExpandAllModelAction extends Action {
@Override
public void run() {
treeViewer.expandToLevel(256);
- // Workaround to force the redraw of the EMFCompareDiffTreeruler
- treeViewer.setSelection(treeViewer.getSelection());
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/ExceptionUtil.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/ExceptionUtil.java
index be034400f..1ab1b6077 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/ExceptionUtil.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/ExceptionUtil.java
@@ -14,6 +14,7 @@ import com.google.common.base.Throwables;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
+import org.eclipse.emf.compare.rcp.ui.internal.util.SWTUtil;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/SWTUtil.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/SWTUtil.java
deleted file mode 100644
index 9e1a64c66..000000000
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/SWTUtil.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2013 Obeo.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.util;
-
-import org.eclipse.swt.widgets.Display;
-
-/**
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class SWTUtil {
-
- public static void safeAsyncExec(final Runnable runnable) {
- if (Display.getCurrent() != null) {
- runnable.run();
- } else {
- Display.getDefault().asyncExec(runnable);
- }
- }
-
- public static void safeSyncExec(final Runnable runnable) {
- if (Display.getCurrent() != null) {
- runnable.run();
- } else {
- Display.getDefault().syncExec(runnable);
- }
- }
-}

Back to the top