1 11 12 package org.eclipse.ui.internal.dialogs; 13 14 import java.util.Hashtable ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 18 import org.eclipse.core.runtime.Assert; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.jface.viewers.LabelProvider; 21 import org.eclipse.swt.graphics.Image; 22 import org.eclipse.ui.IWorkingSet; 23 24 public class WorkingSetLabelProvider extends LabelProvider { 25 private Map icons; 26 27 30 public WorkingSetLabelProvider() { 31 icons = new Hashtable (); 32 } 33 34 public void dispose() { 35 Iterator iterator = icons.values().iterator(); 36 37 while (iterator.hasNext()) { 38 Image icon = (Image) iterator.next(); 39 icon.dispose(); 40 } 41 super.dispose(); 42 } 43 44 public Image getImage(Object object) { 45 Assert.isTrue(object instanceof IWorkingSet); 46 IWorkingSet workingSet = (IWorkingSet) object; 47 ImageDescriptor imageDescriptor = workingSet.getImageDescriptor(); 48 49 if (imageDescriptor == null) { 50 return null; 51 } 52 53 Image icon = (Image) icons.get(imageDescriptor); 54 if (icon == null) { 55 icon = imageDescriptor.createImage(); 56 icons.put(imageDescriptor, icon); 57 } 58 return icon; 59 } 60 61 public String getText(Object object) { 62 Assert.isTrue(object instanceof IWorkingSet); 63 IWorkingSet workingSet = (IWorkingSet) object; 64 return workingSet.getLabel(); 65 } 66 } 67 | Popular Tags |