diff -r 83b2e27bd0c0 spi.viewmodel/apichanges.xml
--- a/spi.viewmodel/apichanges.xml Wed Sep 23 19:19:19 2009 +0200
+++ b/spi.viewmodel/apichanges.xml Wed Sep 23 23:10:03 2009 +0200
@@ -337,7 +337,21 @@
-
+
+
+ Introduction of AsynchronousModelFilter.
+
+
+
+
+
+ This API introduced AsynchronousModelFilter that
+ can be used by clients to override the default threading of their model implementations.
+
+
+
+
+
diff -r 83b2e27bd0c0 spi.viewmodel/manifest.mf
--- a/spi.viewmodel/manifest.mf Wed Sep 23 19:19:19 2009 +0200
+++ b/spi.viewmodel/manifest.mf Wed Sep 23 23:10:03 2009 +0200
@@ -1,5 +1,5 @@
Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.spi.viewmodel/2
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/viewmodel/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.19
+OpenIDE-Module-Specification-Version: 1.20
diff -r 83b2e27bd0c0 spi.viewmodel/src/org/netbeans/spi/viewmodel/AsynchronousModelFilter.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spi.viewmodel/src/org/netbeans/spi/viewmodel/AsynchronousModelFilter.java Wed Sep 23 23:10:03 2009 +0200
@@ -0,0 +1,111 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2009 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.spi.viewmodel;
+
+import java.util.concurrent.Executor;
+
+import org.openide.util.RequestProcessor;
+
+/**
+ * Change threading of implemented models.
+ * Methods implemented in {@link TreeModel}, {@link NodeModel} ({@link ExtendedNodeModel})
+ * and {@link TableModel} can be called synchronously in AWT thread as a direct
+ * response to user action (this is the default behavior),
+ * or asynchronously in a Request Processor or other thread.
+ * Register an implementation of this along with other models,
+ * if you need to change the original threading.
+ *
+ * @author Martin Entlicher
+ * @since 1.20
+ */
+public interface AsynchronousModelFilter extends Model {
+
+ /**
+ * This enumeration identifies method(s) of view models for which
+ * threading information is provided by
+ * {@link #asynchronous(java.util.concurrent.Executor, org.netbeans.spi.viewmodel.AsynchronousModelFilter.CALL, java.lang.Object)} method.
+ *
+ * DISPLAY_NAME is for NodeModel.getDisplayName() and ExtendedNodeModel.setName()
+ *
+ * SHORT_DESCRIPTION for NodeModel.getShortDescription()
+ *
+ * VALUE for TableModel.getValueAt() and TableModel.setValueAt()
+ *
+ * CHILDREN for TreeModel.getChildrenCount() and TreeModel.getChildren()
+ *
+ * The rest of the methods on models are called synchronously, or additional enums can be added.
+ */
+ static enum CALL { DISPLAY_NAME, SHORT_DESCRIPTION, VALUE, CHILDREN }
+
+ /**
+ * Executor for invocation of models method calls in the current thread.
+ * This will make method invocation synchronous. It's important that the
+ * methods execute fast so that they do not block AWT thread.
+ * This is the default executor.
+ */
+ static final Executor CURRENT_THREAD = new Executor() {
+
+ public void execute(Runnable command) {
+ command.run();
+ }
+
+ };
+
+ /**
+ * Executor, which uses a shared {@link RequestProcessor} with
+ * throughoutput = 1 for models method calls, making the method invocation
+ * asynchronous. The UI gives a visual feedback to the user if models method
+ * calls take a long time. Use this to keep the UI responsive.
+ */
+ static final Executor DEFAULT = new RequestProcessor("Asynchronous view model", 1); // NOI18N
+
+ /**
+ * Change the threading information for view models method calls.
+ * The returned ThreadingInfo gives information about the threading
+ * of method calls identified by {@link CALL} enum.
+ *
+ * @param original The original {@link Executor}
+ * @param asynchCall Identification of the method call
+ * @param node Object node
+ * @return an instance of ThreadingInfo
+ */
+ Executor asynchronous(Executor original, CALL asynchCall, Object node) throws UnknownTypeException;
+
+}
diff -r 83b2e27bd0c0 spi.viewmodel/src/org/netbeans/spi/viewmodel/Models.java
--- a/spi.viewmodel/src/org/netbeans/spi/viewmodel/Models.java Wed Sep 23 19:19:19 2009 +0200
+++ b/spi.viewmodel/src/org/netbeans/spi/viewmodel/Models.java Wed Sep 23 23:10:03 2009 +0200
@@ -57,6 +57,7 @@
import java.util.List;
import java.util.Set;
import java.util.WeakHashMap;
+import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
@@ -64,11 +65,13 @@
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
+import org.netbeans.modules.viewmodel.AsynchronousModel;
import org.netbeans.modules.viewmodel.DefaultTreeExpansionManager;
import org.netbeans.modules.viewmodel.HyperCompoundModel;
import org.netbeans.modules.viewmodel.OutlineTable;
import org.netbeans.modules.viewmodel.TreeModelRoot;
+import org.netbeans.spi.viewmodel.AsynchronousModelFilter.CALL;
import org.openide.awt.Actions;
import org.openide.explorer.view.TreeView;
import org.openide.nodes.Node;
@@ -87,7 +90,7 @@
/** Cached default implementations of expansion models. */
private static final WeakHashMap