1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.ui.wizards;
12 
13 import net.sourceforge.phpdt.externaltools.internal.ui.StatusInfo;
14 import net.sourceforge.phpdt.internal.ui.dialogs.StatusUtil;
15 
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.jface.wizard.WizardPage;
18 
19 /**
20  * Base class for wizard page responsible to create PHP elements. The class
21  * provides API to update the wizard's statis line and OK button according to
22  * the value of a <code>IStatus</code> object.
23  *
24  * @since 2.0
25  */
26 public abstract class NewElementWizardPage extends WizardPage {
27 
28 	private IStatus fCurrStatus;
29 
30 	private boolean fPageVisible;
31 
32 	/**
33 	 * Creates a <code>NewElementWizardPage</code>.
34 	 *
35 	 * @param name
36 	 *            the wizard page's name
37 	 */
NewElementWizardPage(String name)38 	public NewElementWizardPage(String name) {
39 		super(name);
40 		fPageVisible = false;
41 		fCurrStatus = new StatusInfo();
42 	}
43 
44 	// ---- WizardPage ----------------
45 
46 	/*
47 	 * @see WizardPage#becomesVisible
48 	 */
setVisible(boolean visible)49 	public void setVisible(boolean visible) {
50 		super.setVisible(visible);
51 		fPageVisible = visible;
52 		// policy: wizards are not allowed to come up with an error message
53 		if (visible && fCurrStatus.matches(IStatus.ERROR)) {
54 			StatusInfo status = new StatusInfo();
55 			status.setError(""); //$NON-NLS-1$
56 			fCurrStatus = status;
57 		}
58 		updateStatus(fCurrStatus);
59 	}
60 
61 	/**
62 	 * Updates the status line and the ok button according to the given status
63 	 *
64 	 * @param status
65 	 *            status to apply
66 	 */
updateStatus(IStatus status)67 	protected void updateStatus(IStatus status) {
68 		fCurrStatus = status;
69 		setPageComplete(!status.matches(IStatus.ERROR));
70 		if (fPageVisible) {
71 			StatusUtil.applyToStatusLine(this, status);
72 		}
73 	}
74 
75 	/**
76 	 * Updates the status line and the ok button according to the status
77 	 * evaluate from an array of status. The most severe error is taken. In case
78 	 * that two status with the same severity exists, the status with lower
79 	 * index is taken.
80 	 *
81 	 * @param status
82 	 *            the array of status
83 	 */
updateStatus(IStatus[] status)84 	protected void updateStatus(IStatus[] status) {
85 		updateStatus(StatusUtil.getMostSevere(status));
86 	}
87 
88 }
89