Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a8a5b786a0153d9b2828cce9c1fda1a5ce82e390 (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
/*******************************************************************************
 * Copyright (c) 2006, 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.team.ui.history;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.history.IFileHistoryProvider;
import org.eclipse.team.internal.ui.Utils;

/**
 * Abstract HistoryPageSource class.
 * @see IHistoryPageSource
 * @since 3.2
 */
public abstract class HistoryPageSource implements IHistoryPageSource {

	/**
	 * Convenience method that returns the history page source for the
	 * given object. This method only finds a source. It does not query the source
	 * to see if the source can display history for the given object.
	 * @param object the object
	 * @return he history page source for the
	 * given object
	 */
	public static IHistoryPageSource getHistoryPageSource(Object object) {
		IResource resource = Utils.getResource(object);
		if (resource != null) {
			RepositoryProvider provider = RepositoryProvider.getProvider(resource.getProject());
			if (provider != null) {
				IFileHistoryProvider fileHistoryProvider = provider.getFileHistoryProvider();
				if (fileHistoryProvider != null) {
					IHistoryPageSource pageSource = Adapters.adapt(fileHistoryProvider, IHistoryPageSource.class);
					if (pageSource != null)
						return pageSource;
				}
				IHistoryPageSource pageSource = Adapters.adapt(provider, IHistoryPageSource.class);
				if (pageSource != null)
					return pageSource;
			}
		}
		IHistoryPageSource pageSource = Adapters.adapt(object, IHistoryPageSource.class);
		return pageSource;
	}

}

Back to the top