Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 08258886b96965581711c40a53be8a6d4ca98281 (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
/*******************************************************************************
 * Copyright (c) 2005, 2008 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
 *     QNX Software System
 *     Anton Leherbauer (Wind River Systems)
 *******************************************************************************/
package org.eclipse.cdt.internal.ui;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.ui.IActionFilter;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
import org.eclipse.ui.views.properties.FilePropertySource;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.ResourcePropertySource;

import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement;

/**
 * Implements basic UI support for C elements.
 */
public class CElementAdapterFactory implements IAdapterFactory {
	
	private static Class<?>[] PROPERTIES= new Class[] {
		IPropertySource.class,
		IResource.class,
		IWorkbenchAdapter.class,
		IPersistableElement.class,
		IDeferredWorkbenchAdapter.class,
		IActionFilter.class 
	};
	
	private static CWorkbenchAdapter fgCWorkbenchAdapter;
	
	/**
	 * @see CElementAdapterFactory#getAdapterList
	 */
	public Class<?>[] getAdapterList() {
		return PROPERTIES;
	}

	/**
	 * @see CElementAdapterFactory#getAdapter
	 */	
	@SuppressWarnings("unchecked")
	public Object getAdapter(Object element, Class key) {
		ICElement celem = (ICElement) element;
		
		if (IPropertySource.class.equals(key)) {
			return getPropertySource(celem);
		} else if (IResource.class.isAssignableFrom(key)) {
			IResource resource= getResource(celem);
			if (resource != null && key.isAssignableFrom(resource.getClass())) {
				return resource;
			}
		} else if (IPersistableElement.class.equals(key)) {
			return new PersistableCElementFactory(celem);
		} else if (IDeferredWorkbenchAdapter.class.equals(key)) {
			return getDeferredWorkbenchAdapter(celem);
		} else if (IWorkbenchAdapter.class.equals(key)) {
			return getWorkbenchAdapter(celem);
		} else if (IActionFilter.class.equals(key)) {
			return getWorkbenchAdapter(celem);
		}
		return null; 
	}

	private IPropertySource getPropertySource(ICElement celement) {
		if (celement instanceof IBinary) {
			return new BinaryPropertySource((IBinary)celement);				
		}
		IResource res = celement.getResource();
		if (res != null) {
			if (res instanceof IFile) {
				return new FilePropertySource((IFile)res);
			}
			return new ResourcePropertySource(res);
		}
		return new CElementPropertySource(celement);		
	}

	private IResource getResource(ICElement celement) {
		return celement.getResource();
	}

	private IDeferredWorkbenchAdapter getDeferredWorkbenchAdapter(ICElement celement) {
		return new DeferredCWorkbenchAdapter(celement);
	}

	private IWorkbenchAdapter getWorkbenchAdapter(ICElement celement) {
		if (fgCWorkbenchAdapter == null) {
			fgCWorkbenchAdapter = new CWorkbenchAdapter();
		}
		return fgCWorkbenchAdapter;
	}
}

Back to the top