Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 156581 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/navigator/AdaptabilityUtility.java (-9 / +30 lines)
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 26-45 Link Here
26
	 * 
28
	 * 
27
	 * @param anElement
29
	 * @param anElement
28
	 *            The element to adapt, which may or may not implement
30
	 *            The element to adapt, which may or may not implement
29
	 *            {@link IAdaptable}
31
	 *            {@link IAdaptable}, or null
30
	 * @param anAdapterType
32
	 * @param anAdapterType
31
	 *            The class type to return
33
	 *            The class type to return
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
		Assert.isNotNull(anAdapterType);
36
			return null;
38
        if (anElement == null) {
37
		} else if (anElement instanceof IAdaptable) {
39
            return null;
38
			return ((IAdaptable) anElement).getAdapter(anAdapterType);
40
        }
39
		} else {
41
        if (anAdapterType.isInstance(anElement)) {
40
			return Platform.getAdapterManager().getAdapter(anElement,
42
            return anElement;
41
					anAdapterType);
43
        }
42
		}
44
45
        if (anElement instanceof IAdaptable) {
46
            IAdaptable adaptable = (IAdaptable) anElement;
47
48
            Object result = adaptable.getAdapter(anAdapterType);
49
            if (result != null) {
50
                // Sanity-check
51
                Assert.isTrue(anAdapterType.isInstance(result));
52
                return result;
53
            }
54
        } 
55
        
56
        if (!(anElement instanceof PlatformObject)) {
57
            Object result = Platform.getAdapterManager().getAdapter(anElement, anAdapterType);
58
            if (result != null) {
59
                return result;
60
            }
61
        }
62
63
        return null;
43
	}
64
	}
44
65
45
}
66
}
(-)src/org/eclipse/ui/internal/navigator/NavigatorSaveablesService.java (-6 / +2 lines)
Lines 21-27 Link Here
21
import java.util.Set;
21
import java.util.Set;
22
import java.util.TreeMap;
22
import java.util.TreeMap;
23
23
24
import org.eclipse.core.runtime.IAdaptable;
25
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.core.runtime.Platform;
26
import org.eclipse.jface.viewers.IStructuredSelection;
25
import org.eclipse.jface.viewers.IStructuredSelection;
27
import org.eclipse.jface.viewers.ITreeContentProvider;
26
import org.eclipse.jface.viewers.ITreeContentProvider;
Lines 462-472 Link Here
462
				.getExtension(descriptor, true);
461
				.getExtension(descriptor, true);
463
		ITreeContentProvider contentProvider = extension
462
		ITreeContentProvider contentProvider = extension
464
				.getContentProvider();
463
				.getContentProvider();
465
		if (contentProvider instanceof IAdaptable) {
464
        
466
			return (SaveablesProvider) ((IAdaptable) contentProvider)
465
        return (SaveablesProvider)AdaptabilityUtility.getAdapter(contentProvider, SaveablesProvider.class);
467
					.getAdapter(SaveablesProvider.class);
468
		}
469
		return null;
470
	}
466
	}
471
467
472
	private Saveable[] getShownSaveables(Saveable[] saveables) {
468
	private Saveable[] getShownSaveables(Saveable[] saveables) {

Return to bug 156581