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