KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > jres > LibraryLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2006 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.jres;
12
13 import java.net.URL JavaDoc;
14
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Path;
18 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
19 import org.eclipse.jdt.internal.debug.ui.JDIImageDescriptor;
20 import org.eclipse.jdt.internal.debug.ui.jres.LibraryContentProvider.SubElement;
21 import org.eclipse.jdt.internal.ui.JavaPlugin;
22 import org.eclipse.jdt.internal.ui.JavaPluginImages;
23 import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
24 import org.eclipse.jdt.ui.ISharedImages;
25 import org.eclipse.jdt.ui.JavaUI;
26 import org.eclipse.jface.resource.ImageDescriptor;
27 import org.eclipse.jface.viewers.LabelProvider;
28 import org.eclipse.swt.graphics.Image;
29
30 /**
31  * Label provider for jre libraries.
32  *
33  * @since 3.2
34  */

35 public class LibraryLabelProvider extends LabelProvider {
36
37     private ImageDescriptorRegistry fRegistry= JavaPlugin.getImageDescriptorRegistry();
38
39     public Image getImage(Object JavaDoc element) {
40         if (element instanceof LibraryStandin) {
41             LibraryStandin library= (LibraryStandin) element;
42             IPath sourcePath= library.getSystemLibrarySourcePath();
43             String JavaDoc key = null;
44             if (sourcePath != null && !Path.EMPTY.equals(sourcePath)) {
45                 key = ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE_WITH_SOURCE;
46             } else {
47                 key = ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE;
48             }
49             IStatus status = library.validate();
50             if (!status.isOK()) {
51                 ImageDescriptor base = JavaUI.getSharedImages().getImageDescriptor(key);
52                 JDIImageDescriptor descriptor= new JDIImageDescriptor(base, JDIImageDescriptor.IS_OUT_OF_SYNCH);
53                 return JDIDebugUIPlugin.getImageDescriptorRegistry().get(descriptor);
54             }
55             return JavaUI.getSharedImages().getImage(key);
56         } else if (element instanceof SubElement) {
57             if (((SubElement)element).getType() == SubElement.SOURCE_PATH) {
58                 return fRegistry.get(JavaPluginImages.DESC_OBJS_SOURCE_ATTACH_ATTRIB); // todo: change image
59
}
60             return fRegistry.get(JavaPluginImages.DESC_OBJS_JAVADOC_LOCATION_ATTRIB); // todo: change image
61
}
62         return null;
63     }
64
65     public String JavaDoc getText(Object JavaDoc element) {
66         if (element instanceof LibraryStandin) {
67             return ((LibraryStandin)element).getSystemLibraryPath().toOSString();
68         } else if (element instanceof SubElement) {
69             SubElement subElement= (SubElement) element;
70             StringBuffer JavaDoc text= new StringBuffer JavaDoc();
71             if (subElement.getType() == SubElement.SOURCE_PATH) {
72                 text.append(JREMessages.VMLibraryBlock_0);
73                 IPath systemLibrarySourcePath= subElement.getParent().getSystemLibrarySourcePath();
74                 if (systemLibrarySourcePath != null && !Path.EMPTY.equals(systemLibrarySourcePath)) {
75                     text.append(systemLibrarySourcePath.toOSString());
76                 } else {
77                     text.append(JREMessages.VMLibraryBlock_1);
78                 }
79             } else {
80                 text.append(JREMessages.VMLibraryBlock_2);
81                 URL JavaDoc javadocLocation= subElement.getParent().getJavadocLocation();
82                 if (javadocLocation != null) {
83                     text.append(javadocLocation.toExternalForm());
84                 } else {
85                     text.append(JREMessages.VMLibraryBlock_1);
86                 }
87             }
88             return text.toString();
89         }
90         return null;
91     }
92
93 }
Popular Tags