KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > extension > NewExtensionWizard


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.extension;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.pde.core.plugin.IPluginModelBase;
15 import org.eclipse.pde.internal.ui.PDEPlugin;
16 import org.eclipse.pde.internal.ui.PDEPluginImages;
17 import org.eclipse.pde.internal.ui.PDEUIMessages;
18 import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
19 import org.eclipse.pde.internal.ui.wizards.NewWizard;
20 import org.eclipse.pde.internal.ui.wizards.WizardCollectionElement;
21 import org.eclipse.pde.internal.ui.wizards.WizardElement;
22
23 public class NewExtensionWizard extends NewWizard {
24     public static final String JavaDoc PLUGIN_POINT = "newExtension"; //$NON-NLS-1$
25
private PointSelectionPage fPointPage;
26     private IPluginModelBase fModel;
27     private IProject fProject;
28     private ManifestEditor fEditor;
29     private WizardCollectionElement fWizardCollection;
30     
31     public NewExtensionWizard(IProject project, IPluginModelBase model, ManifestEditor editor) {
32         setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
33         setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWEX_WIZ);
34         fModel = model;
35         fProject = project;
36         fEditor = editor;
37         setForcePreviousAndNextButtons(true);
38         setWindowTitle(PDEUIMessages.NewExtensionWizard_wtitle);
39         loadWizardCollection();
40     }
41     public void addPages() {
42         fPointPage =
43             new PointSelectionPage(fProject, fModel, fWizardCollection, getTemplates(), this);
44         addPage(fPointPage);
45     }
46     private void loadWizardCollection() {
47         NewExtensionRegistryReader reader = new NewExtensionRegistryReader();
48         fWizardCollection = (WizardCollectionElement) reader.readRegistry(
49                 PDEPlugin.getPluginId(),
50                 PLUGIN_POINT,
51                 false);
52     }
53     
54     public WizardCollectionElement getTemplates() {
55         WizardCollectionElement templateCollection = new WizardCollectionElement("", "", null); //$NON-NLS-1$ //$NON-NLS-2$
56
collectTemplates(fWizardCollection.getChildren(), templateCollection);
57         return templateCollection;
58     }
59     
60     private void collectTemplates(Object JavaDoc [] children, WizardCollectionElement list) {
61         for (int i = 0; i<children.length; i++){
62             if (children[i] instanceof WizardCollectionElement) {
63                 WizardCollectionElement element = (WizardCollectionElement)children[i];
64                 collectTemplates(element.getChildren(), list);
65                 collectTemplates(element.getWizards().getChildren(), list);
66             }
67             else if (children[i] instanceof WizardElement) {
68                 WizardElement wizard = (WizardElement)children[i];
69                 if (wizard.isTemplate())
70                     list.getWizards().add(wizard);
71             }
72         }
73     }
74     public boolean performFinish() {
75         fPointPage.checkModel();
76         if (fPointPage.canFinish())
77             return fPointPage.finish();
78         return true;
79     }
80     
81     public ManifestEditor getEditor() {
82         return fEditor;
83     }
84
85 }
86
Popular Tags