001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 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.ui.internal.intro.impl.model.viewer;
011:
012: import org.eclipse.jface.viewers.LabelProvider;
013: import org.eclipse.swt.graphics.Image;
014: import org.eclipse.ui.internal.intro.impl.model.AbstractIntroElement;
015: import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage;
016: import org.eclipse.ui.internal.intro.impl.model.IntroContentProvider;
017: import org.eclipse.ui.internal.intro.impl.model.IntroExtensionContent;
018: import org.eclipse.ui.internal.intro.impl.model.IntroGroup;
019: import org.eclipse.ui.internal.intro.impl.model.IntroHTML;
020: import org.eclipse.ui.internal.intro.impl.model.IntroImage;
021: import org.eclipse.ui.internal.intro.impl.model.IntroInclude;
022: import org.eclipse.ui.internal.intro.impl.model.IntroLink;
023: import org.eclipse.ui.internal.intro.impl.model.IntroPartPresentation;
024: import org.eclipse.ui.internal.intro.impl.model.IntroSeparator;
025: import org.eclipse.ui.internal.intro.impl.model.IntroText;
026: import org.eclipse.ui.internal.intro.impl.util.ImageUtil;
027:
028: public class IntroModelLabelProvider extends LabelProvider {
029:
030: // Images created in this ILabelProvider
031:
032: static {
033: ImageUtil.registerImage(ImageUtil.INTRO_MODEL_CONTAINER,
034: "container_obj.gif"); //$NON-NLS-1$
035: ImageUtil
036: .registerImage(ImageUtil.INTRO_MODEL_LEAF, "topic.gif"); //$NON-NLS-1$
037: }
038:
039: public IntroModelLabelProvider() {
040: super ();
041: }
042:
043: public Image getImage(Object element) {
044: Image image = null;
045: AbstractIntroElement introElement = null;
046: if (element instanceof AbstractIntroElement)
047: // synch the resource first.
048: introElement = (AbstractIntroElement) element;
049: if (introElement == null)
050: return null;
051:
052: int elementType = introElement.getType();
053: switch (elementType) {
054: case AbstractIntroElement.GROUP:
055: case AbstractIntroElement.PAGE:
056: case AbstractIntroElement.HOME_PAGE:
057: image = ImageUtil.getImage(ImageUtil.INTRO_MODEL_CONTAINER);
058: break;
059: default:
060: image = ImageUtil.getImage(ImageUtil.INTRO_MODEL_LEAF);
061: break;
062: }
063: return image;
064: }
065:
066: public String getText(Object element) {
067:
068: String label = null;
069: AbstractIntroElement introElement = null;
070: if (element instanceof AbstractIntroElement)
071: // synch the resource first.
072: introElement = (AbstractIntroElement) element;
073: if (introElement == null)
074: return null;
075:
076: int elementType = introElement.getType();
077: switch (elementType) {
078: case AbstractIntroElement.GROUP:
079: label = "GROUP: " + ((IntroGroup) introElement).getLabel(); //$NON-NLS-1$
080: break;
081: case AbstractIntroElement.LINK:
082: label = "LINK: " + ((IntroLink) introElement).getLabel(); //$NON-NLS-1$
083: break;
084: case AbstractIntroElement.TEXT:
085: label = "TEXT: " + ((IntroText) introElement).getText(); //$NON-NLS-1$
086: break;
087: case AbstractIntroElement.IMAGE:
088: label = "IMAGE: " + ((IntroImage) introElement).getId(); //$NON-NLS-1$
089: break;
090: case AbstractIntroElement.HR:
091: label = "HR: " + ((IntroSeparator) introElement).getId(); //$NON-NLS-1$
092: break;
093: case AbstractIntroElement.HTML:
094: label = "HTML: " + ((IntroHTML) introElement).getId(); //$NON-NLS-1$
095: break;
096: case AbstractIntroElement.INCLUDE:
097: label = "Unresolved INCLUDE: " //$NON-NLS-1$
098: + ((IntroInclude) introElement).getPath();
099: break;
100: case AbstractIntroElement.PAGE:
101: label = "PAGE: " + ((AbstractIntroPage) introElement).getId(); //$NON-NLS-1$
102: break;
103: case AbstractIntroElement.HOME_PAGE:
104: label = "HOME PAGE: " //$NON-NLS-1$
105: + ((AbstractIntroPage) introElement).getTitle();
106: break;
107: case AbstractIntroElement.PRESENTATION:
108: label = "PRESENTATION: " //$NON-NLS-1$
109: + ((IntroPartPresentation) introElement)
110: .getImplementationKind();
111: break;
112: case AbstractIntroElement.CONTENT_PROVIDER:
113: label = "CONTENT PROVIDER: " //$NON-NLS-1$
114: + ((IntroContentProvider) introElement)
115: .getClassName();
116: break;
117: case AbstractIntroElement.CONTAINER_EXTENSION:
118: label = "Unresolved ConfigExtension: " //$NON-NLS-1$
119: + ((IntroExtensionContent) introElement).getPath();
120: break;
121: default:
122: label = super.getText(element);
123: break;
124: }
125: return label;
126: }
127:
128: }
|