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

(-)windows/src/org/netbeans/core/windows/WindowSystemImpl.java (+2 lines)
Lines 23-28 Link Here
23
23
24
import org.netbeans.core.NbTopManager;
24
import org.netbeans.core.NbTopManager;
25
import org.netbeans.core.windows.persistence.PersistenceManager;
25
import org.netbeans.core.windows.persistence.PersistenceManager;
26
import org.netbeans.core.windows.services.DialogDisplayerImpl;
26
27
27
28
28
/**
29
/**
Lines 59-64 Link Here
59
    public void show() {
60
    public void show() {
60
        WindowManagerImpl.assertEventDispatchThread();
61
        WindowManagerImpl.assertEventDispatchThread();
61
        
62
        
63
        DialogDisplayerImpl.runDelayed();
62
        ShortcutAndMenuKeyEventProcessor.install();
64
        ShortcutAndMenuKeyEventProcessor.install();
63
        WindowManagerImpl.getInstance().setVisible(true);
65
        WindowManagerImpl.getInstance().setVisible(true);
64
    }
66
    }
(-)windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java (-6 / +53 lines)
Lines 21-36 Link Here
21
package org.netbeans.core.windows.services;
21
package org.netbeans.core.windows.services;
22
22
23
23
24
import java.awt.event.FocusEvent;
24
import java.awt.Component;
25
import java.awt.event.FocusListener;
25
import java.awt.Dialog;
26
import javax.swing.JDialog;
26
import java.awt.EventQueue;
27
import java.awt.Frame;
28
import java.awt.KeyboardFocusManager;
29
import java.awt.Window;
27
import org.openide.DialogDescriptor;
30
import org.openide.DialogDescriptor;
28
import org.openide.DialogDisplayer;
31
import org.openide.DialogDisplayer;
29
import org.openide.NotifyDescriptor;
32
import org.openide.NotifyDescriptor;
30
import org.openide.util.Mutex;
33
import org.openide.util.Mutex;
31
import org.openide.windows.WindowManager;
34
import org.openide.windows.WindowManager;
32
35
import java.util.ArrayList;
33
import java.awt.*;
36
import java.util.Collections;
37
import java.util.List;
34
38
35
39
36
// Extracted from core/NbTopManager.
40
// Extracted from core/NbTopManager.
Lines 40-45 Link Here
40
 * @author  Jesse Glick
44
 * @author  Jesse Glick
41
 */
45
 */
42
public class DialogDisplayerImpl extends DialogDisplayer {
46
public class DialogDisplayerImpl extends DialogDisplayer {
47
    /** delayed runnables */
48
    private static List<Runnable> run = Collections.synchronizedList(new ArrayList<Runnable>());
49
    
43
    /** non-null if we are running in unit test and should no show any dialogs */
50
    /** non-null if we are running in unit test and should no show any dialogs */
44
    private Object testResult;
51
    private Object testResult;
45
    
52
    
Lines 51-56 Link Here
51
    DialogDisplayerImpl (Object testResult) {
58
    DialogDisplayerImpl (Object testResult) {
52
        this.testResult = testResult;
59
        this.testResult = testResult;
53
    }
60
    }
61
    
62
    public static void runDelayed() {
63
        List<Runnable> local = run;
64
        run = null;
65
        if (local == null) {
66
            return;
67
        }
68
        
69
        assert EventQueue.isDispatchThread();
70
        for (Runnable r : local) {
71
            r.run();
72
        }
73
    }
74
    
54
75
55
    /** Creates new dialog. */
76
    /** Creates new dialog. */
56
    public Dialog createDialog (final DialogDescriptor d) {
77
    public Dialog createDialog (final DialogDescriptor d) {
Lines 91-97 Link Here
91
    /** Notifies user by a dialog.
112
    /** Notifies user by a dialog.
92
     * @param descriptor description that contains needed informations
113
     * @param descriptor description that contains needed informations
93
     * @return the option that has been choosen in the notification. */
114
     * @return the option that has been choosen in the notification. */
94
    public Object notify (final NotifyDescriptor descriptor) {
115
    public Object notify (NotifyDescriptor descriptor) {
116
        return notify(descriptor, false);
117
    }
118
119
    private Object notify (final NotifyDescriptor descriptor, final boolean noParent) {
95
        class AWTQuery implements Runnable {
120
        class AWTQuery implements Runnable {
96
            public Object result;
121
            public Object result;
97
            public boolean running;
122
            public boolean running;
Lines 150-155 Link Here
150
                            instanceof Frame ? 
175
                            instanceof Frame ? 
151
                            (Frame) KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() 
176
                            (Frame) KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() 
152
                            : WindowManager.getDefault().getMainWindow();
177
                            : WindowManager.getDefault().getMainWindow();
178
                        
179
                        if (noParent) {
180
                            f = null;
181
                        }
153
                        presenter = new NbPresenter(descriptor, f, true);
182
                        presenter = new NbPresenter(descriptor, f, true);
154
                    }
183
                    }
155
                }
184
                }
Lines 204-207 Link Here
204
        }
233
        }
205
    }
234
    }
206
235
236
    public void notifyLater(final NotifyDescriptor descriptor) {
237
        class R implements Runnable {
238
            public boolean noParent;
239
            
240
            public void run() {
241
                DialogDisplayerImpl.this.notify(descriptor, noParent);
242
            }
243
        }
244
        R r = new R();
245
        
246
        List<Runnable> local = run;
247
        if (local != null) {
248
            r.noParent = true;
249
            local.add(r);
250
        } else {
251
            EventQueue.invokeLater(r);
252
        }
253
    }
207
}
254
}
(-)windows/test/unit/src/org/netbeans/core/windows/services/DialogDisplayerImplTest.java (+41 lines)
Lines 226-229 Link Here
226
        }
226
        }
227
    }
227
    }
228
    
228
    
229
    private void waitAWT() throws Exception {
230
        SwingUtilities.invokeAndWait(new Runnable() { public void run() { } });
231
    }
232
233
    public void testIfLasterWhenSplashShownThanWaitTillItFinished() throws Exception {
234
        class MyObj extends Object {
235
            public int called;
236
            
237
            public String toString() {
238
                called = 1;
239
                return "Kuk";
240
            }
241
        }
242
        MyObj obj = new MyObj();
243
        
244
        NotifyDescriptor ownerDD = new NotifyDescriptor.Message(obj);
245
        
246
        
247
        
248
        DialogDisplayer.getDefault ().notifyLater(ownerDD);
249
        waitAWT();
250
        assertEquals("No notify yet", 0, obj.called);
251
        
252
        postInAwtAndWaitOutsideAwt(new Runnable () {
253
            public void run() {
254
                DialogDisplayerImpl.runDelayed();
255
            }
256
        });
257
        
258
        
259
        waitAWT();
260
        assertEquals("Now it is showing", 1, obj.called);
261
        
262
        SwingUtilities.invokeAndWait(new Runnable () {
263
            public void run() {
264
                DialogDisplayerImpl.runDelayed();
265
            }
266
        });
267
        
268
    }
269
    
229
}
270
}

Return to bug 92570