001: /*******************************************************************************
002: * Copyright (c) 2006, 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.pde.internal.ui.wizards.provisioner;
011:
012: import java.io.File;
013:
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.core.runtime.IConfigurationElement;
016: import org.eclipse.core.runtime.IExtension;
017: import org.eclipse.core.runtime.IExtensionPoint;
018: import org.eclipse.core.runtime.IExtensionRegistry;
019: import org.eclipse.core.runtime.Platform;
020: import org.eclipse.jface.dialogs.MessageDialog;
021: import org.eclipse.jface.wizard.IWizardPage;
022: import org.eclipse.pde.internal.ui.PDEPlugin;
023: import org.eclipse.pde.internal.ui.PDEUIMessages;
024: import org.eclipse.pde.internal.ui.elements.ElementList;
025: import org.eclipse.pde.internal.ui.wizards.NewWizard;
026: import org.eclipse.pde.internal.ui.wizards.WizardElement;
027: import org.eclipse.pde.ui.IProvisionerWizard;
028: import org.eclipse.swt.graphics.Image;
029:
030: public class AddTargetPluginsWizard extends NewWizard {
031:
032: private static final String PROVISIONER_POINT = "targetProvisioners"; //$NON-NLS-1$
033: private ProvisionerListSelectionPage fSelectionPage = null;
034: private File[] fDirs = null;
035: private IProvisionerWizard fWizard = null;
036:
037: public AddTargetPluginsWizard() {
038: setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
039: setWindowTitle(PDEUIMessages.AddTargetPluginsWizard_windowTitle);
040: setNeedsProgressMonitor(true);
041: }
042:
043: public void addPages() {
044: setForcePreviousAndNextButtons(true);
045: ElementList list = getAvailableProvisioners();
046: if (list.size() == 1) {
047: try {
048: fWizard = (IProvisionerWizard) ((WizardElement) list
049: .getChildren()[0]).createExecutableExtension();
050: } catch (CoreException e) {
051: MessageDialog.openError(getContainer().getShell(),
052: PDEUIMessages.Errors_CreationError,
053: PDEUIMessages.Errors_CreationError_NoWizard);
054: }
055: fWizard.addPages();
056: IWizardPage[] pages = fWizard.getPages();
057: for (int i = 0; i < pages.length; i++)
058: addPage(pages[i]);
059: } else {
060: fSelectionPage = new ProvisionerListSelectionPage(
061: getAvailableProvisioners());
062: addPage(fSelectionPage);
063: }
064: super .addPages();
065: }
066:
067: private ElementList getAvailableProvisioners() {
068: ElementList list = new ElementList(PROVISIONER_POINT);
069: IExtensionRegistry registry = Platform.getExtensionRegistry();
070: IExtensionPoint point = registry.getExtensionPoint(PDEPlugin
071: .getPluginId(), PROVISIONER_POINT);
072: if (point == null)
073: return list;
074: IExtension[] extensions = point.getExtensions();
075: for (int i = 0; i < extensions.length; i++) {
076: IConfigurationElement[] elements = extensions[i]
077: .getConfigurationElements();
078: for (int j = 0; j < elements.length; j++) {
079: WizardElement element = createWizardElement(elements[j]);
080: if (element != null) {
081: list.add(element);
082: }
083: }
084: }
085: return list;
086: }
087:
088: protected WizardElement createWizardElement(
089: IConfigurationElement config) {
090: String name = config.getAttribute(WizardElement.ATT_NAME);
091: String id = config.getAttribute(WizardElement.ATT_ID);
092: if (name == null || id == null)
093: return null;
094: WizardElement element = new WizardElement(config);
095:
096: String imageName = config.getAttribute(WizardElement.ATT_ICON);
097: Image image = null;
098: if (imageName != null) {
099: String pluginID = config.getNamespaceIdentifier();
100: image = PDEPlugin.getDefault().getLabelProvider()
101: .getImageFromPlugin(pluginID, imageName);
102: }
103: element.setImage(image);
104: return element;
105: }
106:
107: public boolean canFinish() {
108: return ((fSelectionPage != null && getPageCount() > 1) || fSelectionPage == null)
109: && super .canFinish();
110: }
111:
112: public boolean performFinish() {
113: IProvisionerWizard wizard = (fSelectionPage != null) ? (IProvisionerWizard) fSelectionPage
114: .getSelectedWizard()
115: : fWizard;
116: if (wizard == null)
117: return true;
118: fDirs = wizard.getLocations();
119: return super .performFinish();
120: }
121:
122: public File[] getDirectories() {
123: return (fDirs == null) ? new File[0] : fDirs;
124: }
125:
126: }
|