comparison org.eclipse.jface/src/org/eclipse/jface/wizard/WizardPage.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.jface.wizard.WizardPage;
14
15 import org.eclipse.jface.wizard.IWizardPage;
16 import org.eclipse.jface.wizard.IWizard;
17 import org.eclipse.jface.wizard.IWizardContainer;
18
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.widgets.Shell;
21 import org.eclipse.core.runtime.Assert;
22 import org.eclipse.jface.dialogs.DialogPage;
23 import org.eclipse.jface.dialogs.IDialogSettings;
24 import org.eclipse.jface.resource.ImageDescriptor;
25
26 import java.lang.all;
27 import java.util.Set;
28
29 /**
30 * An abstract base implementation of a wizard page.
31 * <p>
32 * Subclasses must implement the <code>createControl</code> method
33 * to create the specific controls for the wizard page.
34 * </p>
35 * <p>
36 * Subclasses may call the following methods to configure the wizard page:
37 * <ul>
38 * <li><code>setDescription</code></li>
39 * <li><code>setErrorMessage</code></li>
40 * <li><code>setImageDescriptor</code></li>
41 * <li><code>setMessage</code></li>
42 * <li><code>setPageComplete</code></li>
43 * <li><code>setPreviousPage</code></li>
44 * <li><code>setTitle</code></li>
45 * </ul>
46 * </p>
47 * <p>
48 * Subclasses may override these methods if required:
49 * <ul>
50 * <li><code>performHelp</code> - may be reimplemented to display help for the page</li>
51 * <li><code>canFlipToNextPage</code> - may be extended or reimplemented</li>
52 * <li><code>isPageComplete</code> - may be extended </li>
53 * <li><code>setDescription</code> - may be extended </li>
54 * <li><code>setTitle</code> - may be extended </li>
55 * <li><code>dispose</code> - may be extended to dispose additional allocated SWT resources</li>
56 * </ul>
57 * </p>
58 * <p>
59 * Note that clients are free to implement <code>IWizardPage</code> from scratch
60 * instead of subclassing <code>WizardPage</code>. Correct implementations of
61 * <code>IWizardPage</code> will work with any correct implementation of
62 * <code>IWizard</code>.
63 * </p>
64 */
65 public abstract class WizardPage : DialogPage, IWizardPage {
66 alias DialogPage.setMessage setMessage;
67
68 /**
69 * This page's name.
70 */
71 private String name;
72
73 /**
74 * The wizard to which this page belongs; <code>null</code>
75 * if this page has yet to be added to a wizard.
76 */
77 private IWizard wizard = null;
78
79 /**
80 * Indicates whether this page is complete.
81 */
82 private bool isPageComplete_ = true;
83
84 /**
85 * The page that was shown right before this page became visible;
86 * <code>null</code> if none.
87 */
88 private IWizardPage previousPage = null;
89
90 /**
91 * Creates a new wizard page with the given name, and
92 * with no title or image.
93 *
94 * @param pageName the name of the page
95 */
96 protected this(String pageName) {
97 this(pageName, null, cast(ImageDescriptor) null);
98 }
99
100 /**
101 * Creates a new wizard page with the given name, title, and image.
102 *
103 * @param pageName the name of the page
104 * @param title the title for this wizard page,
105 * or <code>null</code> if none
106 * @param titleImage the image descriptor for the title of this wizard page,
107 * or <code>null</code> if none
108 */
109 protected this(String pageName, String title,
110 ImageDescriptor titleImage) {
111 super(title, titleImage);
112 Assert.isNotNull(pageName); // page name must not be null
113 name = pageName;
114 }
115
116 /**
117 * The <code>WizardPage</code> implementation of this <code>IWizardPage</code>
118 * method returns <code>true</code> if this page is complete (<code>isPageComplete</code>)
119 * and there is a next page to flip to. Subclasses may override (extend or reimplement).
120 *
121 * @see #getNextPage
122 * @see #isPageComplete()
123 */
124 public bool canFlipToNextPage() {
125 return isPageComplete() && getNextPage() !is null;
126 }
127
128 /**
129 * Returns the wizard container for this wizard page.
130 *
131 * @return the wizard container, or <code>null</code> if this
132 * wizard page has yet to be added to a wizard, or the
133 * wizard has yet to be added to a container
134 */
135 protected IWizardContainer getContainer() {
136 if (wizard is null) {
137 return null;
138 }
139 return wizard.getContainer();
140 }
141
142 /**
143 * Returns the dialog settings for this wizard page.
144 *
145 * @return the dialog settings, or <code>null</code> if none
146 */
147 protected IDialogSettings getDialogSettings() {
148 if (wizard is null) {
149 return null;
150 }
151 return wizard.getDialogSettings();
152 }
153
154 /* (non-Javadoc)
155 * Method declared on IDialogPage.
156 */
157 public override Image getImage() {
158 Image result = super.getImage();
159
160 if (result is null && wizard !is null) {
161 return wizard.getDefaultPageImage();
162 }
163
164 return result;
165 }
166
167 /* (non-Javadoc)
168 * Method declared on IWizardPage.
169 */
170 public String getName() {
171 return name;
172 }
173
174 /* (non-Javadoc)
175 * Method declared on IWizardPage.
176 * The default behavior is to ask the wizard for the next page.
177 */
178 public IWizardPage getNextPage() {
179 if (wizard is null) {
180 return null;
181 }
182 return wizard.getNextPage(this);
183 }
184
185 /* (non-Javadoc)
186 * Method declared on IWizardPage.
187 * The default behavior is return the cached previous back or,
188 * lacking that, to ask the wizard for the previous page.
189 */
190 public IWizardPage getPreviousPage() {
191 if (previousPage !is null) {
192 return previousPage;
193 }
194
195 if (wizard is null) {
196 return null;
197 }
198
199 return wizard.getPreviousPage(this);
200 }
201
202 /**
203 * The <code>WizardPage</code> implementation of this method declared on
204 * <code>DialogPage</code> returns the shell of the container.
205 * The advantage of this implementation is that the shell is accessable
206 * once the container is created even though this page's control may not
207 * yet be created.
208 */
209 public override Shell getShell() {
210
211 IWizardContainer container = getContainer();
212 if (container is null) {
213 return null;
214 }
215
216 // Ask the wizard since our contents may not have been created.
217 return container.getShell();
218 }
219
220 /* (non-Javadoc)
221 * Method declared on IWizardPage.
222 */
223 public IWizard getWizard() {
224 return wizard;
225 }
226
227 /**
228 * Returns whether this page is the current one in the wizard's container.
229 *
230 * @return <code>true</code> if the page is active,
231 * and <code>false</code> otherwise
232 */
233 protected bool isCurrentPage() {
234 return (getContainer() !is null && this is getContainer()
235 .getCurrentPage());
236 }
237
238 /**
239 * The <code>WizardPage</code> implementation of this <code>IWizard</code> method
240 * returns the value of an internal state variable set by
241 * <code>setPageComplete</code>. Subclasses may extend.
242 */
243 public bool isPageComplete() {
244 return isPageComplete_;
245 }
246
247 /**
248 * The <code>WizardPage</code> implementation of this <code>IDialogPage</code>
249 * method extends the <code>DialogPage</code> implementation to update
250 * the wizard container title bar. Subclasses may extend.
251 */
252 public override void setDescription(String description) {
253 super.setDescription(description);
254 if (isCurrentPage()) {
255 getContainer().updateTitleBar();
256 }
257 }
258
259 /**
260 * The <code>WizardPage</code> implementation of this method
261 * declared on <code>DialogPage</code> updates the container
262 * if this is the current page.
263 */
264 public override void setErrorMessage(String newMessage) {
265 super.setErrorMessage(newMessage);
266 if (isCurrentPage()) {
267 getContainer().updateMessage();
268 }
269 }
270
271 /**
272 * The <code>WizardPage</code> implementation of this method
273 * declared on <code>DialogPage</code> updates the container
274 * if this page is the current page.
275 */
276 public override void setImageDescriptor(ImageDescriptor image) {
277 super.setImageDescriptor(image);
278 if (isCurrentPage()) {
279 getContainer().updateTitleBar();
280 }
281 }
282
283 /**
284 * The <code>WizardPage</code> implementation of this method
285 * declared on <code>DialogPage</code> updates the container
286 * if this is the current page.
287 */
288 public override void setMessage(String newMessage, int newType) {
289 super.setMessage(newMessage, newType);
290 if (isCurrentPage()) {
291 getContainer().updateMessage();
292 }
293 }
294
295 /**
296 * Sets whether this page is complete.
297 * <p>
298 * This information is typically used by the wizard to decide
299 * when it is okay to move on to the next page or finish up.
300 * </p>
301 *
302 * @param complete <code>true</code> if this page is complete, and
303 * and <code>false</code> otherwise
304 * @see #isPageComplete()
305 */
306 public void setPageComplete(bool complete) {
307 isPageComplete_ = complete;
308 if (isCurrentPage()) {
309 getContainer().updateButtons();
310 }
311 }
312
313 /* (non-Javadoc)
314 * Method declared on IWizardPage.
315 */
316 public void setPreviousPage(IWizardPage page) {
317 previousPage = page;
318 }
319
320 /**
321 * The <code>WizardPage</code> implementation of this <code>IDialogPage</code>
322 * method extends the <code>DialogPage</code> implementation to update
323 * the wizard container title bar. Subclasses may extend.
324 */
325 public override void setTitle(String title) {
326 super.setTitle(title);
327 if (isCurrentPage()) {
328 getContainer().updateTitleBar();
329 }
330 }
331
332 /* (non-Javadoc)
333 * Method declared on IWizardPage.
334 */
335 public void setWizard(IWizard newWizard) {
336 wizard = newWizard;
337 }
338
339 /**
340 * Returns a printable representation of this wizard page suitable
341 * only for debug purposes.
342 */
343 public override String toString() {
344 return name;
345 }
346 }