Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cfbfe4330dbcb3713c0625fe6bb8fbdfd3c681b1 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*******************************************************************************
 * Copyright (c) 2000, 2011 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.CompareViewerSwitchingPane;
import org.eclipse.compare.Splitter;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.part.IPageSite;
import org.eclipse.ui.part.Page;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;

public class CompareOutlinePage extends Page implements IContentOutlinePage, IPropertyChangeListener {
	private CompareEditor fCompareEditor;
	private Control fControl;
	private CompareViewerSwitchingPane fStructurePane;
	private OutlineViewerCreator fCreator;

	CompareOutlinePage(CompareEditor editor) {
		fCompareEditor= editor;
	}

	@Override
	public void createControl(Composite parent) {
		final Splitter h= new Splitter(parent, SWT.HORIZONTAL);
		fStructurePane= new CompareViewerSwitchingPane(h, SWT.BORDER | SWT.FLAT, true) {
			@Override
			protected Viewer getViewer(Viewer oldViewer, Object input) {
				if (input instanceof ICompareInput)
					return findStructureViewer(oldViewer, (ICompareInput)input, this);
				return null;
			}
		};
		h.setVisible(fStructurePane, true);
		fControl = h;
		IPageSite site = getSite();
		site.setSelectionProvider(fStructurePane);
		h.layout();
		reset();
	}

	private Viewer findStructureViewer(Viewer oldViewer, ICompareInput input, Composite parent) {
		OutlineViewerCreator creator = getCreator();
		if (creator != null)
			return creator.findStructureViewer(oldViewer, input, parent, getCompareConfiguration());
		return null;
	}

	private CompareConfiguration getCompareConfiguration() {
		return fCompareEditor.getCompareConfiguration();
	}

	@Override
	public Control getControl() {
		return fControl;
	}

	@Override
	public void setFocus() {
		if (fStructurePane != null)
			fStructurePane.setFocus();
	}

	@Override
	public void addSelectionChangedListener(ISelectionChangedListener listener) {
		if (fStructurePane != null)
			fStructurePane.addSelectionChangedListener(listener);
	}

	@Override
	public ISelection getSelection() {
		if (fStructurePane != null)
			return fStructurePane.getSelection();
		return StructuredSelection.EMPTY;
	}

	@Override
	public void removeSelectionChangedListener(ISelectionChangedListener listener) {
		if (fStructurePane != null)
			fStructurePane.removeSelectionChangedListener(listener);
	}

	@Override
	public void setSelection(ISelection selection) {
		if (fStructurePane != null)
			fStructurePane.setSelection(selection);
	}

	private void setInput(Object input) {
		if (fStructurePane != null) {
			fStructurePane.setInput(input);
			((Splitter)fControl).layout();
		}
	}

	public OutlineViewerCreator getCreator() {
		if (fCreator == null) {
			fCreator = Adapters.adapt(fCompareEditor, OutlineViewerCreator.class);
			if (fCreator != null)
				fCreator.addPropertyChangeListener(this);
		}
		return fCreator;
	}

	@Override
	public void propertyChange(PropertyChangeEvent event) {
		if (event.getProperty().equals(OutlineViewerCreator.PROP_INPUT)) {
			fStructurePane.setInput(event.getNewValue());
			((Splitter)fControl).layout();
		}
	}

	@Override
	public void dispose() {
		super.dispose();
		if (fCreator != null)
			fCreator.removePropertyChangeListener(this);
		fCreator = null;
	}

	public void reset() {
		if (fCreator != null)
			fCreator.removePropertyChangeListener(this);
		fCreator = null;
		OutlineViewerCreator creator = getCreator();
		if (creator != null) {
			setInput(creator.getInput());
		} else {
			setInput(null);
		}
	}
}

Back to the top