Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / ui / wizards / NewElementWizardPage.java
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.dialog.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 the wizard page's name
36          */     
37         public NewElementWizardPage(String name) {
38                 super(name);
39                 fPageVisible= false;
40                 fCurrStatus=  new StatusInfo();
41         }
42                 
43         // ---- WizardPage ----------------
44         
45         /*
46          * @see WizardPage#becomesVisible
47          */
48         public void setVisible(boolean visible) {
49                 super.setVisible(visible);
50                 fPageVisible= visible;
51                 // policy: wizards are not allowed to come up with an error message
52                 if (visible && fCurrStatus.matches(IStatus.ERROR)) {
53                         StatusInfo status= new StatusInfo();
54                         status.setError("");  //$NON-NLS-1$
55                         fCurrStatus= status;
56                 } 
57                 updateStatus(fCurrStatus);
58         }       
59
60         /**
61          * Updates the status line and the ok button according to the given status
62          * 
63          * @param status status to apply
64          */
65         protected void updateStatus(IStatus status) {
66                 fCurrStatus= status;
67                 setPageComplete(!status.matches(IStatus.ERROR));
68                 if (fPageVisible) {
69                         StatusUtil.applyToStatusLine(this, status);
70                 }
71         }
72         
73         /**
74          * Updates the status line and the ok button according to the status evaluate from
75          * an array of status. The most severe error is taken.  In case that two status with 
76          * the same severity exists, the status with lower index is taken.
77          * 
78          * @param status the array of status
79          */
80         protected void updateStatus(IStatus[] status) {
81                 updateStatus(StatusUtil.getMostSevere(status));
82         }       
83                         
84 }