1 11 package org.eclipse.pde.internal.ui.nls; 12 13 import org.eclipse.pde.core.plugin.IFragmentModel; 14 import org.eclipse.pde.core.plugin.IPluginModel; 15 import org.eclipse.pde.core.plugin.IPluginModelBase; 16 import org.eclipse.pde.internal.ui.PDELabelProvider; 17 import org.eclipse.pde.internal.ui.PDEPluginImages; 18 import org.eclipse.pde.internal.ui.PDEUIMessages; 19 import org.eclipse.swt.graphics.Image; 20 21 public class ModelChangeLabelProvider extends PDELabelProvider { 22 23 private Image manifestImage; 24 private Image xmlImage; 25 26 public ModelChangeLabelProvider() { 27 xmlImage = PDEPluginImages.DESC_PLUGIN_MF_OBJ.createImage(); 28 manifestImage = PDEPluginImages.DESC_PAGE_OBJ.createImage(); 29 } 30 31 public String getText(Object obj) { 32 if (obj instanceof ModelChange) 33 return getObjectText(((ModelChange) obj).getParentModel().getPluginBase()); 34 if (obj instanceof ModelChangeFile) 35 return getObjectText((ModelChangeFile)obj); 36 return super.getText(obj); 37 } 38 39 private String getObjectText(ModelChangeFile pair) { 40 StringBuffer text = new StringBuffer (pair.getFile().getName()); 41 int count = pair.getNumChanges(); 42 text.append(" ["); text.append(count); 44 if (count == 1) 45 text.append(PDEUIMessages.ModelChangeLabelProvider_instance); 46 else 47 text.append(PDEUIMessages.ModelChangeLabelProvider_instances); 48 text.append("]"); 50 return text.toString(); 51 } 52 53 public Image getImage(Object obj) { 54 if (obj instanceof ModelChange) { 55 IPluginModelBase model = ((ModelChange)obj).getParentModel(); 56 if (model instanceof IPluginModel) 57 return getObjectImage(((IPluginModel) model).getPlugin(), false, false); 58 if (model instanceof IFragmentModel) 59 return getObjectImage(((IFragmentModel) model).getFragment(), false, false); 60 } 61 if (obj instanceof ModelChangeFile) 62 return getObjectImage((ModelChangeFile)obj); 63 return super.getImage(obj); 64 } 65 66 private Image getObjectImage(ModelChangeFile file) { 67 String type = file.getFile().getFileExtension(); 68 if ("xml".equalsIgnoreCase(type)) return xmlImage; 70 if ("MF".equalsIgnoreCase(type)) return manifestImage; 72 return null; 73 } 74 75 public void dispose() { 76 if (manifestImage != null) 77 manifestImage.dispose(); 78 if (xmlImage != null) 79 xmlImage.dispose(); 80 super.dispose(); 81 } 82 } 83 | Popular Tags |