KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > provisioner > AddTargetPluginsWizard


1 /*******************************************************************************
2  * Copyright (c) 2006, 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.pde.internal.ui.wizards.provisioner;
12
13 import java.io.File JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.core.runtime.IExtension;
18 import org.eclipse.core.runtime.IExtensionPoint;
19 import org.eclipse.core.runtime.IExtensionRegistry;
20 import org.eclipse.core.runtime.Platform;
21 import org.eclipse.jface.dialogs.MessageDialog;
22 import org.eclipse.jface.wizard.IWizardPage;
23 import org.eclipse.pde.internal.ui.PDEPlugin;
24 import org.eclipse.pde.internal.ui.PDEUIMessages;
25 import org.eclipse.pde.internal.ui.elements.ElementList;
26 import org.eclipse.pde.internal.ui.wizards.NewWizard;
27 import org.eclipse.pde.internal.ui.wizards.WizardElement;
28 import org.eclipse.pde.ui.IProvisionerWizard;
29 import org.eclipse.swt.graphics.Image;
30
31 public class AddTargetPluginsWizard extends NewWizard {
32     
33     private static final String JavaDoc PROVISIONER_POINT = "targetProvisioners"; //$NON-NLS-1$
34
private ProvisionerListSelectionPage fSelectionPage = null;
35     private File JavaDoc[] fDirs = null;
36     private IProvisionerWizard fWizard = null;
37     
38     public AddTargetPluginsWizard() {
39         setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
40         setWindowTitle(PDEUIMessages.AddTargetPluginsWizard_windowTitle);
41         setNeedsProgressMonitor(true);
42     }
43
44     public void addPages() {
45         setForcePreviousAndNextButtons(true);
46         ElementList list = getAvailableProvisioners();
47         if (list.size() == 1) {
48             try {
49                 fWizard = (IProvisionerWizard)((WizardElement)list.getChildren()[0]).createExecutableExtension();
50             } catch (CoreException e) {
51                 MessageDialog.openError(
52                         getContainer().getShell(),
53                         PDEUIMessages.Errors_CreationError,
54                         PDEUIMessages.Errors_CreationError_NoWizard);
55             }
56             fWizard.addPages();
57             IWizardPage[] pages = fWizard.getPages();
58             for (int i = 0; i < pages.length; i++)
59                 addPage(pages[i]);
60         } else {
61             fSelectionPage = new ProvisionerListSelectionPage(getAvailableProvisioners());
62             addPage(fSelectionPage);
63         }
64         super.addPages();
65     }
66     
67     private ElementList getAvailableProvisioners() {
68         ElementList list = new ElementList(PROVISIONER_POINT);
69         IExtensionRegistry registry = Platform.getExtensionRegistry();
70         IExtensionPoint point = registry.getExtensionPoint(PDEPlugin.getPluginId(), PROVISIONER_POINT);
71         if (point == null)
72             return list;
73         IExtension[] extensions = point.getExtensions();
74         for (int i = 0; i < extensions.length; i++) {
75             IConfigurationElement[] elements =
76                 extensions[i].getConfigurationElements();
77             for (int j = 0; j < elements.length; j++) {
78                 WizardElement element = createWizardElement(elements[j]);
79                 if (element != null) {
80                     list.add(element);
81                 }
82             }
83         }
84         return list;
85     }
86     
87     protected WizardElement createWizardElement(IConfigurationElement config) {
88         String JavaDoc name = config.getAttribute(WizardElement.ATT_NAME);
89         String JavaDoc id = config.getAttribute(WizardElement.ATT_ID);
90         if (name == null || id == null)
91             return null;
92         WizardElement element = new WizardElement(config);
93         
94         String JavaDoc imageName = config.getAttribute(WizardElement.ATT_ICON);
95         Image image = null;
96         if (imageName != null) {
97             String JavaDoc pluginID = config.getNamespaceIdentifier();
98             image =
99                 PDEPlugin.getDefault().getLabelProvider().getImageFromPlugin(pluginID, imageName);
100         }
101         element.setImage(image);
102         return element;
103     }
104
105     public boolean canFinish() {
106         return ((fSelectionPage != null && getPageCount() > 1) || fSelectionPage == null) && super.canFinish();
107     }
108
109     public boolean performFinish() {
110         IProvisionerWizard wizard = (fSelectionPage != null) ? (IProvisionerWizard)fSelectionPage.getSelectedWizard() :
111             fWizard;
112         if (wizard == null)
113             return true;
114         fDirs = wizard.getLocations();
115         return super.performFinish();
116     }
117     
118     public File JavaDoc[] getDirectories() {
119         return (fDirs == null) ? new File JavaDoc[0] : fDirs;
120     }
121
122 }
123
Popular Tags