1 11 package org.eclipse.debug.internal.ui.sourcelookup; 12 13 import java.io.File ; 14 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage; 17 import org.eclipse.debug.core.sourcelookup.containers.ZipEntryStorage; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.ui.ISharedImages; 20 import org.eclipse.ui.PlatformUI; 21 import org.eclipse.ui.model.IWorkbenchAdapter; 22 23 28 public class SourceElementWorkbenchAdapter implements IWorkbenchAdapter { 29 32 public Object [] getChildren(Object o) { 33 return null; 34 } 35 38 public ImageDescriptor getImageDescriptor(Object o) { 39 if (o instanceof LocalFileStorage || o instanceof ZipEntryStorage) { 40 return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE); 41 } 42 return null; 43 } 44 47 public String getLabel(Object o) { 48 if (o instanceof LocalFileStorage) { 49 LocalFileStorage storage = (LocalFileStorage) o; 50 IPath path = storage.getFullPath(); 51 return getQualifiedName(path); 52 } 53 if (o instanceof ZipEntryStorage) { 54 ZipEntryStorage storage = (ZipEntryStorage)o; 55 StringBuffer buffer = new StringBuffer (); 56 buffer.append(storage.getZipEntry().getName()); 57 buffer.append(" - "); buffer.append(storage.getArchive().getName()); 59 return buffer.toString(); 60 } 61 return ""; } 63 66 public Object getParent(Object o) { 67 return null; 68 } 69 70 public static String getQualifiedName(IPath path) { 71 StringBuffer buffer = new StringBuffer (); 72 String [] segments = path.segments(); 73 if (segments.length > 0) { 74 buffer.append(path.lastSegment()); 75 if (segments.length > 1) { 76 buffer.append(" - "); if (path.getDevice() != null) { 78 buffer.append(path.getDevice()); 79 } 80 for (int i = 0; i < segments.length - 1; i++) { 81 buffer.append(File.separatorChar); 82 buffer.append(segments[i]); 83 } 84 } 85 return buffer.toString(); 86 } 87 return ""; } 89 } 90 | Popular Tags |