This is an automated email from the ASF dual-hosted git repository.

neilcsmith pushed a commit to branch delivery
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/delivery by this push:
     new 5082b150b9 Fix issue (GH6290) in new DialogDisplayerImpl behaviour 
introduced in GH5989 / GH6216.
     new 5d6c0c0646 Merge pull request #6294 from neilcsmith-net/gh6290
5082b150b9 is described below

commit 5082b150b90cd6789e4275e095444e18e4509fed
Author: Neil C Smith <neilcsm...@apache.org>
AuthorDate: Thu Aug 3 13:30:03 2023 +0100

    Fix issue (GH6290) in new DialogDisplayerImpl behaviour introduced in 
GH5989 / GH6216.
---
 .../core/windows/services/DialogDisplayerImpl.java | 48 ++++++++++++++++------
 .../netbeans/core/windows/services/NbDialog.java   |  8 ----
 .../core/windows/services/NbPresenter.java         | 20 ++-------
 .../core/windows/services/NbDialogTest.java        |  7 ++--
 .../core/windows/services/NbPresenterTest.java     | 11 ++---
 .../core/windows/services/NotifyLaterTest.java     |  2 +-
 6 files changed, 47 insertions(+), 49 deletions(-)

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 eb9df92d42..78c9814a5d 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.EventQueue;
 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.Collections;
 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 class DialogDisplayerImpl extends DialogDisplayer {
                         }
                     }
                 }
-                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 class DialogDisplayerImpl extends DialogDisplayer {
     
     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 class DialogDisplayerImpl extends DialogDisplayer {
             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 8b884d7eb5..196258315b 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 @@ final class NbDialog extends NbPresenter {
         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 aeb1eb7393..e69ac49d4c 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 @@ implements PropertyChangeListener, WindowListener, 
Mutex.Action<Void>, Comparato
         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 @@ implements PropertyChangeListener, WindowListener, 
Mutex.Action<Void>, Comparato
                 }
             }
         }
-        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 50f26c8448..c59799bcbd 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 @@ public class NbDialogTest extends NbTestCase {
     }
 
     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 4b020f8c1e..0f0907e4eb 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 @@ public class NbPresenterTest extends NbTestCase {
     }
 
     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 dfaafebd51..30871cf802 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 class NotifyLaterTest extends NbTestCase {
         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() {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to