KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > launcher > SourceElementQualifierProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.debug.ui.launcher;
12
13
14 import java.io.File JavaDoc;
15 import java.util.zip.ZipFile JavaDoc;
16
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.runtime.IPath;
19 import org.eclipse.core.runtime.Path;
20 import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
21 import org.eclipse.debug.core.sourcelookup.containers.ZipEntryStorage;
22 import org.eclipse.jdt.core.IJavaElement;
23 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
24 import org.eclipse.jdt.launching.JavaRuntime;
25 import org.eclipse.jdt.ui.JavaElementLabelProvider;
26 import org.eclipse.jdt.ui.JavaUI;
27 import org.eclipse.jface.viewers.ILabelProvider;
28 import org.eclipse.jface.viewers.LabelProvider;
29 import org.eclipse.swt.graphics.Image;
30 import org.eclipse.ui.ISharedImages;
31 import org.eclipse.ui.PlatformUI;
32
33 /**
34  * A label provider for source element qualifiers found with a JavaSourceLocator
35  */

36 public class SourceElementQualifierProvider extends LabelProvider implements ILabelProvider {
37     
38     private JavaElementLabelProvider fJavaLabels;
39
40     /* (non-Javadoc)
41      * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
42      */

43     public String JavaDoc getText(Object JavaDoc element) {
44         if (element instanceof IJavaElement) {
45             IJavaElement parent = ((IJavaElement)element).getParent();
46             return fJavaLabels.getText(parent);
47         } else if (element instanceof ZipEntryStorage) {
48             ZipEntryStorage storage = (ZipEntryStorage)element;
49             ZipFile JavaDoc zipFile = storage.getArchive();
50             IPath path = new Path(zipFile.getName());
51             IRuntimeClasspathEntry entry = JavaRuntime.newArchiveRuntimeClasspathEntry(path);
52             IResource res = entry.getResource();
53             if (res == null) {
54                 // external
55
return zipFile.getName();
56             }
57             // internal
58
return res.getName();
59         } else if (element instanceof LocalFileStorage) {
60             LocalFileStorage storage = (LocalFileStorage)element;
61             File JavaDoc extFile = storage.getFile();
62             return extFile.getParent();
63         }
64         return super.getText(element);
65     }
66     
67     /* (non-Javadoc)
68      * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
69      */

70     public Image getImage(Object JavaDoc element) {
71         if (element instanceof IJavaElement) {
72             IJavaElement parent = ((IJavaElement)element).getParent();
73             return fJavaLabels.getImage(parent);
74         } else if (element instanceof ZipEntryStorage) {
75             return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_JAR_WITH_SOURCE);
76         } else if (element instanceof LocalFileStorage) {
77             return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
78         }
79         return super.getImage(element);
80     }
81
82     /**
83      * Constructs a new label provider
84      */

85     public SourceElementQualifierProvider() {
86         super();
87         fJavaLabels = new JavaElementLabelProvider();
88     }
89
90     /* (non-Javadoc)
91      * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
92      */

93     public void dispose() {
94         super.dispose();
95         fJavaLabels.dispose();
96         fJavaLabels = null;
97     }
98 }
99
Popular Tags