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.ui.templates;
11:
12: import java.util.ArrayList;
13:
14: import org.eclipse.jface.dialogs.Dialog;
15: import org.eclipse.jface.wizard.IWizard;
16: import org.eclipse.jface.wizard.WizardPage;
17: import org.eclipse.swt.SWT;
18: import org.eclipse.swt.layout.GridLayout;
19: import org.eclipse.swt.widgets.Composite;
20: import org.eclipse.ui.PlatformUI;
21:
22: /**
23: * An implementation of the standard wizard page that creates its contents from
24: * the list of template options. The options will be created in the order they
25: * are added to the list. When the page is made visible, options that require
26: * late initialization will be given a chance to initialize.
27: *
28: * @since 2.0
29: */
30:
31: public class OptionTemplateWizardPage extends WizardPage {
32: private BaseOptionTemplateSection section;
33: private ArrayList options;
34: private String helpContextId;
35:
36: /**
37: * The constructor.
38: *
39: * @param section
40: * the section that is contributing this page
41: * @param options
42: * a list of options that should be shown in this page.
43: * @param helpContextId
44: * the help context id
45: */
46: public OptionTemplateWizardPage(BaseOptionTemplateSection section,
47: ArrayList options, String helpContextId) {
48: super (""); //$NON-NLS-1$
49: this .section = section;
50: this .options = options;
51: this .helpContextId = helpContextId;
52: }
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(
73: container, helpContextId);
74: setControl(container);
75: Dialog.applyDialogFont(container);
76: }
77:
78: /**
79: * Initializes the options that require late initialization when the page is
80: * made visible.
81: *
82: * @param visible
83: */
84: public void setVisible(boolean visible) {
85: if (visible && section.isDependentOnParentWizard()) {
86: IWizard wizard = getWizard();
87: if (wizard instanceof AbstractNewPluginTemplateWizard) {
88: AbstractNewPluginTemplateWizard templateWizard = (AbstractNewPluginTemplateWizard) wizard;
89: section.initializeFields(templateWizard.getData());
90: }
91: }
92: super.setVisible(visible);
93: }
94: }
|