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 62161
Collapse All | Expand All

(-)openide/dialogs/apichanges.xml (+17 lines)
Lines 17-22 Link Here
17
<apidef name="dialogs">Dialogs API</apidef>
17
<apidef name="dialogs">Dialogs API</apidef>
18
</apidefs>
18
</apidefs>
19
<changes>
19
<changes>
20
    <change id="WizardDescriptor.AsynchronousInstantiatingIterator">
21
           <api name="dialogs"/>
22
           <summary>Interface <code>AsynchronousInstantiatingIterator</code> added</summary>
23
           <version major="6" minor="5"/>
24
           <date day="4" month="12" year="2005"/>
25
           <author login="jrechtacek"/>
26
           <compatibility addition="yes" binary="compatible" semantic="compatible" source="compatible" deprecation="no" deletion="no" modification="no"/>
27
           <description>
28
             The <code>AsynchronousInstantiatingIterator</code> allows to implement
29
             asynchronous instantating of newly created objects. Wizard's framework
30
             esures that the method <code>AsynchronousInstantiatingIterator.instantiate()</code>
31
             will be called ouside of an event queue.
32
           </description>
33
           <class package="org.openide" name="WizardDescriptor"/>
34
           <issue number="62161"/>
35
    </change>
36
20
    <change id="AsynchronousValidatingPanel">
37
    <change id="AsynchronousValidatingPanel">
21
           <api name="dialogs"/>
38
           <api name="dialogs"/>
22
           <summary>Interface <code>AsynchronousValidationgPanel</code> added</summary>
39
           <summary>Interface <code>AsynchronousValidationgPanel</code> added</summary>
(-)openide/dialogs/manifest.mf (-1 / +1 lines)
Lines 1-5 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: 6.4
3
OpenIDE-Module-Specification-Version: 6.5
4
OpenIDE-Module-Localizing-Bundle: org/openide/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/Bundle.properties
5
5
(-)openide/dialogs/nbproject/project.xml (-2 / +2 lines)
Lines 18-24 Link Here
18
            <code-name-base>org.openide.dialogs</code-name-base>
18
            <code-name-base>org.openide.dialogs</code-name-base>
19
            <module-dependencies>
19
            <module-dependencies>
20
                <dependency>
20
                <dependency>
21
                    <code-name-base>org.openide.util</code-name-base>
21
                    <code-name-base>org.openide.awt</code-name-base>
22
                    <build-prerequisite/>
22
                    <build-prerequisite/>
23
                    <compile-dependency/>
23
                    <compile-dependency/>
24
                    <run-dependency>
24
                    <run-dependency>
Lines 26-32 Link Here
26
                    </run-dependency>
26
                    </run-dependency>
27
                </dependency>
27
                </dependency>
28
                <dependency>
28
                <dependency>
29
                    <code-name-base>org.openide.awt</code-name-base>
29
                    <code-name-base>org.openide.util</code-name-base>
30
                    <build-prerequisite/>
30
                    <build-prerequisite/>
31
                    <compile-dependency/>
31
                    <compile-dependency/>
32
                    <run-dependency>
32
                    <run-dependency>
(-)openide/dialogs/src/org/openide/Bundle.properties (+4 lines)
Lines 100-102 Link Here
100
#Property - wizard panel image alignment
100
#Property - wizard panel image alignment
101
#NOI18N
101
#NOI18N
102
STRING_WizardImageAlignment=South
102
STRING_WizardImageAlignment=South
103
104
# MSG_WizardDescriptor_FinishInProgress=In progress ...
105
MSG_WizardDescriptor_FinishInProgress=
106
CTL_InstantiateProgress_Title=Instantiating new objects
(-)openide/dialogs/src/org/openide/WizardDescriptor.java (-27 / +72 lines)
Lines 12-22 Link Here
12
 */
12
 */
13
package org.openide;
13
package org.openide;
14
14
15
import java.lang.reflect.InvocationTargetException;
15
import org.openide.awt.HtmlBrowser;
16
import org.openide.awt.HtmlBrowser;
16
import org.openide.util.HelpCtx;
17
import org.openide.util.HelpCtx;
17
import org.openide.util.Mutex;
18
import org.openide.util.Mutex;
18
import org.openide.util.NbBundle;
19
import org.openide.util.NbBundle;
19
import org.openide.util.RequestProcessor;
20
import org.openide.util.RequestProcessor;
21
import org.openide.util.RequestProcessor.Task;
20
import org.openide.util.Utilities;
22
import org.openide.util.Utilities;
21
import org.openide.util.WeakListeners;
23
import org.openide.util.WeakListeners;
22
24
Lines 1175-1185 Link Here
1175
        panels.current().storeSettings(settings);
1177
        panels.current().storeSettings(settings);
1176
1178
1177
        if (panels instanceof InstantiatingIterator) {
1179
        if (panels instanceof InstantiatingIterator) {
1178
            // PENDING: disable all buttons to indicate that instantiate runs
1179
            // PENDING:  write something to errorMessage (e.g. Wait to finishing.)
1180
            showWaitCursor();
1180
            showWaitCursor();
1181
1181
1182
            try {
1182
            try {
1183
                assert ! (panels instanceof AsynchronousInstantiatingIterator) || ! SwingUtilities.isEventDispatchThread () : "Cannot invoked within EDT if AsynchronousInstantiatingIterator!";
1183
                newObjects = ((InstantiatingIterator) panels).instantiate();
1184
                newObjects = ((InstantiatingIterator) panels).instantiate();
1184
            } finally {
1185
            } finally {
1185
1186
Lines 1461-1466 Link Here
1461
         */
1462
         */
1462
        public void uninitialize(WizardDescriptor wizard);
1463
        public void uninitialize(WizardDescriptor wizard);
1463
    }
1464
    }
1465
    
1466
    /**
1467
     * Iterator for a wizard that needs to somehow instantiate new objects outside ATW queue.
1468
     * (This interface can replace
1469
     * <a href="@OPENIDE/LOADERS@/org/openide/loaders/TemplateWizard.Iterator.html"><code>TemplateWizard.Iterator</code></a>
1470
     * in a template's declaration.)
1471
     * @since org.openide/1 6.5
1472
     */
1473
    public interface AsynchronousInstantiatingIterator extends InstantiatingIterator {
1474
1475
        /**
1476
         * Is called in separate thread when the Finish button
1477
         * are clicked and allows implement asynchronous
1478
         * instantating of newly created objects.
1479
         *
1480
         * @throws WizardValidationException when validation fails
1481
         */
1482
        public Set /*<Object>*/ instantiate () throws IOException;
1483
1484
    }
1464
1485
1465
    /** Special iterator that works on an array of <code>Panel</code>s.
1486
    /** Special iterator that works on an array of <code>Panel</code>s.
1466
    */
1487
    */
Lines 1620-1652 Link Here
1620
            if (ev.getSource() == finishButton) {
1641
            if (ev.getSource() == finishButton) {
1621
                Runnable onValidPerformer = new Runnable() {
1642
                Runnable onValidPerformer = new Runnable() {
1622
                    public void run() {
1643
                    public void run() {
1623
                        // do instantiate
1644
                        // disable all buttons to indicate that instantiate runs
1624
                        try {
1645
                        cancelButton.setEnabled (false);
1625
                            callInstantiate();
1646
                        previousButton.setEnabled (false);
1626
                        } catch (IOException ioe) {
1647
                        nextButton.setEnabled (false);
1627
                            // notify to log
1648
                        finishButton.setEnabled (false);
1628
                            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
1649
                        
1629
1650
                        // write something to errorMessage (e.g. Wait to finishing.)
1630
                            setValueWithoutPCH(NEXT_OPTION);
1651
                        if (wizardPanel != null) wizardPanel.setErrorMessage (NbBundle.getMessage (WizardDescriptor.class, "MSG_WizardDescriptor_FinishInProgress"), Boolean.TRUE); // NOI18N
1631
                            updateStateWithFeedback();
1652
                        
1632
1653
                        Runnable performFinish = new Runnable () {
1633
                            // notify user by the wizard's status line
1654
                            public void run () {
1634
                            putProperty(PROP_ERROR_MESSAGE, ioe.getLocalizedMessage());
1655
                                // do instantiate
1656
                                try {
1657
                                    callInstantiate();
1658
                                } catch (IOException ioe) {
1659
                                    // notify to log
1660
                                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
1661
1662
                                    setValueWithoutPCH(NEXT_OPTION);
1663
                                    updateStateWithFeedback();
1664
1665
                                    // notify user by the wizard's status line
1666
                                    putProperty(PROP_ERROR_MESSAGE, ioe.getLocalizedMessage());
1667
1668
                                    // if validation failed => cannot move to next panel
1669
                                    return;
1670
                                }
1671
                                Object oldValue = getValue();
1672
                                setValueWithoutPCH(OK_OPTION);
1673
1674
                                resetWizard();
1675
1676
                                firePropertyChange(PROP_VALUE, oldValue, OK_OPTION);
1677
                                
1678
                                SwingUtilities.invokeLater (new Runnable () {
1679
                                    public void run () {
1680
                                        // all is OK
1681
                                        // close wizrad
1682
                                        finishOption.fireActionPerformed();
1635
1683
1636
                            // if validation failed => cannot move to next panel
1684
                                    }
1637
                            return;
1685
                                });
1686
                            }
1687
                        };
1688
                        
1689
                        if (panels instanceof AsynchronousInstantiatingIterator) {
1690
                            RequestProcessor.getDefault ().post (performFinish);
1691
                        } else {
1692
                            performFinish.run ();
1638
                        }
1693
                        }
1639
1694
                        
1640
                        // all is OK
1641
                        // close wizrad
1642
                        finishOption.fireActionPerformed();
1643
1644
                        Object oldValue = getValue();
1645
                        setValueWithoutPCH(OK_OPTION);
1646
1647
                        resetWizard();
1648
1649
                        firePropertyChange(PROP_VALUE, oldValue, OK_OPTION);
1650
                    }
1695
                    }
1651
                };
1696
                };
1652
                lazyValidate(panels.current(), onValidPerformer);
1697
                lazyValidate(panels.current(), onValidPerformer);
(-)openide/dialogs/test/unit/src/org/openide/AsynchronousInstantiatingIteratorTest.java (+201 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.openide;
14
15
16
import org.netbeans.junit.NbTestSuite;
17
18
import java.awt.Component;
19
import java.io.IOException;
20
import java.util.*;
21
import javax.swing.*;
22
import javax.swing.JLabel;
23
import javax.swing.event.ChangeListener;
24
import org.openide.InstantiatingIteratorTest.Listener;
25
import org.openide.util.HelpCtx;
26
27
/** Testing functional implementation calling the methods to interface <code>WizardDescriptor.AsynchronousInstantiatingIterator</code>
28
 * from WizardDescriptor. Check if the method <code>instantiate()</code> is called outside AWT in particular.
29
 * @see Issue 62161
30
 */
31
public class AsynchronousInstantiatingIteratorTest extends InstantiatingIteratorTest {
32
33
    
34
    public AsynchronousInstantiatingIteratorTest (String name) {
35
        super(name);
36
    }
37
    
38
    public static void main(String[] args) {
39
        junit.textui.TestRunner.run (new NbTestSuite (AsynchronousInstantiatingIteratorTest.class));
40
        System.exit (0);
41
    }
42
    
43
    private Iterator iterator;
44
45
    protected void setUp () {
46
        iterator = new Iterator ();
47
        wd = new WizardDescriptor (iterator);
48
        wd.addPropertyChangeListener(new Listener ());
49
        java.awt.Dialog d = DialogDisplayer.getDefault ().createDialog (wd);
50
        checkOrder = false;
51
        shouldThrowException = false;
52
        //d.show();
53
    }
54
    
55
    /** Run all tests in AWT thread */
56
    protected boolean runInEQ() {
57
        return true;
58
    }
59
60
    public void testInstantiateInAWTQueueOrNot () {
61
        checkIfInAWT = true;
62
63
        wd.doNextClick ();
64
        finishWizard (wd);
65
        try {
66
            Set newObjects = wd.getInstantiatedObjects ();
67
        } catch (IllegalStateException ise) {
68
            fail ("IllegalStateException was caught because WD.instantiate() called in AWT queue.");
69
        }
70
        assertNotNull ("InstantiatingIterator was correctly instantiated.", getResult ());
71
    }
72
    
73
    public class Panel implements WizardDescriptor.FinishablePanel {
74
        private JLabel component;
75
        private String text;
76
        public Panel(String text) {
77
            this.text = text;
78
        }
79
80
        public Component getComponent() {
81
            if (component == null) {
82
                component = new JLabel (text);
83
            }
84
            return component;
85
        }
86
        
87
        public void addChangeListener(ChangeListener l) {
88
            changeListenersInPanel.add (l);
89
        }
90
        
91
        public HelpCtx getHelp() {
92
            return null;
93
        }
94
        
95
        public boolean isValid() {
96
            return true;
97
        }
98
        
99
        public void readSettings(Object settings) {
100
            log ("readSettings of panel: " + text + " [time: " + System.currentTimeMillis () +
101
                    "] with PROP_VALUE: " + handleValue (wd.getValue ()));
102
        }
103
        
104
        public void removeChangeListener(ChangeListener l) {
105
            changeListenersInPanel.remove (l);
106
        }
107
        
108
        public void storeSettings(Object settings) {
109
            if (checkOrder) {
110
                assertNull ("WD.P.storeSettings() called before WD.I.instantiate()", iterator.result);
111
                // bugfix #45093, remember storeSettings could be called multiple times
112
                // do check order only when the first time
113
                checkOrder = false;
114
            }
115
            log ("storeSettings of panel: " + text + " [time: " + System.currentTimeMillis () +
116
                    "] with PROP_VALUE: " + handleValue (wd.getValue ()));
117
            if (exceptedValue != null) {
118
                assertEquals ("WD.getValue() returns excepted value.", exceptedValue, handleValue (wd.getValue ()));
119
            }
120
        }
121
        
122
        public boolean isFinishPanel () {
123
            return true;
124
        }
125
        
126
    }
127
    
128
    protected Boolean getInitialized () {
129
        return iterator.initialized;
130
    }
131
    
132
    protected Set getResult () {
133
        return iterator.result;
134
    }
135
    
136
    public class Iterator implements WizardDescriptor.AsynchronousInstantiatingIterator {
137
        int index = 0;
138
        WizardDescriptor.Panel panels[] = new WizardDescriptor.Panel[2];
139
        java.util.Set helpSet;
140
        
141
        private Boolean initialized = null;
142
        private Set result = null;
143
        
144
        public WizardDescriptor.Panel current () {
145
            assertTrue ("WD.current() called on initialized iterator.", initialized != null && initialized.booleanValue ());
146
            return panels[index];
147
        }
148
        public String name () {
149
            return "Test iterator";
150
        }
151
        public boolean hasNext () {
152
            return index < 1;
153
        }
154
        public boolean hasPrevious () {
155
            return index > 0;
156
        }
157
        public void nextPanel () {
158
            if (!hasNext ()) throw new NoSuchElementException ();
159
            index ++;
160
        }
161
        public void previousPanel () {
162
            if (!hasPrevious ()) throw new NoSuchElementException ();
163
            index --;
164
        }
165
        public void addChangeListener (ChangeListener l) {
166
            changeListenersInIterator.add (l);
167
        }
168
        public void removeChangeListener (ChangeListener l) {
169
            changeListenersInIterator.remove (l);
170
        }
171
        public java.util.Set instantiate () throws IOException {
172
            if (checkIfInAWT) {
173
                if (SwingUtilities.isEventDispatchThread ()) {
174
                    throw new IOException ("Cannot run in AWT queue.");
175
                }
176
            }
177
            if (shouldThrowException) {
178
                throw new IOException ("Test throw IOException during instantiate().");
179
            }
180
            if (initialized.booleanValue ()) {
181
                helpSet.add ("member");
182
                result = helpSet;
183
            } else {
184
                result = null;
185
            }
186
            return result;
187
        }
188
        public void initialize (WizardDescriptor wizard) {
189
            helpSet = new HashSet ();
190
            panels[0] = new Panel("first panel");
191
            panels[1] = new Panel("second panel");
192
            initialized = Boolean.TRUE;
193
        }
194
        public void uninitialize (WizardDescriptor wizard) {
195
            helpSet.clear ();
196
            initialized = Boolean.FALSE;
197
            panels = null;
198
        }
199
    }
200
    
201
}
(-)openide/dialogs/test/unit/src/org/openide/InstantiatingIteratorTest.java (-47 / +75 lines)
Lines 7-18 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-2004 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
package org.openide;
13
package org.openide;
14
14
15
15
16
import java.lang.reflect.InvocationTargetException;
16
import org.netbeans.junit.*;
17
import org.netbeans.junit.*;
17
import junit.framework.Test;
18
import junit.framework.Test;
18
import junit.framework.TestSuite;
19
import junit.framework.TestSuite;
Lines 30-35 Link Here
30
import org.netbeans.junit.NbTestCase;
31
import org.netbeans.junit.NbTestCase;
31
import org.openide.util.*;
32
import org.openide.util.*;
32
import org.openide.util.HelpCtx;
33
import org.openide.util.HelpCtx;
34
import org.openide.util.RequestProcessor.Task;
33
35
34
/** Testing functional implementation calling the methods to interface <code>WizardDescriptor.InstantiatingIterator</code>
36
/** Testing functional implementation calling the methods to interface <code>WizardDescriptor.InstantiatingIterator</code>
35
 * from WizardDescriptor.
37
 * from WizardDescriptor.
Lines 46-70 Link Here
46
        System.exit (0);
48
        System.exit (0);
47
    }
49
    }
48
    
50
    
49
    private WizardDescriptor wd;
51
    protected WizardDescriptor wd;
50
    private String exceptedValue;
52
    protected String exceptedValue;
51
    private Iterator iterator;
53
    private Iterator iterator;
52
    private int attachedInIterator = 0;
54
    protected int attachedInIterator = 0;
53
    private int attachedInPanel = 0;
55
    protected int attachedInPanel = 0;
54
    private boolean checkOrder = false;
56
    protected boolean checkOrder = false;
55
    private boolean shouldThrowException = false;
57
    protected boolean shouldThrowException = false;
56
    private boolean checkAWTQueue = false;
58
    protected Set/*<ChangeListener>*/ changeListenersInIterator = new HashSet ();
57
    private Set/*<ChangeListener>*/ changeListenersInIterator = new HashSet ();
59
    protected Set/*<ChangeListener>*/ changeListenersInPanel = new HashSet ();
58
    private Set/*<ChangeListener>*/ changeListenersInPanel = new HashSet ();
60
    protected boolean checkIfInAWT;
59
61
60
    protected final void setUp () {
62
    protected void setUp () {
61
        iterator = new Iterator ();
63
        iterator = new Iterator ();
62
        wd = new WizardDescriptor (iterator);
64
        wd = new WizardDescriptor (iterator);
63
        wd.addPropertyChangeListener(new Listener ());
65
        wd.addPropertyChangeListener(new Listener ());
64
        java.awt.Dialog d = DialogDisplayer.getDefault ().createDialog (wd);
66
        java.awt.Dialog d = DialogDisplayer.getDefault ().createDialog (wd);
65
        checkOrder = false;
67
        checkOrder = false;
66
        shouldThrowException = false;
68
        shouldThrowException = false;
67
        checkAWTQueue = false;
68
        //d.show();
69
        //d.show();
69
    }
70
    }
70
    
71
    
Lines 79-85 Link Here
79
        assertEquals ("Still only one listener is attached after Next.", 1, changeListenersInIterator.size ());
80
        assertEquals ("Still only one listener is attached after Next.", 1, changeListenersInIterator.size ());
80
        wd.doPreviousClick ();
81
        wd.doPreviousClick ();
81
        assertEquals ("Still only one listener is attached after Previous.", 1, changeListenersInIterator.size ());
82
        assertEquals ("Still only one listener is attached after Previous.", 1, changeListenersInIterator.size ());
82
        wd.doFinishClick ();
83
        finishWizard (wd);
83
        assertEquals ("No one listener is attached after Finish.", 0, changeListenersInIterator.size ());
84
        assertEquals ("No one listener is attached after Finish.", 0, changeListenersInIterator.size ());
84
        assertEquals ("No one listener is attached in WD.Panel after Finish.", 0, changeListenersInPanel.size ());
85
        assertEquals ("No one listener is attached in WD.Panel after Finish.", 0, changeListenersInPanel.size ());
85
    }
86
    }
Lines 92-147 Link Here
92
    }
93
    }
93
    
94
    
94
    public void testInitializeIterator () throws Exception {
95
    public void testInitializeIterator () throws Exception {
95
        assertTrue ("InstantiatingIterator was initialized.", iterator.initialized.booleanValue ());
96
        assertTrue ("InstantiatingIterator was initialized.", getInitialized ().booleanValue ());
96
        assertNull ("InstantiatingIterator wasn't instantiated.", iterator.result);
97
        assertNull ("InstantiatingIterator wasn't instantiated.", getResult ());
97
    }
98
    }
98
99
99
    public void testUninitializeIterator () throws Exception {
100
    public void testUninitializeIterator () throws Exception {
100
        assertTrue ("InstantiatingIterator was initialized at start.", iterator.initialized.booleanValue ());
101
        assertTrue ("InstantiatingIterator was initialized at start.", getInitialized ().booleanValue ());
101
        wd.doCancelClick ();
102
        wd.doCancelClick ();
102
        assertFalse ("InstantiatingIterator was uninitialized after cancel.", iterator.initialized.booleanValue ());
103
        assertFalse ("InstantiatingIterator was uninitialized after cancel.", getInitialized ().booleanValue ());
103
        assertNull ("InstantiatingIterator wasn't instantiated.", iterator.result);
104
        assertNull ("InstantiatingIterator wasn't instantiated.", getResult ());
104
    }
105
    }
105
106
106
    public void testFinishAndUninitializeIterator () throws Exception {
107
    public void testFinishAndUninitializeIterator () throws Exception {
107
        assertTrue ("InstantiatingIterator was initialized at start.", iterator.initialized.booleanValue ());
108
        assertTrue ("InstantiatingIterator was initialized at start.", getInitialized ().booleanValue ());
108
        wd.doNextClick ();
109
        wd.doNextClick ();
109
        assertTrue ("InstantiatingIterator wasn't uninitialized after next.", iterator.initialized.booleanValue ());
110
        assertTrue ("InstantiatingIterator wasn't uninitialized after next.", getInitialized ().booleanValue ());
110
        wd.doFinishClick ();
111
        finishWizard (wd);
111
        assertFalse ("InstantiatingIterator wasn uninitialized after finish.", iterator.initialized.booleanValue ());
112
        assertFalse ("InstantiatingIterator wasn uninitialized after finish.", getInitialized ().booleanValue ());
112
        assertNotNull ("InstantiatingIterator was instantiated.", iterator.result);
113
        assertNotNull ("InstantiatingIterator was instantiated.", getResult ());
113
    }
114
    }
114
115
115
    public void testUninitializeIteratorAndCalledCurrent () throws Exception {
116
    public void testUninitializeIteratorAndCalledCurrent () throws Exception {
116
        assertTrue ("InstantiatingIterator was initialized at start.", iterator.initialized.booleanValue ());
117
        assertTrue ("InstantiatingIterator was initialized at start.", getInitialized ().booleanValue ());
117
        wd.doNextClick ();
118
        wd.doNextClick ();
118
        assertTrue ("InstantiatingIterator wasn't uninitialized after next.", iterator.initialized.booleanValue ());
119
        assertTrue ("InstantiatingIterator wasn't uninitialized after next.", getInitialized ().booleanValue ());
119
        wd.doFinishClick ();
120
        finishWizard (wd);
120
        assertFalse ("InstantiatingIterator wasn uninitialized after finish.", iterator.initialized.booleanValue ());
121
        assertFalse ("InstantiatingIterator was uninitialized after finish.", getInitialized ().booleanValue ());
121
        assertNotNull ("InstantiatingIterator was instantiated.", iterator.result);
122
        assertNotNull ("InstantiatingIterator was instantiated.", getResult ());
122
    }
123
    }
123
124
124
    public void testOrderStoreSettingAndInstantiate () throws Exception {
125
    public void testOrderStoreSettingAndInstantiate () throws Exception {
125
        checkOrder = true;
126
        checkOrder = true;
126
        wd.doNextClick ();
127
        wd.doNextClick ();
127
        wd.doFinishClick ();
128
        finishWizard (wd);
128
        assertNotNull ("InstantiatingIterator was instantiated.", iterator.result);
129
        assertNotNull ("InstantiatingIterator was instantiated.", getResult ());
129
    }
130
    }
130
131
131
    public void testGetInstantiatedObjects () throws Exception {
132
    public void testGetInstantiatedObjects () throws Exception {
132
        wd.doNextClick ();
133
        wd.doNextClick ();
133
        wd.doFinishClick ();
134
        finishWizard (wd);
134
        assertNotNull ("InstantiatingIterator was instantiated.", iterator.result);
135
        assertNotNull ("InstantiatingIterator was instantiated.", getResult ());
135
        Set newObjects = wd.getInstantiatedObjects ();
136
        Set newObjects = wd.getInstantiatedObjects ();
136
        assertEquals ("WD returns same objects as InstantiatingIterator instantiated.", iterator.result, newObjects);
137
        assertEquals ("WD returns same objects as InstantiatingIterator instantiated.", getResult (), newObjects);
137
        
138
        
138
    }
139
    }
139
    
140
    
140
    public void testInstantiateOutsideAWTQueue () {
141
    public void testInstantiateInAWTQueueOrNot () {
141
        checkAWTQueue = true;
142
        checkIfInAWT = true;
142
143
143
        wd.doNextClick ();
144
        wd.doNextClick ();
144
        wd.doFinishClick ();
145
        finishWizard (wd);
146
        try {
147
            Set newObjects = wd.getInstantiatedObjects ();
148
        } catch (IllegalStateException ise) {
149
            fail ("IllegalStateException was caught because WD.instantiate() called outside AWT queue.");
150
        }
151
        assertNotNull ("InstantiatingIterator was correctly instantiated.", getResult ());
145
    }
152
    }
146
    
153
    
147
    public void testFinishOptionWhenInstantiateFails () throws Exception {
154
    public void testFinishOptionWhenInstantiateFails () throws Exception {
Lines 149-160 Link Here
149
156
150
        wd.doNextClick ();
157
        wd.doNextClick ();
151
        Object state = wd.getValue();
158
        Object state = wd.getValue();
152
        wd.doFinishClick ();
159
        finishWizard (wd);
153
        
160
        
154
        assertNull ("InstantiatingIterator was not correctly instantiated.", iterator.result);
161
        assertNull ("InstantiatingIterator was not correctly instantiated.", getResult ());
155
//        Set newObjects = wd.getInstantiatedObjects ();
162
        try {
156
//        assertEquals ("WD returns no object.", Collections.EMPTY_SET, newObjects);
163
            Set newObjects = wd.getInstantiatedObjects ();
157
        assertSame ("The state is same as before instantiate()", state, wd.getValue ());
164
            fail ("No IllegalStateException was caught. Should be thrown when invoked getInstantiatedObjects() on unfinished wizard.");
165
        } catch (IllegalStateException ise) {
166
            // correct behavior
167
        }
168
        assertEquals ("The state is same as before instantiate()", state, wd.getValue ());
158
    }
169
    }
159
    
170
    
160
    public class Panel implements WizardDescriptor.FinishablePanel {
171
    public class Panel implements WizardDescriptor.FinishablePanel {
Lines 194-200 Link Here
194
        
205
        
195
        public void storeSettings(Object settings) {
206
        public void storeSettings(Object settings) {
196
            if (checkOrder) {
207
            if (checkOrder) {
197
                assertNull ("WD.P.storeSettings() called before WD.I.instantiate()", iterator.result);
208
                assertNull ("WD.P.storeSettings() called before WD.I.instantiate()", getResult ());
198
                // bugfix #45093, remember storeSettings could be called multiple times
209
                // bugfix #45093, remember storeSettings could be called multiple times
199
                // do check order only when the first time
210
                // do check order only when the first time
200
                checkOrder = false;
211
                checkOrder = false;
Lines 212-224 Link Here
212
        
223
        
213
    }
224
    }
214
    
225
    
226
    protected Boolean getInitialized () {
227
        return iterator.initialized;
228
    }
229
    
230
    protected Set getResult () {
231
        return iterator.result;
232
    }
233
    
215
    public class Iterator implements WizardDescriptor.InstantiatingIterator {
234
    public class Iterator implements WizardDescriptor.InstantiatingIterator {
216
        int index = 0;
235
        int index = 0;
217
        WizardDescriptor.Panel panels[] = new WizardDescriptor.Panel[2];
236
        WizardDescriptor.Panel panels[] = new WizardDescriptor.Panel[2];
218
        java.util.Set helpSet;
237
        java.util.Set helpSet;
219
        
238
        
220
        public Boolean initialized = null;
239
        private Boolean initialized = null;
221
        Set result = null;
240
        private Set result = null;
222
        
241
        
223
        public WizardDescriptor.Panel current () {
242
        public WizardDescriptor.Panel current () {
224
            assertTrue ("WD.current() called on initialized iterator.", initialized != null && initialized.booleanValue ());
243
            assertTrue ("WD.current() called on initialized iterator.", initialized != null && initialized.booleanValue ());
Lines 248-255 Link Here
248
            changeListenersInIterator.remove (l);
267
            changeListenersInIterator.remove (l);
249
        }
268
        }
250
        public java.util.Set instantiate () throws IOException {
269
        public java.util.Set instantiate () throws IOException {
251
            if (checkAWTQueue && SwingUtilities.isEventDispatchThread ()) {
270
            if (checkIfInAWT) {
252
                throw new IOException ("Don't call from AWT queue.");
271
                if (! SwingUtilities.isEventDispatchThread ()) {
272
                    throw new IOException ("Must run in AWT queue.");
273
                }
253
            }
274
            }
254
            if (shouldThrowException) {
275
            if (shouldThrowException) {
255
                throw new IOException ("Test throw IOException during instantiate().");
276
                throw new IOException ("Test throw IOException during instantiate().");
Lines 303-306 Link Here
303
        }
324
        }
304
        return "UNKNOWN OPTION: " + val;
325
        return "UNKNOWN OPTION: " + val;
305
    }
326
    }
306
}
327
    
328
    public static void finishWizard (WizardDescriptor wd) {
329
        wd.doFinishClick ();
330
        RequestProcessor.getDefault ().post (new Runnable () {
331
            public void run () {}
332
        }).waitFinished ();
333
    }
334
}

Return to bug 62161