Skip to content

Commit 9d72942

Browse files
Fix issue (GH6290) in new DialogDisplayerImpl behaviour introduced in GH5989 / GH6216.
1 parent 6272f5c commit 9d72942

File tree

5 files changed

+46
-48
lines changed

5 files changed

+46
-48
lines changed

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

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.awt.Frame;
2727
import java.awt.GraphicsEnvironment;
2828
import java.awt.HeadlessException;
29-
import java.awt.KeyboardFocusManager;
3029
import java.awt.Window;
3130
import org.openide.DialogDescriptor;
3231
import org.openide.DialogDisplayer;
@@ -38,6 +37,7 @@
3837
import java.util.List;
3938
import java.util.concurrent.CancellationException;
4039
import java.util.concurrent.CompletableFuture;
40+
import javax.swing.JOptionPane;
4141
import javax.swing.JRootPane;
4242
import javax.swing.SwingUtilities;
4343
import org.netbeans.core.windows.view.ui.DefaultSeparateContainer;
@@ -120,7 +120,14 @@ public Dialog run () {
120120
}
121121
}
122122
}
123-
NbDialog dlg = new NbDialog(d, w);
123+
NbDialog dlg;
124+
if (w instanceof Frame) {
125+
dlg = new NbDialog(d, (Frame) w);
126+
} else if (w instanceof Dialog) {
127+
dlg = new NbDialog(d, (Dialog) w);
128+
} else {
129+
dlg = new NbDialog(d, WindowManager.getDefault().getMainWindow());
130+
}
124131
customizeDlg(dlg);
125132
dlg.requestFocusInWindow ();
126133
return dlg;
@@ -130,19 +137,24 @@ public Dialog run () {
130137

131138
private Window findDialogParent() {
132139
Component parentComponent = Utilities.findDialogParent(null);
133-
if (parentComponent instanceof Window) {
134-
return (Window) parentComponent;
135-
}
136-
Window parent = null;
137-
if (parentComponent != null) {
138-
parent = SwingUtilities.windowForComponent(parentComponent);
139-
}
140-
if (parent == null || parent instanceof NbPresenter && ((NbPresenter) parent).isLeaf ()) {
140+
Window parent = findDialogParent(parentComponent);
141+
if (parent == null || parent == JOptionPane.getRootFrame()
142+
|| parent instanceof NbPresenter && ((NbPresenter) parent).isLeaf()) {
141143
return WindowManager.getDefault().getMainWindow();
142144
}
143145
return parent;
144146
}
145147

148+
private Window findDialogParent(Component component) {
149+
if (component == null) {
150+
return null;
151+
}
152+
if (component instanceof Frame || component instanceof Dialog) {
153+
return (Window) component;
154+
}
155+
return findDialogParent(component.getParent());
156+
}
157+
146158
/** Notifies user by a dialog.
147159
* @param descriptor description that contains needed informations
148160
* @return the option that has been choosen in the notification.
@@ -227,9 +239,21 @@ public void showDialog () {
227239
Window parent = noParent ? null : findDialogParent();
228240

229241
if (descriptor instanceof DialogDescriptor) {
230-
presenter = new NbDialog((DialogDescriptor) descriptor, parent);
242+
if (parent instanceof Dialog) {
243+
presenter = new NbDialog((DialogDescriptor) descriptor, (Dialog) parent);
244+
} else if (parent instanceof Frame) {
245+
presenter = new NbDialog((DialogDescriptor) descriptor, (Frame) parent);
246+
} else {
247+
presenter = new NbDialog((DialogDescriptor) descriptor, (Frame) null);
248+
}
231249
} else {
232-
presenter = new NbPresenter(descriptor, parent, Dialog.DEFAULT_MODALITY_TYPE);
250+
if (parent instanceof Dialog) {
251+
presenter = new NbPresenter(descriptor, (Dialog) parent, true);
252+
} else if (parent instanceof Frame) {
253+
presenter = new NbPresenter(descriptor, (Frame) parent, true);
254+
} else {
255+
presenter = new NbPresenter(descriptor, (Frame) null, true);
256+
}
233257
}
234258

235259
synchronized (this) {

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ public NbDialog (DialogDescriptor d, Dialog owner) {
5050
super (d, owner, d.isModal ());
5151
}
5252

53-
/** Creates a new Dialog from specified DialogDescriptor
54-
* @param d The DialogDescriptor to create the dialog from
55-
* @param owner Owner of this dialog.
56-
*/
57-
public NbDialog(DialogDescriptor d, Window owner) {
58-
super(d, owner, d.isModal() ? Dialog.DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
59-
}
60-
6153
/** Getter for help.
6254
*/
6355
@Override

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,6 @@ public NbPresenter(NotifyDescriptor d, Dialog owner, boolean modal) {
184184
initialize(d);
185185
}
186186

187-
/**
188-
* Creates a new Dialog from the specified NotifyDescriptor and owner.
189-
*
190-
* @param d the non-null descriptor from which to initialize the dialog
191-
* @param owner the owner of the dialog, must be a {@code Dialog} or
192-
* {@code Frame} instance or {@code null} (not recommended)
193-
* @param modality specifies whether dialog blocks input to other windows
194-
* when shown. {@code null} value and unsupported modality types are
195-
* equivalent to {@code MODELESS}
196-
*/
197-
public NbPresenter(NotifyDescriptor d, Window owner, ModalityType modality) {
198-
super(owner, d.getTitle(), modality);
199-
initialize(d);
200-
}
201-
202187
boolean isLeaf () {
203188
return leaf;
204189
}
@@ -1599,7 +1584,10 @@ private Window findFocusedWindow() {
15991584
}
16001585
}
16011586
}
1602-
while( null != w && !w.isShowing() ) {
1587+
while( null != w ) {
1588+
if ((w instanceof Frame || w instanceof Dialog) && w.isShowing()) {
1589+
break;
1590+
}
16031591
w = w.getOwner();
16041592
}
16051593
return w;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
package org.netbeans.core.windows.services;
2020

2121
import java.awt.Dialog;
22+
import java.awt.Frame;
2223
import java.awt.GraphicsEnvironment;
23-
import java.awt.Window;
24-
import javax.swing.JLabel;
2524
import junit.framework.Test;
2625
import junit.framework.TestSuite;
2726
import org.netbeans.junit.NbTestCase;
@@ -42,12 +41,12 @@ protected boolean runInEQ() {
4241
}
4342

4443
public void testModalityIsDefaultWhenModal() {
45-
NbDialog d = new NbDialog(new DialogDescriptor(null, null, true, null), (Window) null);
44+
NbDialog d = new NbDialog(new DialogDescriptor(null, null, true, null), (Frame) null);
4645
assertEquals(Dialog.DEFAULT_MODALITY_TYPE, d.getModalityType());
4746
}
4847

4948
public void testModalityIsModelessWhenNotModal() {
50-
NbDialog d = new NbDialog(new DialogDescriptor(null, null, false, null), (Window) null);
49+
NbDialog d = new NbDialog(new DialogDescriptor(null, null, false, null), (Frame) null);
5150
assertEquals(Dialog.ModalityType.MODELESS, d.getModalityType());
5251
}
5352
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,16 @@ protected boolean runInEQ () {
5757
}
5858

5959
public void testOwnerIsWindow() {
60-
Window owner = new Frame();
61-
NbPresenter p = new NbPresenter(DESCRIPTOR, owner, Dialog.ModalityType.APPLICATION_MODAL);
60+
Frame owner = new Frame();
61+
NbPresenter p = new NbPresenter(DESCRIPTOR, owner, true);
6262
assertSame(owner, p.getOwner());
6363
}
6464

6565
public void testTitleIsFromDescriptor() {
66-
NbPresenter p = new NbPresenter(DESCRIPTOR, null, Dialog.ModalityType.APPLICATION_MODAL);
66+
NbPresenter p = new NbPresenter(DESCRIPTOR, (Frame) null, true);
6767
assertEquals(TITLE, p.getTitle());
6868
}
6969

70-
public void testModalityIsSet() {
71-
NbPresenter p = new NbPresenter(DESCRIPTOR, null, Dialog.ModalityType.APPLICATION_MODAL);
72-
assertEquals(Dialog.ModalityType.APPLICATION_MODAL, p.getModalityType());
73-
}
74-
7570
public void testDialogsOptionsOnDefaultSystem () {
7671
System.setProperty ("xtest.looks_as_mac", "false");
7772
doTestDialogsOptions ();

0 commit comments

Comments
 (0)