diff --git a/platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java b/platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java index eb9df92d420a..78c9814a5d22 100644 --- a/platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java +++ b/platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java @@ -26,7 +26,6 @@ import java.awt.Frame; import java.awt.GraphicsEnvironment; import java.awt.HeadlessException; -import java.awt.KeyboardFocusManager; import java.awt.Window; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; @@ -38,6 +37,7 @@ import java.util.List; import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; +import javax.swing.JOptionPane; import javax.swing.JRootPane; import javax.swing.SwingUtilities; import org.netbeans.core.windows.view.ui.DefaultSeparateContainer; @@ -120,7 +120,14 @@ public Dialog run () { } } } - NbDialog dlg = new NbDialog(d, w); + NbDialog dlg; + if (w instanceof Frame) { + dlg = new NbDialog(d, (Frame) w); + } else if (w instanceof Dialog) { + dlg = new NbDialog(d, (Dialog) w); + } else { + dlg = new NbDialog(d, WindowManager.getDefault().getMainWindow()); + } customizeDlg(dlg); dlg.requestFocusInWindow (); return dlg; @@ -130,19 +137,24 @@ public Dialog run () { private Window findDialogParent() { Component parentComponent = Utilities.findDialogParent(null); - if (parentComponent instanceof Window) { - return (Window) parentComponent; - } - Window parent = null; - if (parentComponent != null) { - parent = SwingUtilities.windowForComponent(parentComponent); - } - if (parent == null || parent instanceof NbPresenter && ((NbPresenter) parent).isLeaf ()) { + Window parent = findDialogParent(parentComponent); + if (parent == null || parent == JOptionPane.getRootFrame() + || parent instanceof NbPresenter && ((NbPresenter) parent).isLeaf()) { return WindowManager.getDefault().getMainWindow(); } return parent; } + private Window findDialogParent(Component component) { + if (component == null) { + return null; + } + if (component instanceof Frame || component instanceof Dialog) { + return (Window) component; + } + return findDialogParent(component.getParent()); + } + /** Notifies user by a dialog. * @param descriptor description that contains needed informations * @return the option that has been choosen in the notification. @@ -227,9 +239,21 @@ public void showDialog () { Window parent = noParent ? null : findDialogParent(); if (descriptor instanceof DialogDescriptor) { - presenter = new NbDialog((DialogDescriptor) descriptor, parent); + if (parent instanceof Dialog) { + presenter = new NbDialog((DialogDescriptor) descriptor, (Dialog) parent); + } else if (parent instanceof Frame) { + presenter = new NbDialog((DialogDescriptor) descriptor, (Frame) parent); + } else { + presenter = new NbDialog((DialogDescriptor) descriptor, (Frame) null); + } } else { - presenter = new NbPresenter(descriptor, parent, Dialog.DEFAULT_MODALITY_TYPE); + if (parent instanceof Dialog) { + presenter = new NbPresenter(descriptor, (Dialog) parent, true); + } else if (parent instanceof Frame) { + presenter = new NbPresenter(descriptor, (Frame) parent, true); + } else { + presenter = new NbPresenter(descriptor, (Frame) null, true); + } } synchronized (this) { diff --git a/platform/core.windows/src/org/netbeans/core/windows/services/NbDialog.java b/platform/core.windows/src/org/netbeans/core/windows/services/NbDialog.java index 8b884d7eb5d0..196258315be1 100644 --- a/platform/core.windows/src/org/netbeans/core/windows/services/NbDialog.java +++ b/platform/core.windows/src/org/netbeans/core/windows/services/NbDialog.java @@ -50,14 +50,6 @@ public NbDialog (DialogDescriptor d, Dialog owner) { super (d, owner, d.isModal ()); } - /** Creates a new Dialog from specified DialogDescriptor - * @param d The DialogDescriptor to create the dialog from - * @param owner Owner of this dialog. - */ - public NbDialog(DialogDescriptor d, Window owner) { - super(d, owner, d.isModal() ? Dialog.DEFAULT_MODALITY_TYPE : ModalityType.MODELESS); - } - /** Getter for help. */ @Override diff --git a/platform/core.windows/src/org/netbeans/core/windows/services/NbPresenter.java b/platform/core.windows/src/org/netbeans/core/windows/services/NbPresenter.java index aeb1eb7393d9..e69ac49d4cb4 100644 --- a/platform/core.windows/src/org/netbeans/core/windows/services/NbPresenter.java +++ b/platform/core.windows/src/org/netbeans/core/windows/services/NbPresenter.java @@ -184,21 +184,6 @@ public NbPresenter(NotifyDescriptor d, Dialog owner, boolean modal) { initialize(d); } - /** - * Creates a new Dialog from the specified NotifyDescriptor and owner. - * - * @param d the non-null descriptor from which to initialize the dialog - * @param owner the owner of the dialog, must be a {@code Dialog} or - * {@code Frame} instance or {@code null} (not recommended) - * @param modality specifies whether dialog blocks input to other windows - * when shown. {@code null} value and unsupported modality types are - * equivalent to {@code MODELESS} - */ - public NbPresenter(NotifyDescriptor d, Window owner, ModalityType modality) { - super(owner, d.getTitle(), modality); - initialize(d); - } - boolean isLeaf () { return leaf; } @@ -1599,7 +1584,10 @@ private Window findFocusedWindow() { } } } - while( null != w && !w.isShowing() ) { + while( null != w ) { + if ((w instanceof Frame || w instanceof Dialog) && w.isShowing()) { + break; + } w = w.getOwner(); } return w; diff --git a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbDialogTest.java b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbDialogTest.java index 50f26c844861..c59799bcbd1c 100644 --- a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbDialogTest.java +++ b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbDialogTest.java @@ -19,9 +19,8 @@ package org.netbeans.core.windows.services; import java.awt.Dialog; +import java.awt.Frame; import java.awt.GraphicsEnvironment; -import java.awt.Window; -import javax.swing.JLabel; import junit.framework.Test; import junit.framework.TestSuite; import org.netbeans.junit.NbTestCase; @@ -42,12 +41,12 @@ protected boolean runInEQ() { } public void testModalityIsDefaultWhenModal() { - NbDialog d = new NbDialog(new DialogDescriptor(null, null, true, null), (Window) null); + NbDialog d = new NbDialog(new DialogDescriptor(null, null, true, null), (Frame) null); assertEquals(Dialog.DEFAULT_MODALITY_TYPE, d.getModalityType()); } public void testModalityIsModelessWhenNotModal() { - NbDialog d = new NbDialog(new DialogDescriptor(null, null, false, null), (Window) null); + NbDialog d = new NbDialog(new DialogDescriptor(null, null, false, null), (Frame) null); assertEquals(Dialog.ModalityType.MODELESS, d.getModalityType()); } } diff --git a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbPresenterTest.java b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbPresenterTest.java index 4b020f8c1e2a..0f0907e4eb2a 100644 --- a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbPresenterTest.java +++ b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbPresenterTest.java @@ -57,21 +57,16 @@ protected boolean runInEQ () { } public void testOwnerIsWindow() { - Window owner = new Frame(); - NbPresenter p = new NbPresenter(DESCRIPTOR, owner, Dialog.ModalityType.APPLICATION_MODAL); + Frame owner = new Frame(); + NbPresenter p = new NbPresenter(DESCRIPTOR, owner, true); assertSame(owner, p.getOwner()); } public void testTitleIsFromDescriptor() { - NbPresenter p = new NbPresenter(DESCRIPTOR, null, Dialog.ModalityType.APPLICATION_MODAL); + NbPresenter p = new NbPresenter(DESCRIPTOR, (Frame) null, true); assertEquals(TITLE, p.getTitle()); } - public void testModalityIsSet() { - NbPresenter p = new NbPresenter(DESCRIPTOR, null, Dialog.ModalityType.APPLICATION_MODAL); - assertEquals(Dialog.ModalityType.APPLICATION_MODAL, p.getModalityType()); - } - public void testDialogsOptionsOnDefaultSystem () { System.setProperty ("xtest.looks_as_mac", "false"); doTestDialogsOptions (); diff --git a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NotifyLaterTest.java b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NotifyLaterTest.java index dfaafebd515b..30871cf80295 100644 --- a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NotifyLaterTest.java +++ b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NotifyLaterTest.java @@ -116,7 +116,7 @@ public void run() { assertNotNull("There is parent window", root); assertTrue("It is a dialog", root instanceof JDialog); JDialog d = (JDialog)root; - assertNull("d should have no owner", d.getParent()); + assertEquals("The owner of d is the same as owner of dialog without owner", new JDialog().getParent(), d.getParent()); SwingUtilities.invokeAndWait(new Runnable () { public void run() {