1 11 package org.eclipse.pde.internal.ui.editor.site; 12 13 import org.eclipse.jface.viewers.LabelProvider; 14 import org.eclipse.pde.internal.core.PDECore; 15 import org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition; 16 import org.eclipse.pde.internal.core.isite.ISiteFeature; 17 import org.eclipse.pde.internal.ui.PDELabelProvider; 18 import org.eclipse.pde.internal.ui.PDEPlugin; 19 import org.eclipse.pde.internal.ui.PDEPluginImages; 20 import org.eclipse.swt.graphics.Image; 21 import org.eclipse.ui.forms.editor.IFormPage; 22 23 class SiteLabelProvider extends LabelProvider { 24 25 private PDELabelProvider fSharedProvider; 26 27 30 private Image fSiteFeatureImage; 31 32 private Image fMissingSiteFeatureImage; 33 34 private Image fPageImage; 35 36 private Image fCatDefImage; 37 38 public SiteLabelProvider() { 39 fSiteFeatureImage = PDEPluginImages.DESC_FEATURE_OBJ.createImage(); 40 fMissingSiteFeatureImage = PDEPluginImages.DESC_NOREF_FEATURE_OBJ.createImage(); 41 fCatDefImage = PDEPluginImages.DESC_CATEGORY_OBJ.createImage(); 42 fPageImage = PDEPluginImages.DESC_PAGE_OBJ.createImage(); 43 fSharedProvider = PDEPlugin.getDefault().getLabelProvider(); 44 fSharedProvider.connect(this); 45 } 46 47 48 public Image getImage(Object element) { 49 if (element instanceof ISiteCategoryDefinition) 50 return fCatDefImage; 51 if (element instanceof SiteFeatureAdapter) { 52 if (PDECore.getDefault().getFeatureModelManager().findFeatureModelRelaxed( 53 ((SiteFeatureAdapter) element).feature.getId(), 54 ((SiteFeatureAdapter) element).feature.getVersion()) == null) 55 return fMissingSiteFeatureImage; 56 return fSiteFeatureImage; 57 } 58 if (element instanceof IFormPage) 59 return fPageImage; 60 return fSharedProvider.getImage(element); 61 } 62 63 public String getText(Object element) { 64 if (element instanceof ISiteCategoryDefinition) 65 return ((ISiteCategoryDefinition) element).getName(); 66 if (element instanceof SiteFeatureAdapter) { 67 ISiteFeature feature = ((SiteFeatureAdapter) element).feature; 68 return fSharedProvider.getObjectText(feature); 69 } 70 if (element instanceof IFormPage) 71 return ((IFormPage)element).getTitle(); 72 return fSharedProvider.getText(element); 73 } 74 75 78 public void dispose() { 79 fSharedProvider.disconnect(this); 80 if ((fCatDefImage != null) && 82 (fCatDefImage.isDisposed() == false)) { 83 fCatDefImage.dispose(); 84 fCatDefImage = null; 85 } 86 if ((fSiteFeatureImage != null) && 87 (fSiteFeatureImage.isDisposed() == false)) { 88 fSiteFeatureImage.dispose(); 89 fSiteFeatureImage = null; 90 } 91 if ((fMissingSiteFeatureImage != null) && 92 (fMissingSiteFeatureImage.isDisposed() == false)) { 93 fMissingSiteFeatureImage.dispose(); 94 fMissingSiteFeatureImage = null; 95 } 96 if ((fPageImage != null) && 97 (fPageImage.isDisposed() == false)) { 98 fPageImage.dispose(); 99 fPageImage = null; 100 } 101 super.dispose(); 102 } 103 } | Popular Tags |