Skip to content

Commit 6e5b104

Browse files
committed
#5987: Use the currently active dialog as the presenter parent.
1 parent ff991ea commit 6e5b104

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,16 @@ public void showDialog () {
252252
presenter = new NbPresenter(descriptor, NbPresenter.currentModalDialog, true);
253253
}
254254
} else {
255-
Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow ();
256-
Frame f = w instanceof Frame ? (Frame) w : WindowManager.getDefault().getMainWindow();
255+
Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
257256
if (noParent) {
258-
f = null;
257+
presenter = new NbPresenter(descriptor, (Frame) null, true);
258+
} else if (w instanceof Frame) {
259+
presenter = new NbPresenter(descriptor, (Frame) w, true);
260+
} else if (w instanceof Dialog) {
261+
presenter = new NbPresenter(descriptor, (Dialog) w, true);
262+
} else {
263+
presenter = new NbPresenter(descriptor, WindowManager.getDefault().getMainWindow(), true);
259264
}
260-
presenter = new NbPresenter(descriptor, f, true);
261265
}
262266
}
263267

platform/core.windows/test/unit/src/org/netbeans/core/windows/services/DialogDisplayerImplTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.awt.Dialog;
2424
import java.awt.EventQueue;
2525
import java.awt.Frame;
26+
import java.awt.KeyboardFocusManager;
2627
import java.awt.Window;
2728
import java.util.concurrent.CancellationException;
2829
import java.util.concurrent.CompletableFuture;
@@ -86,6 +87,11 @@ protected void tearDown() throws Exception {
8687
NbPresenter.currentModalDialog.dispose();
8788
NbPresenter.currentModalDialog = null;
8889
}
90+
Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
91+
if (w != null) {
92+
w.setVisible(false);
93+
w.dispose();
94+
}
8995
super.tearDown();
9096
}
9197

@@ -347,6 +353,22 @@ public void testParent() {
347353
assertEquals(frame, dlg.getOwner());
348354
}
349355

356+
@RandomlyFails
357+
public void testNestedDialogParent() throws Exception {
358+
Frame f = null;
359+
Dialog owner = new Dialog(f);
360+
postInAwtAndWaitOutsideAwt(() -> owner.setVisible(true));
361+
assertShowing("Owner is invisible", true, owner);
362+
363+
child = new JButton();
364+
final NotifyDescriptor nd = new NotifyDescriptor.Message(child);
365+
postInAwtAndWaitOutsideAwt(() -> DialogDisplayer.getDefault().notify(nd));
366+
367+
assertShowing("Child is invisible", true, child);
368+
Window w = SwingUtilities.windowForComponent(child);
369+
assertSame("Window parent is not owner", owner, w.getParent());
370+
}
371+
350372
static void postInAwtAndWaitOutsideAwt (final Runnable run) throws Exception {
351373
// pendig to better implementation
352374
SwingUtilities.invokeLater (run);

0 commit comments

Comments
 (0)