Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikaël Barbero2013-10-09 10:09:25 -0400
committerMikaël Barbero2013-10-11 10:22:33 -0400
commitf7ac84f00a6137a5c3aee59ea2eaadf602d0d44e (patch)
tree871a7d1621eb3b8e4908f9531f24fb40dbc99219 /plugins/org.eclipse.emf.compare.ide.ui/src
parent0c04b5ad46212bc9a376ac38bcb36223c14a55b5 (diff)
downloadorg.eclipse.emf.compare-f7ac84f00a6137a5c3aee59ea2eaadf602d0d44e.tar.gz
org.eclipse.emf.compare-f7ac84f00a6137a5c3aee59ea2eaadf602d0d44e.tar.xz
org.eclipse.emf.compare-f7ac84f00a6137a5c3aee59ea2eaadf602d0d44e.zip
Extract Toolbar in its own class.
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/structuremergeviewer/CompareToolBar.java220
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java345
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java72
3 files changed, 295 insertions, 342 deletions
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
new file mode 100644
index 000000000..025f8bf25
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/CompareToolBar.java
@@ -0,0 +1,220 @@
+/*******************************************************************************
+ * 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.structuremergeviewer;
+
+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 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;
+import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.ExpandAllModelAction;
+import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeAction;
+import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeAllNonConflictingAction;
+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.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.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.jface.action.Separator;
+import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.menus.IMenuService;
+import org.eclipse.ui.services.IServiceLocator;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class CompareToolBar {
+
+ private final GroupActionMenu groupActionMenu;
+
+ private final FilterActionMenu filterActionMenu;
+
+ private final List<MergeAction> mergeActions = newArrayListWithCapacity(2);
+
+ private final List<MergeAllNonConflictingAction> mergeAllNonConflictingActions = newArrayListWithCapacity(2);
+
+ private final CompareConfigurationListener configurationChangeListener;
+
+ private final EMFCompareConfiguration compareConfiguration;
+
+ private final AbstractTreeViewer viewer;
+
+ /**
+ *
+ */
+ public CompareToolBar(AbstractTreeViewer viewer, ToolBarManager toolbarManager,
+ StructureMergeViewerGrouper viewerGrouper, StructureMergeViewerFilter viewerFilter,
+ EMFCompareConfiguration compareConfiguration) {
+ this.viewer = viewer;
+ this.compareConfiguration = compareConfiguration;
+ // 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();
+
+ final EnumSet<MergeMode> modes;
+ if (rightEditable && leftEditable) {
+ modes = EnumSet.of(MergeMode.RIGHT_TO_LEFT, MergeMode.LEFT_TO_RIGHT);
+ } else {
+ modes = EnumSet.of(MergeMode.ACCEPT, MergeMode.REJECT);
+ }
+
+ toolbarManager.add(new DropDownMergeMenuAction(compareConfiguration, modes));
+ for (MergeMode mode : modes) {
+ toolbarManager.add(createMergeAction(mode));
+ }
+ for (MergeMode mode : modes) {
+ toolbarManager.add(createMergeAllNonConflictingAction(mode));
+ }
+
+ toolbarManager.add(new Separator());
+ toolbarManager.add(new SelectNextDiffAction(compareConfiguration));
+ toolbarManager.add(new SelectPreviousDiffAction(compareConfiguration));
+ toolbarManager.add(new Separator());
+ toolbarManager.add(new ExpandAllModelAction(viewer));
+ toolbarManager.add(new CollapseAllModelAction(viewer));
+ toolbarManager.add(new Separator());
+ toolbarManager.add(groupActionMenu);
+ toolbarManager.add(filterActionMenu);
+ toolbarManager.add(new Separator());
+ toolbarManager.add(new SaveComparisonModelAction(compareConfiguration));
+
+ toolbarManager.update(true);
+ }
+
+ private MergeAction createMergeAction(MergeMode mergeMode) {
+ EMFCompareConfiguration cc = compareConfiguration;
+ 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;
+ 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);
+ for (MergeAction mergeAction : mergeActions) {
+ viewer.removeSelectionChangedListener(mergeAction);
+ }
+ for (MergeAllNonConflictingAction mergeAllNonConflictingAction : mergeAllNonConflictingActions) {
+ viewer.removeSelectionChangedListener(mergeAllNonConflictingAction);
+ }
+ }
+
+ 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);
+ }
+ }
+
+ /**
+ * {@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);
+ }
+ }
+
+ /**
+ * {@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);
+ }
+ }
+
+ /**
+ * {@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());
+ }
+ });
+ }
+ }
+}
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 cef6e56ce..368bd1fbc 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java
@@ -10,66 +10,33 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer;
-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 static com.google.common.collect.Sets.newHashSet;
-import static com.google.common.collect.Sets.newLinkedHashSet;
import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.eventbus.EventBus;
-import com.google.common.eventbus.Subscribe;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
-import java.util.EnumSet;
-import java.util.List;
import java.util.Set;
-import org.eclipse.compare.CompareViewerPane;
import org.eclipse.compare.CompareViewerSwitchingPane;
import org.eclipse.compare.structuremergeviewer.DiffTreeViewer;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.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;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.ExpandAllModelAction;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeAction;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeAllNonConflictingAction;
-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.JFaceUtil;
import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.internal.utils.DiffUtil;
-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.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.IDifferenceFilterSelectionChangeEvent;
-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.IDifferenceGroupProvider;
-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.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.tree.TreeNode;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
import org.eclipse.jface.viewers.ISelection;
@@ -88,9 +55,6 @@ import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.menus.IMenuService;
-import org.eclipse.ui.services.IServiceLocator;
/**
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
@@ -111,42 +75,12 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
private final CompareViewerSwitchingPane fParent;
- private ToolBarManager toolbarManager;
-
private Object fRoot;
- /**
- * The difference filter that will be applied to the structure viewer. Note that this will be initialized
- * from {@link #createToolItems(ToolBarManager)} since that method is called from the super-constructor
- * and we cannot init ourselves beforehand.
- */
- private StructureMergeViewerFilter structureMergeViewerFilter;
-
- /**
- * This will be used by our adapter factory in order to group together the differences located under the
- * Comparison. Note that this will be initialized from {@link #createToolItems(ToolBarManager)} since that
- * method is called from the super-constructor and we cannot init ourselves beforehand.
- */
- private StructureMergeViewerGrouper structureMergeViewerGrouper;
-
- private MenuManager groupsMenuManager;
-
- private MenuManager filtersMenuManager;
-
- private GroupActionMenu groupActionMenu;
-
- private FilterActionMenu filterActionMenu;
-
- private EventBus eventBus;
-
private Listener fEraseItemListener;
private AdapterFactory adapterFactory;
- private List<MergeAction> mergeActions = newArrayListWithCapacity(4);
-
- private List<MergeAllNonConflictingAction> mergeAllNonConflictingActions = newArrayListWithCapacity(2);
-
/**
* @param parent
* @param adapterFactory
@@ -157,20 +91,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
super(parent, configuration);
this.adapterFactory = adapterFactory;
- ToolBarManager tbm = CompareViewerPane.getToolBarManager(parent.getParent());
- if (tbm != null) {
- tbm.removeAll();
-
- tbm.add(new Separator("merge")); //$NON-NLS-1$
- tbm.add(new Separator("modes")); //$NON-NLS-1$
- tbm.add(new Separator("navigation")); //$NON-NLS-1$
-
- createToolItems(tbm);
- // updateActions();
-
- tbm.update(true);
- }
-
setLabelProvider(new DelegatingStyledCellLabelProvider(
new EMFCompareStructureMergeViewerLabelProvider(adapterFactory, this)));
setContentProvider(new EMFCompareStructureMergeViewerContentProvider(adapterFactory));
@@ -188,11 +108,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
};
getControl().addListener(SWT.EraseItem, fEraseItemListener);
- if (eventBus == null) {
- eventBus = new EventBus();
- eventBus.register(this);
- }
-
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));
@@ -202,18 +117,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
unmergeableDiffColor = JFaceResources.getColorRegistry().get(UNMERGEABLE_DIFF_COLOR);
configurationChangeListener = new 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);
- }
- }
/**
* {@inheritDoc}
@@ -224,36 +127,33 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
@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);
- }
getTree().redraw();
+ 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)
+ * @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 mergePreviewModeChange(MergeMode oldValue, MergeMode newValue) {
- getTree().redraw();
+ public void selectedDifferenceGroupProviderChange(IDifferenceGroupProvider oldValue,
+ IDifferenceGroupProvider newValue) {
+ refreshTitle();
}
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener#comparisonChange(org.eclipse.emf.compare.Comparison,
- * org.eclipse.emf.compare.Comparison)
+ * @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 comparisonChange(Comparison oldValue, Comparison newValue) {
- for (MergeAllNonConflictingAction mergeAction : mergeAllNonConflictingActions) {
- mergeAction.setComparison(newValue);
- }
+ public void mergePreviewModeChange(MergeMode oldValue, MergeMode newValue) {
+ getTree().redraw();
}
+
};
configuration.addChangeListener(configurationChangeListener);
setUseHashlookup(true);
@@ -282,43 +182,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
return null;
}
- @SuppressWarnings("unchecked")
- @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();
- }
-
- getCompareConfiguration().setSelectedDifferenceFilters(ImmutableSet.copyOf(selectedFilters));
- getCompareConfiguration().setAggregatedViewerPredicate(event.getAggregatedPredicate());
-
- refreshTitle();
- }
-
- @Subscribe
- public void recordGroupProviderSelectionChange(IDifferenceGroupProvider differenceGroupProvider) {
- EList<Adapter> eAdapters = ((Adapter)fRoot).getTarget().eAdapters();
- IDifferenceGroupProvider oldDifferenceGroupProvider = (IDifferenceGroupProvider)EcoreUtil.getAdapter(
- eAdapters, IDifferenceGroupProvider.class);
- if (oldDifferenceGroupProvider != null) {
- eAdapters.remove(oldDifferenceGroupProvider);
- }
- eAdapters.add(differenceGroupProvider);
- getCompareConfiguration().setSelectedDifferenceGroupProvider(differenceGroupProvider);
-
- refreshTitle();
- }
-
/**
* {@inheritDoc}
*
@@ -419,197 +282,11 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
/**
* {@inheritDoc}
*
- * @see org.eclipse.compare.structuremergeviewer.DiffTreeViewer#createToolItems(org.eclipse.jface.action.ToolBarManager)
- */
- @Override
- protected void createToolItems(ToolBarManager toolbarManager) {
-
- this.toolbarManager = toolbarManager;
-
- super.createToolItems(toolbarManager);
-
- // 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");
- }
-
- groupActionMenu = new GroupActionMenu(getStructureMergeViewerGrouper(), getGroupsMenuManager(),
- getDefaultGroupProvider());
- filterActionMenu = new FilterActionMenu(getStructureMergeViewerFilter(), getFiltersMenuManager());
-
- boolean leftEditable = getCompareConfiguration().isLeftEditable();
- boolean rightEditable = getCompareConfiguration().isRightEditable();
-
- final EnumSet<MergeMode> modes;
- if (rightEditable && leftEditable) {
- modes = EnumSet.of(MergeMode.RIGHT_TO_LEFT, MergeMode.LEFT_TO_RIGHT);
- } else {
- modes = EnumSet.of(MergeMode.ACCEPT, MergeMode.REJECT);
- }
-
- toolbarManager.add(new DropDownMergeMenuAction(getCompareConfiguration(), modes));
- for (MergeMode mode : modes) {
- toolbarManager.add(createMergeAction(mode));
- }
- for (MergeMode mode : modes) {
- toolbarManager.add(createMergeAllNonConflictingAction(mode));
- }
-
- toolbarManager.add(new Separator());
- toolbarManager.add(new SelectNextDiffAction(getCompareConfiguration()));
- toolbarManager.add(new SelectPreviousDiffAction(getCompareConfiguration()));
- toolbarManager.add(new Separator());
- toolbarManager.add(new ExpandAllModelAction(this));
- toolbarManager.add(new CollapseAllModelAction(this));
- toolbarManager.add(new Separator());
- toolbarManager.add(groupActionMenu);
- toolbarManager.add(filterActionMenu);
- toolbarManager.add(new Separator());
- toolbarManager.add(new SaveComparisonModelAction(getCompareConfiguration()));
- }
-
- private MergeAction createMergeAction(MergeMode mergeMode) {
- EMFCompareConfiguration cc = getCompareConfiguration();
- IMerger.Registry mergerRegistry = EMFCompareRCPPlugin.getDefault().getMergerRegistry();
- MergeAction mergeAction = new MergeAction(cc.getEditingDomain(), mergerRegistry, mergeMode, cc
- .isLeftEditable(), cc.isRightEditable());
- addSelectionChangedListener(mergeAction);
- mergeActions.add(mergeAction);
- return mergeAction;
- }
-
- private MergeAction createMergeAllNonConflictingAction(MergeMode mergeMode) {
- EMFCompareConfiguration cc = getCompareConfiguration();
- IMerger.Registry mergerRegistry = EMFCompareRCPPlugin.getDefault().getMergerRegistry();
- MergeAllNonConflictingAction mergeAction = new MergeAllNonConflictingAction(cc.getEditingDomain(), cc
- .getComparison(), mergerRegistry, mergeMode, cc.isLeftEditable(), cc.isRightEditable());
- addSelectionChangedListener(mergeAction);
- mergeActions.add(mergeAction);
- mergeAllNonConflictingActions.add(mergeAction);
- return mergeAction;
- }
-
- /**
- * Returns the viewer filter that is to be applied on the structure viewer.
- * <p>
- * Note that this will be called from {@link #createToolItems(ToolBarManager)}, which is called from the
- * super-constructor, when we have had no time to initialize the {@link #structureMergeViewerFilter}
- * field.
- * </p>
- *
- * @return The difference filter that is to be applied on the structure viewer.
- */
- protected StructureMergeViewerFilter getStructureMergeViewerFilter() {
- if (structureMergeViewerFilter == null) {
- if (eventBus == null) {
- eventBus = new EventBus();
- eventBus.register(this);
- }
- structureMergeViewerFilter = new StructureMergeViewerFilter(eventBus);
- structureMergeViewerFilter.install(this);
- }
- return structureMergeViewerFilter;
- }
-
- /**
- * Returns the viewer grouper that is to be applied on the structure viewer.
- * <p>
- * Note that this will be called from {@link #createToolItems(ToolBarManager)}, which is called from the
- * super-constructor, when we have had no time to initialize the {@link #structureMergeViewerGrouper}
- * field.
- * </p>
- *
- * @return The viewer grouper grouper that is to be applied on the structure viewer.
- */
- protected StructureMergeViewerGrouper getStructureMergeViewerGrouper() {
- if (structureMergeViewerGrouper == null) {
- if (eventBus == null) {
- eventBus = new EventBus();
- eventBus.register(this);
- }
- structureMergeViewerGrouper = new StructureMergeViewerGrouper(eventBus);
- structureMergeViewerGrouper.install(this);
- }
- return structureMergeViewerGrouper;
- }
-
- /**
- * Returns the menu manager that is to be applied to groups on the structure viewer.
- *
- * @return The menu manager that is to be applied to groups on the structure viewer.
- */
- public MenuManager getGroupsMenuManager() {
- if (groupsMenuManager == null) {
- groupsMenuManager = new MenuManager();
- }
- return groupsMenuManager;
- }
-
- /**
- * @return the groupActionMenu
- */
- public GroupActionMenu getGroupActionMenu() {
- return groupActionMenu;
- }
-
- /**
- * @param groupActionMenu
- * the groupActionMenu to set
- */
- public void setGroupActionMenu(GroupActionMenu groupActionMenu) {
- this.groupActionMenu = groupActionMenu;
- }
-
- /**
- * Returns the menu manager that is to be applied to filters on the structure viewer.
- *
- * @return The menu manager that is to be applied to filters on the structure viewer.
- */
- public MenuManager getFiltersMenuManager() {
- if (filtersMenuManager == null) {
- filtersMenuManager = new MenuManager();
- }
- return filtersMenuManager;
- }
-
- /**
- * @return the filterActionMenu
- */
- public FilterActionMenu getFilterActionMenu() {
- return filterActionMenu;
- }
-
- /**
- * @param filterActionMenu
- * the filterActionMenu to set
- */
- public void setFilterActionMenu(FilterActionMenu filterActionMenu) {
- this.filterActionMenu = filterActionMenu;
- }
-
- /**
- * Returns the default group provider that is to be applied on the structure viewer.
- *
- * @return The default group provider that is to be applied on the structure viewer.
- */
- public DefaultGroupProvider getDefaultGroupProvider() {
- return new DefaultGroupProvider();
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.eclipse.compare.structuremergeviewer.DiffTreeViewer#handleDispose(org.eclipse.swt.events.DisposeEvent)
*/
@Override
protected void handleDispose(DisposeEvent event) {
getControl().removeListener(SWT.EraseItem, fEraseItemListener);
- for (MergeAction mergeAction : mergeActions) {
- removeSelectionChangedListener(mergeAction);
- }
getCompareConfiguration().removeChangeListener(configurationChangeListener);
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 90d4cc117..72ff5fe3b 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,8 +11,12 @@
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;
import java.lang.reflect.Field;
import java.security.AccessController;
@@ -20,9 +24,12 @@ import java.security.PrivilegedAction;
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;
+import org.eclipse.compare.CompareViewerPane;
import org.eclipse.compare.INavigatable;
import org.eclipse.compare.ITypedElement;
import org.eclipse.compare.internal.CompareHandlerService;
@@ -38,6 +45,7 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.command.CommandStackListener;
+import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.ui.dialogs.DiagnosticDialog;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.compare.Comparison;
@@ -65,12 +73,18 @@ 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.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.scope.IComparisonScope;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IDisposable;
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
@@ -240,9 +254,54 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
fHandlerService = CompareHandlerService.createFor(getCompareConfiguration().getContainer(),
diffTreeViewer.getControl().getShell());
+ EventBus eventBus = new EventBus();
+ eventBus.register(this);
+
+ StructureMergeViewerFilter structureMergeViewerFilter = new StructureMergeViewerFilter(eventBus);
+ structureMergeViewerFilter.install(diffTreeViewer);
+
+ StructureMergeViewerGrouper structureMergeViewerGrouper = new StructureMergeViewerGrouper(eventBus);
+ structureMergeViewerGrouper.install(diffTreeViewer);
+
+ toolBar = new CompareToolBar(diffTreeViewer, CompareViewerPane.getToolBarManager(parent),
+ structureMergeViewerGrouper, structureMergeViewerFilter, getCompareConfiguration());
+
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();
+ }
+
+ getCompareConfiguration().setSelectedDifferenceFilters(ImmutableSet.copyOf(selectedFilters));
+ getCompareConfiguration().setAggregatedViewerPredicate(event.getAggregatedPredicate());
+ }
+
+ @Subscribe
+ public void recordGroupProviderSelectionChange(IDifferenceGroupProvider differenceGroupProvider) {
+ List<Adapter> eAdapters = ((Adapter)diffTreeViewer.getRoot()).getTarget().eAdapters();
+ IDifferenceGroupProvider oldDifferenceGroupProvider = (IDifferenceGroupProvider)EcoreUtil.getAdapter(
+ eAdapters, IDifferenceGroupProvider.class);
+ if (oldDifferenceGroupProvider != null) {
+ eAdapters.remove(oldDifferenceGroupProvider);
+ }
+ eAdapters.add(differenceGroupProvider);
+
+ getCompareConfiguration().setSelectedDifferenceGroupProvider(differenceGroupProvider);
+ }
+
/**
* {@inheritDoc}
*
@@ -300,6 +359,7 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
compareInputChanged((ICompareInput)null);
treeRuler.handleDispose();
fAdapterFactory.dispose();
+ toolBar.dispose();
super.handleDispose(event);
}
@@ -362,6 +422,8 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
}
};
+ private CompareToolBar toolBar;
+
/**
* Triggered by fCompareInputChangeListener and {@link #inputChanged(Object, Object)}.
*/
@@ -404,8 +466,8 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
.getSelectedDifferenceGroupProvider();
final TreeNode treeNode = TreeFactory.eINSTANCE.createTreeNode();
treeNode.setData(comparison);
- if (selectedGroup == null) {
- selectedGroup = diffTreeViewer.getDefaultGroupProvider();
+ if (selectedGroup == IDifferenceGroupProvider.EMPTY) {
+ selectedGroup = new DefaultGroupProvider();
}
treeNode.eAdapters().add(selectedGroup);
@@ -415,12 +477,6 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
SWTUtil.safeAsyncExec(new Runnable() {
public void run() {
- if (diffTreeViewer.getGroupActionMenu() != null) {
- diffTreeViewer.getGroupActionMenu().createActions(scope, comparison);
- }
- if (diffTreeViewer.getFilterActionMenu() != null) {
- diffTreeViewer.getFilterActionMenu().createActions(scope, comparison);
- }
// Mandatory for the EMFCompareDiffTreeRuler, all TreeItems must have been created
diffTreeViewer.createChildrenSilently(diffTreeViewer.getTree());
diffTreeViewer.refreshAfterDiff(diffTreeViewer.getRoot());

Back to the top