This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 228411
Collapse All | Expand All

(-)openide.dialogs/apichanges.xml (+19 lines)
Lines 51-56 Link Here
51
</apidefs>
51
</apidefs>
52
<changes>
52
<changes>
53
53
54
    <change id="ExtendedAsynchronousValidatingPanel">
55
        <api name="dialogs"/>
56
        <summary>Added <code>ExtendedAsynchronousValidatingPanel</code></summary>
57
        <version major="7" minor="31"/>
58
        <date day="10" month="4" year="2013"/>
59
        <author login="saubrecht"/>
60
        <compatibility addition="yes"/>
61
        <description>
62
            <p>
63
                Added a new wizard panel type which introduces <code>finishValidation()</code>
64
                method. It is complementary to <code>prepareValidation()</code>
65
                method in <code>AsynchronousValidatingPanel</code> and should be
66
                used to unlock user interface when the validation is finished.
67
            </p>
68
        </description>
69
        <class package="org.openide" name="WizardDescriptor"/>
70
        <issue number="228411"/>
71
    </change>
72
54
    <change id="BackgroundInstantiatingIterator">
73
    <change id="BackgroundInstantiatingIterator">
55
        <api name="dialogs"/>
74
        <api name="dialogs"/>
56
        <summary>Added <code>BackgroundInstantiatingIterator</code></summary>
75
        <summary>Added <code>BackgroundInstantiatingIterator</code></summary>
(-)openide.dialogs/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.dialogs
2
OpenIDE-Module: org.openide.dialogs
3
OpenIDE-Module-Specification-Version: 7.30
3
OpenIDE-Module-Specification-Version: 7.31
4
OpenIDE-Module-Localizing-Bundle: org/openide/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/Bundle.properties
5
AutoUpdate-Essential-Module: true
5
AutoUpdate-Essential-Module: true
6
6
(-)openide.dialogs/src/org/openide/WizardDescriptor.java (+53 lines)
Lines 1469-1474 Link Here
1469
                            public void run () {
1469
                            public void run () {
1470
                                if( initialized.get() ) {  //#220286
1470
                                if( initialized.get() ) {  //#220286
1471
                                    err.log (Level.FINE, "Runs onValidPerformer from invokeLater."); // NOI18N
1471
                                    err.log (Level.FINE, "Runs onValidPerformer from invokeLater."); // NOI18N
1472
                                    if( panel instanceof ExtendedAsynchronousValidatingPanel ) {
1473
                                        ((ExtendedAsynchronousValidatingPanel)panel).finishValidation();
1474
                                    }
1472
                                    onValidPerformer.run();
1475
                                    onValidPerformer.run();
1473
                                }
1476
                                }
1474
                            }
1477
                            }
Lines 1484-1489 Link Here
1484
                    SwingUtilities.invokeLater( new Runnable() {
1487
                    SwingUtilities.invokeLater( new Runnable() {
1485
                        @Override
1488
                        @Override
1486
                        public void run() {
1489
                        public void run() {
1490
                            if( panel instanceof ExtendedAsynchronousValidatingPanel ) {
1491
                                ((ExtendedAsynchronousValidatingPanel)panel).finishValidation();
1492
                            }
1487
                            onValidationFailed( wve );
1493
                            onValidationFailed( wve );
1488
                        }
1494
                        }
1489
                    });
1495
                    });
Lines 1859-1864 Link Here
1859
     * <p>During background validation Cancel button is hooked
1865
     * <p>During background validation Cancel button is hooked
1860
     * to signal the validation thread using interrupt().
1866
     * to signal the validation thread using interrupt().
1861
     *
1867
     *
1868
     * <p>Note: It is recommended to use ExtendedAsynchronousValidatingPanel instead
1869
     * as it adds a method to conveniently unlock wizard's user interface when
1870
     * the validation is finished.
1871
     *
1862
     * @since 6.2 (16 May 2005)
1872
     * @since 6.2 (16 May 2005)
1863
     */
1873
     */
1864
    public interface AsynchronousValidatingPanel<Data> extends ValidatingPanel<Data> {
1874
    public interface AsynchronousValidatingPanel<Data> extends ValidatingPanel<Data> {
Lines 1881-1887 Link Here
1881
        public void validate() throws WizardValidationException;
1891
        public void validate() throws WizardValidationException;
1882
    }
1892
    }
1883
1893
1894
    /**
1895
     * A special interface for panels that need to do additional
1896
     * asynchronous validation when Next or Finish button is clicked.
1897
     *
1898
     * <p>During background validation is Next or Finish button
1899
     * disabled. On validation success wizard automatically
1900
     * progress to next panel or finishes.
1901
     *
1902
     * <p>During background validation Cancel button is hooked
1903
     * to signal the validation thread using interrupt().
1904
     *
1905
     * @param <Data>
1906
     *
1907
     * @since 7.31
1908
     */
1909
    public interface ExtendedAsynchronousValidatingPanel<Data> extends AsynchronousValidatingPanel<Data> {
1884
1910
1911
        /**
1912
         * Called synchronously from UI thread when Next
1913
         * of Finish buttons clicked. It allows to lock user
1914
         * input to assure official data for background validation.
1915
         */
1916
        @Override
1917
        public void prepareValidation();
1918
1919
        /**
1920
         * Is called in separate thread when Next of Finish buttons
1921
         * are clicked and allows deeper check to find out that panel
1922
         * is in valid state and it is ok to leave it.
1923
         *
1924
         * @throws WizardValidationException when validation fails
1925
         */
1926
        @Override
1927
        public void validate() throws WizardValidationException;
1928
1929
        /**
1930
         * Called synchronously from UI thread when the background validation
1931
         * is finished (even when throwing validation exception).
1932
         * It allows to enable user input locked in prepareValidation() method.
1933
         */
1934
        public void finishValidation();
1935
    }
1936
1937
1885
    /** A special interface for panel that needs to dynamically enabled
1938
    /** A special interface for panel that needs to dynamically enabled
1886
     * Finish button.
1939
     * Finish button.
1887
     * @since 4.28
1940
     * @since 4.28
(-)openide.dialogs/test/unit/src/org/openide/AsynchronousValidatingPanelTest.java (-2 / +12 lines)
Lines 49-54 Link Here
49
import javax.swing.*;
49
import javax.swing.*;
50
import javax.swing.JLabel;
50
import javax.swing.JLabel;
51
import javax.swing.event.ChangeListener;
51
import javax.swing.event.ChangeListener;
52
import static junit.framework.Assert.assertTrue;
52
import org.netbeans.junit.RandomlyFails;
53
import org.netbeans.junit.RandomlyFails;
53
import org.openide.util.*;
54
import org.openide.util.*;
54
import org.openide.util.HelpCtx;
55
import org.openide.util.HelpCtx;
Lines 85-95 Link Here
85
    public void testAsynchronousLazyValidation () throws Exception {
86
    public void testAsynchronousLazyValidation () throws Exception {
86
        Panel panels[] = new Panel[3];
87
        Panel panels[] = new Panel[3];
87
        
88
        
88
        class MyPanel extends Panel implements WizardDescriptor.AsynchronousValidatingPanel<WizardDescriptor> {
89
        class MyPanel extends Panel implements WizardDescriptor.ExtendedAsynchronousValidatingPanel<WizardDescriptor> {
89
            public String validateMsg;
90
            public String validateMsg;
90
            public String failedMsg;
91
            public String failedMsg;
91
            public boolean running;
92
            public boolean running;
92
            public boolean wasEnabled;
93
            public boolean wasEnabled;
94
            public boolean validationFinished;
93
            
95
            
94
            public MyPanel () {
96
            public MyPanel () {
95
                super ("enhanced panel");
97
                super ("enhanced panel");
Lines 97-109 Link Here
97
            
99
            
98
            public void prepareValidation () {
100
            public void prepareValidation () {
99
                running = true;
101
                running = true;
102
                validationFinished = false;
100
            }
103
            }
101
            
104
            
102
            public synchronized void validate () throws WizardValidationException {
105
            public synchronized void validate () throws WizardValidationException {
103
                err.log ("validate() entry.");
106
                err.log ("validate() entry.");
104
                wasEnabled = wd.isNextEnabled () || wd.isFinishEnabled ();
107
                wasEnabled = wd.isNextEnabled () || wd.isFinishEnabled ();
105
                running = false;
108
                running = false;
106
                notifyAll ();
107
                if (validateMsg != null) {
109
                if (validateMsg != null) {
108
                    failedMsg = validateMsg;
110
                    failedMsg = validateMsg;
109
                    err.log ("Throw WizardValidationException.");
111
                    err.log ("Throw WizardValidationException.");
Lines 112-118 Link Here
112
                err.log ("validate() exit.");
114
                err.log ("validate() exit.");
113
                return;
115
                return;
114
            }
116
            }
117
118
            public synchronized void finishValidation() {
119
                assert SwingUtilities.isEventDispatchThread();
120
                validationFinished = true;
121
                notifyAll ();
115
        }
122
        }
123
        }
116
        
124
        
117
        class MyFinishPanel extends MyPanel implements WizardDescriptor.FinishablePanel<WizardDescriptor> {
125
        class MyFinishPanel extends MyPanel implements WizardDescriptor.FinishablePanel<WizardDescriptor> {
118
            @Override
126
            @Override
Lines 149-154 Link Here
149
        }
157
        }
150
        assertFalse ("Finish is disabled during validation.", mp.wasEnabled);
158
        assertFalse ("Finish is disabled during validation.", mp.wasEnabled);
151
        assertTrue ("Wizard is ready to next validation however previous failed.",  wd.isForwardEnabled ());
159
        assertTrue ("Wizard is ready to next validation however previous failed.",  wd.isForwardEnabled ());
160
        assertTrue ("finishValidation() was called even when validation failed.",  mp.validationFinished);
152
        assertEquals ("The lazy validation failed on Next.", mp.validateMsg, mp.failedMsg);
161
        assertEquals ("The lazy validation failed on Next.", mp.validateMsg, mp.failedMsg);
153
        assertNull ("The lazy validation failed, still no initialiaation", panels[1].component);
162
        assertNull ("The lazy validation failed, still no initialiaation", panels[1].component);
154
        assertNull ("The lazy validation failed, still no initialiaation", panels[2].component);
163
        assertNull ("The lazy validation failed, still no initialiaation", panels[2].component);
Lines 174-179 Link Here
174
        assertNull ("Validation on Next passes", mp.failedMsg);
183
        assertNull ("Validation on Next passes", mp.failedMsg);
175
        assertNotNull ("Now we switched to another panel", panels[1].component);
184
        assertNotNull ("Now we switched to another panel", panels[1].component);
176
        assertNull ("The lazy validation failed, still no initialiaation", panels[2].component);
185
        assertNull ("The lazy validation failed, still no initialiaation", panels[2].component);
186
        assertTrue ("finishValidation() was called when validation finished.",  mp.validationFinished);
177
187
178
        // remember previous state
188
        // remember previous state
179
        Object state = wd.getValue();
189
        Object state = wd.getValue();

Return to bug 228411