KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > impl > model > viewer > IntroModelLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.intro.impl.model.viewer;
13
14 import org.eclipse.jface.viewers.LabelProvider;
15 import org.eclipse.swt.graphics.Image;
16 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroElement;
17 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage;
18 import org.eclipse.ui.internal.intro.impl.model.IntroContentProvider;
19 import org.eclipse.ui.internal.intro.impl.model.IntroExtensionContent;
20 import org.eclipse.ui.internal.intro.impl.model.IntroGroup;
21 import org.eclipse.ui.internal.intro.impl.model.IntroHTML;
22 import org.eclipse.ui.internal.intro.impl.model.IntroImage;
23 import org.eclipse.ui.internal.intro.impl.model.IntroInclude;
24 import org.eclipse.ui.internal.intro.impl.model.IntroLink;
25 import org.eclipse.ui.internal.intro.impl.model.IntroPartPresentation;
26 import org.eclipse.ui.internal.intro.impl.model.IntroSeparator;
27 import org.eclipse.ui.internal.intro.impl.model.IntroText;
28 import org.eclipse.ui.internal.intro.impl.util.ImageUtil;
29
30 public class IntroModelLabelProvider extends LabelProvider {
31
32     // Images created in this ILabelProvider
33

34     static {
35         ImageUtil.registerImage(ImageUtil.INTRO_MODEL_CONTAINER,
36             "container_obj.gif"); //$NON-NLS-1$
37
ImageUtil.registerImage(ImageUtil.INTRO_MODEL_LEAF, "topic.gif"); //$NON-NLS-1$
38
}
39
40     public IntroModelLabelProvider() {
41         super();
42     }
43
44     public Image getImage(Object JavaDoc element) {
45         Image image = null;
46         AbstractIntroElement introElement = null;
47         if (element instanceof AbstractIntroElement)
48             // synch the resource first.
49
introElement = (AbstractIntroElement) element;
50         if (introElement == null)
51             return null;
52
53         int elementType = introElement.getType();
54         switch (elementType) {
55         case AbstractIntroElement.GROUP:
56         case AbstractIntroElement.PAGE:
57         case AbstractIntroElement.HOME_PAGE:
58             image = ImageUtil.getImage(ImageUtil.INTRO_MODEL_CONTAINER);
59             break;
60         default:
61             image = ImageUtil.getImage(ImageUtil.INTRO_MODEL_LEAF);
62             break;
63         }
64         return image;
65     }
66
67     public String JavaDoc getText(Object JavaDoc element) {
68
69         String JavaDoc label = null;
70         AbstractIntroElement introElement = null;
71         if (element instanceof AbstractIntroElement)
72             // synch the resource first.
73
introElement = (AbstractIntroElement) element;
74         if (introElement == null)
75             return null;
76
77         int elementType = introElement.getType();
78         switch (elementType) {
79         case AbstractIntroElement.GROUP:
80             label = "GROUP: " + ((IntroGroup) introElement).getLabel(); //$NON-NLS-1$
81
break;
82         case AbstractIntroElement.LINK:
83             label = "LINK: " + ((IntroLink) introElement).getLabel(); //$NON-NLS-1$
84
break;
85         case AbstractIntroElement.TEXT:
86             label = "TEXT: " + ((IntroText) introElement).getText(); //$NON-NLS-1$
87
break;
88         case AbstractIntroElement.IMAGE:
89             label = "IMAGE: " + ((IntroImage) introElement).getId(); //$NON-NLS-1$
90
break;
91         case AbstractIntroElement.HR:
92             label = "HR: " + ((IntroSeparator) introElement).getId(); //$NON-NLS-1$
93
break;
94         case AbstractIntroElement.HTML:
95             label = "HTML: " + ((IntroHTML) introElement).getId(); //$NON-NLS-1$
96
break;
97         case AbstractIntroElement.INCLUDE:
98             label = "Unresolved INCLUDE: " //$NON-NLS-1$
99
+ ((IntroInclude) introElement).getPath();
100             break;
101         case AbstractIntroElement.PAGE:
102             label = "PAGE: " + ((AbstractIntroPage) introElement).getId(); //$NON-NLS-1$
103
break;
104         case AbstractIntroElement.HOME_PAGE:
105             label = "HOME PAGE: " //$NON-NLS-1$
106
+ ((AbstractIntroPage) introElement).getTitle();
107             break;
108         case AbstractIntroElement.PRESENTATION:
109             label = "PRESENTATION: " //$NON-NLS-1$
110
+ ((IntroPartPresentation) introElement)
111                         .getImplementationKind();
112             break;
113         case AbstractIntroElement.CONTENT_PROVIDER:
114             label = "CONTENT PROVIDER: " //$NON-NLS-1$
115
+ ((IntroContentProvider) introElement).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 }
129
Popular Tags