001: /*******************************************************************************
002: * Copyright (c) 2003, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.site;
011:
012: import org.eclipse.jface.viewers.LabelProvider;
013: import org.eclipse.pde.internal.core.PDECore;
014: import org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition;
015: import org.eclipse.pde.internal.core.isite.ISiteFeature;
016: import org.eclipse.pde.internal.ui.PDELabelProvider;
017: import org.eclipse.pde.internal.ui.PDEPlugin;
018: import org.eclipse.pde.internal.ui.PDEPluginImages;
019: import org.eclipse.swt.graphics.Image;
020: import org.eclipse.ui.forms.editor.IFormPage;
021:
022: class SiteLabelProvider extends LabelProvider {
023:
024: private PDELabelProvider fSharedProvider;
025:
026: /**
027: * Comment for <code>fLabelProvider</code>
028: */
029: private Image fSiteFeatureImage;
030:
031: private Image fMissingSiteFeatureImage;
032:
033: private Image fPageImage;
034:
035: private Image fCatDefImage;
036:
037: public SiteLabelProvider() {
038: fSiteFeatureImage = PDEPluginImages.DESC_FEATURE_OBJ
039: .createImage();
040: fMissingSiteFeatureImage = PDEPluginImages.DESC_NOREF_FEATURE_OBJ
041: .createImage();
042: fCatDefImage = PDEPluginImages.DESC_CATEGORY_OBJ.createImage();
043: fPageImage = PDEPluginImages.DESC_PAGE_OBJ.createImage();
044: fSharedProvider = PDEPlugin.getDefault().getLabelProvider();
045: fSharedProvider.connect(this );
046: }
047:
048: public Image getImage(Object element) {
049: if (element instanceof ISiteCategoryDefinition)
050: return fCatDefImage;
051: if (element instanceof SiteFeatureAdapter) {
052: if (PDECore.getDefault().getFeatureModelManager()
053: .findFeatureModelRelaxed(
054: ((SiteFeatureAdapter) element).feature
055: .getId(),
056: ((SiteFeatureAdapter) element).feature
057: .getVersion()) == null)
058: return fMissingSiteFeatureImage;
059: return fSiteFeatureImage;
060: }
061: if (element instanceof IFormPage)
062: return fPageImage;
063: return fSharedProvider.getImage(element);
064: }
065:
066: public String getText(Object element) {
067: if (element instanceof ISiteCategoryDefinition)
068: return ((ISiteCategoryDefinition) element).getName();
069: if (element instanceof SiteFeatureAdapter) {
070: ISiteFeature feature = ((SiteFeatureAdapter) element).feature;
071: return fSharedProvider.getObjectText(feature);
072: }
073: if (element instanceof IFormPage)
074: return ((IFormPage) element).getTitle();
075: return fSharedProvider.getText(element);
076: }
077:
078: /* (non-Javadoc)
079: * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose()
080: */
081: public void dispose() {
082: fSharedProvider.disconnect(this );
083: // Dispose of images
084: if ((fCatDefImage != null)
085: && (fCatDefImage.isDisposed() == false)) {
086: fCatDefImage.dispose();
087: fCatDefImage = null;
088: }
089: if ((fSiteFeatureImage != null)
090: && (fSiteFeatureImage.isDisposed() == false)) {
091: fSiteFeatureImage.dispose();
092: fSiteFeatureImage = null;
093: }
094: if ((fMissingSiteFeatureImage != null)
095: && (fMissingSiteFeatureImage.isDisposed() == false)) {
096: fMissingSiteFeatureImage.dispose();
097: fMissingSiteFeatureImage = null;
098: }
099: if ((fPageImage != null) && (fPageImage.isDisposed() == false)) {
100: fPageImage.dispose();
101: fPageImage = null;
102: }
103: super.dispose();
104: }
105: }
|