# HG changeset patch # Parent 36cb6ccf9e785f348b5b4a6ba65356aade6d8eec # User Jesse Glick #206208: Build button should be greyed out during builds. diff --git a/projectui/src/org/netbeans/modules/project/ui/actions/MainProjectAction.java b/projectui/src/org/netbeans/modules/project/ui/actions/MainProjectAction.java --- a/projectui/src/org/netbeans/modules/project/ui/actions/MainProjectAction.java +++ b/projectui/src/org/netbeans/modules/project/ui/actions/MainProjectAction.java @@ -77,17 +77,16 @@ private String name; public MainProjectAction(ProjectActionPerformer performer, String name, Icon icon) { - this( null, performer, name, icon ); + this(null, performer, name, icon, null); } public MainProjectAction(String command, String name, Icon icon) { - this( command, null, name, icon ); + this(command, null, name, icon, null); } @SuppressWarnings("LeakingThisInConstructor") - private MainProjectAction(String command, ProjectActionPerformer performer, String name, Icon icon) { - - super(icon, null, new Class[] {Project.class, DataObject.class}); + MainProjectAction(String command, ProjectActionPerformer performer, String name, Icon icon, Lookup lookup) { + super(icon, lookup, new Class[] {Project.class, DataObject.class}); this.command = command; this.performer = performer; this.name = name; diff --git a/projectui/src/org/netbeans/modules/project/ui/actions/ProjectAction.java b/projectui/src/org/netbeans/modules/project/ui/actions/ProjectAction.java --- a/projectui/src/org/netbeans/modules/project/ui/actions/ProjectAction.java +++ b/projectui/src/org/netbeans/modules/project/ui/actions/ProjectAction.java @@ -140,7 +140,7 @@ if (!Arrays.asList(ap.getSupportedActions()).contains(command)) { // #47160: was a supported command (e.g. on a freeform project) but was then removed. Toolkit.getDefaultToolkit().beep(); - a.refresh(a.getLookup(), false); + a.resultChanged(null); return; } LogRecord r = new LogRecord(Level.FINE, "PROJECT_ACTION"); // NOI18N @@ -154,24 +154,24 @@ UILOG.log(r); Mutex.EVENT.writeAccess(new Runnable() { @Override public void run() { - if (queue.isEmpty()) { - ap.invokeAction(command, Lookup.EMPTY); - } else { - final AtomicBoolean started = new AtomicBoolean(); - ap.invokeAction(command, Lookups.singleton(new ActionProgress() { - @Override protected void started() { - started.set(true); + final AtomicBoolean started = new AtomicBoolean(); + ap.invokeAction(command, Lookups.singleton(new ActionProgress() { + @Override protected void started() { + started.set(true); + } + @Override public void finished(boolean success) { + if (success && !queue.isEmpty()) { // OK, next... + runSequentially(queue, a, command); + } else { // stopping now; restore natural action enablement state + a.resultChanged(null); } - @Override public void finished(boolean success) { - if (success) { // OK, next... - runSequentially(queue, a, command); - } // else build failed, so skip others - } - })); - if (!started.get()) { - // Did not run action for some reason; try others? - runSequentially(queue, a, command); } + })); + if (started.get()) { + a.setEnabled(false); + } else if (!queue.isEmpty()) { + // Did not run action for some reason; try others? + runSequentially(queue, a, command); } } }); diff --git a/projectui/test/unit/src/org/netbeans/modules/project/ui/actions/MainProjectActionTest.java b/projectui/test/unit/src/org/netbeans/modules/project/ui/actions/MainProjectActionTest.java --- a/projectui/test/unit/src/org/netbeans/modules/project/ui/actions/MainProjectActionTest.java +++ b/projectui/test/unit/src/org/netbeans/modules/project/ui/actions/MainProjectActionTest.java @@ -44,6 +44,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Semaphore; import org.netbeans.api.annotations.common.SuppressWarnings; import org.netbeans.api.project.ProjectManager; import org.netbeans.junit.NbTestCase; @@ -52,9 +53,12 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.Lookup; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; import org.openide.util.lookup.Lookups; import org.openide.util.test.MockLookup; +@SuppressWarnings({"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "SIC_INNER_SHOULD_BE_STATIC_ANON"}) public class MainProjectActionTest extends NbTestCase { public MainProjectActionTest(String name) { @@ -77,7 +81,6 @@ prj2 = (TestSupport.TestProject) ProjectManager.getDefault().findProject(p2); } - @SuppressWarnings({"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "SIC_INNER_SHOULD_BE_STATIC_ANON"}) public void testSeqRun() throws Exception { final String CMD = "cmd"; final List invocations = new ArrayList(); @@ -117,4 +120,48 @@ assertEquals("[1, 2, 1, 2, 1]", invocations.toString()); } + public void testDisableMultiRun() throws Exception { + final String CMD = "cmd"; + final Semaphore s1 = new Semaphore(0); + final Semaphore s2 = new Semaphore(0); + class SlowRun implements ActionProvider { + @Override public String[] getSupportedActions() { + return new String[] {CMD}; + } + @Override public boolean isActionEnabled(String command, Lookup context) { + return true; + } + @Override public void invokeAction(String command, Lookup context) { + final ActionProgress listener = ActionProgress.start(context); + new Thread() { + @Override public void run() { + s1.acquireUninterruptibly(); + listener.finished(true); + s2.release(); + } + }.start(); + } + } + InstanceContent ic = new InstanceContent(); + Lookup context = new AbstractLookup(ic); + prj1.setLookup(Lookups.singleton(new SlowRun())); + LookupSensitiveAction a = new MainProjectAction(CMD, null, "a", null, context); + assertFalse(a.isEnabled()); + ic.add(prj1); + a.refresh(context, true); + assertTrue(a.isEnabled()); + a.actionPerformed(context); + assertFalse(a.isEnabled()); + s1.release(); + s2.acquireUninterruptibly(); + assertTrue(a.isEnabled()); + a.actionPerformed(context); + assertFalse(a.isEnabled()); + prj2.setLookup(Lookups.singleton(new SlowRun())); + ic.remove(prj1); + ic.add(prj2); + a.refresh(context, true); + assertTrue(a.isEnabled()); + } + }