Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikaël Barbero2013-10-08 06:37:14 -0400
committerMikaël Barbero2013-10-18 13:47:51 -0400
commit897c84fee8722b11a2b7890c030be502a39c637c (patch)
tree3673687a92f0fb8a95c75e893f37b06a13d61144 /plugins/org.eclipse.emf.compare.ide.ui/src
parent4809958be3654a31aa539794aebfd70726e4741b (diff)
downloadorg.eclipse.emf.compare-897c84fee8722b11a2b7890c030be502a39c637c.tar.gz
org.eclipse.emf.compare-897c84fee8722b11a2b7890c030be502a39c637c.tar.xz
org.eclipse.emf.compare-897c84fee8722b11a2b7890c030be502a39c637c.zip
Rewrite viewer wrapper delegation logic.
The decorated viewer is not leaked anymore through #input and event Change-Id: I50e2737a1f9921a5b0b41a4104f4162d35f58309
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/AbstractStructuredViewerWrapper.java525
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractViewerWrapper.java369
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java21
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java103
4 files changed, 589 insertions, 429 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractStructuredViewerWrapper.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractStructuredViewerWrapper.java
new file mode 100644
index 000000000..35ef8cae5
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractStructuredViewerWrapper.java
@@ -0,0 +1,525 @@
+/*******************************************************************************
+ * 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 java.util.List;
+
+import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IElementComparer;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.dnd.DragSourceListener;
+import org.eclipse.swt.dnd.DropTargetListener;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.HelpEvent;
+import org.eclipse.swt.events.HelpListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public abstract class AbstractStructuredViewerWrapper<C extends Control, V extends StructuredViewer> extends StructuredViewer {
+
+ /** The wrapped Viewer. */
+ private final V fViewer;
+
+ /** A composite control that will contains all sub-control of this wrapper. */
+ private final C fControl;
+
+ /** The compare configuration object. */
+ private final EMFCompareConfiguration fConfiguration;
+
+ /** The selection changed listener of the wrapped viewer. */
+ private final ISelectionChangedListener fWrappedViewerSelectionChangedListener;
+
+ /** The help listener of the wrapped viewer. */
+ private final HelpListener fWrappedViewerHelpListener;
+
+ public final IDoubleClickListener fWrappedViewerDoubleClickListener;
+
+ public final ISelectionChangedListener fWrappedViewerPostSelectionChangedListener;
+
+ public final IOpenListener fWrappedViewerOpenListener;
+
+ /**
+ * Constructor.
+ *
+ * @param parent
+ * the SWT parent control under which to create the viewer's SWT control.
+ */
+ public AbstractStructuredViewerWrapper(Composite parent, EMFCompareConfiguration compareConfiguration) {
+ fConfiguration = compareConfiguration;
+
+ preHookCreateControlAndViewer();
+ ControlAndViewer<C, V> cv = createControlAndViewer(parent);
+ fControl = cv.getControl();
+ fViewer = cv.getViewer();
+ hookControl(fControl);
+
+ fWrappedViewerSelectionChangedListener = new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ fireSelectionChanged(new SelectionChangedEvent(AbstractStructuredViewerWrapper.this, event
+ .getSelection()));
+ }
+ };
+ fViewer.addSelectionChangedListener(fWrappedViewerSelectionChangedListener);
+
+ fWrappedViewerHelpListener = new HelpListener() {
+ public void helpRequested(HelpEvent e) {
+ Event event = new Event();
+ event.widget = fControl;
+ event.display = e.display;
+ event.widget = e.widget;
+ event.time = e.time;
+ event.data = e.data;
+ fireHelpRequested(new HelpEvent(event));
+ }
+ };
+ fViewer.addHelpListener(fWrappedViewerHelpListener);
+
+ fWrappedViewerDoubleClickListener = new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ fireDoubleClick(new DoubleClickEvent(AbstractStructuredViewerWrapper.this, event
+ .getSelection()));
+ }
+ };
+ fViewer.addDoubleClickListener(fWrappedViewerDoubleClickListener);
+
+ fWrappedViewerPostSelectionChangedListener = new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ fireSelectionChanged(new SelectionChangedEvent(AbstractStructuredViewerWrapper.this, event
+ .getSelection()));
+ }
+ };
+ fViewer.addPostSelectionChangedListener(fWrappedViewerPostSelectionChangedListener);
+
+ fWrappedViewerOpenListener = new IOpenListener() {
+ public void open(OpenEvent event) {
+ fireOpen(new OpenEvent(AbstractStructuredViewerWrapper.this, event.getSelection()));
+ }
+ };
+ fViewer.addOpenListener(fWrappedViewerOpenListener);
+
+ }
+
+ /**
+ * Get the compare configuration object.
+ *
+ * @return the compare configuration object.
+ */
+ protected final EMFCompareConfiguration getCompareConfiguration() {
+ return fConfiguration;
+ }
+
+ @Override
+ protected final void hookControl(Control control) {
+ control.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent event) {
+ handleDispose(event);
+ }
+ });
+ }
+
+ /**
+ *
+ */
+ protected void preHookCreateControlAndViewer() {
+
+ }
+
+ /**
+ * Should call {@link #setViewer(org.eclipse.jface.viewers.Viewer)}.
+ *
+ * @param parent
+ * the SWT control under which to create the viewer.
+ * @return a composite control that will contains all sub-control of this wrapper.
+ */
+ protected abstract ControlAndViewer<C, V> createControlAndViewer(Composite parent);
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.Viewer#getControl()
+ */
+ @Override
+ public final Control getControl() {
+ return fControl;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.ContentViewer#getInput()
+ */
+ @Override
+ public final Object getInput() {
+ return super.getInput();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#getSelection()
+ */
+ @Override
+ public final ISelection getSelection() {
+ return fViewer.getSelection();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#setSelection(ISelection, boolean)
+ */
+ @Override
+ public final void setSelection(ISelection selection, boolean reveal) {
+ fViewer.setSelection(selection, reveal);
+ }
+
+ /**
+ * Returns the {@link StructuredViewer} associated with this wrapper.
+ *
+ * @return a StructuredViewer.
+ */
+ protected final V getViewer() {
+ return fViewer;
+ }
+
+ @Override
+ protected void handleDispose(DisposeEvent event) {
+ fViewer.removeOpenListener(fWrappedViewerOpenListener);
+ fViewer.removePostSelectionChangedListener(fWrappedViewerPostSelectionChangedListener);
+ fViewer.removeDoubleClickListener(fWrappedViewerDoubleClickListener);
+ fViewer.removeSelectionChangedListener(fWrappedViewerSelectionChangedListener);
+ fViewer.removeHelpListener(fWrappedViewerHelpListener);
+ super.handleDispose(event);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#setContentProvider(org.eclipse.jface.viewers.IContentProvider)
+ */
+ @Override
+ public final void setContentProvider(IContentProvider provider) {
+ fViewer.setContentProvider(provider);
+ super.setContentProvider(provider);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#setLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider)
+ */
+ @Override
+ public final void setLabelProvider(IBaseLabelProvider labelProvider) {
+ fViewer.setLabelProvider(labelProvider);
+ super.setLabelProvider(labelProvider);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#addDragSupport(int, org.eclipse.swt.dnd.Transfer[],
+ * org.eclipse.swt.dnd.DragSourceListener)
+ */
+ @Override
+ public final void addDragSupport(int operations, Transfer[] transferTypes, DragSourceListener listener) {
+ fViewer.addDragSupport(operations, transferTypes, listener);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#addDropSupport(int, org.eclipse.swt.dnd.Transfer[],
+ * org.eclipse.swt.dnd.DropTargetListener)
+ */
+ @Override
+ public final void addDropSupport(int operations, Transfer[] transferTypes, DropTargetListener listener) {
+ fViewer.addDropSupport(operations, transferTypes, listener);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#addFilter(org.eclipse.jface.viewers.ViewerFilter)
+ */
+ @Override
+ public final void addFilter(ViewerFilter filter) {
+ fViewer.addFilter(filter);
+ super.addFilter(filter);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(java.lang.Object)
+ */
+ @Override
+ protected final Widget doFindInputItem(Object element) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object)
+ */
+ @Override
+ protected final Widget doFindItem(Object element) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(org.eclipse.swt.widgets.Widget,
+ * java.lang.Object, boolean)
+ */
+ @Override
+ protected void doUpdateItem(Widget item, Object element, boolean fullMap) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#getComparer()
+ */
+ @Override
+ public final IElementComparer getComparer() {
+ return fViewer.getComparer();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#getFilters()
+ */
+ @Override
+ public final ViewerFilter[] getFilters() {
+ return fViewer.getFilters();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#removeFilter(org.eclipse.jface.viewers.ViewerFilter)
+ */
+ @Override
+ public final void removeFilter(ViewerFilter filter) {
+ fViewer.removeFilter(filter);
+ super.removeFilter(filter);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#setFilters(org.eclipse.jface.viewers.ViewerFilter[])
+ */
+ @Override
+ public final void setFilters(ViewerFilter[] filters) {
+ fViewer.setFilters(filters);
+ super.setFilters(filters);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#resetFilters()
+ */
+ @Override
+ public final void resetFilters() {
+ fViewer.resetFilters();
+ super.resetFilters();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#reveal(java.lang.Object)
+ */
+ @Override
+ public void reveal(Object element) {
+ fViewer.reveal(element);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#getSelectionFromWidget()
+ */
+ @SuppressWarnings("rawtypes")
+ @Override
+ protected List getSelectionFromWidget() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#getSorter()
+ */
+ @Override
+ public final ViewerSorter getSorter() {
+ return fViewer.getSorter();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#getComparator()
+ */
+ @Override
+ public final ViewerComparator getComparator() {
+ return fViewer.getComparator();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java.util.List, boolean)
+ */
+ @Override
+ protected final void setSelectionToWidget(List l, boolean reveal) {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#updateSelection(org.eclipse.jface.viewers.ISelection)
+ */
+ @Override
+ protected void updateSelection(ISelection selection) {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#handleInvalidSelection(org.eclipse.jface.viewers.ISelection,
+ * org.eclipse.jface.viewers.ISelection)
+ */
+ @Override
+ protected void handleInvalidSelection(ISelection invalidSelection, ISelection newSelection) {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#setSorter(org.eclipse.jface.viewers.ViewerSorter)
+ */
+ @Override
+ public final void setSorter(ViewerSorter sorter) {
+ fViewer.setSorter(sorter);
+ super.setSorter(sorter);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#setComparator(org.eclipse.jface.viewers.ViewerComparator)
+ */
+ @Override
+ public final void setComparator(ViewerComparator comparator) {
+ fViewer.setComparator(comparator);
+ super.setComparator(comparator);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#setUseHashlookup(boolean)
+ */
+ @Override
+ public final void setUseHashlookup(boolean enable) {
+ fViewer.setUseHashlookup(enable);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#setComparer(org.eclipse.jface.viewers.IElementComparer)
+ */
+ @Override
+ public void setComparer(IElementComparer comparer) {
+ fViewer.setComparer(comparer);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#update(java.lang.Object[], java.lang.String[])
+ */
+ @Override
+ public void update(Object[] elements, String[] properties) {
+ fViewer.update(elements, properties);
+ super.update(elements, properties);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.StructuredViewer#update(java.lang.Object, java.lang.String[])
+ */
+ @Override
+ public final void update(Object element, String[] properties) {
+ fViewer.update(element, properties);
+ super.update(element, properties);
+ }
+
+ public static final class ControlAndViewer<C extends Control, V extends Viewer> {
+ private final C control;
+
+ private final V viewer;
+
+ private ControlAndViewer(C control, V viewer) {
+ this.control = control;
+ this.viewer = viewer;
+ }
+
+ /**
+ * @return the c
+ */
+ public C getControl() {
+ return control;
+ }
+
+ /**
+ * @return the v
+ */
+ public V getViewer() {
+ return viewer;
+ }
+
+ public static <C extends Control, V extends Viewer> ControlAndViewer<C, V> create(C control, V viewer) {
+ return new ControlAndViewer<C, V>(control, viewer);
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractViewerWrapper.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractViewerWrapper.java
deleted file mode 100644
index 41b62f00b..000000000
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/AbstractViewerWrapper.java
+++ /dev/null
@@ -1,369 +0,0 @@
-/*******************************************************************************
- * 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 java.util.List;
-
-import org.eclipse.compare.CompareConfiguration;
-import org.eclipse.jface.viewers.IBaseLabelProvider;
-import org.eclipse.jface.viewers.IContentProvider;
-import org.eclipse.jface.viewers.IOpenListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredViewer;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Widget;
-
-/**
- * A control that wrapped a StructuredViewer and another control.
- *
- * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
- */
-public abstract class AbstractViewerWrapper extends StructuredViewer {
-
- /** The StructuredViewer associated with this wrapper. */
- private StructuredViewer fViewer;
-
- /** A composite control that will contains all sub-control of this wrapper. */
- private final Control fControl;
-
- /** The selection changed listener. */
- private ISelectionChangedListener fWrappedViewerListener;
-
- /** The compare configuration object. */
- private final CompareConfiguration fConfiguration;
-
- /**
- * Constructor.
- *
- * @param parent
- * the SWT parent control under which to create the viewer's SWT control.
- * @param config
- * a compare configuration the newly created viewer might want to use.
- */
- public AbstractViewerWrapper(Composite parent, CompareConfiguration config) {
- fConfiguration = config;
- fControl = createControl(parent, config);
- hookControl(fControl);
- fWrappedViewerListener = new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- fireSelectionChanged(new SelectionChangedEvent(AbstractViewerWrapper.this, event
- .getSelection()));
- }
- };
- fViewer.addSelectionChangedListener(fWrappedViewerListener);
-
- setLabelProvider(fViewer.getLabelProvider());
- setContentProvider(fViewer.getContentProvider());
- }
-
- /**
- * Should call {@link #setViewer(org.eclipse.jface.viewers.Viewer)}.
- *
- * @param parent
- * the SWT control under which to create the viewer.
- * @param config
- * the compare configuration object.
- * @return a composite control that will contains all sub-control of this wrapper.
- */
- protected abstract Control createControl(Composite parent, CompareConfiguration config);
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#addOpenListener(IOpenListener)
- */
- @Override
- public void addOpenListener(IOpenListener listener) {
- fViewer.addOpenListener(listener);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#removeOpenListener(IOpenListener)
- */
- @Override
- public void removeOpenListener(IOpenListener listener) {
- fViewer.removeOpenListener(listener);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#update(Object, String[])
- */
- @Override
- public void update(Object element, String[] properties) {
- fViewer.update(element, properties);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.Viewer#getControl()
- */
- @Override
- public Control getControl() {
- return fControl;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.ContentViewer#getInput()
- */
- @Override
- public Object getInput() {
- return super.getInput();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#getSelection()
- */
- @Override
- public ISelection getSelection() {
- return fViewer.getSelection();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#refresh()
- */
- @Override
- public void refresh() {
- fViewer.refresh();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#refresh(boolean)
- */
- @Override
- public void refresh(boolean updateLabels) {
- fViewer.refresh(updateLabels);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#setSelection(ISelection, boolean)
- */
- @Override
- public void setSelection(ISelection selection, boolean reveal) {
- fViewer.setSelection(selection, reveal);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#reveal(Object)
- */
- @Override
- public void reveal(Object element) {
- fViewer.reveal(element);
-
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.ContentViewer#getContentProvider()
- */
- @Override
- public IContentProvider getContentProvider() {
- return super.getContentProvider();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.ContentViewer#setContentProvider(IContentProvider)
- */
- @Override
- public void setContentProvider(IContentProvider provider) {
- super.setContentProvider(provider);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.ContentViewer#getLabelProvider()
- */
- @Override
- public IBaseLabelProvider getLabelProvider() {
- return super.getLabelProvider();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.ContentViewer#setLabelProvider(IBaseLabelProvider)
- */
- @Override
- public void setLabelProvider(IBaseLabelProvider labelProvider) {
- super.setLabelProvider(labelProvider);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(Object)
- */
- @Override
- protected Widget doFindInputItem(Object element) {
- /*
- * Nothing to do here. The method doFindInputItem(Object element) is only called by
- * StructuredViewer#update(Object element, String[] properties), which is override in this class.
- */
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(Object)
- */
- @Override
- protected Widget doFindItem(Object element) {
- /*
- * Nothing to do here. The method doFindItem(Object element) is only called by
- * StructuredViewer#update(Object element, String[] properties), which is override in this class.
- */
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(Widget, Object, boolean)
- */
- @Override
- protected void doUpdateItem(Widget item, Object element, boolean fullMap) {
- /*
- * Nothing to do here. The method doUpdateItem(Widget item, Object element, boolean fullMap) is only
- * called by StructuredViewer#update(Object element, String[] properties), which is override in this
- * class.
- */
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#getSelectionFromWidget()
- */
- @Override
- protected List getSelectionFromWidget() {
- /*
- * Nothing to do here. The method getSelectionFromWidget() is only called by
- * StructuredViewer#getSelection(), which is override in this class.
- */
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(Object)
- */
- @Override
- protected void internalRefresh(Object element) {
- /*
- * Nothing to do here. The method internalRefresh(Object element) is only called by
- * StructuredViewer#internalRefresh(Object element, boolean updateLabels), which is override in
- * AbstractTreeViewer.
- */
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(List, boolean)
- */
- @Override
- protected void setSelectionToWidget(List l, boolean reveal) {
- /*
- * Nothing to do here. The method setSelectionToWidget(List l, boolean reveal) is only called by
- * StructuredViewer#setSelectionToWidget(ISelection selection, boolean reveal), which is override in
- * AbstractTreeViewer.
- */
- }
-
- /**
- * Adds event listener hooks to the given control.
- * <p>
- * All subclasses must call this method when their control is first established.
- * </p>
- * <p>
- * The <code>ContentViewer</code> implementation of this method hooks dispose events for the given
- * control. Subclasses may override if they need to add other control hooks; however,
- * <code>super.hookControl</code> must be invoked.
- * </p>
- *
- * @param control
- * the control
- */
- @Override
- protected void hookControl(Control control) {
- control.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent event) {
- handleDispose(event);
- }
- });
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#handleDispose(DisposeEvent)
- */
- @Override
- protected void handleDispose(DisposeEvent event) {
- fViewer.removeSelectionChangedListener(fWrappedViewerListener);
- }
-
- /**
- * Returns the {@link StructuredViewer} associated with this wrapper.
- *
- * @return a StructuredViewer.
- */
- protected StructuredViewer getViewer() {
- return fViewer;
- }
-
- /**
- * Set the {@link StructuredViewer} of this wrapper.
- *
- * @param fViewer
- * a StructuredViewer.
- */
- protected void setViewer(StructuredViewer viewer) {
- fViewer = viewer;
- }
-
- /**
- * Get the compare configuration object.
- *
- * @return the compare configuration object.
- */
- public CompareConfiguration getCompareConfiguration() {
- return fConfiguration;
- }
-
-}
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 553d226d1..757af17d7 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
@@ -41,7 +41,6 @@ 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;
@@ -80,8 +79,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
private final CompareViewerSwitchingPane fParent;
- private Object fRoot;
-
private Listener fEraseItemListener;
private AdapterFactory adapterFactory;
@@ -100,10 +97,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
getCompareConfiguration().getEventBus().register(this);
- setLabelProvider(new DelegatingStyledCellLabelProvider(
- new EMFCompareStructureMergeViewerLabelProvider(adapterFactory, this)));
- setContentProvider(new EMFCompareStructureMergeViewerContentProvider(adapterFactory));
-
if (parent.getParent() instanceof CompareViewerSwitchingPane) {
fParent = (CompareViewerSwitchingPane)parent.getParent();
} else {
@@ -185,20 +178,6 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer {
return null;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.StructuredViewer#getRoot()
- */
- @Override
- public Object getRoot() {
- return fRoot;
- }
-
- public void setRoot(Object root) {
- fRoot = root;
- }
-
public void createChildrenSilently(Object o) {
if (o instanceof Tree) {
createChildren((Widget)o);
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 89611fbf9..e85da2a97 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
@@ -23,7 +23,6 @@ import java.util.EventObject;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareUI;
import org.eclipse.compare.CompareViewerPane;
import org.eclipse.compare.INavigatable;
@@ -65,6 +64,7 @@ import org.eclipse.emf.compare.ide.ui.logical.IModelResolver;
import org.eclipse.emf.compare.ide.ui.logical.IStorageProviderAccessor;
import org.eclipse.emf.compare.internal.utils.ComparisonUtil;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
+import org.eclipse.emf.compare.rcp.ui.internal.configuration.IMergePreviewModeChange;
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;
@@ -82,16 +82,17 @@ import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
import org.eclipse.emf.edit.tree.TreeFactory;
import org.eclipse.emf.edit.tree.TreeNode;
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
import org.eclipse.jface.viewers.ITreeViewerListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeExpansionEvent;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.team.core.subscribers.Subscriber;
import org.eclipse.team.core.subscribers.SubscriberMergeContext;
@@ -105,7 +106,7 @@ import org.eclipse.ui.actions.ActionFactory;
*
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
*/
-public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implements CommandStackListener {
+public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrapper<Composite, TreeViewer> implements CommandStackListener {
/** The width of the tree ruler. */
private static final int TREE_RULER_WIDTH = 17;
@@ -122,7 +123,6 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
private ITreeViewerListener fWrappedTreeListener;
/** The tree viewer. */
- private EMFCompareDiffTreeViewer diffTreeViewer;
/** The undo action. */
private UndoAction undoAction;
@@ -152,27 +152,46 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
config.getEventBus().register(this);
+ fHandlerService = CompareHandlerService.createFor(getCompareConfiguration().getContainer(),
+ getControl().getShell());
+
+ setLabelProvider(new DelegatingStyledCellLabelProvider(
+ new EMFCompareStructureMergeViewerLabelProvider(
+ getCompareConfiguration().getAdapterFactory(), this)));
+ setContentProvider(new EMFCompareStructureMergeViewerContentProvider(getCompareConfiguration()
+ .getAdapterFactory()));
+
inputChangedTask.setPriority(Job.LONG);
}
/**
* {@inheritDoc}
*
- * @see
- * org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.ViewerWrapper.createControl(Composite,
- * CompareConfiguration)
+ * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.AbstractViewerWrapper#preHookCreateControlAndViewer()
*/
@Override
- protected Control createControl(Composite parent, CompareConfiguration config) {
- Composite control = new Composite(parent, SWT.NONE);
-
+ protected void preHookCreateControlAndViewer() {
+ super.preHookCreateControlAndViewer();
fAdapterFactory = new ComposedAdapterFactory(EMFCompareRCPPlugin.getDefault()
.getAdapterFactoryRegistry());
fAdapterFactory.addAdapterFactory(new TreeItemProviderAdapterFactorySpec());
fAdapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
fAdapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
+
getCompareConfiguration().setAdapterFactory(fAdapterFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
+ * org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.ViewerWrapper.createControl(Composite,
+ * CompareConfiguration)
+ */
+ @Override
+ protected ControlAndViewer<Composite, TreeViewer> createControlAndViewer(Composite parent) {
+ Composite control = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginWidth = 0;
@@ -182,16 +201,16 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
control.setLayout(layout);
control.setLayoutData(data);
- diffTreeViewer = new EMFCompareDiffTreeViewer(control, fAdapterFactory, getCompareConfiguration());
- setViewer(diffTreeViewer);
- INavigatable nav = new Navigatable(fAdapterFactory, diffTreeViewer);
+ final TreeViewer treeViewer = new EMFCompareDiffTreeViewer(control, fAdapterFactory,
+ getCompareConfiguration());
+ INavigatable nav = new Navigatable(fAdapterFactory, treeViewer);
control.setData(INavigatable.NAVIGATOR_PROPERTY, nav);
control.setData(CompareUI.COMPARE_VIEWER_TITLE, "Model differences");
- diffTreeViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ treeViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
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, diffTreeViewer,
+ treeRuler = new EMFCompareDiffTreeRuler(control, SWT.NONE, layoutData.widthHint, treeViewer,
getCompareConfiguration());
treeRuler.setLayoutData(layoutData);
@@ -202,7 +221,6 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
};
fWrappedTreeListener = new ITreeViewerListener() {
-
public void treeExpanded(TreeExpansionEvent event) {
treeRuler.redraw();
}
@@ -211,35 +229,35 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
treeRuler.redraw();
}
};
- diffTreeViewer.addTreeListener(fWrappedTreeListener);
+ treeViewer.addTreeListener(fWrappedTreeListener);
fHandlerService = CompareHandlerService.createFor(getCompareConfiguration().getContainer(),
- diffTreeViewer.getControl().getShell());
+ treeViewer.getControl().getShell());
EventBus eventBus = new EventBus();
eventBus.register(this);
StructureMergeViewerFilter structureMergeViewerFilter = getCompareConfiguration()
.getStructureMergeViewerFilter();
- structureMergeViewerFilter.install(diffTreeViewer);
+ structureMergeViewerFilter.install(treeViewer);
StructureMergeViewerGrouper structureMergeViewerGrouper = getCompareConfiguration()
.getStructureMergeViewerGrouper();
- structureMergeViewerGrouper.install(diffTreeViewer);
+ structureMergeViewerGrouper.install(treeViewer);
toolBar = new CompareToolBar(structureMergeViewerGrouper, structureMergeViewerFilter,
getCompareConfiguration());
- diffTreeViewer.addSelectionChangedListener(toolBar);
- toolBar.initToolbar(CompareViewerPane.getToolBarManager(parent), diffTreeViewer);
+ treeViewer.addSelectionChangedListener(toolBar);
+ toolBar.initToolbar(CompareViewerPane.getToolBarManager(parent), treeViewer);
- return control;
+ return ControlAndViewer.create(control, treeViewer);
}
@Subscribe
public void handleGroupProviderSelectionChange(IDifferenceGroupProviderChange event) {
differenceGroupProvider = event.getDifferenceGroupProvider();
- Adapter root = (Adapter)diffTreeViewer.getRoot();
+ Adapter root = (Adapter)getViewer().getInput();
if (root != null) {
TreeNode target = (TreeNode)root.getTarget();
registerDifferenceGroupProvider(target, differenceGroupProvider);
@@ -247,7 +265,7 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
SWTUtil.safeAsyncExec(new Runnable() {
public void run() {
- ((EMFCompareDiffTreeViewer)diffTreeViewer).createChildrenSilently(diffTreeViewer.getTree());
+ ((EMFCompareDiffTreeViewer)getViewer()).createChildrenSilently(getViewer().getTree());
treeRuler.computeConsequences();
treeRuler.redraw();
}
@@ -274,6 +292,15 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
eAdapters.remove(oldDifferenceGroupProvider);
}
eAdapters.add(differenceGroupProvider);
+
+ treeRuler.computeConsequences();
+ treeRuler.redraw();
+ }
+
+ @Subscribe
+ public void mergePreviewModeChange(IMergePreviewModeChange event) {
+ treeRuler.computeConsequences();
+ treeRuler.redraw();
}
/**
@@ -300,13 +327,11 @@ 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)
ICompareInput ci = (ICompareInput)input;
ci.addCompareInputChangeListener(fCompareInputChangeListener);
// Hack to display a message in the tree viewer while the differences are being computed.
- TreeItem item = new TreeItem(diffTreeViewer.getTree(), SWT.NONE);
+ TreeItem item = new TreeItem(getViewer().getTree(), SWT.NONE);
item.setText("Computing model differences...");
compareInputChanged(ci);
@@ -324,13 +349,13 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
fHandlerService.dispose();
}
getCompareConfiguration().getEventBus().unregister(this);
- diffTreeViewer.removeTreeListener(fWrappedTreeListener);
+ getViewer().removeTreeListener(fWrappedTreeListener);
Object input = getInput();
if (input instanceof ICompareInput) {
ICompareInput ci = (ICompareInput)input;
ci.removeCompareInputChangeListener(fCompareInputChangeListener);
}
- diffTreeViewer.removeSelectionChangedListener(toolBar);
+ getViewer().removeSelectionChangedListener(toolBar);
compareInputChanged((ICompareInput)null);
treeRuler.handleDispose();
fAdapterFactory.dispose();
@@ -358,7 +383,7 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
SWTUtil.safeAsyncExec(new Runnable() {
public void run() {
treeRuler.computeConsequences();
- diffTreeViewer.createChildrenSilently(diffTreeViewer.getTree());
+ ((EMFCompareDiffTreeViewer)getViewer()).createChildrenSilently(getViewer().getTree());
treeRuler.redraw();
}
});
@@ -444,14 +469,13 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
getCompareConfiguration().setComparisonAndScope(comparison, scope);
registerDifferenceGroupProvider(treeNode, getSelectedDifferenceGroupProvider());
- diffTreeViewer.setRoot(fAdapterFactory.adapt(treeNode, ICompareInput.class));
SWTUtil.safeAsyncExec(new Runnable() {
public void run() {
// Mandatory for the EMFCompareDiffTreeRuler, all TreeItems must have been created
- diffTreeViewer.refreshAfterDiff(diffTreeViewer.getRoot());
- diffTreeViewer.createChildrenSilently(diffTreeViewer.getTree());
- diffTreeViewer.initialSelection();
+ ((EMFCompareDiffTreeViewer)getViewer()).refreshAfterDiff(getViewer().getInput());
+ ((EMFCompareDiffTreeViewer)getViewer()).createChildrenSilently(getViewer().getTree());
+ ((EMFCompareDiffTreeViewer)getViewer()).initialSelection();
}
});
@@ -581,7 +605,7 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
if (getCompareConfiguration() != null) {
getCompareConfiguration().dispose();
}
- diffTreeViewer.setRoot(null);
+ getViewer().setInput(null);
}
}
@@ -698,10 +722,11 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.AbstractViewerWrapper#getCompareConfiguration()
+ * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object)
*/
@Override
- public EMFCompareConfiguration getCompareConfiguration() {
- return (EMFCompareConfiguration)super.getCompareConfiguration();
+ protected void internalRefresh(Object element) {
+ getViewer().refresh();
+
}
}

Back to the top