This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 102081
Collapse All | Expand All

(-)a/projectapi/src/org/netbeans/spi/project/ActionProvider.java (+6 lines)
Lines 46-51 Link Here
46
/**
46
/**
47
 * Ability for a project to have various actions (e.g. Build) invoked on it.
47
 * Ability for a project to have various actions (e.g. Build) invoked on it.
48
 * Should be registered in a project's lookup and will be used by UI infrastructure.
48
 * Should be registered in a project's lookup and will be used by UI infrastructure.
49
 * <p>
50
 * Implementations supporting single file commands (command constants ending with
51
 * {@code _SINGLE}) can also be registered in default lookup. If a provider in project
52
 * lookup does not enable the action for a given command on the selected file then
53
 * the first implementation found in default lookup that is enabled will be used.
54
 * </p>
49
 * @see org.netbeans.api.project.Project#getLookup
55
 * @see org.netbeans.api.project.Project#getLookup
50
 * @see <a href="@org-apache-tools-ant-module@/org/apache/tools/ant/module/api/support/ActionUtils.html"><code>ActionUtils</code></a>
56
 * @see <a href="@org-apache-tools-ant-module@/org/apache/tools/ant/module/api/support/ActionUtils.html"><code>ActionUtils</code></a>
51
 * @see <a href="@org-netbeans-modules-projectuiapi@/org/netbeans/spi/project/ui/support/ProjectSensitiveActions.html#projectCommandAction(java.lang.String,%20java.lang.String,%20javax.swing.Icon)"><code>ProjectSensitiveActions.projectCommandAction(...)</code></a>
57
 * @see <a href="@org-netbeans-modules-projectuiapi@/org/netbeans/spi/project/ui/support/ProjectSensitiveActions.html#projectCommandAction(java.lang.String,%20java.lang.String,%20javax.swing.Icon)"><code>ProjectSensitiveActions.projectCommandAction(...)</code></a>
(-)a/projectui/src/org/netbeans/modules/project/ui/actions/FileCommandAction.java (-3 / +31 lines)
Lines 41-49 Link Here
41
41
42
package org.netbeans.modules.project.ui.actions;
42
package org.netbeans.modules.project.ui.actions;
43
43
44
import java.util.ArrayList;
45
import java.util.Arrays;
46
import java.util.Collection;
44
import javax.swing.Action;
47
import javax.swing.Action;
45
import javax.swing.Icon;
48
import javax.swing.Icon;
46
import javax.swing.ImageIcon;
47
import org.netbeans.api.project.Project;
49
import org.netbeans.api.project.Project;
48
import org.netbeans.spi.project.ActionProvider;
50
import org.netbeans.spi.project.ActionProvider;
49
import org.openide.awt.Actions;
51
import org.openide.awt.Actions;
Lines 56-61 Link Here
56
public final class FileCommandAction extends ProjectAction {
58
public final class FileCommandAction extends ProjectAction {
57
59
58
    private String presenterName;
60
    private String presenterName;
61
    private Collection<ActionProvider> providers = new ArrayList<ActionProvider>();
59
        
62
        
60
    public FileCommandAction( String command, String namePattern, String iconResource, Lookup lookup ) {
63
    public FileCommandAction( String command, String namePattern, String iconResource, Lookup lookup ) {
61
        this( command, namePattern, ImageUtilities.loadImageIcon(iconResource, false), lookup );
64
        this( command, namePattern, ImageUtilities.loadImageIcon(iconResource, false), lookup );
Lines 67-72 Link Here
67
        presenterName = ActionsUtil.formatName( getNamePattern(), 0, "" );
70
        presenterName = ActionsUtil.formatName( getNamePattern(), 0, "" );
68
        setDisplayName( presenterName );
71
        setDisplayName( presenterName );
69
        putValue(SHORT_DESCRIPTION, Actions.cutAmpersand(presenterName));
72
        putValue(SHORT_DESCRIPTION, Actions.cutAmpersand(presenterName));
73
74
        Collection<? extends ActionProvider> registeredProviders = Lookup.getDefault().lookupAll(ActionProvider.class);
75
        for (ActionProvider p : registeredProviders) {
76
            if (Arrays.asList(p.getSupportedActions()).contains(getCommand())) {
77
                providers.add(p);
78
            }
79
        }
70
    }
80
    }
71
    
81
    
72
    @Override
82
    @Override
Lines 74-81 Link Here
74
        Project[] projects = ActionsUtil.getProjectsFromLookup( context, getCommand() );
84
        Project[] projects = ActionsUtil.getProjectsFromLookup( context, getCommand() );
75
85
76
        if ( projects.length != 1 ) {
86
        if ( projects.length != 1 ) {
77
            setEnabled( false ); // Zero or more than one projects found or command not supported            
87
            boolean supportedByProvider = false;
78
            presenterName = ActionsUtil.formatName( getNamePattern(), 0, "" );            
88
            for (ActionProvider provider : providers) {
89
                if (provider.isActionEnabled(getCommand(), context)) {
90
                    setEnabled(true);
91
                    presenterName = ActionsUtil.formatName(getNamePattern(), 0, "");
92
                    supportedByProvider = true;
93
                    break;
94
                }
95
            }
96
            if (!supportedByProvider) {
97
                setEnabled(false); // Zero or more than one projects found or command not supported
98
                presenterName = ActionsUtil.formatName(getNamePattern(), 0, "");
99
            }
79
        }
100
        }
80
        else {
101
        else {
81
            FileObject[] files = ActionsUtil.getFilesFromLookup( context, projects[0] );
102
            FileObject[] files = ActionsUtil.getFilesFromLookup( context, projects[0] );
Lines 94-101 Link Here
94
        if ( projects.length == 1 ) {            
115
        if ( projects.length == 1 ) {            
95
            ActionProvider ap = (ActionProvider)projects[0].getLookup().lookup( ActionProvider.class );
116
            ActionProvider ap = (ActionProvider)projects[0].getLookup().lookup( ActionProvider.class );
96
            ap.invokeAction( getCommand(), context );
117
            ap.invokeAction( getCommand(), context );
118
            return;
97
        }
119
        }
98
        
120
        
121
        for (ActionProvider provider : providers) {
122
            if (provider.isActionEnabled(getCommand(), context)) {
123
                provider.invokeAction(getCommand(), context);
124
                return;
125
            }
126
        }
99
    }
127
    }
100
    
128
    
101
129

Return to bug 102081