KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > ui > wizards > NewElementWizardPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  *******************************************************************************/

11 package org.eclipse.jdt.ui.wizards;
12
13 import org.eclipse.core.runtime.IStatus;
14
15 import org.eclipse.jface.wizard.WizardPage;
16
17 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
18 import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
19
20 /**
21  * Base class for wizard page responsible to create Java elements. The class
22  * provides API to update the wizard's status line and OK button according to
23  * the value of a <code>IStatus</code> object.
24  *
25  * <p>
26  * Clients may subclass.
27  * </p>
28  *
29  * @since 2.0
30  */

31 public abstract class NewElementWizardPage extends WizardPage {
32
33     private IStatus fCurrStatus;
34     
35     private boolean fPageVisible;
36
37     /**
38      * Creates a <code>NewElementWizardPage</code>.
39      *
40      * @param name the wizard page's name
41      */

42     public NewElementWizardPage(String JavaDoc name) {
43         super(name);
44         fPageVisible= false;
45         fCurrStatus= new StatusInfo();
46     }
47         
48     // ---- WizardPage ----------------
49

50     /*
51      * @see WizardPage#becomesVisible
52      */

53     public void setVisible(boolean visible) {
54         super.setVisible(visible);
55         fPageVisible= visible;
56         // policy: wizards are not allowed to come up with an error message
57
if (visible && fCurrStatus.matches(IStatus.ERROR)) {
58             StatusInfo status= new StatusInfo();
59             status.setError(""); //$NON-NLS-1$
60
fCurrStatus= status;
61         }
62         updateStatus(fCurrStatus);
63     }
64
65     /**
66      * Updates the status line and the OK button according to the given status
67      *
68      * @param status status to apply
69      */

70     protected void updateStatus(IStatus status) {
71         fCurrStatus= status;
72         setPageComplete(!status.matches(IStatus.ERROR));
73         if (fPageVisible) {
74             StatusUtil.applyToStatusLine(this, status);
75         }
76     }
77     
78     /**
79      * Updates the status line and the OK button according to the status evaluate from
80      * an array of status. The most severe error is taken. In case that two status with
81      * the same severity exists, the status with lower index is taken.
82      *
83      * @param status the array of status
84      */

85     protected void updateStatus(IStatus[] status) {
86         updateStatus(StatusUtil.getMostSevere(status));
87     }
88             
89 }
90
Popular Tags