KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > search > DependencyExtentLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.search;
12
13 import org.eclipse.jdt.core.IJavaElement;
14 import org.eclipse.jdt.core.IType;
15 import org.eclipse.jdt.ui.JavaElementLabelProvider;
16 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
17 import org.eclipse.pde.internal.ui.*;
18 import org.eclipse.search.ui.ISearchResultViewEntry;
19 import org.eclipse.swt.graphics.Image;
20
21
22 public class DependencyExtentLabelProvider extends JavaElementLabelProvider {
23
24     public Image getImage(Object JavaDoc element) {
25         if (element instanceof ISearchResultViewEntry) {
26             ISearchResultViewEntry entry = (ISearchResultViewEntry) element;
27             element = entry.getGroupByKey();
28         }
29         if (element instanceof IPluginExtensionPoint)
30             return PDEPlugin.getDefault().getLabelProvider().getImage(
31                 (IPluginExtensionPoint) element);
32
33         return super.getImage(element);
34     }
35
36     public String JavaDoc getText(Object JavaDoc element) {
37         if (element instanceof ISearchResultViewEntry) {
38             ISearchResultViewEntry entry = (ISearchResultViewEntry) element;
39             element = entry.getGroupByKey();
40         }
41         if (element instanceof IPluginExtensionPoint) {
42             return ((IPluginExtensionPoint) element)
43                 .getPluginModel()
44                 .getPluginBase()
45                 .getId()
46                 + "." //$NON-NLS-1$
47
+ ((IPluginExtensionPoint) element).getId();
48         } else if (element instanceof IJavaElement) {
49             IJavaElement javaElement = (IJavaElement) element;
50             String JavaDoc text =
51                 super.getText(javaElement)
52                     + " - " //$NON-NLS-1$
53
+ javaElement
54                         .getAncestor(IJavaElement.PACKAGE_FRAGMENT)
55                         .getElementName();
56             if (!(javaElement instanceof IType)) {
57                 IJavaElement ancestor = javaElement.getAncestor(IJavaElement.TYPE);
58                 if (ancestor == null)
59                     ancestor = javaElement.getAncestor(IJavaElement.CLASS_FILE);
60                 if (ancestor == null)
61                     ancestor = javaElement.getAncestor(IJavaElement.COMPILATION_UNIT);
62                 if (ancestor != null)
63                     text += "." + ancestor.getElementName(); //$NON-NLS-1$
64
}
65             return text;
66         }
67         return super.getText(element);
68     }
69 }
70
Popular Tags