KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > IntroDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 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 package org.eclipse.ui.internal.intro;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IConfigurationElement;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.ui.IPluginContribution;
19 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
20 import org.eclipse.ui.intro.IIntroPart;
21 import org.eclipse.ui.intro.IntroContentDetector;
22 import org.eclipse.ui.plugin.AbstractUIPlugin;
23
24 /**
25  * Describes an introduction extension.
26  *
27  * @since 3.0
28  */

29 public class IntroDescriptor implements IIntroDescriptor, IPluginContribution {
30
31
32     private IConfigurationElement element;
33
34     private ImageDescriptor imageDescriptor;
35
36     /**
37      * Create a new IntroDescriptor for an extension.
38      */

39     public IntroDescriptor(IConfigurationElement configElement)
40             throws CoreException {
41         element = configElement;
42
43         if (configElement.getAttribute(IWorkbenchRegistryConstants.ATT_CLASS) == null) {
44             throw new CoreException(new Status(IStatus.ERROR, configElement
45                     .getNamespace(), 0,
46                     "Invalid extension (Missing class name): " + getId(), //$NON-NLS-1$
47
null));
48         }
49     }
50
51     /* (non-Javadoc)
52      * @see org.eclipse.ui.intro.IIntroDescriptor#createIntro()
53      */

54     public IIntroPart createIntro() throws CoreException {
55         return (IIntroPart) element.createExecutableExtension(IWorkbenchRegistryConstants.ATT_CLASS);
56     }
57     
58     public IntroContentDetector getIntroContentDetector() throws CoreException {
59         if (element.getAttribute(IWorkbenchRegistryConstants.ATT_CONTENT_DETECTOR) == null) {
60             return null;
61         }
62         return (IntroContentDetector) element.createExecutableExtension(IWorkbenchRegistryConstants.ATT_CONTENT_DETECTOR);
63     }
64
65     /* (non-Javadoc)
66      * @see org.eclipse.ui.IIntroDescriptor#getId()
67      */

68     public String JavaDoc getId() {
69         return element.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
70     }
71
72     /* (non-Javadoc)
73      * @see org.eclipse.ui.IIntroDescriptor#getImageDescriptor()
74      */

75     public ImageDescriptor getImageDescriptor() {
76         if (imageDescriptor != null) {
77             return imageDescriptor;
78         }
79         String JavaDoc iconName = element.getAttribute(IWorkbenchRegistryConstants.ATT_ICON);
80         if (iconName == null) {
81             return null;
82         }
83         
84         imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(element
85                 .getNamespace(), iconName);
86         return imageDescriptor;
87     }
88
89     /* (non-Javadoc)
90      * @see org.eclipse.ui.IPluginContribution#getLocalId()
91      */

92     public String JavaDoc getLocalId() {
93         return element.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
94     }
95
96     /* (non-Javadoc)
97      * @see org.eclipse.ui.IPluginContribution#getPluginId()
98      */

99     public String JavaDoc getPluginId() {
100         return element.getNamespace();
101     }
102     
103     /**
104      * Returns the configuration element.
105      *
106      * @return the configuration element
107      * @since 3.1
108      */

109     public IConfigurationElement getConfigurationElement() {
110         return element;
111     }
112
113     /* (non-Javadoc)
114      * @see org.eclipse.ui.internal.intro.IIntroDescriptor#getLabelOverride()
115      */

116     public String JavaDoc getLabelOverride() {
117         return element.getAttribute(IWorkbenchRegistryConstants.ATT_LABEL);
118     }
119 }
120
Popular Tags