1 11 package org.eclipse.ui.model; 12 13 import java.util.HashMap ; 14 15 import org.eclipse.jface.resource.DeviceResourceException; 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.jface.resource.JFaceResources; 18 import org.eclipse.jface.resource.LocalResourceManager; 19 import org.eclipse.jface.resource.ResourceManager; 20 import org.eclipse.jface.viewers.ITableLabelProvider; 21 import org.eclipse.jface.viewers.LabelProvider; 22 import org.eclipse.swt.graphics.Image; 23 import org.eclipse.ui.IWorkbenchPart; 24 import org.eclipse.ui.Saveable; 25 import org.eclipse.ui.internal.WorkbenchPlugin; 26 27 37 public final class WorkbenchPartLabelProvider extends LabelProvider implements 38 ITableLabelProvider { 39 40 private ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources()); 41 private HashMap images = new HashMap (); 42 43 46 public WorkbenchPartLabelProvider() { 47 super(); 48 } 49 50 53 public final Image getImage(Object element) { 54 if (element instanceof IWorkbenchPart) { 55 return ((IWorkbenchPart) element).getTitleImage(); 56 } 57 if (element instanceof Saveable) { 58 Saveable model = (Saveable) element; 59 ImageDescriptor imageDesc = model.getImageDescriptor(); 60 if (imageDesc == null) { 62 return null; 63 } 64 Image image = (Image) images.get(imageDesc); 65 if (image == null) { 66 try { 67 image = resourceManager.createImage(imageDesc); 68 images.put(imageDesc, image); 69 } 70 catch (DeviceResourceException e) { 71 WorkbenchPlugin.log(getClass(), "getImage", e); } 73 } 74 return image; 75 } 76 return null; 77 } 78 79 82 public final String getText(Object element) { 83 if (element instanceof IWorkbenchPart) { 84 IWorkbenchPart part = (IWorkbenchPart) element; 85 String path = part.getTitleToolTip(); 86 if (path == null || path.trim().length() == 0) { 87 return part.getTitle(); 88 } 89 return part.getTitle() + " [" + path + "]"; } 91 if (element instanceof Saveable) { 92 Saveable model = (Saveable) element; 93 String path = model.getToolTipText(); 94 if (path == null || path.trim().length() == 0) { 95 return model.getName(); 96 } 97 return model.getName() + " [" + path + "]"; 99 } 100 return null; 101 } 102 103 106 public final Image getColumnImage(Object element, int columnIndex) { 107 return getImage(element); 108 } 109 110 113 public final String getColumnText(Object element, int columnIndex) { 114 return getText(element); 115 } 116 117 122 public void dispose() { 123 resourceManager.dispose(); 124 super.dispose(); 125 } 126 } 127 | Popular Tags |