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 71515
Collapse All | Expand All

(-)a/projectui/src/org/netbeans/modules/project/ui/actions/MainProjectAction.java (-5 / +4 lines)
Lines 77-93 Link Here
77
    private String name;
77
    private String name;
78
78
79
    public MainProjectAction(ProjectActionPerformer performer, String name, Icon icon) {
79
    public MainProjectAction(ProjectActionPerformer performer, String name, Icon icon) {
80
        this( null, performer, name, icon );
80
        this(null, performer, name, icon, null);
81
    }
81
    }
82
82
83
    public MainProjectAction(String command, String name, Icon icon) {
83
    public MainProjectAction(String command, String name, Icon icon) {
84
        this( command, null, name, icon );
84
        this(command, null, name, icon, null);
85
    }
85
    }
86
86
87
    @SuppressWarnings("LeakingThisInConstructor")
87
    @SuppressWarnings("LeakingThisInConstructor")
88
    private MainProjectAction(String command, ProjectActionPerformer performer, String name, Icon icon) {
88
    MainProjectAction(String command, ProjectActionPerformer performer, String name, Icon icon, Lookup lookup) {
89
89
        super(icon, lookup, new Class<?>[] {Project.class, DataObject.class});
90
        super(icon, null, new Class<?>[] {Project.class, DataObject.class});
91
        this.command = command;
90
        this.command = command;
92
        this.performer = performer;
91
        this.performer = performer;
93
        this.name = name;
92
        this.name = name;
(-)a/projectui/src/org/netbeans/modules/project/ui/actions/ProjectAction.java (-17 / +17 lines)
Lines 140-146 Link Here
140
        if (!Arrays.asList(ap.getSupportedActions()).contains(command)) {
140
        if (!Arrays.asList(ap.getSupportedActions()).contains(command)) {
141
            // #47160: was a supported command (e.g. on a freeform project) but was then removed.
141
            // #47160: was a supported command (e.g. on a freeform project) but was then removed.
142
            Toolkit.getDefaultToolkit().beep();
142
            Toolkit.getDefaultToolkit().beep();
143
            a.refresh(a.getLookup(), false);
143
            a.resultChanged(null);
144
            return;
144
            return;
145
        }
145
        }
146
        LogRecord r = new LogRecord(Level.FINE, "PROJECT_ACTION"); // NOI18N
146
        LogRecord r = new LogRecord(Level.FINE, "PROJECT_ACTION"); // NOI18N
Lines 154-177 Link Here
154
        UILOG.log(r);
154
        UILOG.log(r);
155
        Mutex.EVENT.writeAccess(new Runnable() {
155
        Mutex.EVENT.writeAccess(new Runnable() {
156
            @Override public void run() {
156
            @Override public void run() {
157
                if (queue.isEmpty()) {
157
                final AtomicBoolean started = new AtomicBoolean();
158
                    ap.invokeAction(command, Lookup.EMPTY);
158
                ap.invokeAction(command, Lookups.singleton(new ActionProgress() {
159
                } else {
159
                    @Override protected void started() {
160
                    final AtomicBoolean started = new AtomicBoolean();
160
                        started.set(true);
161
                    ap.invokeAction(command, Lookups.singleton(new ActionProgress() {
161
                    }
162
                        @Override protected void started() {
162
                    @Override public void finished(boolean success) {
163
                            started.set(true);
163
                        if (success && !queue.isEmpty()) { // OK, next...
164
                            runSequentially(queue, a, command);
165
                        } else { // stopping now; restore natural action enablement state
166
                            a.resultChanged(null);
164
                        }
167
                        }
165
                        @Override public void finished(boolean success) {
166
                            if (success) { // OK, next...
167
                                runSequentially(queue, a, command);
168
                            } // else build failed, so skip others
169
                        }
170
                    }));
171
                    if (!started.get()) {
172
                        // Did not run action for some reason; try others?
173
                        runSequentially(queue, a, command);
174
                    }
168
                    }
169
                }));
170
                if (started.get()) {
171
                    a.setEnabled(false);
172
                } else if (!queue.isEmpty()) {
173
                    // Did not run action for some reason; try others?
174
                    runSequentially(queue, a, command);
175
                }
175
                }
176
            }
176
            }
177
        });
177
        });
(-)a/projectui/test/unit/src/org/netbeans/modules/project/ui/actions/MainProjectActionTest.java (-1 / +48 lines)
Lines 44-49 Link Here
44
44
45
import java.util.ArrayList;
45
import java.util.ArrayList;
46
import java.util.List;
46
import java.util.List;
47
import java.util.concurrent.Semaphore;
47
import org.netbeans.api.annotations.common.SuppressWarnings;
48
import org.netbeans.api.annotations.common.SuppressWarnings;
48
import org.netbeans.api.project.ProjectManager;
49
import org.netbeans.api.project.ProjectManager;
49
import org.netbeans.junit.NbTestCase;
50
import org.netbeans.junit.NbTestCase;
Lines 52-60 Link Here
52
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileUtil;
54
import org.openide.filesystems.FileUtil;
54
import org.openide.util.Lookup;
55
import org.openide.util.Lookup;
56
import org.openide.util.lookup.AbstractLookup;
57
import org.openide.util.lookup.InstanceContent;
55
import org.openide.util.lookup.Lookups;
58
import org.openide.util.lookup.Lookups;
56
import org.openide.util.test.MockLookup;
59
import org.openide.util.test.MockLookup;
57
60
61
@SuppressWarnings({"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "SIC_INNER_SHOULD_BE_STATIC_ANON"})
58
public class MainProjectActionTest extends NbTestCase {
62
public class MainProjectActionTest extends NbTestCase {
59
63
60
    public MainProjectActionTest(String name) {
64
    public MainProjectActionTest(String name) {
Lines 77-83 Link Here
77
        prj2 = (TestSupport.TestProject) ProjectManager.getDefault().findProject(p2);
81
        prj2 = (TestSupport.TestProject) ProjectManager.getDefault().findProject(p2);
78
    }
82
    }
79
83
80
    @SuppressWarnings({"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "SIC_INNER_SHOULD_BE_STATIC_ANON"})
81
    public void testSeqRun() throws Exception {
84
    public void testSeqRun() throws Exception {
82
        final String CMD = "cmd";
85
        final String CMD = "cmd";
83
        final List<Integer> invocations = new ArrayList<Integer>();
86
        final List<Integer> invocations = new ArrayList<Integer>();
Lines 117-120 Link Here
117
        assertEquals("[1, 2, 1, 2, 1]", invocations.toString());
120
        assertEquals("[1, 2, 1, 2, 1]", invocations.toString());
118
    }
121
    }
119
122
123
    public void testDisableMultiRun() throws Exception {
124
        final String CMD = "cmd";
125
        final Semaphore s1 = new Semaphore(0);
126
        final Semaphore s2 = new Semaphore(0);
127
        class SlowRun implements ActionProvider {
128
            @Override public String[] getSupportedActions() {
129
                return new String[] {CMD};
130
            }
131
            @Override public boolean isActionEnabled(String command, Lookup context) {
132
                return true;
133
            }
134
            @Override public void invokeAction(String command, Lookup context) {
135
                final ActionProgress listener = ActionProgress.start(context);
136
                new Thread() {
137
                    @Override public void run() {
138
                        s1.acquireUninterruptibly();
139
                        listener.finished(true);
140
                        s2.release();
141
                    }
142
                }.start();
143
            }
144
        }
145
        InstanceContent ic = new InstanceContent();
146
        Lookup context = new AbstractLookup(ic);
147
        prj1.setLookup(Lookups.singleton(new SlowRun()));
148
        LookupSensitiveAction a = new MainProjectAction(CMD, null, "a", null, context);
149
        assertFalse(a.isEnabled());
150
        ic.add(prj1);
151
        a.refresh(context, true);
152
        assertTrue(a.isEnabled());
153
        a.actionPerformed(context);
154
        assertFalse(a.isEnabled());
155
        s1.release();
156
        s2.acquireUninterruptibly();
157
        assertTrue(a.isEnabled());
158
        a.actionPerformed(context);
159
        assertFalse(a.isEnabled());
160
        prj2.setLookup(Lookups.singleton(new SlowRun()));
161
        ic.remove(prj1);
162
        ic.add(prj2);
163
        a.refresh(context, true);
164
        assertTrue(a.isEnabled());
165
    }
166
120
}
167
}

Return to bug 71515