Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d34913b709c7d7ebf5e52e1550bbd30e6c956ba7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************************************
 * Copyright (c) 2007, 2017 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.compare.internal;

import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.core.runtime.*;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Composite;

/**
 * Class which allows content merge viewer to provide a structure viewer that can be used in the outline
 * view.
 */
public abstract class OutlineViewerCreator {

	/**
	 * Property constant that identifies the input of the outline view.
	 */
	public static final String PROP_INPUT = "org.eclipse.compare.OutlineInput"; //$NON-NLS-1$

	private ListenerList<IPropertyChangeListener> listeners = new ListenerList<>(ListenerList.IDENTITY);

	/**
	 * Method called by the editor to create a structure viewer for the current content merge viewer.
	 * @param oldViewer the current viewer that is being used to show the structure
	 * @param input the input
	 * @param parent the parent composite
	 * @param configuration the compare configuration
	 * @return a viewer to be placed in the outline viewer or <code>null</code>
	 */
	public abstract Viewer findStructureViewer(Viewer oldViewer, ICompareInput input,
			Composite parent, CompareConfiguration configuration);

	public abstract boolean hasViewerFor(Object input);

	public void addPropertyChangeListener(IPropertyChangeListener listener) {
		listeners.add(listener);
	}

	public void removePropertyChangeListener(IPropertyChangeListener listener) {
		listeners.remove(listener);
	}

	public void fireInputChange(Object oldInput, Object newInput) {
		final PropertyChangeEvent event = new PropertyChangeEvent(this, PROP_INPUT, oldInput, newInput);
		for (final IPropertyChangeListener listener : listeners) {
			SafeRunner.run(new ISafeRunnable() {
				@Override
				public void run() throws Exception {
					listener.propertyChange(event);
				}
				@Override
				public void handleException(Throwable exception) {
					// Logged by SafeRunner
				}
			});
		}
	}

	public abstract Object getInput();

}

Back to the top