errael commented on code in PR #6294:
URL: https://github.com/apache/netbeans/pull/6294#discussion_r1283407307


##########
platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java:
##########
@@ -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());
+    }
+

Review Comment:
   In NB18, this class had no `findDialogParent`, now it has two and one of 
them is even recursive ;-)



##########
platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java:
##########
@@ -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);
+                }

Review Comment:
   Could be written as
   ```
   if (parent instanceof Dialog)
       presenter = new NbDialog((DialogDescriptor) descriptor, (Dialog) parent);
   else 
       presenter = new NbDialog((DialogDescriptor) descriptor, (Frame) parent);
   ```
   But changing it makes it more difficult to change the default between 
Dialog/Frame.
   
   Wondering why one is a better choice than the other. The first 
frame-->dialog made sense from the point of view of being able to have an 
unowned JDialog.
   
   Why change it back? Not that I have much of an opinion one way or the other.



##########
platform/core.windows/src/org/netbeans/core/windows/services/NbPresenter.java:
##########
@@ -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;
+            }

Review Comment:
   This private method is only used from private initBounds for placement 
purposes; not a parenting decision.
   
   Seems better to place it near the focused window, rather than who knows 
where.



##########
platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java:
##########
@@ -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()) {

Review Comment:
   Adding `getRootFrame()` seems like a nice touch. Changes the default `Frame` 
to the `MainWindow`. I wonder if there's a resonance with default to `Frame` in 
`showDialog`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to