Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikaël Barbero2013-10-14 07:44:50 -0400
committerMikaël Barbero2013-10-18 15:29:57 -0400
commit95a92eea2b3b444285fc691f7f4aae26cb739a1b (patch)
treef5f9a5491147a9a19eb2d632d8188ac252af2155 /plugins/org.eclipse.emf.compare.ide.ui/src
parent8753b3076c819a1bb63365d7305228ea1eb0a72c (diff)
downloadorg.eclipse.emf.compare-95a92eea2b3b444285fc691f7f4aae26cb739a1b.tar.gz
org.eclipse.emf.compare-95a92eea2b3b444285fc691f7f4aae26cb739a1b.tar.xz
org.eclipse.emf.compare-95a92eea2b3b444285fc691f7f4aae26cb739a1b.zip
Remove unnecessary DiffTreeViewer subclass.
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/DependencyData.java25
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java18
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java195
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java189
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/CompareHandlerService.java160
5 files changed, 315 insertions, 272 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/DependencyData.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/DependencyData.java
index 7c62d5830..deab9c81c 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/DependencyData.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/DependencyData.java
@@ -17,6 +17,7 @@ import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newHashSet;
+import com.google.common.base.Function;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
@@ -46,27 +47,20 @@ public class DependencyData {
private Set<Diff> unmergeables;
- private WrappableTreeViewer treeViewer;
+ private final WrappableTreeViewer treeViewer;
/** A map that links a diff with tree items. */
private Multimap<Diff, TreeItem> diffToItemsMappings;
- public DependencyData(IEMFCompareConfiguration compareConfiguration) {
+ public DependencyData(IEMFCompareConfiguration compareConfiguration, WrappableTreeViewer treeViewer) {
this.compareConfiguration = compareConfiguration;
+ this.treeViewer = treeViewer;
requires = newHashSet();
unmergeables = newHashSet();
diffToItemsMappings = HashMultimap.create();
}
/**
- * @param treeViewer
- * the treeViewer to set
- */
- void setTreeViewer(WrappableTreeViewer treeViewer) {
- this.treeViewer = treeViewer;
- }
-
- /**
* @param selection
*/
public void updateDependencies(ISelection selection) {
@@ -92,7 +86,7 @@ public class DependencyData {
TreeItem[] children = tree.getItems();
// item with non created children has a fake child item with null data.
- if (children.length > 0 && children[0].getData() == null) {
+ if (children.length == 1 && children[0].getData() == null) {
treeViewer.createChildren(tree);
}
@@ -132,14 +126,19 @@ public class DependencyData {
List<EObject> ret = newArrayList();
if (selection instanceof IStructuredSelection) {
List<?> selectedObjects = ((IStructuredSelection)selection).toList();
- Iterable<EObject> data = transform(selectedObjects,
- EMFCompareStructureMergeViewer.ADAPTER__TARGET__DATA);
+ Iterable<EObject> data = transform(selectedObjects, ADAPTER__TARGET__DATA);
Iterable<EObject> notNullData = Iterables.filter(data, notNull());
addAll(ret, notNullData);
}
return ret;
}
+ private static final Function<Object, EObject> ADAPTER__TARGET__DATA = new Function<Object, EObject>() {
+ public EObject apply(Object object) {
+ return EMFCompareStructureMergeViewer.getDataOfTreeNodeOfAdapter(object);
+ }
+ };
+
/**
* @return the requires
*/
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 1cd845c08..a79fba542 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
@@ -67,9 +67,6 @@ public class EMFCompareDiffTreeRuler extends Canvas {
/** The border color an unmergeable diff. */
private final Color unmergeableDiffBorderColor;
- /** The width of this tree ruler. */
- private final int fWidth;
-
/** A map that links a rectangle with a tree item. */
private Map<Rectangle, TreeItem> annotationsData;
@@ -104,21 +101,20 @@ public class EMFCompareDiffTreeRuler extends Canvas {
* @param config
* the configuration for this control.
*/
- EMFCompareDiffTreeRuler(Composite parent, int style, int width, WrappableTreeViewer treeViewer,
+ EMFCompareDiffTreeRuler(Composite parent, int style, WrappableTreeViewer treeViewer,
DependencyData dependencyData) {
super(parent, style);
- fWidth = width;
fTreeViewer = treeViewer;
this.dependencyData = dependencyData;
requiredDiffFillColor = JFaceResources.getColorRegistry().get(
- EMFCompareDiffTreeViewer.REQUIRED_DIFF_COLOR);
+ EMFCompareStructureMergeViewer.REQUIRED_DIFF_COLOR);
requiredDiffBorderColor = JFaceResources.getColorRegistry().get(
- EMFCompareDiffTreeViewer.REQUIRED_DIFF_BORDER_COLOR);
+ EMFCompareStructureMergeViewer.REQUIRED_DIFF_BORDER_COLOR);
unmergeableDiffFillColor = JFaceResources.getColorRegistry().get(
- EMFCompareDiffTreeViewer.UNMERGEABLE_DIFF_COLOR);
+ EMFCompareStructureMergeViewer.UNMERGEABLE_DIFF_COLOR);
unmergeableDiffBorderColor = JFaceResources.getColorRegistry().get(
- EMFCompareDiffTreeViewer.UNMERGEABLE_DIFF_BORDER_COLOR);
+ EMFCompareStructureMergeViewer.UNMERGEABLE_DIFF_BORDER_COLOR);
annotationsData = Maps.newHashMap();
@@ -293,8 +289,8 @@ public class EMFCompareDiffTreeRuler extends Canvas {
y = yRuler - Y_OFFSET - ANNOTATION_HEIGHT;
}
}
- Rectangle rect = drawAnnotation(e.gc, 2, y + Y_OFFSET, fWidth - 5, ANNOTATION_HEIGHT, fill,
- border);
+ Rectangle rect = drawAnnotation(e.gc, 2, y + Y_OFFSET, getBounds().width - 5, ANNOTATION_HEIGHT,
+ fill, border);
annotationsData.put(rect, treeItem);
}
}
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
deleted file mode 100644
index c493f78d4..000000000
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java
+++ /dev/null
@@ -1,195 +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.structuremergeviewer;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Set;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.compare.Conflict;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.tree.TreeNode;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
-
-/**
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class EMFCompareDiffTreeViewer extends WrappableTreeViewer {
-
- public static final String REQUIRED_DIFF_COLOR = "RequiredDiffColor"; //$NON-NLS-1$
-
- public static final String REQUIRED_DIFF_BORDER_COLOR = "RequiredDiffBorderColor"; //$NON-NLS-1$
-
- public static final String UNMERGEABLE_DIFF_COLOR = "UnmergeableDiffColor"; //$NON-NLS-1$
-
- public static final String UNMERGEABLE_DIFF_BORDER_COLOR = "UnmergeableDiffBorderColor"; //$NON-NLS-1$
-
- private final Color requiredDiffColor;
-
- private final Color unmergeableDiffColor;
-
- private final Listener fEraseItemListener;
-
- private final DependencyData dependencyData;
-
- /**
- * @param parent
- * @param adapterFactory
- * @param configuration
- */
- public EMFCompareDiffTreeViewer(Composite parent, DependencyData dependencyData) {
- super(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- this.dependencyData = dependencyData;
-
- fEraseItemListener = new Listener() {
- public void handleEvent(Event event) {
- handleEraseItemEvent(event);
- }
- };
- getControl().addListener(SWT.EraseItem, fEraseItemListener);
-
- 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));
- JFaceResources.getColorRegistry().put(UNMERGEABLE_DIFF_BORDER_COLOR, new RGB(235, 185, 160));
-
- requiredDiffColor = JFaceResources.getColorRegistry().get(REQUIRED_DIFF_COLOR);
- unmergeableDiffColor = JFaceResources.getColorRegistry().get(UNMERGEABLE_DIFF_COLOR);
-
- setUseHashlookup(true);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.TreeViewer#isExpandable(java.lang.Object)
- */
- @Override
- public boolean isExpandable(Object parent) {
- if (hasFilters()) {
- // workaround for 65762
- return getFilteredChildren(parent).length > 0;
- }
- return super.isExpandable(parent);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.compare.structuremergeviewer.DiffTreeViewer#handleDispose(org.eclipse.swt.events.DisposeEvent)
- */
- @Override
- public void handleDispose(DisposeEvent event) {
- getControl().removeListener(SWT.EraseItem, fEraseItemListener);
- super.handleDispose(event);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.AbstractTreeViewer#getSortedChildren(java.lang.Object)
- */
- @Override
- public Object[] getSortedChildren(Object parentElementOrTreePath) {
- Object[] result = super.getSortedChildren(parentElementOrTreePath);
- if (parentElementOrTreePath instanceof Adapter) {
- Notifier target = ((Adapter)parentElementOrTreePath).getTarget();
- if (target instanceof TreeNode) {
- EObject data = ((TreeNode)target).getData();
- if (data instanceof Conflict) {
- Collections.sort(Arrays.asList(result), new Comparator<Object>() {
- public int compare(Object o1, Object o2) {
- return getValue(o1) - getValue(o2);
- }
-
- public int getValue(Object o) {
- int value = 0;
- if (o instanceof Adapter) {
- Notifier n = ((Adapter)o).getTarget();
- if (n instanceof TreeNode) {
- EObject d = ((TreeNode)n).getData();
- if (d instanceof Diff) {
- if (((Diff)d).getSource() == DifferenceSource.LEFT) {
- value = 1;
- } else {
- value = 2;
- }
- }
- }
- }
- return value;
- }
- });
- }
- }
- }
-
- return result;
- }
-
- /**
- * Handle the erase item event. When select a difference in the structure merge viewer, highlight required
- * differences with a specific color, and highlight unmergeable differences with another color.
- *
- * @param event
- * the erase item event.
- */
- protected void handleEraseItemEvent(Event event) {
- TreeItem item = (TreeItem)event.item;
- EObject dataItem = EMFCompareStructureMergeViewer.getDataOfTreeNodeOfAdapter(item.getData());
- if (dataItem != null) {
- final Set<Diff> requires = dependencyData.getRequires();
- final Set<Diff> unmergeables = dependencyData.getUnmergeables();
- final GC g = event.gc;
- if (requires.contains(dataItem)) {
- paintItemBackground(g, item, requiredDiffColor);
- } else if (unmergeables.contains(dataItem)) {
- paintItemBackground(g, item, unmergeableDiffColor);
- }
- }
- }
-
- /**
- * Paint the background of the given item with the given color.
- *
- * @param g
- * the GC associated to the item.
- * @param item
- * the given item.
- * @param color
- * the given color.
- */
- private void paintItemBackground(GC g, TreeItem item, Color color) {
- Rectangle itemBounds = item.getBounds();
- Tree tree = item.getParent();
- Rectangle areaBounds = tree.getClientArea();
- g.setClipping(areaBounds.x, itemBounds.y, areaBounds.width, itemBounds.height);
- g.setBackground(color);
- g.fillRectangle(areaBounds.x, itemBounds.y, areaBounds.width, itemBounds.height);
- }
-
-}
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 67f5b5d6c..0747a1097 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
@@ -16,7 +16,6 @@ import static com.google.common.collect.Iterables.size;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasConflict;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasState;
-import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.eventbus.Subscribe;
@@ -25,13 +24,14 @@ import java.util.Collection;
import java.util.EventObject;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import org.eclipse.compare.CompareUI;
import org.eclipse.compare.CompareViewerPane;
import org.eclipse.compare.CompareViewerSwitchingPane;
+import org.eclipse.compare.ICompareNavigator;
import org.eclipse.compare.INavigatable;
import org.eclipse.compare.ITypedElement;
-import org.eclipse.compare.internal.CompareHandlerService;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -61,6 +61,7 @@ import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.RedoActio
import org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.UndoAction;
import org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonScopeInput;
import org.eclipse.emf.compare.ide.ui.internal.logical.ComparisonScopeBuilder;
+import org.eclipse.emf.compare.ide.ui.internal.util.CompareHandlerService;
import org.eclipse.emf.compare.ide.ui.internal.util.ExceptionUtil;
import org.eclipse.emf.compare.ide.ui.internal.util.JFaceUtil;
import org.eclipse.emf.compare.internal.utils.ComparisonUtil;
@@ -83,6 +84,7 @@ import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
import org.eclipse.emf.edit.tree.TreeFactory;
import org.eclipse.emf.edit.tree.TreeNode;
+import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITreeViewerListener;
@@ -91,9 +93,16 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeExpansionEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.actions.ActionFactory;
@@ -110,16 +119,34 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
private static final Predicate<Diff> UNRESOLVED_OR_WITHOUT_PSEUDO_CONFLICT = or(
hasState(DifferenceState.UNRESOLVED), hasConflict(ConflictKind.PSEUDO));
+ static final String REQUIRED_DIFF_COLOR = "RequiredDiffColor"; //$NON-NLS-1$
+
+ static final String REQUIRED_DIFF_BORDER_COLOR = "RequiredDiffBorderColor"; //$NON-NLS-1$
+
+ static final String UNMERGEABLE_DIFF_COLOR = "UnmergeableDiffColor"; //$NON-NLS-1$
+
+ static final String UNMERGEABLE_DIFF_BORDER_COLOR = "UnmergeableDiffBorderColor"; //$NON-NLS-1$
+
+ private Color requiredDiffColor;
+
+ private Color unmergeableDiffColor;
+
/** The width of the tree ruler. */
private static final int TREE_RULER_WIDTH = 17;
+ private static final Predicate<? super Object> IS_DIFF = new Predicate<Object>() {
+ public boolean apply(Object object) {
+ return getDataOfTreeNodeOfAdapter(object) instanceof Diff;
+ }
+ };
+
/** The adapter factory. */
private ComposedAdapterFactory fAdapterFactory;
/** The tree ruler associated with this viewer. */
private EMFCompareDiffTreeRuler treeRuler;
- private ICompareInputChangeListener fCompareInputChangeListener;
+ private final ICompareInputChangeListener fCompareInputChangeListener;
/** The expand/collapse item listener. */
private ITreeViewerListener fWrappedTreeListener;
@@ -145,6 +172,8 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
private ISelectionChangedListener selectionChangeListener;
+ private final Listener fEraseItemListener;
+
private final Job inputChangedTask = new Job("Compute Model Differences") {
@Override
public IStatus run(IProgressMonitor monitor) {
@@ -175,6 +204,12 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
.getStructureMergeViewerGrouper();
structureMergeViewerGrouper.install(getViewer());
+ fCompareInputChangeListener = new ICompareInputChangeListener() {
+ public void compareInputChanged(ICompareInput input) {
+ EMFCompareStructureMergeViewer.this.compareInputChanged(input);
+ }
+ };
+
toolBar = new CompareToolBar(structureMergeViewerGrouper, structureMergeViewerFilter,
getCompareConfiguration());
getViewer().addSelectionChangedListener(toolBar);
@@ -187,6 +222,24 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
};
addSelectionChangedListener(selectionChangeListener);
+ fWrappedTreeListener = new ITreeViewerListener() {
+ public void treeExpanded(TreeExpansionEvent event) {
+ treeRuler.redraw();
+ }
+
+ public void treeCollapsed(TreeExpansionEvent event) {
+ treeRuler.redraw();
+ }
+ };
+ getViewer().addTreeListener(fWrappedTreeListener);
+
+ fEraseItemListener = new Listener() {
+ public void handleEvent(Event event) {
+ handleEraseItemEvent(event);
+ }
+ };
+ getViewer().getControl().addListener(SWT.EraseItem, fEraseItemListener);
+
fHandlerService = CompareHandlerService.createFor(getCompareConfiguration().getContainer(),
getControl().getShell());
@@ -200,6 +253,7 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
redoAction = new RedoAction(getCompareConfiguration().getEditingDomain());
inputChangedTask.setPriority(Job.LONG);
+
config.getEventBus().register(this);
}
@@ -219,7 +273,13 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
getCompareConfiguration().setAdapterFactory(fAdapterFactory);
- dependencyData = new DependencyData(getCompareConfiguration());
+ 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));
+ JFaceResources.getColorRegistry().put(UNMERGEABLE_DIFF_BORDER_COLOR, new RGB(235, 185, 160));
+
+ requiredDiffColor = JFaceResources.getColorRegistry().get(REQUIRED_DIFF_COLOR);
+ unmergeableDiffColor = JFaceResources.getColorRegistry().get(UNMERGEABLE_DIFF_COLOR);
}
/**
@@ -241,39 +301,38 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
control.setLayout(layout);
control.setLayoutData(data);
- final WrappableTreeViewer treeViewer = new EMFCompareDiffTreeViewer(control, dependencyData);
- dependencyData.setTreeViewer(treeViewer);
+
+ final WrappableTreeViewer treeViewer = new WrappableTreeViewer(control, SWT.MULTI | SWT.H_SCROLL
+ | SWT.V_SCROLL) {
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.TreeViewer#isExpandable(java.lang.Object)
+ */
+ @Override
+ public boolean isExpandable(Object parent) {
+ if (hasFilters()) {
+ // workaround for 65762
+ return getFilteredChildren(parent).length > 0;
+ }
+ return super.isExpandable(parent);
+ }
+ };
+ treeViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ treeViewer.setUseHashlookup(true);
+
+ dependencyData = new DependencyData(getCompareConfiguration(), treeViewer);
+
INavigatable nav = new Navigatable(fAdapterFactory, treeViewer);
control.setData(INavigatable.NAVIGATOR_PROPERTY, nav);
control.setData(CompareUI.COMPARE_VIEWER_TITLE, "Model differences");
- treeViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ treeRuler = new EMFCompareDiffTreeRuler(control, SWT.NONE, treeViewer, dependencyData);
GridData layoutData = new GridData(SWT.FILL, SWT.FILL, false, true);
layoutData.widthHint = TREE_RULER_WIDTH;
layoutData.minimumWidth = TREE_RULER_WIDTH;
- treeRuler = new EMFCompareDiffTreeRuler(control, SWT.NONE, layoutData.widthHint, treeViewer,
- dependencyData);
treeRuler.setLayoutData(layoutData);
- fCompareInputChangeListener = new ICompareInputChangeListener() {
- public void compareInputChanged(ICompareInput input) {
- EMFCompareStructureMergeViewer.this.compareInputChanged(input);
- }
- };
-
- fWrappedTreeListener = new ITreeViewerListener() {
- public void treeExpanded(TreeExpansionEvent event) {
- treeRuler.redraw();
- }
-
- public void treeCollapsed(TreeExpansionEvent event) {
- treeRuler.redraw();
- }
- };
- treeViewer.addTreeListener(fWrappedTreeListener);
-
- fHandlerService = CompareHandlerService.createFor(getCompareConfiguration().getContainer(),
- treeViewer.getControl().getShell());
-
return ControlAndViewer.create(control, treeViewer);
}
@@ -282,7 +341,7 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
editingDomainChange(event.getOldValue(), event.getNewValue());
}
- protected void editingDomainChange(ICompareEditingDomain oldValue, ICompareEditingDomain newValue) {
+ private void editingDomainChange(ICompareEditingDomain oldValue, ICompareEditingDomain newValue) {
if (newValue != oldValue) {
if (oldValue != null) {
oldValue.getCommandStack().removeCommandStackListener(this);
@@ -290,8 +349,6 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
if (newValue != null) {
newValue.getCommandStack().addCommandStackListener(this);
- // setLeftDirty(newValue.getCommandStack().isLeftSaveNeeded());
- // setRightDirty(newValue.getCommandStack().isRightSaveNeeded());
}
undoAction.setEditingDomain(newValue);
@@ -317,12 +374,6 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
}
}
- private static final Predicate<? super Object> IS_DIFF = new Predicate<Object>() {
- public boolean apply(Object object) {
- return getDataOfTreeNodeOfAdapter(object) instanceof Diff;
- }
- };
-
static EObject getDataOfTreeNodeOfAdapter(Object object) {
EObject data = null;
if (object instanceof Adapter) {
@@ -334,12 +385,6 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
return data;
}
- static final Function<Object, EObject> ADAPTER__TARGET__DATA = new Function<Object, EObject>() {
- public EObject apply(Object object) {
- return getDataOfTreeNodeOfAdapter(object);
- }
- };
-
@Subscribe
public void mergePreviewModeChange(IMergePreviewModeChange event) {
dependencyData.updateDependencies(getSelection());
@@ -348,12 +393,12 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
@Subscribe
public void handleDifferenceFilterChange(IDifferenceFilterChange event) {
- SWTUtil.safeRefresh(this, true);
+ SWTUtil.safeRefresh(this, false);
}
@Subscribe
public void handleDifferenceGroupProviderChange(IDifferenceGroupProviderChange event) {
- SWTUtil.safeRefresh(this, true);
+ SWTUtil.safeRefresh(this, false);
}
/**
@@ -398,6 +443,7 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
}
removeSelectionChangedListener(selectionChangeListener);
getViewer().removeSelectionChangedListener(toolBar);
+ getViewer().getTree().removeListener(SWT.EraseItem, fEraseItemListener);
compareInputChanged((ICompareInput)null);
treeRuler.handleDispose();
fAdapterFactory.dispose();
@@ -430,7 +476,7 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
if (treeNode != null) {
final Object adaptedAffectedObject = fAdapterFactory.adapt(treeNode,
ICompareInput.class);
- SWTUtil.safeAsyncExec(new Runnable() {
+ SWTUtil.safeSyncExec(new Runnable() {
public void run() {
refresh();
setSelection(new StructuredSelection(adaptedAffectedObject), true);
@@ -500,16 +546,12 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
SWTUtil.safeAsyncExec(new Runnable() {
public void run() {
- // the tree has now a proper group provider and its input, so we can create the child
- // silently.
- // ((EMFCompareDiffTreeViewer)getViewer()).createChildrenSilently();
-
// title is not initialized as the comparison was set in the configuration after the
// refresh caused by the initialization of the viewer filters and the groupe providers.
refreshTitle();
- // XXX: fixme!!
- // ((EMFCompareDiffTreeViewer)getViewer()).initialSelection();
+ ICompareNavigator navigator = getCompareConfiguration().getContainer().getNavigator();
+ navigator.selectChange(true);
}
});
@@ -624,6 +666,47 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
getViewer().setInput(null);
}
+ /**
+ * Handle the erase item event. When select a difference in the structure merge viewer, highlight required
+ * differences with a specific color, and highlight unmergeable differences with another color.
+ *
+ * @param event
+ * the erase item event.
+ */
+ private void handleEraseItemEvent(Event event) {
+ TreeItem item = (TreeItem)event.item;
+ EObject dataItem = EMFCompareStructureMergeViewer.getDataOfTreeNodeOfAdapter(item.getData());
+ if (dataItem != null) {
+ final Set<Diff> requires = dependencyData.getRequires();
+ final Set<Diff> unmergeables = dependencyData.getUnmergeables();
+ final GC g = event.gc;
+ if (requires.contains(dataItem)) {
+ paintItemBackground(g, item, requiredDiffColor);
+ } else if (unmergeables.contains(dataItem)) {
+ paintItemBackground(g, item, unmergeableDiffColor);
+ }
+ }
+ }
+
+ /**
+ * Paint the background of the given item with the given color.
+ *
+ * @param g
+ * the GC associated to the item.
+ * @param item
+ * the given item.
+ * @param color
+ * the given color.
+ */
+ private void paintItemBackground(GC g, TreeItem item, Color color) {
+ Rectangle itemBounds = item.getBounds();
+ Tree tree = item.getParent();
+ Rectangle areaBounds = tree.getClientArea();
+ g.setClipping(areaBounds.x, itemBounds.y, areaBounds.width, itemBounds.height);
+ g.setBackground(color);
+ g.fillRectangle(areaBounds.x, itemBounds.y, areaBounds.width, itemBounds.height);
+ }
+
private void reportErrors(final Comparison comparison) {
if (ComparisonUtil.containsErrors(comparison)) {
SWTUtil.safeAsyncExec(new Runnable() {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/CompareHandlerService.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/CompareHandlerService.java
new file mode 100644
index 000000000..460e88017
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/util/CompareHandlerService.java
@@ -0,0 +1,160 @@
+package org.eclipse.emf.compare.ide.ui.internal.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.compare.ICompareContainer;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.commands.ActionHandler;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.ActiveShellExpression;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.IHandlerActivation;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.services.IServiceLocator;
+
+public class CompareHandlerService {
+
+ private final List fActivations = new ArrayList();
+
+ private final Expression fExpression;
+
+ private ICompareContainer fContainer;
+
+ private boolean fDisposed;
+
+ private List fPaneActivations = new ArrayList();
+
+ private IHandlerService fHandlerService;
+
+ public static CompareHandlerService createFor(ICompareContainer container, Shell shell) {
+ IServiceLocator serviceLocator = container.getServiceLocator();
+ if (serviceLocator != null) {
+ IHandlerService service = (IHandlerService)serviceLocator.getService(IHandlerService.class);
+ if (service != null) {
+ return new CompareHandlerService(container, null);
+ }
+ }
+ if (container.getWorkbenchPart() == null && shell != null) {
+ // We're in a dialog so we can use an active shell expression
+ IHandlerService service = (IHandlerService)PlatformUI.getWorkbench().getService(
+ IHandlerService.class);
+ if (service != null) {
+ Expression e = new ActiveShellExpression(shell);
+ return new CompareHandlerService(container, e);
+ }
+ }
+ return new CompareHandlerService(null, null);
+ }
+
+ private CompareHandlerService(ICompareContainer container, Expression expression) {
+ fContainer = container;
+ fExpression = expression;
+ initialize();
+ }
+
+ public void registerAction(IAction action, String commandId) {
+ IHandlerService handlerService = getHandlerService();
+ if (handlerService == null) {
+ return;
+ }
+ action.setActionDefinitionId(commandId);
+ IHandlerActivation activation;
+ if (fExpression == null) {
+ activation = handlerService.activateHandler(commandId, new ActionHandler(action));
+ } else {
+ activation = handlerService.activateHandler(commandId, new ActionHandler(action), fExpression);
+ }
+ if (activation != null) {
+ fActivations.add(activation);
+ }
+ }
+
+ private IHandlerService getHandlerService() {
+ if (fDisposed) {
+ return null;
+ }
+ return fHandlerService;
+ }
+
+ private void initialize() {
+ if (fHandlerService == null) {
+ IServiceLocator serviceLocator = fContainer.getServiceLocator();
+ if (serviceLocator != null) {
+ IHandlerService service = (IHandlerService)serviceLocator.getService(IHandlerService.class);
+ if (service != null) {
+ fHandlerService = service;
+ }
+ }
+ if (fHandlerService == null && fContainer.getWorkbenchPart() == null && fExpression != null) {
+ // We're in a dialog so we can use an active shell expression
+ IHandlerService service = (IHandlerService)PlatformUI.getWorkbench().getService(
+ IHandlerService.class);
+ if (service != null) {
+ fHandlerService = service;
+ }
+ }
+ }
+ }
+
+ public void setGlobalActionHandler(String actionId, IAction actionHandler) {
+ IActionBars bars = getActionBars();
+ if (bars != null) {
+ bars.setGlobalActionHandler(actionId, actionHandler);
+ return;
+ } else if (fExpression != null && actionHandler != null
+ && actionHandler.getActionDefinitionId() != null) {
+ IHandlerService service = getHandlerService();
+ if (service != null) {
+ IHandlerActivation activation = service.activateHandler(
+ actionHandler.getActionDefinitionId(), new ActionHandler(actionHandler), fExpression);
+ fPaneActivations.add(activation);
+ return;
+ }
+ }
+ // Remove the action definition id since we won't get key bindings
+ if (actionHandler != null) {
+ actionHandler.setActionDefinitionId(null);
+ }
+ }
+
+ private void updateActionBars() {
+ IActionBars bars = getActionBars();
+ if (bars != null) {
+ bars.updateActionBars();
+ }
+ }
+
+ private void clearPaneActionHandlers() {
+ if (!fPaneActivations.isEmpty()) {
+ IHandlerService service = getHandlerService();
+ if (service != null) {
+ service.deactivateHandlers(fPaneActivations);
+ fPaneActivations.clear();
+ }
+ }
+ }
+
+ private IActionBars getActionBars() {
+ return fContainer.getActionBars();
+ }
+
+ public void dispose() {
+ clearPaneActionHandlers();
+ IHandlerService service = getHandlerService();
+ if (service == null) {
+ return;
+ }
+ service.deactivateHandlers(fActivations);
+ fActivations.clear();
+ fDisposed = true;
+ }
+
+ public void updatePaneActionHandlers(Runnable runnable) {
+ clearPaneActionHandlers();
+ runnable.run();
+ updateActionBars();
+ }
+}

Back to the top