Index: openide/src/org/openide/actions/DeleteAction.java
===================================================================
RCS file: /cvs/openide/src/org/openide/actions/DeleteAction.java,v
--- openide/src/org/openide/actions/DeleteAction.java 27 Aug 2003 20:35:01 -0000 1.20
+++ openide/src/org/openide/actions/DeleteAction.java 13 Feb 2004 17:10:47 -0000
@@ -46,7 +46,7 @@
}
protected boolean asynchronous() {
- return false;
+ return true;
}
}
Index: openide/src/org/openide/actions/PasteAction.java
===================================================================
RCS file: /cvs/openide/src/org/openide/actions/PasteAction.java,v
--- openide/src/org/openide/actions/PasteAction.java 7 Jan 2004 13:19:50 -0000 1.52
+++ openide/src/org/openide/actions/PasteAction.java 13 Feb 2004 17:10:47 -0000
@@ -139,7 +139,8 @@
}
if(t != null) {
- executePasteType (t);
+ // posts the action in RP thread
+ new ActionPT (t, ev.getActionCommand ());
} else {
ErrorManager.getDefault().notify(
ErrorManager.INFORMATIONAL,
@@ -147,43 +148,11 @@
"No paste types available when performing paste action")); // NOI18N
}
}
-
+
protected boolean asynchronous() {
return false;
}
- /** Does the execution of a paste type with all handling around
- */
- private static void executePasteType (PasteType t) {
- NodeSelector sel = null;
- try {
- ExplorerManager em = findExplorerManager ();
- if (em != null) {
- sel = new NodeSelector (em, null);
- }
-
- Transferable trans = t.paste();
- Clipboard clipboard = getClipboard();
-
-
- if (trans != null) {
- ClipboardOwner owner = trans instanceof ClipboardOwner ?
- (ClipboardOwner)trans
- :
- new StringSelection (""); // NOI18N
- clipboard.setContents(trans, owner);
- }
- } catch (UserCancelException exc) {
- // ignore - user just pressed cancel in some dialog....
- } catch (java.io.IOException e) {
- ErrorManager.getDefault().notify(e);
- } finally {
- if (sel != null) {
- sel.select ();
- }
- }
- }
-
/** Set possible paste types.
* Automatically enables or disables the paste action according to whether there are any.
* @param types the new types to allow, or null
@@ -392,6 +361,10 @@
}
public void performActionAt(int index) {
+ performActionAt (index, null);
+ }
+
+ public void performActionAt(int index, ActionEvent ev) {
Action[] action = new Action[1];
Object[] arr = getPasteTypesOrActions (action);
@@ -401,7 +374,8 @@
if (arr[index] instanceof PasteType) {
PasteType t = (PasteType)arr[index];
- new ActionPT(t).actionPerformed(new ActionEvent(t, ActionEvent.ACTION_PERFORMED, javax.swing.Action.NAME));
+ // posts the action is RP thread
+ new ActionPT(t, ev == null ? null : ev.getActionCommand ());
return;
} else {
// is action
@@ -676,7 +650,7 @@
*/
public void actionPerformed(java.awt.event.ActionEvent e) {
if (model != null) {
- model.performActionAt(0);
+ model.performActionAt(0, e);
}
}
@@ -710,15 +684,72 @@
/** Action that wraps paste type.
*/
- private static final class ActionPT extends javax.swing.AbstractAction {
+ private static final class ActionPT extends javax.swing.AbstractAction
+ implements Runnable {
private PasteType t;
+ private NodeSelector sel;
+ private boolean secondInvocation;
- public ActionPT (PasteType t) {
+ public ActionPT (PasteType t, String command) {
this.t = t;
+
+ ExplorerManager em = findExplorerManager ();
+ if (em != null) {
+ this.sel = new NodeSelector (em, null);
+ }
+
+ if ("synchronous".equals (command)) {
+ run ();
+ } else {
+ org.openide.util.RequestProcessor.getDefault ().post (this);
+ }
}
+
public void actionPerformed (java.awt.event.ActionEvent ev) {
- executePasteType (t);
+ try {
+ Transferable trans = t.paste();
+ Clipboard clipboard = getClipboard();
+
+
+ if (trans != null) {
+ ClipboardOwner owner = trans instanceof ClipboardOwner ?
+ (ClipboardOwner)trans
+ :
+ new StringSelection (""); // NOI18N
+ clipboard.setContents(trans, owner);
+ }
+ } catch (UserCancelException exc) {
+ // ignore - user just pressed cancel in some dialog....
+ } catch (java.io.IOException e) {
+ ErrorManager.getDefault().notify(e);
+ } finally {
+ javax.swing.SwingUtilities.invokeLater (this);
+ }
}
+
+ public void run () {
+ if (secondInvocation) {
+ if (sel != null) {
+ sel.select ();
+ }
+ } else {
+ secondInvocation = true;
+ ActionManager.getDefault ().invokeAction (
+ this,
+ new ActionEvent (t, ActionEvent.ACTION_PERFORMED, javax.swing.Action.NAME)
+ );
+ }
+ }
+
+ public boolean isEnabled () {
+ return ((PasteAction)PasteAction.get (PasteAction.class)).isEnabled ();
+ }
+
+ public Object getValue (String key) {
+ return ((PasteAction)PasteAction.get (PasteAction.class)).getValue (key);
+ }
+
}
+
}
Index: openide/src/org/openide/actions/PrintAction.java
===================================================================
RCS file: /cvs/openide/src/org/openide/actions/PrintAction.java,v
--- openide/src/org/openide/actions/PrintAction.java 3 Feb 2004 15:24:19 -0000 1.20
+++ openide/src/org/openide/actions/PrintAction.java 13 Feb 2004 17:10:47 -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: openide/src/org/openide/explorer/ExplorerActions.java
===================================================================
RCS file: /cvs/openide/src/org/openide/explorer/ExplorerActions.java,v
--- openide/src/org/openide/explorer/ExplorerActions.java 21 Nov 2003 10:51:19 -0000 1.63
+++ openide/src/org/openide/explorer/ExplorerActions.java 13 Feb 2004 17:10:47 -0000
@@ -617,12 +617,17 @@
}
doDestroy(sel);
-
- if (attachPerformers) {
- delete.setActionPerformer (null); // fixes bug #673
- } else {
- setEnabled (false);
+
+ class Run implements Runnable {
+ public void run () {
+ if (attachPerformers) {
+ delete.setActionPerformer (null); // fixes bug #673
+ } else {
+ setEnabled (false);
+ }
+ }
}
+ org.openide.util.Mutex.EVENT.readAccess (new Run ());
}
}
Index: openide/src/org/openide/util/actions/CallableSystemAction.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/actions/CallableSystemAction.java,v
--- openide/src/org/openide/util/actions/CallableSystemAction.java 6 Sep 2003 16:14:02 -0000 1.16
+++ openide/src/org/openide/util/actions/CallableSystemAction.java 13 Feb 2004 17:10:47 -0000
@@ -73,7 +73,7 @@
*/
public void actionPerformed(ActionEvent ev) {
if (isEnabled()) {
- doPerformAction(new Runnable() {
+ doPerformAction(new ActionRunnable(ev) {
public void run() {
performAction();
}
@@ -103,31 +103,12 @@
* @param r a block to run
* @see #asynchronous
*/
- final void doPerformAction(final Runnable r) {
+ final void doPerformAction(final ActionRunnable 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");
- }
+ if (asynchronous() && !r.needsToBeSynchronous ()) {
Runnable r2 = new Runnable() {
public void run() {
- try {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- MouseCursorUtils.showWaitCursor(r);
- }
- });
- //addRunningAction(r);
- r.run();
- } finally {
- //removeRunningAction(r);
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- MouseCursorUtils.hideWaitCursor(r);
- }
- });
- //fireRunningActionsChange();
- }
+ r.doRun();
}
};
RP.post(r2);
@@ -155,10 +136,55 @@
* @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");
+ /** variables for invokeAction methods */
+ private static Object invokeInstance;
+ private static Object invokeAction;
+ /** Call ActionManager.invokeAction method.
+ */
+ public static void invokeAction (javax.swing.Action action, java.awt.event.ActionEvent ev) {
+ if (invokeAction == null) {
+ ClassLoader loader = (ClassLoader)org.openide.util.Lookup.getDefault ().lookup (ClassLoader.class);
+ if (loader != null) {
+ loader = CallableSystemAction.class.getClassLoader ();
+ }
+ try {
+ Class clazz = Class.forName ("org.openide.actions.ActionManager", true, loader);
+ invokeInstance = org.openide.util.Lookup.getDefault ().lookup (clazz);
+ if (invokeInstance != null) {
+ invokeAction = clazz.getMethod ("invokeAction", new Class[] {
+ javax.swing.Action.class,
+ java.awt.event.ActionEvent.class
+ });
+ } else {
+ // dummy value
+ invokeAction = new Object ();
+ }
+ } catch (Exception ex) {
+ ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, ex);
+ // some empty value
+ invokeAction = new Object ();
+ }
+ }
+
+ if (invokeAction instanceof java.lang.reflect.Method) {
+ java.lang.reflect.Method m = (java.lang.reflect.Method)invokeAction;
+ try {
+ m.invoke (invokeInstance, new Object[] { action, ev });
+ return;
+ } catch (Exception ex) {
+ ErrorManager.getDefault ().notify (ex);
+ }
+ }
+ action.actionPerformed (ev);
+ }
+
/**
* Adds action to runningActions
map using runnable as a key.
* @param r the block being run
@@ -196,5 +222,56 @@
// whatever
}
*/
+
+ /** Special class that can be passed to invokeAction and delegates
+ * to correct values
+ */
+ abstract class ActionRunnable implements javax.swing.Action {
+ private ActionEvent ev;
+
+ public ActionRunnable (ActionEvent ev) {
+ this.ev = ev;
+ }
+
+ public final boolean needsToBeSynchronous () {
+ return "synchronous".equals (ev.getActionCommand ()); // NOI18N
+ }
+
+ public final void doRun () {
+ invokeAction (this, ev);
+ }
+
+ protected abstract void run ();
+
+ public final void actionPerformed (ActionEvent e) {
+ run ();
+ }
+
+ public final void addPropertyChangeListener (java.beans.PropertyChangeListener listener) {
+ throw new java.lang.UnsupportedOperationException ();
+ }
+
+ public final Object getValue (String key) {
+ return CallableSystemAction.this.getValue (key);
+ }
+
+ public final boolean isEnabled () {
+ return CallableSystemAction.this.isEnabled ();
+ }
+
+ public final void putValue (String key, Object value) {
+ throw new java.lang.UnsupportedOperationException ();
+ }
+
+ public final void removePropertyChangeListener (java.beans.PropertyChangeListener listener) {
+ throw new java.lang.UnsupportedOperationException ();
+ }
+
+ public final void setEnabled (boolean b) {
+ throw new java.lang.UnsupportedOperationException ();
+ }
+
+ } // end of ActionRunnable
+
}
Index: openide/src/org/openide/util/actions/CallbackSystemAction.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/actions/CallbackSystemAction.java,v
--- openide/src/org/openide/util/actions/CallbackSystemAction.java 6 Sep 2003 16:17:37 -0000 1.36
+++ openide/src/org/openide/util/actions/CallbackSystemAction.java 13 Feb 2004 17:10:47 -0000
@@ -175,7 +175,7 @@
final ActionPerformer ap = getActionPerformer ();
if (ap != null) {
- doPerformAction(new Runnable() {
+ doPerformAction(new ActionRunnable (ev) {
public void run() {
ap.performAction(CallbackSystemAction.this);
}
@@ -430,10 +430,15 @@
/** Invoked when an action occurs.
*/
- public void actionPerformed(java.awt.event.ActionEvent e) {
- javax.swing.Action a = findAction ();
+ public void actionPerformed(final java.awt.event.ActionEvent e) {
+ final javax.swing.Action a = findAction ();
if (a != null) {
- a.actionPerformed(e);
+ ActionRunnable run = delegate.new ActionRunnable (e) {
+ public void run () {
+ a.actionPerformed(e);
+ }
+ };
+ delegate.doPerformAction (run);
} else {
// XXX #30303 if the action falls back to the old behaviour
// it may not be performed in case it is in dialog and
Index: openide/src/org/openide/util/actions/MouseCursorUtils.java
===================================================================
RCS file: openide/src/org/openide/util/actions/MouseCursorUtils.java
--- openide/src/org/openide/util/actions/MouseCursorUtils.java 25 Aug 2003 21:50:28 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,127 +0,0 @@
-/*
- * 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-2003 Sun
- * Microsystems, Inc. All Rights Reserved.
- */
-
-package org.openide.util.actions;
-
-import java.awt.Component;
-import java.awt.Cursor;
-import java.awt.EventQueue;
-import java.awt.KeyboardFocusManager;
-import java.awt.Window;
-import java.util.HashMap;
-import java.util.Map;
-import javax.swing.RootPaneContainer;
-import org.openide.ErrorManager;
-import org.openide.util.Utilities;
-
-/**
- * Static utility class for setting/resetting mouse cursor on surface of
- * whatever window (e.g. main window) is associated with events.
- * Event thread only.
- * @author David Simonek, Jesse Glick
- * @see "#27780"
- */
-final class MouseCursorUtils {
-
- private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.openide.util.actions.MouseCursorUtils"); // NOI18N
-
- private MouseCursorUtils() {}
-
- /**
- * Running show/hide count for glass panes in use.
- * Maps arbitrary keys to glass panes.
- * Several keys may map to the same glass pane - the wait cursor is shown
- * so long as there are any.
- */
- private static final Map glassPaneUses = new HashMap(); // Map