Lines 7-13
Link Here
|
7 |
* http://www.sun.com/ |
7 |
* http://www.sun.com/ |
8 |
* |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
12 |
*/ |
13 |
|
13 |
|
Lines 267-273
Link Here
|
267 |
cancelButton.addActionListener (listener); |
267 |
cancelButton.addActionListener (listener); |
268 |
|
268 |
|
269 |
super.setOptions (new Object[] { previousButton, nextButton, finishButton, cancelButton }); |
269 |
super.setOptions (new Object[] { previousButton, nextButton, finishButton, cancelButton }); |
270 |
super.setClosingOptions (new Object[] { finishButton, cancelButton }); |
270 |
super.setClosingOptions (new Object[] { WizardDescriptor.FinishAction.FINISH_ACTION, cancelButton }); |
271 |
|
271 |
|
272 |
this.panels = panels; |
272 |
this.panels = panels; |
273 |
panels.addChangeListener (listener); |
273 |
panels.addChangeListener (listener); |
Lines 1013-1018
Link Here
|
1013 |
public interface FinishPanel extends Panel { |
1013 |
public interface FinishPanel extends Panel { |
1014 |
} |
1014 |
} |
1015 |
|
1015 |
|
|
|
1016 |
/** A special interface for panels that need to do additional |
1017 |
* validation when Next or Finish button is clicked. |
1018 |
*/ |
1019 |
public interface ValidatingPanel extends Panel { |
1020 |
|
1021 |
/** |
1022 |
* Is called when Next of Finish buttons are clicked and |
1023 |
* allows deeper check to find out that panel is in valid |
1024 |
* state and it is ok to leave it. |
1025 |
* |
1026 |
* @throws WizardValidationException when validation fails |
1027 |
*/ |
1028 |
public void validate () throws WizardValidationException; |
1029 |
} |
1030 |
|
1016 |
/** Special iterator that works on an array of <code>Panel</code>s. |
1031 |
/** Special iterator that works on an array of <code>Panel</code>s. |
1017 |
*/ |
1032 |
*/ |
1018 |
public static class ArrayIterator extends Object implements Iterator { |
1033 |
public static class ArrayIterator extends Object implements Iterator { |
Lines 1109-1114
Link Here
|
1109 |
} |
1124 |
} |
1110 |
|
1125 |
|
1111 |
} |
1126 |
} |
|
|
1127 |
|
1128 |
private boolean lazyValidate (WizardDescriptor.Panel panel, WizardDescriptor.WizardPanel wizard) { |
1129 |
if (panel instanceof ValidatingPanel) { |
1130 |
ValidatingPanel v = (ValidatingPanel)panel; |
1131 |
try { |
1132 |
// try validation current panel |
1133 |
v.validate(); |
1134 |
} catch (WizardValidationException wve) { |
1135 |
// cannot continue, notify user |
1136 |
if (wizardPanel != null) { |
1137 |
wizardPanel.setErrorMessage (wve.getLocalizedMessage ()); |
1138 |
} |
1139 |
// focus source of this problem |
1140 |
if (wve.getSource () != null) { |
1141 |
final JComponent comp = (JComponent) wve.getSource (); |
1142 |
if (comp.isFocusable ()) { |
1143 |
comp.requestFocus (); |
1144 |
} |
1145 |
} |
1146 |
// lazy validation failed |
1147 |
return false; |
1148 |
} |
1149 |
} |
1150 |
return true; |
1151 |
} |
1112 |
|
1152 |
|
1113 |
/** Listener to changes in the iterator and panels. |
1153 |
/** Listener to changes in the iterator and panels. |
1114 |
*/ |
1154 |
*/ |
Lines 1120-1127
Link Here
|
1120 |
} |
1160 |
} |
1121 |
/** Action listener */ |
1161 |
/** Action listener */ |
1122 |
public void actionPerformed (ActionEvent ev) { |
1162 |
public void actionPerformed (ActionEvent ev) { |
|
|
1163 |
if (wizardPanel != null) { |
1164 |
wizardPanel.setErrorMessage(" "); //NOI18N |
1165 |
} |
1123 |
if (ev.getSource () == nextButton) { |
1166 |
if (ev.getSource () == nextButton) { |
1124 |
Dimension previousSize = panels.current().getComponent().getSize(); |
1167 |
Dimension previousSize = panels.current().getComponent().getSize(); |
|
|
1168 |
|
1169 |
// do lazy validation |
1170 |
if (!lazyValidate (panels.current (), wizardPanel)) { |
1171 |
// if validation failed => cannot move to next panel |
1172 |
return ; |
1173 |
} |
1174 |
|
1125 |
panels.nextPanel (); |
1175 |
panels.nextPanel (); |
1126 |
try { |
1176 |
try { |
1127 |
// change UI to show next step, show wait cursor during |
1177 |
// change UI to show next step, show wait cursor during |
Lines 1142-1156
Link Here
|
1142 |
} |
1192 |
} |
1143 |
|
1193 |
|
1144 |
if (ev.getSource () == previousButton) { |
1194 |
if (ev.getSource () == previousButton) { |
1145 |
if (wizardPanel != null) { |
|
|
1146 |
wizardPanel.setErrorMessage(" "); //NOI18N |
1147 |
} |
1148 |
panels.previousPanel (); |
1195 |
panels.previousPanel (); |
1149 |
// show wait cursor when updating previous button |
1196 |
// show wait cursor when updating previous button |
1150 |
updateStateWithFeedback (); |
1197 |
updateStateWithFeedback (); |
1151 |
} |
1198 |
} |
1152 |
|
1199 |
|
1153 |
if (ev.getSource () == finishButton) { |
1200 |
if (ev.getSource () == finishButton) { |
|
|
1201 |
|
1202 |
// do lazy validation |
1203 |
if (!lazyValidate (panels.current (), wizardPanel)) { |
1204 |
// if validation failed => cannot move to next panel |
1205 |
return ; |
1206 |
} |
1207 |
|
1208 |
// all is OK |
1209 |
|
1210 |
// close wizrd |
1211 |
FinishAction.FINISH_ACTION.fireActionPerformed (); |
1154 |
Object oldValue = getValue (); |
1212 |
Object oldValue = getValue (); |
1155 |
setValueWithoutPCH (OK_OPTION); |
1213 |
setValueWithoutPCH (OK_OPTION); |
1156 |
if (Arrays.asList(getClosingOptions()).contains(finishButton)) { |
1214 |
if (Arrays.asList(getClosingOptions()).contains(finishButton)) { |
Lines 1168-1173
Link Here
|
1168 |
firePropertyChange (PROP_VALUE, oldValue, CANCEL_OPTION); |
1226 |
firePropertyChange (PROP_VALUE, oldValue, CANCEL_OPTION); |
1169 |
} |
1227 |
} |
1170 |
} |
1228 |
} |
|
|
1229 |
|
1171 |
} |
1230 |
} |
1172 |
|
1231 |
|
1173 |
/** Listenes on a users client property changes |
1232 |
/** Listenes on a users client property changes |
Lines 1526-1532
Link Here
|
1526 |
public void setErrorMessage(String msg) { |
1585 |
public void setErrorMessage(String msg) { |
1527 |
m_lblMessage.setText(msg); |
1586 |
m_lblMessage.setText(msg); |
1528 |
} |
1587 |
} |
1529 |
|
1588 |
|
1530 |
/** Creates content panel. |
1589 |
/** Creates content panel. |
1531 |
* @param contentNumbered <CODE>boolean</CODE> whether content will be numbered |
1590 |
* @param contentNumbered <CODE>boolean</CODE> whether content will be numbered |
1532 |
* @param leftDimension <CODE>Dimension</CODE> dimension of content pane |
1591 |
* @param leftDimension <CODE>Dimension</CODE> dimension of content pane |
Lines 1789-1794
Link Here
|
1789 |
void doCancelClick () { |
1848 |
void doCancelClick () { |
1790 |
if (cancelButton.isEnabled ()) { |
1849 |
if (cancelButton.isEnabled ()) { |
1791 |
cancelButton.doClick (); |
1850 |
cancelButton.doClick (); |
|
|
1851 |
} |
1852 |
} |
1853 |
|
1854 |
// helper, make possible close wizard as finish |
1855 |
static class FinishAction extends Object { |
1856 |
static public FinishAction FINISH_ACTION = new FinishAction (); |
1857 |
ActionListener listner; |
1858 |
public void addActionListener (ActionListener ac) { |
1859 |
listner = ac; |
1860 |
} |
1861 |
|
1862 |
public void removeActionListener (ActionListener ac) { |
1863 |
listner = null; |
1864 |
} |
1865 |
|
1866 |
public void fireActionPerformed () { |
1867 |
if (listner != null) { |
1868 |
listner.actionPerformed (new ActionEvent (this, 0, "")); |
1869 |
} |
1792 |
} |
1870 |
} |
1793 |
} |
1871 |
} |
1794 |
|
1872 |
|