Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Update dialog parent API, displayer impl and test." #6291

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import javax.swing.SwingUtilities;
import org.netbeans.core.windows.view.ui.DefaultSeparateContainer;
import org.openide.util.Lookup;
import org.openide.util.Utilities;
import org.openide.util.lookup.ServiceProvider;

/**
Expand Down Expand Up @@ -96,53 +95,53 @@ public Dialog createDialog (final DialogDescriptor d, final Frame preferredParen
}
return Mutex.EVENT.readAccess (new Mutex.Action<Dialog> () {
public Dialog run () {
Window w = preferredParent;
if (w != null) {
// Verify the preferred parent
Component p = Utilities.findDialogParent(w);
if (p != w) {
w = null;
// if a modal dialog active use it as parent
// otherwise use the main window
if (NbPresenter.currentModalDialog != null) {
NbDialog dlg;
if (NbPresenter.currentModalDialog.isLeaf ()) {
dlg = new NbDialog(d, WindowManager.getDefault ().getMainWindow ());
} else {
dlg = new NbDialog(d, NbPresenter.currentModalDialog);
}
customizeDlg(dlg);
return dlg;
}
if (w == null) {
w = findDialogParent();
if (!(w instanceof NbPresenter) || !w.isVisible()) {
// undocked window is not instanceof NbPresenter although it's NetBeans's native window
// all docked windows implements ModeUIBase interface
if (! (w instanceof DefaultSeparateContainer.ModeUIBase)) {
Container cont = SwingUtilities.getAncestorOfClass(Window.class, w);
if (cont instanceof DefaultSeparateContainer.ModeUIBase) {
w = (Window) cont;
} else {
// don't set non-ide window as parent
w = WindowManager.getDefault ().getMainWindow ();
else {
Window w = preferredParent;
if( null == w ) {
w = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow ();
if (!(w instanceof NbPresenter) || !w.isVisible()) {
// undocked window is not instanceof NbPresenter although it's NetBeans's native window
// all docked windows implements ModeUIBase interface
if (! (w instanceof DefaultSeparateContainer.ModeUIBase)) {
Container cont = SwingUtilities.getAncestorOfClass(Window.class, w);
if (cont instanceof DefaultSeparateContainer.ModeUIBase) {
w = (Window) cont;
} else {
// don't set non-ide window as parent
w = WindowManager.getDefault ().getMainWindow ();
}
}
} else if (w instanceof NbPresenter && ((NbPresenter) w).isLeaf ()) {
w = WindowManager.getDefault ().getMainWindow ();
}
}
NbDialog dlg;
if (w instanceof Dialog) {
dlg = new NbDialog(d, (Dialog) w);
} else {
Frame f = w instanceof Frame ? (Frame) w : WindowManager.getDefault ().getMainWindow ();
dlg = new NbDialog(d, f);
}
customizeDlg(dlg);
dlg.requestFocusInWindow ();
return dlg;
}
NbDialog dlg = new NbDialog(d, w);
customizeDlg(dlg);
dlg.requestFocusInWindow ();
return dlg;
}
});
}

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 ()) {
return WindowManager.getDefault().getMainWindow();
}
return parent;
}

/** Notifies user by a dialog.
* @param descriptor description that contains needed informations
* @return the option that has been choosen in the notification.
Expand Down Expand Up @@ -223,13 +222,43 @@ public void showDialog () {
while ((win != null) && (!(win instanceof Window))) win = win.getParent ();
if (win != null) focusOwner = ((Window)win).getFocusOwner ();

NbPresenter presenter;
Window parent = noParent ? null : findDialogParent();
// if a modal dialog is active use it as parent
// otherwise use the main window

NbPresenter presenter;
if (descriptor instanceof DialogDescriptor) {
presenter = new NbDialog((DialogDescriptor) descriptor, parent);
if (NbPresenter.currentModalDialog != null) {
if (NbPresenter.currentModalDialog.isLeaf ()) {
presenter = new NbDialog((DialogDescriptor) descriptor, WindowManager.getDefault ().getMainWindow ());
} else {
presenter = new NbDialog((DialogDescriptor) descriptor, NbPresenter.currentModalDialog);
}
} else {
Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow ();
if (w instanceof NbPresenter && ((NbPresenter) w).isLeaf ()) {
w = WindowManager.getDefault ().getMainWindow ();
}
Frame f = w instanceof Frame ? (Frame) w : WindowManager.getDefault().getMainWindow();
if (noParent) {
f = null;
}
presenter = new NbDialog((DialogDescriptor) descriptor, f);
}
} else {
presenter = new NbPresenter(descriptor, parent, Dialog.DEFAULT_MODALITY_TYPE);
if (NbPresenter.currentModalDialog != null) {
if (NbPresenter.currentModalDialog.isLeaf()) {
presenter = new NbPresenter(descriptor, WindowManager.getDefault().getMainWindow(), true);
} else {
presenter = new NbPresenter(descriptor, NbPresenter.currentModalDialog, true);
}
} else {
Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow ();
Frame f = w instanceof Frame ? (Frame) w : WindowManager.getDefault().getMainWindow();
if (noParent) {
f = null;
}
presenter = new NbPresenter(descriptor, f, true);
}
}

synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,7 @@ 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.
/** Geter for help.
*/
@Override
protected HelpCtx getHelpCtx () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.awt.DefaultKeyboardFocusManager;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GraphicsDevice;
Expand Down Expand Up @@ -88,6 +89,7 @@
import org.openide.NotifyDescriptor;
import org.openide.WizardDescriptor;
import org.openide.awt.Mnemonics;
import org.openide.util.ChangeSupport;
import org.openide.util.HelpCtx;
import org.openide.util.ImageUtilities;
import org.openide.util.Mutex;
Expand All @@ -104,6 +106,9 @@
class NbPresenter extends JDialog
implements PropertyChangeListener, WindowListener, Mutex.Action<Void>, Comparator<Object> {

/** variable holding current modal dialog in the system */
public static NbPresenter currentModalDialog;
private static final ChangeSupport cs = new ChangeSupport(NbPresenter.class);
private static Boolean isJava17 = null;

protected NotifyDescriptor descriptor;
Expand Down Expand Up @@ -184,21 +189,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;
}
Expand Down Expand Up @@ -1102,7 +1092,6 @@ public void run () {
}
}

@Override
public Void run() {
doShow();
return null;
Expand All @@ -1119,21 +1108,30 @@ private void doShow () {
gd.setFullScreenWindow( null );
}
}
NbPresenter prev = null;
try {
MenuSelectionManager.defaultManager().clearSelectedPath();
} catch( NullPointerException npE ) {
//#216184
LOG.log( Level.FINE, null, npE );
}
if (isModal()) {
prev = currentModalDialog;
currentModalDialog = this;
fireChangeEvent();
}

superShow();

if( null != fullScreenWindow ) {
if( null != fullScreenWindow )
getGraphicsConfiguration().getDevice().setFullScreenWindow( fullScreenWindow );

if (currentModalDialog != prev) {
currentModalDialog = prev;
fireChangeEvent();
}
}

@Override
public void propertyChange(final java.beans.PropertyChangeEvent evt) {
if( !SwingUtilities.isEventDispatchThread() ) {
SwingUtilities.invokeLater(new Runnable() {
Expand Down Expand Up @@ -1276,13 +1274,19 @@ public void windowClosing(final java.awt.event.WindowEvent p1) {
public void windowActivated(final java.awt.event.WindowEvent p1) {
}

@Deprecated
// Used by JavaHelp:
public static void addChangeListener(ChangeListener l) {
// Does nothing
cs.addChangeListener(l);
}
@Deprecated
public static void removeChangeListener(ChangeListener l) {
// Does nothing
cs.removeChangeListener(l);
}
private static void fireChangeEvent() {
EventQueue.invokeLater(new Runnable() {
public void run() {
cs.fireChange();
}
});
}

private final class EscapeAction extends AbstractAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.openide.util.Mutex;
import org.openide.util.NbBundle;
import org.openide.util.UserCancelException;
import org.openide.util.Utilities;
import org.openide.util.WeakSet;
import org.openide.util.lookup.ServiceProvider;
import org.openide.windows.Mode;
Expand Down Expand Up @@ -351,7 +350,12 @@ private static void openProperties (final NbSheet sheet, final Node[] nds) {
// Mutex.EVENT.readAccess (new Runnable () { // PENDING
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run () {
boolean modal = Utilities.isModalDialogOpen();
boolean modal;
if(NbPresenter.currentModalDialog == null) {
modal = false;
} else {
modal = true;
}

Dialog dlg = org.openide.DialogDisplayer.getDefault().createDialog(new DialogDescriptor (
sheet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.awt.Dialog;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.KeyboardFocusManager;
import java.awt.Window;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -82,13 +81,10 @@ protected void setUp() throws Exception {

@Override
protected void tearDown() throws Exception {
while (true) {
Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
if (w == null) {
break;
}
w.setVisible(false);
w.dispose();
if (NbPresenter.currentModalDialog != null) {
NbPresenter.currentModalDialog.setVisible(false);
NbPresenter.currentModalDialog.dispose();
NbPresenter.currentModalDialog = null;
}
super.tearDown();
}
Expand Down Expand Up @@ -351,23 +347,6 @@ public void testParent() {
assertEquals(frame, dlg.getOwner());
}

@RandomlyFails
public void testNestedDialogParent() throws Exception {
Frame f = null;
Dialog owner = new Dialog(f, true);
postInAwtAndWaitOutsideAwt(() -> owner.setVisible(true));
assertShowing("Owner is invisible", true, owner);

child = new JButton();
final NotifyDescriptor nd = new NotifyDescriptor.Message(child);
postInAwtAndWaitOutsideAwt(() -> DialogDisplayer.getDefault().notify(nd));

assertShowing("Child is invisible", true, child);
Window w = SwingUtilities.windowForComponent(child);
assertSame("Window parent is not owner", owner, w.getParent());
postInAwtAndWaitOutsideAwt(() -> owner.setVisible(false));
}

static void postInAwtAndWaitOutsideAwt (final Runnable run) throws Exception {
// pendig to better implementation
SwingUtilities.invokeLater (run);
Expand Down Expand Up @@ -465,7 +444,7 @@ public void testUserCancelClosesDialog() throws Exception {
thenApply((x) -> x);

// wait for the dialog to be displayed
assertTrue(panel.displayed.await(10, TimeUnit.SECONDS));
panel.displayed.await(10, TimeUnit.SECONDS);

cf.cancel(true);

Expand Down
Loading