#168547: Support for asynchrounous declarative actions and its usage in 'delete' callback action
authorJaroslav Tulach <jtulach@netbeans.org>
Mon, 27 Jul 2009 21:41:39 +0200
changeset 806a5f4f72fac68
parent 805 a8a3ba796802
child 807 51a1c9914d38
#168547: Support for asynchrounous declarative actions and its usage in 'delete' callback action
openide.util/src/org/netbeans/modules/openide/util/ActionsBridge.java
     1.1 --- a/openide.util/src/org/netbeans/modules/openide/util/ActionsBridge.java	Thu Jul 23 11:28:31 2009 -0400
     1.2 +++ b/openide.util/src/org/netbeans/modules/openide/util/ActionsBridge.java	Mon Jul 27 21:41:39 2009 +0200
     1.3 @@ -61,6 +61,12 @@
     1.4      protected abstract void invokeAction(Action action, ActionEvent ev);
     1.5  
     1.6      public static void doPerformAction(CallableSystemAction action, final ActionsBridge.ActionRunnable r) {
     1.7 +        implPerformAction(action, r);
     1.8 +    }
     1.9 +    public static void doPerformAction(Action action, final ActionsBridge.ActionRunnable r) {
    1.10 +        implPerformAction(action, r);
    1.11 +    }
    1.12 +    private static void implPerformAction(Action action, final ActionsBridge.ActionRunnable r) {
    1.13          assert java.awt.EventQueue.isDispatchThread() : "Action " + action.getClass().getName() +
    1.14          " may not be invoked from the thread " + Thread.currentThread().getName() +
    1.15          ", only the event queue: http://www.netbeans.org/download/4_1/javadoc/OpenAPIs/apichanges.html#actions-event-thread";
    1.16 @@ -83,15 +89,27 @@
    1.17       */
    1.18      public static abstract class ActionRunnable implements Action {
    1.19          final ActionEvent ev;
    1.20 -        final SystemAction action;
    1.21 +        final Action action;
    1.22          final boolean async;
    1.23  
    1.24          public ActionRunnable(ActionEvent ev, SystemAction action, boolean async) {
    1.25 +            this(ev, (Action)action, async);
    1.26 +        }
    1.27 +        public ActionRunnable(ActionEvent ev, Action action, boolean async) {
    1.28              this.ev = ev;
    1.29              this.action = action;
    1.30              this.async = async;
    1.31          }
    1.32  
    1.33 +        public static ActionRunnable create(ActionEvent ev, Action a, boolean async) {
    1.34 +            return new ActionRunnable(ev, a, async) {
    1.35 +                @Override
    1.36 +                protected void run() {
    1.37 +                    action.actionPerformed(ev);
    1.38 +                }
    1.39 +            };
    1.40 +        }
    1.41 +
    1.42          public final boolean needsToBeSynchronous() {
    1.43              return "waitFinished".equals(ev.getActionCommand()); // NOI18N
    1.44          }