KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > sourcelookup > SourceContainerLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.debug.internal.ui.sourcelookup;
12
13 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
14 import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
15 import org.eclipse.debug.ui.DebugUITools;
16 import org.eclipse.jface.viewers.ILabelProvider;
17 import org.eclipse.jface.viewers.LabelProvider;
18 import org.eclipse.swt.graphics.Image;
19 import org.eclipse.ui.model.WorkbenchLabelProvider;
20
21 /**
22  * Label provider for source containers and source container types.
23  *
24  * @since 3.0
25  */

26 public class SourceContainerLabelProvider extends LabelProvider {
27     
28     private ILabelProvider fLabelProvider = null;
29     
30     /* (non-Javadoc)
31      * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
32      */

33     public Image getImage(Object JavaDoc element) {
34         // first allow workbench adapter to provide image
35
Image image = getWorkbenchLabelProvider().getImage(element);
36         if (image == null) {
37             ISourceContainerType type = null;
38             if (element instanceof ISourceContainer) {
39                 type = ((ISourceContainer)element).getType();
40             } else if (element instanceof ISourceContainerType) {
41                 type = (ISourceContainerType) element;
42             }
43             if (type != null) {
44                 // next consult contributed image
45
image = DebugUITools.getSourceContainerImage(type.getId());
46             }
47         }
48         if (image != null) {
49             return image;
50         }
51         return super.getImage(element);
52     }
53     
54     /* (non-Javadoc)
55      * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
56      */

57     public String JavaDoc getText(Object JavaDoc element) {
58         // first, allo workbench adapter to provide label
59
String JavaDoc label = getWorkbenchLabelProvider().getText(element);
60         if (label == null || label.length() == 0) {
61             if (element instanceof ISourceContainer) {
62                 return ((ISourceContainer) element).getName();
63             } else if (element instanceof ISourceContainerType) {
64                 return ((ISourceContainerType)element).getName();
65             }
66         } else {
67             return label;
68         }
69         return super.getText(element);
70     }
71     
72     private ILabelProvider getWorkbenchLabelProvider() {
73         if (fLabelProvider == null) {
74             fLabelProvider = new WorkbenchLabelProvider();
75         }
76         return fLabelProvider;
77     }
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
81      */

82     public void dispose() {
83         super.dispose();
84         if (fLabelProvider != null) {
85             fLabelProvider.dispose();
86         }
87     }
88 }
89
Popular Tags