| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2006 IBM Corporation and others. |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| // |
| // Contributors: |
| // IBM Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.publishing.ui.internal.wizards; |
| |
| import org.eclipse.core.runtime.IConfigurationElement; |
| import org.eclipse.core.runtime.IExtension; |
| import org.eclipse.core.runtime.IExtensionPoint; |
| import org.eclipse.core.runtime.IExtensionRegistry; |
| import org.eclipse.core.runtime.Platform; |
| import org.eclipse.epf.publishing.services.PublishManager; |
| import org.eclipse.epf.publishing.ui.PublishingUIPlugin; |
| import org.eclipse.epf.publishing.ui.wizards.IPublishConfigWizardExtender; |
| import org.eclipse.epf.ui.wizards.NewWizardPageContribution; |
| import org.eclipse.epf.ui.wizards.ReplaceWizardPageContribution; |
| import org.eclipse.jface.wizard.IWizardPage; |
| |
| /** |
| * Manages the "org.eclipse.epf.publishing.ui.publishConfigWizard" extension |
| * point. |
| * |
| * @author Kelvin Low |
| * @since 1.0 |
| */ |
| public class PublishConfigWizardExtensionManager { |
| |
| /** |
| * The extension point namespace. |
| */ |
| public static final String EXTENSION_POINT_NAMESPACE = "org.eclipse.epf.publishing.ui"; //$NON-NLS-1$ |
| |
| /** |
| * The extension point name. |
| */ |
| public static final String EXTENSION_POINT_NAME = "publishConfigWizard"; //$NON-NLS-1$ |
| |
| // The shared instance. |
| private static PublishConfigWizardExtensionManager instance = new PublishConfigWizardExtensionManager(); |
| |
| // An extender of the Publish Method Configuration wizard. |
| private IPublishConfigWizardExtender wizardExtender; |
| |
| /** |
| * Creates a new instance. |
| */ |
| private PublishConfigWizardExtensionManager() { |
| processExtensionPoint(); |
| } |
| |
| /** |
| * Returns the shared instance. |
| * |
| * @return the shared instance |
| */ |
| public static PublishConfigWizardExtensionManager getInstance() { |
| return instance; |
| } |
| |
| /** |
| * Processes the "org.eclipse.epf.publishing.ui.publishConfigWizard" |
| * extension point. |
| */ |
| protected void processExtensionPoint() { |
| IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); |
| IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint( |
| EXTENSION_POINT_NAMESPACE, EXTENSION_POINT_NAME); |
| if (extensionPoint != null) { |
| IExtension[] extensions = extensionPoint.getExtensions(); |
| for (int i = 0; i < extensions.length; i++) { |
| IExtension extension = extensions[i]; |
| IConfigurationElement[] configElements = extension |
| .getConfigurationElements(); |
| for (int j = 0; j < configElements.length; j++) { |
| IConfigurationElement configElement = configElements[j]; |
| try { |
| IPublishConfigWizardExtender extender = (IPublishConfigWizardExtender) configElement |
| .createExecutableExtension("class"); //$NON-NLS-1$ |
| if (wizardExtender == null) { |
| wizardExtender = extender; |
| |
| IConfigurationElement[] childConfigElements = configElement |
| .getChildren("wizardPage"); //$NON-NLS-1$ |
| for (int k = 0; k < childConfigElements.length; k++) { |
| IConfigurationElement childConfigElement = childConfigElements[k]; |
| IWizardPage wizardPage = (IWizardPage) childConfigElement |
| .createExecutableExtension("class"); //$NON-NLS-1$ |
| String type = childConfigElement |
| .getAttribute("type"); //$NON-NLS-1$ |
| String target = childConfigElement |
| .getAttribute("target"); //$NON-NLS-1$ |
| String insert = childConfigElement |
| .getAttribute("insert"); //$NON-NLS-1$ |
| if (wizardPage != null && type != null |
| && type.length() > 0) { |
| if (type.equals("replace")) { //$NON-NLS-1$ |
| wizardExtender |
| .addReplaceWizardPageContribution(new ReplaceWizardPageContribution( |
| wizardPage, target)); |
| } else if (type.equals("new")) { //$NON-NLS-1$ |
| boolean insertAfter = true; |
| if (insert != null |
| && insert.equals("before")) { //$NON-NLS-1$ |
| insertAfter = false; |
| } |
| wizardExtender |
| .addNewWizardPageContribution(new NewWizardPageContribution( |
| wizardPage, target, |
| insertAfter)); |
| } |
| } |
| } |
| |
| childConfigElements = configElement |
| .getChildren("publisher"); //$NON-NLS-1$ |
| if (childConfigElements.length > 0) { |
| IConfigurationElement childConfigElement = childConfigElements[0]; |
| PublishManager publisher = (PublishManager) childConfigElement |
| .createExecutableExtension("class"); //$NON-NLS-1$ |
| wizardExtender.setPublisher(publisher); |
| } |
| |
| return; |
| } |
| } catch (Exception e) { |
| PublishingUIPlugin.getDefault().getLogger().logError(e); |
| } |
| } |
| } |
| } |
| } |
| |
| /** |
| * Gets the Publish Method Configuration wizard extender loaded via the |
| * "org.eclipse.epf.publishing.ui.publishConfigWizard" extension point. |
| * |
| * @return an Export MSP wizard extender or <code>null</code> |
| */ |
| public IPublishConfigWizardExtender getWizardExtender() { |
| return wizardExtender; |
| } |
| |
| } |