Lines 45-50
Link Here
|
45 |
import java.util.Collection; |
45 |
import java.util.Collection; |
46 |
import java.util.Iterator; |
46 |
import java.util.Iterator; |
47 |
import java.util.List; |
47 |
import java.util.List; |
|
|
48 |
import java.util.concurrent.atomic.AtomicInteger; |
49 |
import javax.swing.Action; |
48 |
import javax.swing.Icon; |
50 |
import javax.swing.Icon; |
49 |
import org.netbeans.api.project.Project; |
51 |
import org.netbeans.api.project.Project; |
50 |
import org.netbeans.api.project.ProjectManager; |
52 |
import org.netbeans.api.project.ProjectManager; |
Lines 52-63
Link Here
|
52 |
import org.netbeans.junit.NbTestCase; |
54 |
import org.netbeans.junit.NbTestCase; |
53 |
import org.netbeans.modules.project.ui.actions.ProjectActionTest.ActionCreator; |
55 |
import org.netbeans.modules.project.ui.actions.ProjectActionTest.ActionCreator; |
54 |
import org.netbeans.spi.project.ActionProvider; |
56 |
import org.netbeans.spi.project.ActionProvider; |
|
|
57 |
import org.netbeans.spi.project.ui.support.FileSensitiveActions; |
55 |
import org.netbeans.spi.project.ui.support.ProjectActionPerformer; |
58 |
import org.netbeans.spi.project.ui.support.ProjectActionPerformer; |
56 |
import org.openide.filesystems.FileObject; |
59 |
import org.openide.filesystems.FileObject; |
57 |
import org.openide.filesystems.FileUtil; |
60 |
import org.openide.filesystems.FileUtil; |
58 |
import org.openide.loaders.DataObject; |
61 |
import org.openide.loaders.DataObject; |
|
|
62 |
import org.openide.util.ContextAwareAction; |
59 |
import org.openide.util.Lookup; |
63 |
import org.openide.util.Lookup; |
60 |
import org.openide.util.lookup.Lookups; |
64 |
import org.openide.util.lookup.Lookups; |
|
|
65 |
import org.openide.util.test.MockLookup; |
61 |
|
66 |
|
62 |
public class FileCommandActionTest extends NbTestCase { |
67 |
public class FileCommandActionTest extends NbTestCase { |
63 |
|
68 |
|
Lines 132-137
Link Here
|
132 |
} |
137 |
} |
133 |
}, true); |
138 |
}, true); |
134 |
} |
139 |
} |
|
|
140 |
|
141 |
public void testGlobalActions() throws Exception { |
142 |
final AtomicInteger runCount = new AtomicInteger(); |
143 |
MockLookup.setInstances(new ActionProvider() { |
144 |
public String[] getSupportedActions() { |
145 |
return new String[] {"run"}; |
146 |
} |
147 |
public boolean isActionEnabled(String command, Lookup context) throws IllegalArgumentException { |
148 |
DataObject d = context.lookup(DataObject.class); |
149 |
return d != null && d.getPrimaryFile().getName().equals("foo"); |
150 |
} |
151 |
public void invokeAction(String command, Lookup context) throws IllegalArgumentException { |
152 |
runCount.incrementAndGet(); |
153 |
} |
154 |
}); |
155 |
ContextAwareAction global = (ContextAwareAction) FileSensitiveActions.fileCommandAction("run", "Run {0,choice,0#File|1#\"{1}\"|1<Files}", null); |
156 |
DataObject foo = DataObject.find(FileUtil.createMemoryFileSystem().getRoot().createData("foo")); |
157 |
DataObject bar = DataObject.find(FileUtil.createMemoryFileSystem().getRoot().createData("bar")); |
158 |
Action local = global.createContextAwareInstance(Lookups.fixed(foo)); |
159 |
assertTrue(local.isEnabled()); |
160 |
assertEquals("Run \"foo\"", local.getValue("menuText")); |
161 |
local.actionPerformed(null); |
162 |
assertEquals(1, runCount.get()); |
163 |
local = global.createContextAwareInstance(Lookups.fixed(bar)); |
164 |
assertFalse(local.isEnabled()); |
165 |
assertEquals("Run File", local.getValue("menuText")); |
166 |
// XXX could test more complex interactions, e.g. >1 project responds, or file owned by project but project does not respond |
167 |
} |
135 |
|
168 |
|
136 |
private static class TestActionProvider implements ActionProvider { |
169 |
private static class TestActionProvider implements ActionProvider { |
137 |
|
170 |
|