1.1 --- a/openide.util/src/org/openide/util/actions/CallableSystemAction.java Wed Jan 27 17:46:23 2010 -0500
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,164 +0,0 @@
1.4 -/*
1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 - *
1.7 - * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
1.8 - *
1.9 - * The contents of this file are subject to the terms of either the GNU
1.10 - * General Public License Version 2 only ("GPL") or the Common
1.11 - * Development and Distribution License("CDDL") (collectively, the
1.12 - * "License"). You may not use this file except in compliance with the
1.13 - * License. You can obtain a copy of the License at
1.14 - * http://www.netbeans.org/cddl-gplv2.html
1.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
1.16 - * specific language governing permissions and limitations under the
1.17 - * License. When distributing the software, include this License Header
1.18 - * Notice in each file and include the License file at
1.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
1.20 - * particular file as subject to the "Classpath" exception as provided
1.21 - * by Sun in the GPL Version 2 section of the License file that
1.22 - * accompanied this code. If applicable, add the following below the
1.23 - * License Header, with the fields enclosed by brackets [] replaced by
1.24 - * your own identifying information:
1.25 - * "Portions Copyrighted [year] [name of copyright owner]"
1.26 - *
1.27 - * Contributor(s):
1.28 - *
1.29 - * The Original Software is NetBeans. The Initial Developer of the Original
1.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
1.31 - * Microsystems, Inc. All Rights Reserved.
1.32 - *
1.33 - * If you wish your version of this file to be governed by only the CDDL
1.34 - * or only the GPL Version 2, indicate your decision by adding
1.35 - * "[Contributor] elects to include this software in this distribution
1.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
1.37 - * single choice of license, a recipient has the option to distribute
1.38 - * your version of this file under either the CDDL, the GPL Version 2 or
1.39 - * to extend the choice of license to its licensees as provided above.
1.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
1.41 - * Version 2 license, then the option applies only if the new code is
1.42 - * made subject to such option by the copyright holder.
1.43 - */
1.44 -
1.45 -package org.openide.util.actions;
1.46 -
1.47 -import java.awt.Toolkit;
1.48 -import java.awt.event.ActionEvent;
1.49 -import java.util.Set;
1.50 -import java.util.logging.Logger;
1.51 -import org.openide.util.WeakSet;
1.52 -
1.53 -/** Not preferred anymore, use <a href="@org-openide-awt@/org/openide/awt/Actions.html#alwaysEnabled(java.awt.event.ActionListener,%20java.lang.String,%20java.lang.String,%20boolean)">Actions.alwaysEnabled</a>
1.54 -* instead. To migrate your
1.55 -* <a href="@org-openide-modules@/org/openide/modules/doc-files/api.html#how-layer">
1.56 -* layer definition</a> use:
1.57 -* <pre>
1.58 -* <file name="your-pkg-action-id.instance">
1.59 -* <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
1.60 -* <attr name="delegate" methodvalue="your.pkg.YourAction.factoryMethod"/>
1.61 -* <attr name="displayName" bundlevalue="your.pkg.Bundle#key"/>
1.62 -* <attr name="iconBase" stringvalue="your/pkg/YourImage.png"/>
1.63 -* <!-- if desired: <attr name="noIconInMenu" boolvalue="false"/> -->
1.64 -* </file>
1.65 -* </pre>
1.66 -*
1.67 -* @author Ian Formanek, Jaroslav Tulach, Jan Jancura, Petr Hamernik
1.68 -*/
1.69 -public abstract class CallableSystemAction extends SystemAction implements Presenter.Menu, Presenter.Popup,
1.70 - Presenter.Toolbar {
1.71 - /** serialVersionUID */
1.72 - static final long serialVersionUID = 2339794599168944156L;
1.73 -
1.74 - // ASYNCHRONICITY
1.75 - // Adapted from org.netbeans.core.ModuleActions by jglick
1.76 -
1.77 - /**
1.78 - * Set of action classes for which we have already issued a warning that
1.79 - * {@link #asynchronous} was not overridden to return false.
1.80 - */
1.81 - private static final Set<Class> warnedAsynchronousActions = new WeakSet<Class>();
1.82 - private static final boolean DEFAULT_ASYNCH = !Boolean.getBoolean(
1.83 - "org.openide.util.actions.CallableSystemAction.synchronousByDefault"
1.84 - );
1.85 -
1.86 - /* Returns a JMenuItem that presents the Action, that implements this
1.87 - * interface, in a MenuBar.
1.88 - * @return the JMenuItem representation for the Action
1.89 - */
1.90 - public javax.swing.JMenuItem getMenuPresenter() {
1.91 - return org.openide.util.actions.ActionPresenterProvider.getDefault().createMenuPresenter(this);
1.92 - }
1.93 -
1.94 - /* Returns a JMenuItem that presents the Action, that implements this
1.95 - * interface, in a Popup Menu.
1.96 - * @return the JMenuItem representation for the Action
1.97 - */
1.98 - public javax.swing.JMenuItem getPopupPresenter() {
1.99 - return org.openide.util.actions.ActionPresenterProvider.getDefault().createPopupPresenter(this);
1.100 - }
1.101 -
1.102 - /* Returns a Component that presents the Action, that implements this
1.103 - * interface, in a ToolBar.
1.104 - * @return the Component representation for the Action
1.105 - */
1.106 - public java.awt.Component getToolbarPresenter() {
1.107 - return org.openide.util.actions.ActionPresenterProvider.getDefault().createToolbarPresenter(this);
1.108 - }
1.109 -
1.110 - /** Actually perform the action.
1.111 - * This is the method which should be called programmatically.
1.112 - * Presenters in <a href="@org-openide-awt@/org/openide/awt/Actions.html">Actions</a> use this.
1.113 - * <p>See {@link SystemAction#actionPerformed} for a note on
1.114 - * threading usage: in particular, do not access GUI components
1.115 - * without explicitly asking for the AWT event thread!
1.116 - */
1.117 - public abstract void performAction();
1.118 -
1.119 - /* Implementation of method of javax.swing.Action interface.
1.120 - * Delegates the execution to performAction method.
1.121 - *
1.122 - * @param ev the action event
1.123 - */
1.124 - public void actionPerformed(ActionEvent ev) {
1.125 - if (isEnabled()) {
1.126 - org.openide.util.actions.ActionInvoker.invokeAction(
1.127 - this, ev, asynchronous(), new Runnable() {
1.128 - public void run() {
1.129 - performAction();
1.130 - }
1.131 - }
1.132 - );
1.133 - } else {
1.134 - // Should not normally happen.
1.135 - Toolkit.getDefaultToolkit().beep();
1.136 - }
1.137 - }
1.138 -
1.139 - /**
1.140 - * If true, this action should be performed asynchronously in a private thread.
1.141 - * If false, it will be performed synchronously as called in the event thread.
1.142 - * <p>The default value is true for compatibility reasons; subclasses are strongly
1.143 - * encouraged to override it to be false, and to either do their work promptly
1.144 - * in the event thread and return, or to somehow do work asynchronously (for example
1.145 - * using {@link org.openide.util.RequestProcessor#getDefault}).
1.146 - * <p class="nonnormative">You may currently set the global default to false
1.147 - * by setting the system property
1.148 - * <code>org.openide.util.actions.CallableSystemAction.synchronousByDefault</code>
1.149 - * to <code>true</code>.</p>
1.150 - * <p class="nonnormative">When true, the current implementation also provides for a wait cursor during
1.151 - * the execution of the action. Subclasses which override to return false should
1.152 - * consider directly providing a wait or busy cursor if the nature of the action
1.153 - * merits it.</p>
1.154 - * @return true if this action should automatically be performed asynchronously
1.155 - * @since 4.11
1.156 - */
1.157 - protected boolean asynchronous() {
1.158 - if (warnedAsynchronousActions.add(getClass())) {
1.159 - Logger.getLogger(CallableSystemAction.class.getName()).warning(
1.160 - "Warning - " + getClass().getName() +
1.161 - " should override CallableSystemAction.asynchronous() to return false"
1.162 - );
1.163 - }
1.164 -
1.165 - return DEFAULT_ASYNCH;
1.166 - }
1.167 -}