1.1 --- a/openide.util/arch.xml Fri Jun 03 01:07:03 2005 +0000
1.2 +++ b/openide.util/arch.xml Sat Jun 04 05:10:39 2005 +0000
1.3 @@ -500,8 +500,9 @@
1.4 <api category="devel" group="java" name="Lookups.metaInfServices" type="export" url="@TOP@/org/openide/util/lookup/Lookups.html#metaInfServices(java.lang.ClassLoader)">
1.5 calls constructor of registered classes using reflection
1.6 </api>.
1.7 - <api category="private" group="java" name="ActionManagerInvocation" type="import" >
1.8 - because of the API separation, <a href="@TOP@/org/openide/util/actions/CallableSystemAction.html">CallableSystemAction</a> uses reflection
1.9 + <api category="private" group="lookup" name="ActionManagerInvocation" type="export" >
1.10 + because of the API separation, <a href="@TOP@/org/openide/util/actions/CallableSystemAction.html">CallableSystemAction</a> uses lookup for <code>ActionsBridge</code>
1.11 + provided by <code>org-openide-actions</code> module
1.12 when looking for <a href="@org-openide-actions@/org/openide/actions/ActionManager.html">org.openide.actions.ActionManager</a> implementation.
1.13 </api>.
1.14
2.1 --- a/openide.util/nbproject/project.xml Fri Jun 03 01:07:03 2005 +0000
2.2 +++ b/openide.util/nbproject/project.xml Sat Jun 04 05:10:39 2005 +0000
2.3 @@ -17,17 +17,6 @@
2.4 <data xmlns="http://www.netbeans.org/ns/nb-module-project/2">
2.5 <code-name-base>org.openide.util</code-name-base>
2.6 <module-dependencies>
2.7 - <!--
2.8 - <dependency>
2.9 - <code-name-base>org.openide</code-name-base>
2.10 - <build-prerequisite/>
2.11 - <compile-dependency/>
2.12 - <run-dependency>
2.13 - <release-version>1</release-version>
2.14 - <specification-version>4.48</specification-version>
2.15 - </run-dependency>
2.16 - </dependency>
2.17 - -->
2.18 </module-dependencies>
2.19 <public-packages>
2.20 <package>org.openide</package>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/openide.util/src/org/netbeans/modules/openide/util/ActionsBridge.java Sat Jun 04 05:10:39 2005 +0000
3.3 @@ -0,0 +1,109 @@
3.4 +/*
3.5 + * Sun Public License Notice
3.6 + *
3.7 + * The contents of this file are subject to the Sun Public License
3.8 + * Version 1.0 (the "License"). You may not use this file except in
3.9 + * compliance with the License. A copy of the License is available at
3.10 + * http://www.sun.com/
3.11 + *
3.12 + * The Original Code is NetBeans. The Initial Developer of the Original
3.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
3.14 + * Microsystems, Inc. All Rights Reserved.
3.15 + */
3.16 +
3.17 +package org.netbeans.modules.openide.util;
3.18 +
3.19 +import java.awt.event.ActionEvent;
3.20 +
3.21 +import org.openide.ErrorManager;
3.22 +import org.openide.util.RequestProcessor;
3.23 +import org.openide.util.actions.CallableSystemAction;
3.24 +
3.25 +/** Allows Node action to get access to special tricks in CallableSystemAction.
3.26 + */
3.27 +public abstract class ActionsBridge extends Object {
3.28 + /** thread to run actions in */
3.29 + private static RequestProcessor RP = new RequestProcessor("Module-Actions", Integer.MAX_VALUE); // NOI18N
3.30 +
3.31 +
3.32 + /** Invokes an action.
3.33 + */
3.34 + protected abstract void invokeAction (javax.swing.Action action, java.awt.event.ActionEvent ev);
3.35 +
3.36 + public static void doPerformAction(CallableSystemAction action, final org.netbeans.modules.openide.util.ActionsBridge.ActionRunnable r) {
3.37 + assert java.awt.EventQueue.isDispatchThread() : "Action " + action.getClass().getName() +
3.38 + " may not be invoked from the thread " + Thread.currentThread().getName() +
3.39 + ", only the event queue: http://www.netbeans.org/download/4_1/javadoc/OpenAPIs/apichanges.html#actions-event-thread";
3.40 +
3.41 + if (r.async && !r.needsToBeSynchronous()) {
3.42 + Runnable r2 = new Runnable() {
3.43 + public void run() {
3.44 + r.doRun();
3.45 + }
3.46 + };
3.47 +
3.48 + RP.post(r2);
3.49 + } else {
3.50 + r.run();
3.51 + }
3.52 + }
3.53 +
3.54 + /** Special class that can be passed to invokeAction and delegates
3.55 + * to correct values
3.56 + */
3.57 + public static abstract class ActionRunnable implements javax.swing.Action {
3.58 + final ActionEvent ev;
3.59 + final org.openide.util.actions.SystemAction action;
3.60 + final boolean async;
3.61 +
3.62 + public ActionRunnable(ActionEvent ev, org.openide.util.actions.SystemAction action, boolean async) {
3.63 + this.ev = ev;
3.64 + this.action = action;
3.65 + this.async = async;
3.66 + }
3.67 +
3.68 + public final boolean needsToBeSynchronous() {
3.69 + return "waitFinished".equals(ev.getActionCommand()); // NOI18N
3.70 + }
3.71 +
3.72 + public final void doRun() {
3.73 + ActionsBridge bridge = (ActionsBridge)org.openide.util.Lookup.getDefault().lookup (ActionsBridge.class);
3.74 + if (bridge != null) {
3.75 + bridge.invokeAction (this, ev);
3.76 + } else {
3.77 + this.actionPerformed(ev);
3.78 + }
3.79 + }
3.80 +
3.81 + protected abstract void run();
3.82 +
3.83 + public final void actionPerformed(ActionEvent e) {
3.84 + run();
3.85 + }
3.86 +
3.87 + public final void addPropertyChangeListener(java.beans.PropertyChangeListener listener) {
3.88 + throw new java.lang.UnsupportedOperationException();
3.89 + }
3.90 +
3.91 + public final Object getValue(String key) {
3.92 + return action.getValue(key);
3.93 + }
3.94 +
3.95 + public final boolean isEnabled() {
3.96 + return action.isEnabled();
3.97 + }
3.98 +
3.99 + public final void putValue(String key, Object value) {
3.100 + throw new java.lang.UnsupportedOperationException();
3.101 + }
3.102 +
3.103 + public final void removePropertyChangeListener(java.beans.PropertyChangeListener listener) {
3.104 + throw new java.lang.UnsupportedOperationException();
3.105 + }
3.106 +
3.107 + public final void setEnabled(boolean b) {
3.108 + throw new java.lang.UnsupportedOperationException();
3.109 + }
3.110 + }
3.111 + // end of ActionRunnable
3.112 +}
4.1 --- a/openide.util/src/org/openide/util/actions/CallableSystemAction.java Fri Jun 03 01:07:03 2005 +0000
4.2 +++ b/openide.util/src/org/openide/util/actions/CallableSystemAction.java Sat Jun 04 05:10:39 2005 +0000
4.3 @@ -43,15 +43,10 @@
4.4 * {@link #asynchronous} was not overridden to return false.
4.5 */
4.6 private static final Set warnedAsynchronousActions = new WeakSet(); // Set<Class>
4.7 - private static RequestProcessor RP = new RequestProcessor("Module-Actions", Integer.MAX_VALUE); // NOI18N
4.8 private static final boolean DEFAULT_ASYNCH = !Boolean.getBoolean(
4.9 "org.openide.util.actions.CallableSystemAction.synchronousByDefault"
4.10 );
4.11
4.12 - /** variables for invokeAction methods */
4.13 - private static Object invokeInstance;
4.14 - private static Object invokeAction;
4.15 -
4.16 /* Returns a JMenuItem that presents the Action, that implements this
4.17 * interface, in a MenuBar.
4.18 * @return the JMenuItem representation for the Action
4.19 @@ -92,8 +87,9 @@
4.20 */
4.21 public void actionPerformed(ActionEvent ev) {
4.22 if (isEnabled()) {
4.23 - doPerformAction(
4.24 - new ActionRunnable(ev) {
4.25 + org.netbeans.modules.openide.util.ActionsBridge.doPerformAction(
4.26 + this,
4.27 + new org.netbeans.modules.openide.util.ActionsBridge.ActionRunnable(ev, this, asynchronous()) {
4.28 public void run() {
4.29 performAction();
4.30 }
4.31 @@ -105,24 +101,6 @@
4.32 }
4.33 }
4.34
4.35 - final void doPerformAction(final ActionRunnable r) {
4.36 - assert EventQueue.isDispatchThread() : "Action " + getClass().getName() +
4.37 - " may not be invoked from the thread " + Thread.currentThread().getName() +
4.38 - ", only the event queue: http://www.netbeans.org/download/dev/javadoc/OpenAPIs/apichanges.html#actions-event-thread";
4.39 -
4.40 - if (asynchronous() && !r.needsToBeSynchronous()) {
4.41 - Runnable r2 = new Runnable() {
4.42 - public void run() {
4.43 - r.doRun();
4.44 - }
4.45 - };
4.46 -
4.47 - RP.post(r2);
4.48 - } else {
4.49 - r.run();
4.50 - }
4.51 - }
4.52 -
4.53 /**
4.54 * If true, this action should be performed asynchronously in a private thread.
4.55 * If false, it will be performed synchronously as called in the event thread.
4.56 @@ -152,136 +130,4 @@
4.57
4.58 return DEFAULT_ASYNCH;
4.59 }
4.60 -
4.61 - /** Call ActionManager.invokeAction method.
4.62 - */
4.63 - private static void invokeAction(javax.swing.Action action, java.awt.event.ActionEvent ev) {
4.64 - if (invokeAction == null) {
4.65 - ClassLoader loader = (ClassLoader) org.openide.util.Lookup.getDefault().lookup(ClassLoader.class);
4.66 -
4.67 - if (loader == null) {
4.68 - loader = CallableSystemAction.class.getClassLoader();
4.69 - }
4.70 -
4.71 - try {
4.72 - Class clazz = Class.forName("org.openide.actions.ActionManager", true, loader);
4.73 - invokeInstance = org.openide.util.Lookup.getDefault().lookup(clazz);
4.74 -
4.75 - if (invokeInstance != null) {
4.76 - invokeAction = clazz.getMethod(
4.77 - "invokeAction", new Class[] { javax.swing.Action.class, java.awt.event.ActionEvent.class }
4.78 - );
4.79 - } else {
4.80 - // dummy value
4.81 - invokeAction = new Object();
4.82 - }
4.83 - } catch (Exception ex) {
4.84 - ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
4.85 -
4.86 - // some empty value
4.87 - invokeAction = new Object();
4.88 - }
4.89 - }
4.90 -
4.91 - if (invokeAction instanceof java.lang.reflect.Method) {
4.92 - java.lang.reflect.Method m = (java.lang.reflect.Method) invokeAction;
4.93 -
4.94 - try {
4.95 - m.invoke(invokeInstance, new Object[] { action, ev });
4.96 -
4.97 - return;
4.98 - } catch (Exception ex) {
4.99 - ErrorManager.getDefault().notify(ex);
4.100 - }
4.101 - }
4.102 -
4.103 - action.actionPerformed(ev);
4.104 - }
4.105 -
4.106 - /**
4.107 - * Adds action to <code>runningActions</code> map using runnable as a key.
4.108 - * @param r the block being run
4.109 - * /
4.110 - private void addRunningAction(Runnable r) {
4.111 - synchronized (runningActions) {
4.112 - runningActions.put(r, this);
4.113 - }
4.114 - }
4.115 -
4.116 - /**
4.117 - * Removes action from <code>runningActions</code> map.
4.118 - * @param r the block just run
4.119 - * /
4.120 - private void removeRunningAction(Runnable r) {
4.121 - synchronized (runningActions) {
4.122 - runningActions.remove(r);
4.123 - }
4.124 - }
4.125 -
4.126 - /** Gets collection of currently running actions. * /
4.127 - public static Collection getRunningActions() {
4.128 - synchronized (runningActions) {
4.129 - return new HashSet(runningActions.values());
4.130 - }
4.131 - }
4.132 -
4.133 - /** Tries to stop all processors executing currently running
4.134 - * action tasks. * /
4.135 - public static void killRunningActions() {
4.136 - RP.stop();
4.137 - }
4.138 -
4.139 - private static void fireRunningActionsChange() {
4.140 - // whatever
4.141 - }
4.142 - */
4.143 - /** Special class that can be passed to invokeAction and delegates
4.144 - * to correct values
4.145 - */
4.146 - abstract class ActionRunnable implements javax.swing.Action {
4.147 - private ActionEvent ev;
4.148 -
4.149 - public ActionRunnable(ActionEvent ev) {
4.150 - this.ev = ev;
4.151 - }
4.152 -
4.153 - public final boolean needsToBeSynchronous() {
4.154 - return "waitFinished".equals(ev.getActionCommand()); // NOI18N
4.155 - }
4.156 -
4.157 - public final void doRun() {
4.158 - invokeAction(this, ev);
4.159 - }
4.160 -
4.161 - protected abstract void run();
4.162 -
4.163 - public final void actionPerformed(ActionEvent e) {
4.164 - run();
4.165 - }
4.166 -
4.167 - public final void addPropertyChangeListener(java.beans.PropertyChangeListener listener) {
4.168 - throw new java.lang.UnsupportedOperationException();
4.169 - }
4.170 -
4.171 - public final Object getValue(String key) {
4.172 - return CallableSystemAction.this.getValue(key);
4.173 - }
4.174 -
4.175 - public final boolean isEnabled() {
4.176 - return CallableSystemAction.this.isEnabled();
4.177 - }
4.178 -
4.179 - public final void putValue(String key, Object value) {
4.180 - throw new java.lang.UnsupportedOperationException();
4.181 - }
4.182 -
4.183 - public final void removePropertyChangeListener(java.beans.PropertyChangeListener listener) {
4.184 - throw new java.lang.UnsupportedOperationException();
4.185 - }
4.186 -
4.187 - public final void setEnabled(boolean b) {
4.188 - throw new java.lang.UnsupportedOperationException();
4.189 - }
4.190 - }
4.191 - // end of ActionRunnable
4.192 }
5.1 --- a/openide.util/src/org/openide/util/actions/CallbackSystemAction.java Fri Jun 03 01:07:03 2005 +0000
5.2 +++ b/openide.util/src/org/openide/util/actions/CallbackSystemAction.java Sat Jun 04 05:10:39 2005 +0000
5.3 @@ -193,8 +193,9 @@
5.4 final ActionPerformer ap = getActionPerformer();
5.5
5.6 if (ap != null) {
5.7 - doPerformAction(
5.8 - new ActionRunnable(ev) {
5.9 + org.netbeans.modules.openide.util.ActionsBridge.doPerformAction(
5.10 + this,
5.11 + new org.netbeans.modules.openide.util.ActionsBridge.ActionRunnable(ev, this, asynchronous ()) {
5.12 public void run() {
5.13 ap.performAction(CallbackSystemAction.this);
5.14 }
5.15 @@ -546,13 +547,14 @@
5.16 final javax.swing.Action a = findAction();
5.17
5.18 if (a != null) {
5.19 - ActionRunnable run = delegate.new ActionRunnable(e) {
5.20 + org.netbeans.modules.openide.util.ActionsBridge.ActionRunnable run;
5.21 + run = new org.netbeans.modules.openide.util.ActionsBridge.ActionRunnable(e, delegate, delegate.asynchronous()) {
5.22 public void run() {
5.23 a.actionPerformed(e);
5.24 }
5.25 };
5.26
5.27 - delegate.doPerformAction(run);
5.28 + org.netbeans.modules.openide.util.ActionsBridge.doPerformAction(delegate, run);
5.29 } else {
5.30 // XXX #30303 if the action falls back to the old behaviour
5.31 // it may not be performed in case it is in dialog and
6.1 --- a/openide.util/test/build.xml Fri Jun 03 01:07:03 2005 +0000
6.2 +++ b/openide.util/test/build.xml Sat Jun 04 05:10:39 2005 +0000
6.3 @@ -22,9 +22,11 @@
6.4 <property name="xtest.testtype" value="unit"/>
6.5 <property name="xtest.attribs" value="stable"/>
6.6
6.7 - <target name="buildtests" >
6.8 + <target name="build-data" >
6.9 <ant dir="unit/src/org/openide/util/data"/>
6.10 - <antcall target="xtest.buildtests" />
6.11 + </target>
6.12 +
6.13 + <target name="buildtests" depends="build-data,xtest.buildtests" >
6.14 </target>
6.15
6.16 <target name="cleantests" depends="xtest.cleantests" >