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 |
|