Index: src/org/openide/actions/PrintAction.java =================================================================== RCS file: /cvs/openide/src/org/openide/actions/PrintAction.java,v retrieving revision 1.20 diff -u -r1.20 PrintAction.java --- src/org/openide/actions/PrintAction.java 3 Feb 2004 15:24:19 -0000 1.20 +++ src/org/openide/actions/PrintAction.java 5 Feb 2004 13:17:41 -0000 @@ -32,20 +32,16 @@ } protected void performAction(final Node[] activatedNodes) { - RequestProcessor.getDefault().post(new Runnable() { - public void run() { - for (int i = 0; i < activatedNodes.length; i++) { - PrintCookie pc = (PrintCookie)activatedNodes[i].getCookie (PrintCookie.class); - if (pc != null) { - pc.print(); - } - } - } - }); + for (int i = 0; i < activatedNodes.length; i++) { + PrintCookie pc = (PrintCookie)activatedNodes[i].getCookie (PrintCookie.class); + if (pc != null) { + pc.print(); + } + } } protected boolean asynchronous() { - return false; + return true; } protected int mode () { Index: src/org/openide/util/actions/CallableSystemAction.java =================================================================== RCS file: /cvs/openide/src/org/openide/util/actions/CallableSystemAction.java,v retrieving revision 1.16 diff -u -r1.16 CallableSystemAction.java --- src/org/openide/util/actions/CallableSystemAction.java 6 Sep 2003 16:14:02 -0000 1.16 +++ src/org/openide/util/actions/CallableSystemAction.java 5 Feb 2004 13:17:41 -0000 @@ -106,9 +106,6 @@ final void doPerformAction(final Runnable r) { assert EventQueue.isDispatchThread() : "Action " + getClass().getName() + " may not be invoked from the thread " + Thread.currentThread().getName() + ", only the event queue: http://www.netbeans.org/download/dev/javadoc/OpenAPIs/apichanges.html#actions-event-thread"; if (asynchronous()) { - if (warnedAsynchronousActions.add(getClass())) { - ErrorManager.getDefault().log(ErrorManager.WARNING, "Warning - " + getClass().getName() + " should override CallableSystemAction.asynchronous() to return false"); - } Runnable r2 = new Runnable() { public void run() { try { @@ -155,6 +152,9 @@ * @since 4.11 */ protected boolean asynchronous() { + if (warnedAsynchronousActions.add(getClass())) { + ErrorManager.getDefault().log(ErrorManager.WARNING, "Warning - " + getClass().getName() + " should override CallableSystemAction.asynchronous() to return false"); + } return DEFAULT_ASYNCH; } private static final boolean DEFAULT_ASYNCH = !Boolean.getBoolean("org.openide.util.actions.CallableSystemAction.synchronousByDefault"); Index: test/unit/src/org/openide/util/actions/AsynchronousTest.java =================================================================== RCS file: test/unit/src/org/openide/util/actions/AsynchronousTest.java diff -N test/unit/src/org/openide/util/actions/AsynchronousTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ test/unit/src/org/openide/util/actions/AsynchronousTest.java 5 Feb 2004 13:17:41 -0000 @@ -0,0 +1,164 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.openide.util.actions; + +import java.awt.Image; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.image.BufferedImage; +import java.awt.image.ImageObserver; +import java.awt.image.PixelGrabber; +import javax.swing.Icon; +import javax.swing.JButton; +import org.netbeans.junit.*; +import junit.textui.TestRunner; +import org.openide.util.HelpCtx; +import org.openide.util.lookup.AbstractLookup; + +/** Test general aspects of system actions. + * Currently, just the icon. + * @author Jesse Glick + */ +public class AsynchronousTest extends NbTestCase { + + public AsynchronousTest (String name) { + super(name); + } + + public static void main(String[] args) { + System.setProperty("org.openide.util.Lookup", Lkp.class.getName ()); + TestRunner.run(new NbTestSuite(AsynchronousTest.class)); + } + + protected void setUp () { + ErrManager.messages.delete (0, ErrManager.messages.length ()); + } + + public void testExecutionOfActionsThatDoesNotOverrideAsynchronousIsAsynchronousButWarningIsPrinted () throws Exception { + DoesNotOverride action = (DoesNotOverride)DoesNotOverride.get (DoesNotOverride.class); + + synchronized (action) { + action.actionPerformed (new ActionEvent(this, 0, "")); + Thread.sleep (500); + assertFalse ("Not yet finished", action.finished); + action.wait (); + assertTrue ("The asynchronous action is finished", action.finished); + } + + if (ErrManager.messages.toString ().indexOf (DoesNotOverride.class.getName () + " should override") < 0) { + fail ("There should be warning about not overriding asynchronous: " + ErrManager.messages); + } + } + + public void testExecutionCanBeAsynchronous () throws Exception { + DoesOverrideAndReturnsTrue action = (DoesOverrideAndReturnsTrue)DoesOverrideAndReturnsTrue.get (DoesOverrideAndReturnsTrue.class); + + synchronized (action) { + action.actionPerformed (new ActionEvent(this, 0, "")); + Thread.sleep (500); + assertFalse ("Not yet finished", action.finished); + action.wait (); + assertTrue ("The asynchronous action is finished", action.finished); + } + + if (ErrManager.messages.toString ().indexOf (DoesOverrideAndReturnsTrue.class.getName ()) >= 0) { + fail ("No warning about the class: " + ErrManager.messages); + } + } + + public void testExecutionCanBeSynchronous () throws Exception { + DoesOverrideAndReturnsFalse action = (DoesOverrideAndReturnsFalse)DoesOverrideAndReturnsFalse.get (DoesOverrideAndReturnsFalse.class); + + synchronized (action) { + action.actionPerformed (new ActionEvent(this, 0, "")); + assertTrue ("The synchronous action is finished immediatelly", action.finished); + } + + if (ErrManager.messages.toString ().indexOf (DoesOverrideAndReturnsTrue.class.getName ()) >= 0) { + fail ("No warning about the class: " + ErrManager.messages); + } + } + + + public static class DoesNotOverride extends CallableSystemAction { + boolean finished; + + public HelpCtx getHelpCtx () { + return HelpCtx.DEFAULT_HELP; + } + + public String getName () { + return "Should warn action"; + } + + public synchronized void performAction () { + notifyAll (); + finished = true; + } + + } + + public static class DoesOverrideAndReturnsTrue extends DoesNotOverride { + public boolean asynchronous () { + return true; + } + } + + public static final class DoesOverrideAndReturnsFalse extends DoesOverrideAndReturnsTrue { + public boolean asynchronous () { + return false; + } + } + + + public static final class Lkp extends AbstractLookup { + public Lkp () { + this (new org.openide.util.lookup.InstanceContent ()); + } + + private Lkp (org.openide.util.lookup.InstanceContent ic) { + super (ic); + ic.add (new ErrManager ()); + } + } + + private static final class ErrManager extends org.openide.ErrorManager { + public static final StringBuffer messages = new StringBuffer (); + + public Throwable annotate (Throwable t, int severity, String message, String localizedMessage, Throwable stackTrace, java.util.Date date) { + return t; + } + + public Throwable attachAnnotations (Throwable t, org.openide.ErrorManager.Annotation[] arr) { + return t; + } + + public org.openide.ErrorManager.Annotation[] findAnnotations (Throwable t) { + return null; + } + + public org.openide.ErrorManager getInstance (String name) { + return this; + } + + public void log (int severity, String s) { + messages.append (s); + messages.append ('\n'); + } + + public void notify (int severity, Throwable t) { + } + + } +}