001: /*******************************************************************************
002: * Copyright (c) 2004, 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.ui.internal.intro;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IConfigurationElement;
014: import org.eclipse.core.runtime.IStatus;
015: import org.eclipse.core.runtime.Status;
016: import org.eclipse.jface.resource.ImageDescriptor;
017: import org.eclipse.ui.IPluginContribution;
018: import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
019: import org.eclipse.ui.intro.IIntroPart;
020: import org.eclipse.ui.intro.IntroContentDetector;
021: import org.eclipse.ui.plugin.AbstractUIPlugin;
022:
023: /**
024: * Describes an introduction extension.
025: *
026: * @since 3.0
027: */
028: public class IntroDescriptor implements IIntroDescriptor,
029: IPluginContribution {
030:
031: private IConfigurationElement element;
032:
033: private ImageDescriptor imageDescriptor;
034:
035: /**
036: * Create a new IntroDescriptor for an extension.
037: */
038: public IntroDescriptor(IConfigurationElement configElement)
039: throws CoreException {
040: element = configElement;
041:
042: if (configElement
043: .getAttribute(IWorkbenchRegistryConstants.ATT_CLASS) == null) {
044: throw new CoreException(
045: new Status(
046: IStatus.ERROR,
047: configElement.getNamespace(),
048: 0,
049: "Invalid extension (Missing class name): " + getId(), //$NON-NLS-1$
050: null));
051: }
052: }
053:
054: /* (non-Javadoc)
055: * @see org.eclipse.ui.intro.IIntroDescriptor#createIntro()
056: */
057: public IIntroPart createIntro() throws CoreException {
058: return (IIntroPart) element
059: .createExecutableExtension(IWorkbenchRegistryConstants.ATT_CLASS);
060: }
061:
062: public IntroContentDetector getIntroContentDetector()
063: throws CoreException {
064: if (element
065: .getAttribute(IWorkbenchRegistryConstants.ATT_CONTENT_DETECTOR) == null) {
066: return null;
067: }
068: return (IntroContentDetector) element
069: .createExecutableExtension(IWorkbenchRegistryConstants.ATT_CONTENT_DETECTOR);
070: }
071:
072: /* (non-Javadoc)
073: * @see org.eclipse.ui.IIntroDescriptor#getId()
074: */
075: public String getId() {
076: return element.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
077: }
078:
079: /* (non-Javadoc)
080: * @see org.eclipse.ui.IIntroDescriptor#getImageDescriptor()
081: */
082: public ImageDescriptor getImageDescriptor() {
083: if (imageDescriptor != null) {
084: return imageDescriptor;
085: }
086: String iconName = element
087: .getAttribute(IWorkbenchRegistryConstants.ATT_ICON);
088: if (iconName == null) {
089: return null;
090: }
091:
092: imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
093: element.getNamespace(), iconName);
094: return imageDescriptor;
095: }
096:
097: /* (non-Javadoc)
098: * @see org.eclipse.ui.IPluginContribution#getLocalId()
099: */
100: public String getLocalId() {
101: return element.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
102: }
103:
104: /* (non-Javadoc)
105: * @see org.eclipse.ui.IPluginContribution#getPluginId()
106: */
107: public String getPluginId() {
108: return element.getNamespace();
109: }
110:
111: /**
112: * Returns the configuration element.
113: *
114: * @return the configuration element
115: * @since 3.1
116: */
117: public IConfigurationElement getConfigurationElement() {
118: return element;
119: }
120:
121: /* (non-Javadoc)
122: * @see org.eclipse.ui.internal.intro.IIntroDescriptor#getLabelOverride()
123: */
124: public String getLabelOverride() {
125: return element
126: .getAttribute(IWorkbenchRegistryConstants.ATT_LABEL);
127: }
128: }
|