01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.extension;
11:
12: import org.eclipse.core.resources.IProject;
13: import org.eclipse.pde.core.plugin.IPluginModelBase;
14: import org.eclipse.pde.internal.ui.PDEPlugin;
15: import org.eclipse.pde.internal.ui.PDEPluginImages;
16: import org.eclipse.pde.internal.ui.PDEUIMessages;
17: import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
18: import org.eclipse.pde.internal.ui.wizards.NewWizard;
19: import org.eclipse.pde.internal.ui.wizards.WizardCollectionElement;
20: import org.eclipse.pde.internal.ui.wizards.WizardElement;
21:
22: public class NewExtensionWizard extends NewWizard {
23: public static final String PLUGIN_POINT = "newExtension"; //$NON-NLS-1$
24: private PointSelectionPage fPointPage;
25: private IPluginModelBase fModel;
26: private IProject fProject;
27: private ManifestEditor fEditor;
28: private WizardCollectionElement fWizardCollection;
29:
30: public NewExtensionWizard(IProject project, IPluginModelBase model,
31: 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:
42: public void addPages() {
43: fPointPage = new PointSelectionPage(fProject, fModel,
44: fWizardCollection, getTemplates(), this );
45: addPage(fPointPage);
46: }
47:
48: private void loadWizardCollection() {
49: NewExtensionRegistryReader reader = new NewExtensionRegistryReader();
50: fWizardCollection = (WizardCollectionElement) reader
51: .readRegistry(PDEPlugin.getPluginId(), PLUGIN_POINT,
52: false);
53: }
54:
55: public WizardCollectionElement getTemplates() {
56: WizardCollectionElement templateCollection = new WizardCollectionElement(
57: "", "", null); //$NON-NLS-1$ //$NON-NLS-2$
58: collectTemplates(fWizardCollection.getChildren(),
59: templateCollection);
60: return templateCollection;
61: }
62:
63: private void collectTemplates(Object[] children,
64: WizardCollectionElement list) {
65: for (int i = 0; i < children.length; i++) {
66: if (children[i] instanceof WizardCollectionElement) {
67: WizardCollectionElement element = (WizardCollectionElement) children[i];
68: collectTemplates(element.getChildren(), list);
69: collectTemplates(element.getWizards().getChildren(),
70: list);
71: } else if (children[i] instanceof WizardElement) {
72: WizardElement wizard = (WizardElement) children[i];
73: if (wizard.isTemplate())
74: list.getWizards().add(wizard);
75: }
76: }
77: }
78:
79: public boolean performFinish() {
80: fPointPage.checkModel();
81: if (fPointPage.canFinish())
82: return fPointPage.finish();
83: return true;
84: }
85:
86: public ManifestEditor getEditor() {
87: return fEditor;
88: }
89:
90: }
|