Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e5049a378d46914b8defe1cff94fbba1a89d0c5f (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
package org.eclipse.compare.internal;

import org.eclipse.compare.CompareEditorInput;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.ui.IContributorResourceAdapter;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;

public class AdapterFactory implements IAdapterFactory {

	public Object getAdapter(final Object adaptableObject, Class adapterType) {
		if (IContributorResourceAdapter.class.equals(adapterType)
				&& adaptableObject instanceof CompareEditorInput) {
			return new IContributorResourceAdapter() {
				public IResource getAdaptedResource(IAdaptable adaptable) {
					Object ei = ((CompareEditorInput) adaptableObject)
							.getAdapter(IEditorInput.class);
					if (ei instanceof IFileEditorInput) {
						return ((IFileEditorInput) ei).getFile();
					}
					return null;
				}
			};
		}
		return null;
	}

	public Class[] getAdapterList() {
		return new Class[] { IContributorResourceAdapter.class };
	}
}

Back to the top