]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.ui; | |
12 | ||
13 | ||
14 | import org.eclipse.jface.resource.ImageDescriptor; | |
15 | ||
16 | import org.eclipse.ui.model.IWorkbenchAdapter; | |
17 | ||
18 | import org.eclipse.jdt.core.IJavaElement; | |
19 | import org.eclipse.jdt.core.IParent; | |
20 | import org.eclipse.jdt.core.JavaModelException; | |
21 | ||
22 | import org.eclipse.jdt.ui.JavaElementLabels; | |
23 | ||
24 | import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput; | |
25 | import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider; | |
26 | ||
27 | /** | |
28 | * An imlementation of the IWorkbenchAdapter for IJavaElements. | |
29 | */ | |
30 | public class JavaWorkbenchAdapter implements IWorkbenchAdapter { | |
31 | ||
32 | protected static final Object[] NO_CHILDREN= new Object[0]; | |
33 | ||
34 | private JavaElementImageProvider fImageProvider; | |
35 | ||
36 | public JavaWorkbenchAdapter() { | |
37 | fImageProvider= new JavaElementImageProvider(); | |
38 | } | |
39 | ||
40 | public Object[] getChildren(Object element) { | |
41 | IJavaElement je= getJavaElement(element); | |
42 | if (je instanceof IParent) { | |
43 | try { | |
44 | return ((IParent)je).getChildren(); | |
45 | } catch(JavaModelException e) { | |
46 | JavaPlugin.log(e); | |
47 | } | |
48 | } | |
49 | return NO_CHILDREN; | |
50 | } | |
51 | ||
52 | public ImageDescriptor getImageDescriptor(Object element) { | |
53 | IJavaElement je= getJavaElement(element); | |
54 | if (je != null) | |
55 | return fImageProvider.getJavaImageDescriptor(je, JavaElementImageProvider.OVERLAY_ICONS | JavaElementImageProvider.SMALL_ICONS); | |
56 | ||
57 | return null; | |
58 | ||
59 | } | |
60 | ||
61 | public String getLabel(Object element) { | |
62 | return JavaElementLabels.getTextLabel(getJavaElement(element), JavaElementLabels.ALL_DEFAULT); | |
63 | } | |
64 | ||
65 | public Object getParent(Object element) { | |
66 | IJavaElement je= getJavaElement(element); | |
67 | return je != null ? je.getParent() : null; | |
68 | } | |
69 | ||
70 | private IJavaElement getJavaElement(Object element) { | |
71 | if (element instanceof IJavaElement) | |
72 | return (IJavaElement)element; | |
73 | if (element instanceof IClassFileEditorInput) | |
74 | return ((IClassFileEditorInput)element).getClassFile().getPrimaryElement(); | |
75 | ||
76 | return null; | |
77 | } | |
78 | } |