|
Lines 10-17
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.internal.navigator; |
11 |
package org.eclipse.ui.internal.navigator; |
| 12 |
|
12 |
|
|
|
13 |
import org.eclipse.core.runtime.Assert; |
| 13 |
import org.eclipse.core.runtime.IAdaptable; |
14 |
import org.eclipse.core.runtime.IAdaptable; |
| 14 |
import org.eclipse.core.runtime.Platform; |
15 |
import org.eclipse.core.runtime.Platform; |
|
|
16 |
import org.eclipse.core.runtime.PlatformObject; |
| 15 |
|
17 |
|
| 16 |
/** |
18 |
/** |
| 17 |
* Provides utilities for working with adaptable and non-adaptable objects. |
19 |
* Provides utilities for working with adaptable and non-adaptable objects. |
|
Lines 32-45
Link Here
|
| 32 |
* @return An adapter of the requested type or null |
34 |
* @return An adapter of the requested type or null |
| 33 |
*/ |
35 |
*/ |
| 34 |
public static Object getAdapter(Object anElement, Class anAdapterType) { |
36 |
public static Object getAdapter(Object anElement, Class anAdapterType) { |
| 35 |
if (anElement == null) { |
37 |
if (anElement == null || anAdapterType == null) { |
| 36 |
return null; |
38 |
return null; |
| 37 |
} else if (anElement instanceof IAdaptable) { |
39 |
} |
| 38 |
return ((IAdaptable) anElement).getAdapter(anAdapterType); |
40 |
if (anAdapterType.isInstance(anElement)) { |
| 39 |
} else { |
41 |
return anElement; |
| 40 |
return Platform.getAdapterManager().getAdapter(anElement, |
42 |
} |
| 41 |
anAdapterType); |
43 |
|
| 42 |
} |
44 |
if (anElement instanceof IAdaptable) { |
|
|
45 |
IAdaptable adaptable = (IAdaptable) anElement; |
| 46 |
|
| 47 |
Object result = adaptable.getAdapter(anAdapterType); |
| 48 |
if (result != null) { |
| 49 |
// Sanity-check |
| 50 |
Assert.isTrue(anAdapterType.isInstance(result)); |
| 51 |
return result; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
if (!(anElement instanceof PlatformObject)) { |
| 56 |
Object result = Platform.getAdapterManager().loadAdapter(anElement, anAdapterType.getName()); |
| 57 |
if (result != null) { |
| 58 |
return result; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
return null; |
| 43 |
} |
63 |
} |
| 44 |
|
64 |
|
| 45 |
} |
65 |
} |