Index: FileCommandAction.java =================================================================== RCS file: /cvs/projects/projectui/src/org/netbeans/modules/project/ui/actions/FileCommandAction.java,v retrieving revision 1.14 diff -u -r1.14 FileCommandAction.java --- FileCommandAction.java 30 Jun 2006 21:27:22 -0000 1.14 +++ FileCommandAction.java 23 Apr 2007 06:07:59 -0000 @@ -19,25 +19,26 @@ package org.netbeans.modules.project.ui.actions; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import javax.swing.Action; import javax.swing.Icon; import javax.swing.ImageIcon; -import javax.swing.JMenuItem; import org.netbeans.api.project.Project; import org.netbeans.spi.project.ActionProvider; import org.openide.awt.Actions; -import org.openide.awt.Mnemonics; import org.openide.filesystems.FileObject; import org.openide.util.Lookup; import org.openide.util.Utilities; -import org.openide.util.actions.Presenter; /** An action sensitive to selected node. Used for 1-off actions */ public final class FileCommandAction extends ProjectAction { private String presenterName; - + private Collection providers = new ArrayList(); + public FileCommandAction( String command, String namePattern, String iconResource, Lookup lookup ) { this( command, namePattern, new ImageIcon( Utilities.loadImage( iconResource ) ), lookup ); } @@ -48,14 +49,32 @@ presenterName = ActionsUtil.formatName( getNamePattern(), 0, "" ); setDisplayName( presenterName ); putValue(SHORT_DESCRIPTION, Actions.cutAmpersand(presenterName)); + + Collection registeredProviders = Lookup.getDefault().lookupAll(ActionProvider.class); + for (ActionProvider p : registeredProviders) { + if (Arrays.asList(p.getSupportedActions()).contains(command)) { + providers.add(p); + } + } } protected void refresh( Lookup context ) { Project[] projects = ActionsUtil.getProjectsFromLookup( context, getCommand() ); if ( projects.length != 1 ) { - setEnabled( false ); // Zero or more than one projects found or command not supported - presenterName = ActionsUtil.formatName( getNamePattern(), 0, "" ); + boolean supportedByProvider = false; + for (ActionProvider provider : providers) { + if (provider.isActionEnabled(getCommand(), context)) { + setEnabled( true ); + presenterName = ActionsUtil.formatName( getNamePattern(), 0, "" ); + supportedByProvider = true; + break; + } + } + if (!supportedByProvider) { + setEnabled( false ); // Zero or more than one projects found or command not supported + presenterName = ActionsUtil.formatName( getNamePattern(), 0, "" ); + } } else { FileObject[] files = ActionsUtil.getFilesFromLookup( context, projects[0] ); @@ -75,8 +94,15 @@ if ( projects.length == 1 ) { ActionProvider ap = (ActionProvider)projects[0].getLookup().lookup( ActionProvider.class ); ap.invokeAction( getCommand(), context ); + return; + } + + for (ActionProvider provider : providers) { + if (provider.isActionEnabled(getCommand(), context)) { + provider.invokeAction(getCommand(), context); + return; + } } - } Index: src/org/netbeans/spi/project/ActionProvider.java =================================================================== RCS file: /cvs/projects/projectapi/src/org/netbeans/spi/project/ActionProvider.java,v retrieving revision 1.12 diff -u -r1.12 ActionProvider.java --- src/org/netbeans/spi/project/ActionProvider.java 13 Feb 2007 20:19:35 -0000 1.12 +++ src/org/netbeans/spi/project/ActionProvider.java 23 Apr 2007 06:10:17 -0000 @@ -24,6 +24,12 @@ /** * Ability for a project to have various actions (e.g. Build) invoked on it. * Should be registered in a project's lookup and will be used by UI infrastructure. + *

+ * Implementations supporting single file commands (command constants ending with + * "_SINGLE") can also be registered in default lookup. If ActionProvider in project + * lookup does not enable the action for a given command on the selected file then + * first implementation found in default lookup that is enabled will be used. + *

* @see org.netbeans.api.project.Project#getLookup * @see ActionUtils * @see ProjectSensitiveActions.projectCommandAction(...)