1 11 package org.eclipse.jdt.internal.debug.ui; 12 13 14 import java.io.IOException ; 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 34 class JavaSourceLocationWorkbenchAdapterFactory implements IAdapterFactory { 35 36 class SourceLocationPropertiesAdapter implements IWorkbenchAdapter { 37 38 private JavaElementLabelProvider fJavaElementLabelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_BASICS); 39 40 43 public Object [] getChildren(Object o) { 44 return new Object [0]; 45 } 46 47 50 public ImageDescriptor getImageDescriptor(Object 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 64 public String getLabel(Object 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 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 83 public Object getParent(Object o) { 84 return null; 85 } 86 } 87 88 91 public Object getAdapter(Object obj, Class 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 106 public Class [] getAdapterList() { 107 return new Class [] { 108 IWorkbenchAdapter.class, 109 }; 110 } 111 } 112 113 114 | Popular Tags |