KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
15 import org.eclipse.debug.core.sourcelookup.containers.ZipEntryStorage;
16 import org.eclipse.jdt.core.IClassFile;
17 import org.eclipse.jdt.core.ICompilationUnit;
18 import org.eclipse.jdt.core.IJavaElement;
19 import org.eclipse.jdt.ui.JavaUI;
20 import org.eclipse.jface.viewers.ILabelProvider;
21 import org.eclipse.jface.viewers.LabelProvider;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.ui.ISharedImages;
24 import org.eclipse.ui.PlatformUI;
25
26 /**
27  * A label provider for source elements found with a JavaSourceLocator
28  */

29 public class SourceElementLabelProvider extends LabelProvider implements ILabelProvider {
30
31     /**
32      * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
33      */

34     public String JavaDoc getText(Object JavaDoc element) {
35         if (element instanceof IJavaElement) {
36             return ((IJavaElement)element).getElementName();
37         } else if (element instanceof ZipEntryStorage) {
38             ZipEntryStorage storage = (ZipEntryStorage)element;
39             return storage.getZipEntry().getName();
40         } else if (element instanceof LocalFileStorage) {
41             LocalFileStorage storage = (LocalFileStorage)element;
42             return storage.getName();
43         }
44         return super.getText(element);
45     }
46
47     /**
48      * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
49      */

50     public Image getImage(Object JavaDoc element) {
51         if (element instanceof ICompilationUnit) {
52             return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_CUNIT);
53         } else if (element instanceof IClassFile) {
54             return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_CFILE);
55         } else if (element instanceof ZipEntryStorage) {
56             return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
57         } else if (element instanceof LocalFileStorage) {
58             return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
59         }
60         return super.getImage(element);
61     }
62
63 }
64
Popular Tags