KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > JavaSourceLocationWorkbenchAdapterFactory


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;
12
13  
14 import java.io.IOException JavaDoc;
15
16 import org.eclipse.core.runtime.IAdapterFactory;
17 import org.eclipse.jdt.launching.sourcelookup.ArchiveSourceLocation;
18 import org.eclipse.jdt.launching.sourcelookup.DirectorySourceLocation;
19 import org.eclipse.jdt.launching.sourcelookup.IJavaSourceLocation;
20 import org.eclipse.jdt.launching.sourcelookup.JavaProjectSourceLocation;
21 import org.eclipse.jdt.ui.JavaElementLabelProvider;
22 import org.eclipse.jdt.ui.JavaUI;
23 import org.eclipse.jface.resource.ImageDescriptor;
24 import org.eclipse.ui.ISharedImages;
25 import org.eclipse.ui.PlatformUI;
26 import org.eclipse.ui.ide.IDE;
27 import org.eclipse.ui.model.IWorkbenchAdapter;
28
29 /**
30  * UI adapter factory for JDI Debug
31  *
32  * @deprecated
33  */

34 /*package*/ class JavaSourceLocationWorkbenchAdapterFactory implements IAdapterFactory {
35
36     class SourceLocationPropertiesAdapter implements IWorkbenchAdapter {
37         
38         private JavaElementLabelProvider fJavaElementLabelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_BASICS);
39     
40         /**
41          * @see IWorkbenchAdapter#getChildren(Object)
42          */

43         public Object JavaDoc[] getChildren(Object JavaDoc o) {
44             return new Object JavaDoc[0];
45         }
46
47         /**
48          * @see IWorkbenchAdapter#getImageDescriptor(Object)
49          */

50         public ImageDescriptor getImageDescriptor(Object JavaDoc o) {
51             if (o instanceof JavaProjectSourceLocation) {
52                 return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT);
53             } else if (o instanceof DirectorySourceLocation) {
54                 return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
55             } else if (o instanceof ArchiveSourceLocation) {
56                 return JavaUI.getSharedImages().getImageDescriptor(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_JAR);
57             }
58             return null;
59         }
60
61         /**
62          * @see IWorkbenchAdapter#getLabel(Object)
63          */

64         public String JavaDoc getLabel(Object JavaDoc o) {
65             if (o instanceof JavaProjectSourceLocation) {
66                 return fJavaElementLabelProvider.getText(((JavaProjectSourceLocation)o).getJavaProject());
67             } else if (o instanceof DirectorySourceLocation) {
68                 try {
69                     return ((DirectorySourceLocation)o).getDirectory().getCanonicalPath();
70                 } catch (IOException JavaDoc e) {
71                     JDIDebugUIPlugin.log(e);
72                     return ((DirectorySourceLocation)o).getDirectory().getName();
73                 }
74             } else if (o instanceof ArchiveSourceLocation) {
75                 return ((ArchiveSourceLocation)o).getName();
76             }
77             return null;
78         }
79
80         /**
81          * @see IWorkbenchAdapter#getParent(Object)
82          */

83         public Object JavaDoc getParent(Object JavaDoc o) {
84             return null;
85         }
86     }
87     
88     /**
89      * @see IAdapterFactory#getAdapter(Object, Class)
90      */

91     public Object JavaDoc getAdapter(Object JavaDoc obj, Class JavaDoc adapterType) {
92         if (adapterType.isInstance(obj)) {
93             return obj;
94         }
95         if (adapterType == IWorkbenchAdapter.class) {
96             if (obj instanceof IJavaSourceLocation) {
97                 return new SourceLocationPropertiesAdapter();
98             }
99         }
100         return null;
101     }
102
103     /**
104      * @see IAdapterFactory#getAdapterList()
105      */

106     public Class JavaDoc[] getAdapterList() {
107         return new Class JavaDoc[] {
108             IWorkbenchAdapter.class,
109         };
110     }
111 }
112
113
114
Popular Tags