Lines 256-261
Link Here
|
256 |
private Map properties; |
256 |
private Map properties; |
257 |
ResourceBundle bundle = NbBundle.getBundle(WizardDescriptor.class); |
257 |
ResourceBundle bundle = NbBundle.getBundle(WizardDescriptor.class); |
258 |
|
258 |
|
|
|
259 |
private Thread backgroundValidationTask; |
260 |
private Runnable onValidPerformer; |
261 |
|
259 |
{ |
262 |
{ |
260 |
// button init |
263 |
// button init |
261 |
ResourceBundle b = NbBundle.getBundle("org.openide.Bundle"); // NOI18N |
264 |
ResourceBundle b = NbBundle.getBundle("org.openide.Bundle"); // NOI18N |
Lines 609-629
Link Here
|
609 |
boolean prev = panels.hasPrevious(); |
612 |
boolean prev = panels.hasPrevious(); |
610 |
boolean valid = p.isValid(); |
613 |
boolean valid = p.isValid(); |
611 |
|
614 |
|
612 |
nextButton.setEnabled(next && valid); |
615 |
// AWT sensitive code |
613 |
previousButton.setEnabled(prev); |
616 |
if (SwingUtilities.isEventDispatchThread ()) { |
614 |
|
617 |
updateStateInAWT (); |
615 |
if (current instanceof FinishablePanel) { |
|
|
616 |
// check if isFinishPanel |
617 |
if (((FinishablePanel) current).isFinishPanel()) { |
618 |
finishButton.setEnabled(valid); |
619 |
} else { |
618 |
} else { |
620 |
// XXX What if the last panel is not FinishPanel ??? enable ? |
619 |
SwingUtilities.invokeLater (new Runnable () { |
621 |
finishButton.setEnabled(valid && !next); |
620 |
public void run () { |
|
|
621 |
updateStateInAWT (); |
622 |
} |
622 |
} |
623 |
} else { |
623 |
}); |
624 |
// original way |
|
|
625 |
finishButton.setEnabled(valid && (!next || (current instanceof FinishPanel))); |
626 |
} |
624 |
} |
|
|
625 |
// end of AWT sensitive code |
627 |
|
626 |
|
628 |
// nextButton.setVisible (next); |
627 |
// nextButton.setVisible (next); |
629 |
// finishButton.setVisible (!next || (current instanceof FinishPanel)); |
628 |
// finishButton.setVisible (!next || (current instanceof FinishPanel)); |
Lines 721-726
Link Here
|
721 |
} |
720 |
} |
722 |
} |
721 |
} |
723 |
|
722 |
|
|
|
723 |
private void updateStateInAWT () { |
724 |
Panel p = panels.current (); |
725 |
boolean next = panels.hasNext (); |
726 |
boolean prev = panels.hasPrevious (); |
727 |
boolean valid = p.isValid (); |
728 |
|
729 |
nextButton.setEnabled (next && valid); |
730 |
previousButton.setEnabled (prev); |
731 |
|
732 |
if (current instanceof FinishablePanel) { |
733 |
// check if isFinishPanel |
734 |
if (((FinishablePanel)current).isFinishPanel ()) { |
735 |
finishButton.setEnabled (valid); |
736 |
} else { |
737 |
// XXX What if the last panel is not FinishPanel ??? enable ? |
738 |
finishButton.setEnabled (valid && !next); |
739 |
} |
740 |
} else { |
741 |
// original way |
742 |
finishButton.setEnabled ( |
743 |
valid && |
744 |
(!next || (current instanceof FinishPanel)) |
745 |
); |
746 |
} |
747 |
} |
748 |
|
749 |
|
724 |
/** Shows blocking wait cursor during updateState run */ |
750 |
/** Shows blocking wait cursor during updateState run */ |
725 |
private void updateStateWithFeedback() { |
751 |
private void updateStateWithFeedback() { |
726 |
try { |
752 |
try { |
Lines 1064-1076
Link Here
|
1064 |
); |
1090 |
); |
1065 |
} |
1091 |
} |
1066 |
|
1092 |
|
1067 |
private boolean lazyValidate(WizardDescriptor.Panel panel) { |
1093 |
private void lazyValidate(final WizardDescriptor.Panel panel, final JButton origin) { |
1068 |
if (panel instanceof ValidatingPanel) { |
1094 |
|
|
|
1095 |
Runnable validationPeformar = new Runnable() { |
1096 |
public void run() { |
1069 |
ValidatingPanel v = (ValidatingPanel) panel; |
1097 |
ValidatingPanel v = (ValidatingPanel) panel; |
1070 |
|
1098 |
|
1071 |
try { |
1099 |
try { |
1072 |
// try validation current panel |
1100 |
// try validation current panel |
1073 |
v.validate(); |
1101 |
v.validate(); |
|
|
1102 |
|
1103 |
// validation succesfull |
1104 |
SwingUtilities.invokeLater(new Runnable() { |
1105 |
public void run() { |
1106 |
setValid(true); |
1107 |
onValidPerformer.run(); |
1108 |
} |
1109 |
}); |
1110 |
|
1074 |
} catch (WizardValidationException wve) { |
1111 |
} catch (WizardValidationException wve) { |
1075 |
// cannot continue, notify user |
1112 |
// cannot continue, notify user |
1076 |
if (wizardPanel != null) { |
1113 |
if (wizardPanel != null) { |
Lines 1086-1097
Link Here
|
1086 |
} |
1123 |
} |
1087 |
} |
1124 |
} |
1088 |
|
1125 |
|
1089 |
// lazy validation failed |
|
|
1090 |
return false; |
1091 |
} |
1126 |
} |
|
|
1127 |
|
1128 |
} |
1129 |
}; |
1130 |
|
1131 |
if (panel instanceof AsynchronousValidatingPanel) { |
1132 |
AsynchronousValidatingPanel p = (AsynchronousValidatingPanel) panel; |
1133 |
setValid(false); // disable Next> Finish buttons |
1134 |
p.prepareValidation(); |
1135 |
backgroundValidationTask = new Thread(validationPeformar); |
1136 |
backgroundValidationTask.start(); |
1137 |
} else if (panel instanceof ValidatingPanel) { |
1138 |
validationPeformar.run(); |
1139 |
} else { |
1140 |
onValidPerformer.run(); |
1092 |
} |
1141 |
} |
1093 |
|
1142 |
|
1094 |
return true; |
|
|
1095 |
} |
1143 |
} |
1096 |
|
1144 |
|
1097 |
// helper methods which call to InstantiatingIterator |
1145 |
// helper methods which call to InstantiatingIterator |
Lines 1325-1330
Link Here
|
1325 |
public void validate() throws WizardValidationException; |
1373 |
public void validate() throws WizardValidationException; |
1326 |
} |
1374 |
} |
1327 |
|
1375 |
|
|
|
1376 |
|
1377 |
/** |
1378 |
* A special interface for panels that need to do additional |
1379 |
* asynchronous validation when Next or Finish button is clicked. |
1380 |
* |
1381 |
* <p>During backround validation is Next or Finish button |
1382 |
* disabled. On validation success wizard automatically |
1383 |
* progress to next panel or finishes. |
1384 |
* |
1385 |
* <p>During backround validation Cancel button is hooked |
1386 |
* to signal the validation thread using interrupt(). |
1387 |
*/ |
1388 |
public interface AsynchronousValidatingPanel extends ValidatingPanel { |
1389 |
|
1390 |
/** |
1391 |
* Called synchronously from UI thread when Next |
1392 |
* of Finish buttons clicked. It allows to lock user |
1393 |
* input to assure official data for background validation. |
1394 |
*/ |
1395 |
public void prepareValidation(); |
1396 |
|
1397 |
/** |
1398 |
* Is called in separate thread when Next of Finish buttons |
1399 |
* are clicked and allows deeper check to find out that panel |
1400 |
* is in valid state and it is ok to leave it. |
1401 |
* |
1402 |
* @throws WizardValidationException when validation fails |
1403 |
*/ |
1404 |
public void validate() throws WizardValidationException; |
1405 |
} |
1406 |
|
1407 |
|
1328 |
/** A special interface for panel that needs to dynamically enabled |
1408 |
/** A special interface for panel that needs to dynamically enabled |
1329 |
* Finish button. |
1409 |
* Finish button. |
1330 |
* @since 4.28 |
1410 |
* @since 4.28 |
Lines 1489-1502
Link Here
|
1489 |
} |
1569 |
} |
1490 |
|
1570 |
|
1491 |
if (ev.getSource() == nextButton) { |
1571 |
if (ev.getSource() == nextButton) { |
1492 |
Dimension previousSize = panels.current().getComponent().getSize(); |
1572 |
final Dimension previousSize = panels.current().getComponent().getSize(); |
1493 |
|
1573 |
onValidPerformer = new Runnable() { |
1494 |
// do lazy validation |
1574 |
public void run() { |
1495 |
if (!lazyValidate(panels.current())) { |
|
|
1496 |
// if validation failed => cannot move to next panel |
1497 |
return; |
1498 |
} |
1499 |
|
1500 |
panels.nextPanel(); |
1575 |
panels.nextPanel(); |
1501 |
|
1576 |
|
1502 |
try { |
1577 |
try { |
Lines 1518-1523
Link Here
|
1518 |
updateState(); |
1593 |
updateState(); |
1519 |
} |
1594 |
} |
1520 |
} |
1595 |
} |
|
|
1596 |
}; |
1597 |
lazyValidate(panels.current(), nextButton); |
1598 |
} |
1521 |
|
1599 |
|
1522 |
if (ev.getSource() == previousButton) { |
1600 |
if (ev.getSource() == previousButton) { |
1523 |
panels.previousPanel(); |
1601 |
panels.previousPanel(); |
Lines 1527-1538
Link Here
|
1527 |
} |
1605 |
} |
1528 |
|
1606 |
|
1529 |
if (ev.getSource() == finishButton) { |
1607 |
if (ev.getSource() == finishButton) { |
1530 |
// do lazy validation |
1608 |
onValidPerformer = new Runnable() { |
1531 |
if (!lazyValidate(panels.current())) { |
1609 |
public void run() { |
1532 |
// if validation failed => cannot move to next panel |
|
|
1533 |
return; |
1534 |
} |
1535 |
|
1536 |
// do instantiate |
1610 |
// do instantiate |
1537 |
try { |
1611 |
try { |
1538 |
callInstantiate(); |
1612 |
callInstantiate(); |
Lines 1561-1568
Link Here
|
1561 |
|
1635 |
|
1562 |
firePropertyChange(PROP_VALUE, oldValue, OK_OPTION); |
1636 |
firePropertyChange(PROP_VALUE, oldValue, OK_OPTION); |
1563 |
} |
1637 |
} |
|
|
1638 |
}; |
1639 |
lazyValidate(panels.current(), finishButton); |
1640 |
} |
1564 |
|
1641 |
|
1565 |
if (ev.getSource() == cancelButton) { |
1642 |
if (ev.getSource() == cancelButton) { |
|
|
1643 |
if (backgroundValidationTask != null) { |
1644 |
backgroundValidationTask.interrupt(); |
1645 |
} |
1566 |
Object oldValue = getValue(); |
1646 |
Object oldValue = getValue(); |
1567 |
setValueWithoutPCH(CANCEL_OPTION); |
1647 |
setValueWithoutPCH(CANCEL_OPTION); |
1568 |
|
1648 |
|