KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > dialogs > MultiStepReviewWizardPage


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  * Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog font should be
11  * activated and used by other components.
12  *******************************************************************************/

13 package org.eclipse.ui.internal.ide.dialogs;
14
15 import org.eclipse.jface.viewers.ISelectionChangedListener;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.jface.viewers.SelectionChangedEvent;
18 import org.eclipse.jface.wizard.WizardPage;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.graphics.Font;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Text;
26 import org.eclipse.ui.PlatformUI;
27 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
28 import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
29 import org.eclipse.ui.internal.ide.misc.WizardStepGroup;
30
31 /**
32  * This page allows the user to review the steps to be done.
33  * <p>
34  * Example usage:
35  * <pre>
36  * mainPage = new MultiStepReviewWizardPage("multiStepReviewPage");
37  * mainPage.setTitle("Project");
38  * mainPage.setDescription("Review project.");
39  * </pre>
40  * </p>
41  */

42 public class MultiStepReviewWizardPage extends WizardPage {
43     private Text detailsField;
44
45     private Label instructionLabel;
46
47     private WizardStepGroup stepGroup;
48
49     private MultiStepWizard stepWizard;
50
51     /**
52      * Creates a new step review wizard page.
53      *
54      * @param pageName the name of this page
55      * @param stepWizard the wizard
56      */

57     public MultiStepReviewWizardPage(String JavaDoc pageName, MultiStepWizard stepWizard) {
58         super(pageName);
59         this.stepWizard = stepWizard;
60     }
61
62     /* (non-Javadoc)
63      * Method declared on IWizardPage
64      */

65     public boolean canFlipToNextPage() {
66         // Already know there is a next page...
67
return isPageComplete() && !stepWizard.canFinishOnReviewPage();
68     }
69
70     /* (non-Javadoc)
71      * Method declared on IDialogPage.
72      */

73     public void createControl(Composite parent) {
74         Composite composite = new Composite(parent, SWT.NULL);
75         GridLayout layout = new GridLayout();
76         layout.numColumns = 2;
77         composite.setLayout(layout);
78         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
79
80         PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
81                 IIDEHelpContextIds.NEW_PROJECT_REVIEW_WIZARD_PAGE);
82
83         createStepGroup(composite);
84         createDetailsGroup(composite);
85         createInstructionsGroup(composite);
86
87         setControl(composite);
88     }
89
90     /**
91      * Creates the control for the details
92      */

93     private void createDetailsGroup(Composite parent) {
94         Font font = parent.getFont();
95         // Create a composite to hold everything together
96
Composite composite = new Composite(parent, SWT.NULL);
97         composite.setLayout(new GridLayout());
98         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
99
100         // Add a label to identify the details text field
101
Label label = new Label(composite, SWT.LEFT);
102         label.setText(IDEWorkbenchMessages.MultiStepReviewWizardPage_detailsLabel);
103         GridData data = new GridData();
104         data.verticalAlignment = SWT.TOP;
105         label.setLayoutData(data);
106         label.setFont(font);
107
108         // Text field to display the step's details
109
detailsField = new Text(composite, SWT.WRAP | SWT.MULTI | SWT.V_SCROLL
110                 | SWT.BORDER);
111         detailsField.setText("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); // prefill to show 15 lines //$NON-NLS-1$
112
detailsField.setEditable(false);
113         detailsField.setLayoutData(new GridData(GridData.FILL_BOTH));
114         detailsField.setFont(font);
115     }
116
117     /**
118      * Creates the control for the instructions
119      */

120     private void createInstructionsGroup(Composite parent) {
121         instructionLabel = new Label(parent, SWT.LEFT);
122         instructionLabel.setText(IDEWorkbenchMessages.MultiStepReviewWizardPage_instructionFinishLabel);
123         GridData data = new GridData();
124         data.verticalAlignment = SWT.TOP;
125         data.horizontalSpan = 2;
126         instructionLabel.setLayoutData(data);
127         instructionLabel.setFont(parent.getFont());
128     }
129
130     /**
131      * Creates the control for the step list
132      */

133     private void createStepGroup(Composite parent) {
134         stepGroup = new WizardStepGroup();
135         stepGroup.createContents(parent);
136         stepGroup.setSelectionListener(new ISelectionChangedListener() {
137             public void selectionChanged(SelectionChangedEvent event) {
138                 if (event.getSelection() instanceof IStructuredSelection) {
139                     IStructuredSelection sel = (IStructuredSelection) event
140                             .getSelection();
141                     WizardStep step = (WizardStep) sel.getFirstElement();
142                     if (step != null) {
143                         detailsField.setText(step.getDetails());
144                     }
145                 }
146             }
147         });
148     }
149
150     /**
151      * Returns the steps to be displayed.
152      */

153     /* package */WizardStep[] getSteps() {
154         if (stepGroup != null) {
155             return stepGroup.getSteps();
156         }
157
158         return new WizardStep[0];
159     }
160
161     /**
162      * Sets the steps to be displayed. Has no effect if
163      * the page is not yet created.
164      *
165      * @param steps the collection of steps
166      */

167     /* package */void setSteps(WizardStep[] steps) {
168         if (stepGroup != null) {
169             stepGroup.setSteps(steps);
170         }
171     }
172
173     /* (non-Javadoc)
174      * Method declared on IDialogPage.
175      */

176     public void setVisible(boolean visible) {
177         super.setVisible(visible);
178         if (visible) {
179             if (stepWizard.canFinishOnReviewPage()) {
180                 instructionLabel.setText(IDEWorkbenchMessages.MultiStepReviewWizardPage_instructionFinishLabel);
181             } else {
182                 instructionLabel.setText(IDEWorkbenchMessages.MultiStepReviewWizardPage_instructionNextLabel);
183             }
184             ((Composite) getControl()).layout(true);
185         }
186     }
187 }
188
Popular Tags