KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > ui > templates > OptionTemplateWizardPage


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.ui.templates;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.jface.wizard.IWizard;
17 import org.eclipse.jface.wizard.WizardPage;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.ui.PlatformUI;
22
23 /**
24  * An implementation of the standard wizard page that creates its contents from
25  * the list of template options. The options will be created in the order they
26  * are added to the list. When the page is made visible, options that require
27  * late initialization will be given a chance to initialize.
28  *
29  * @since 2.0
30  */

31
32 public class OptionTemplateWizardPage extends WizardPage {
33     private BaseOptionTemplateSection section;
34     private ArrayList JavaDoc options;
35     private String JavaDoc helpContextId;
36
37     /**
38      * The constructor.
39      *
40      * @param section
41      * the section that is contributing this page
42      * @param options
43      * a list of options that should be shown in this page.
44      * @param helpContextId
45      * the help context id
46      */

47     public OptionTemplateWizardPage(BaseOptionTemplateSection section,
48             ArrayList JavaDoc options, String JavaDoc helpContextId) {
49         super(""); //$NON-NLS-1$
50
this.section = section;
51         this.options = options;
52         this.helpContextId = helpContextId;
53     }
54     /**
55      * Creates the page control by creating individual options in the order
56      * subject to their position in the list.'
57      *
58      * @param composite
59      */

60     public void createControl(Composite composite) {
61         Composite container = new Composite(composite, SWT.NULL);
62         GridLayout layout = new GridLayout();
63         layout.numColumns = 2;
64         layout.verticalSpacing = 9;
65         container.setLayout(layout);
66
67         for (int i = 0; i < options.size(); i++) {
68             TemplateOption option = (TemplateOption) options.get(i);
69             option.createControl(container, 2);
70         }
71         if (helpContextId != null)
72             PlatformUI.getWorkbench().getHelpSystem().setHelp(container, helpContextId);
73         setControl(container);
74         Dialog.applyDialogFont(container);
75     }
76     /**
77      * Initializes the options that require late initialization when the page is
78      * made visible.
79      *
80      * @param visible
81      */

82     public void setVisible(boolean visible) {
83         if (visible && section.isDependentOnParentWizard()) {
84             IWizard wizard = getWizard();
85             if (wizard instanceof AbstractNewPluginTemplateWizard) {
86                 AbstractNewPluginTemplateWizard templateWizard = (AbstractNewPluginTemplateWizard) wizard;
87                 section.initializeFields(templateWizard.getData());
88             }
89         }
90         super.setVisible(visible);
91     }
92 }
93
Popular Tags