1 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 26 public class SourceContainerLabelProvider extends LabelProvider { 27 28 private ILabelProvider fLabelProvider = null; 29 30 33 public Image getImage(Object element) { 34 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 image = DebugUITools.getSourceContainerImage(type.getId()); 46 } 47 } 48 if (image != null) { 49 return image; 50 } 51 return super.getImage(element); 52 } 53 54 57 public String getText(Object element) { 58 String 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 82 public void dispose() { 83 super.dispose(); 84 if (fLabelProvider != null) { 85 fLabelProvider.dispose(); 86 } 87 } 88 } 89 | Popular Tags |