Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 193872 | Differences between
and this patch

Collapse All | Expand All

(-)a/spi.debugger.ui/nbproject/project.xml (-1 / +1 lines)
 Lines 109-115    Link Here 
109
                    <compile-dependency/>
109
                    <compile-dependency/>
110
                    <run-dependency>
110
                    <run-dependency>
111
                        <release-version>1</release-version>
111
                        <release-version>1</release-version>
112
                        <specification-version>1.24</specification-version>
112
                        <specification-version>1.78</specification-version>
113
                    </run-dependency>
113
                    </run-dependency>
114
                </dependency>
114
                </dependency>
115
                <dependency>
115
                <dependency>
(-)a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/actions/DebugMainProjectAction.java (-2 / +121 lines)
 Lines 52-57    Link Here 
52
import java.beans.PropertyChangeListener;
52
import java.beans.PropertyChangeListener;
53
import java.lang.reflect.InvocationTargetException;
53
import java.lang.reflect.InvocationTargetException;
54
import java.lang.reflect.Method;
54
import java.lang.reflect.Method;
55
import java.util.LinkedList;
55
import java.util.List;
56
import java.util.List;
56
import javax.swing.Action;
57
import javax.swing.Action;
57
import javax.swing.ImageIcon;
58
import javax.swing.ImageIcon;
 Lines 61-66    Link Here 
61
import javax.swing.JPopupMenu;
62
import javax.swing.JPopupMenu;
62
import javax.swing.JSeparator;
63
import javax.swing.JSeparator;
63
import javax.swing.SwingUtilities;
64
import javax.swing.SwingUtilities;
65
import javax.swing.event.ChangeEvent;
66
import javax.swing.event.ChangeListener;
64
import javax.swing.event.PopupMenuEvent;
67
import javax.swing.event.PopupMenuEvent;
65
import javax.swing.event.PopupMenuListener;
68
import javax.swing.event.PopupMenuListener;
66
import org.netbeans.api.debugger.DebuggerManager;
69
import org.netbeans.api.debugger.DebuggerManager;
 Lines 70-75    Link Here 
70
import org.netbeans.spi.debugger.ui.AttachType;
73
import org.netbeans.spi.debugger.ui.AttachType;
71
import org.netbeans.spi.debugger.ui.Controller;
74
import org.netbeans.spi.debugger.ui.Controller;
72
import org.netbeans.spi.project.ActionProvider;
75
import org.netbeans.spi.project.ActionProvider;
76
import org.netbeans.spi.project.ui.support.BuildExecutionSupport;
73
import org.netbeans.spi.project.ui.support.MainProjectSensitiveActions;
77
import org.netbeans.spi.project.ui.support.MainProjectSensitiveActions;
74
import org.openide.awt.Actions;
78
import org.openide.awt.Actions;
75
import org.openide.awt.DropDownButtonFactory;
79
import org.openide.awt.DropDownButtonFactory;
 Lines 78-83    Link Here 
78
import org.openide.util.ImageUtilities;
82
import org.openide.util.ImageUtilities;
79
import org.openide.util.NbBundle;
83
import org.openide.util.NbBundle;
80
import org.openide.util.RequestProcessor;
84
import org.openide.util.RequestProcessor;
85
import org.openide.util.WeakListeners;
81
import org.openide.util.WeakSet;
86
import org.openide.util.WeakSet;
82
import org.openide.util.actions.Presenter;
87
import org.openide.util.actions.Presenter;
83
88
 Lines 89-96    Link Here 
89
94
90
    private static WeakSet<AttachHistorySupport> ahs = null;
95
    private static WeakSet<AttachHistorySupport> ahs = null;
91
    
96
    
92
    private Action delegate;
97
    private final Action delegate;
93
    private AttachHistorySupport attachHistorySupport;
98
    private final DebugHistorySupport debugHistorySupport;
99
    private final AttachHistorySupport attachHistorySupport;
94
    
100
    
95
    /** Creates a new instance of DebugMainProjectAction */
101
    /** Creates a new instance of DebugMainProjectAction */
96
    public DebugMainProjectAction() {
102
    public DebugMainProjectAction() {
 Lines 98-103    Link Here 
98
                ActionProvider.COMMAND_DEBUG,
104
                ActionProvider.COMMAND_DEBUG,
99
                NbBundle.getMessage(DebugMainProjectAction.class, "LBL_DebugMainProjectAction_Name" ),ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debugProject.png", false)); // NOI18N
105
                NbBundle.getMessage(DebugMainProjectAction.class, "LBL_DebugMainProjectAction_Name" ),ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debugProject.png", false)); // NOI18N
100
        delegate.putValue("iconBase","org/netbeans/modules/debugger/resources/debugProject.png"); //NOI18N
106
        delegate.putValue("iconBase","org/netbeans/modules/debugger/resources/debugProject.png"); //NOI18N
107
        debugHistorySupport = new DebugHistorySupport();
101
        attachHistorySupport = new AttachHistorySupport();
108
        attachHistorySupport = new AttachHistorySupport();
102
    }
109
    }
103
    
110
    
 Lines 188-193    Link Here 
188
195
189
    @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
196
    @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
190
        JPopupMenu menu = (JPopupMenu)e.getSource();
197
        JPopupMenu menu = (JPopupMenu)e.getSource();
198
        debugHistorySupport.init(menu);
191
        attachHistorySupport.init(menu);
199
        attachHistorySupport.init(menu);
192
        menu.removePopupMenuListener(this);
200
        menu.removePopupMenuListener(this);
193
    }
201
    }
 Lines 197-202    Link Here 
197
205
198
    @Override public void popupMenuCanceled(PopupMenuEvent e) {
206
    @Override public void popupMenuCanceled(PopupMenuEvent e) {
199
    }
207
    }
208
    
209
    private static class DebugHistorySupport implements ActionListener, ChangeListener {
210
211
        private JPopupMenu menu;
212
        private JMenuItem[] items = new JMenuItem[0];
213
        private final JSeparator separator1 = new JPopupMenu.Separator();
214
        private final JSeparator separator2 = new JPopupMenu.Separator();
215
        private final BuildExecutionSupportChangeSupport besc;
216
        private final LinkedList<BuildExecutionSupport.ActionItem> debugItems = new LinkedList<BuildExecutionSupport.ActionItem>();
217
        
218
        private static final int MAX_ITEMS_COUNT = 7;
219
        private static final String DEBUG_ACTION_ITEM_PROP_NAME = "debug action item";
220
        private static final RequestProcessor RP = new RequestProcessor(DebugHistorySupport.class.getName());
221
        
222
        public DebugHistorySupport() {
223
            besc = new BuildExecutionSupportChangeSupport();
224
            besc.addChangeListener(WeakListeners.change(this, besc));
225
        }
226
        
227
        void init(JPopupMenu menu) {
228
            this.menu = menu;
229
            computeItems();
230
        }
231
        
232
        private void computeItems() {
233
            boolean wasSeparator = items.length > 0;
234
            for (int i = 0; i < items.length; i++) {
235
                menu.remove(items[i]);
236
            }
237
            synchronized (debugItems) {
238
                if (debugItems.isEmpty()) {
239
                    items = new JMenuItem[0];
240
                } else {
241
                    int n = debugItems.size();
242
                    items = new JMenuItem[n];
243
                    int i = 0;
244
                    for (BuildExecutionSupport.ActionItem ai : debugItems) {
245
                        String dispName = ai.getDisplayName();
246
                        items[i] = new JMenuItem(dispName);
247
                        items[i].putClientProperty(DEBUG_ACTION_ITEM_PROP_NAME, ai);
248
                        items[i].addActionListener(this);
249
                        i++;
250
                    }
251
                }
252
            }
253
            if (items.length == 0) {
254
                if (wasSeparator) {
255
                    menu.remove(separator1);
256
                    menu.remove(separator2);
257
                }
258
            } else {
259
                if (!wasSeparator) {
260
                    menu.insert(separator1, 1);
261
                }
262
                int i;
263
                for (i = 0; i < items.length; i++) {
264
                    menu.insert(items[i], i + 2);
265
                }
266
                menu.insert(separator2, i + 2);
267
            }
268
        }
269
270
        @Override
271
        public void actionPerformed(ActionEvent e) {
272
            JMenuItem item = (JMenuItem)e.getSource();
273
            final BuildExecutionSupport.ActionItem ai =
274
                    (BuildExecutionSupport.ActionItem) item.getClientProperty(DEBUG_ACTION_ITEM_PROP_NAME);
275
            RP.post(new Runnable() {
276
                @Override
277
                public void run() {
278
                    ai.repeatExecution();
279
                }
280
            });
281
        }
282
283
        @Override
284
        public void stateChanged(ChangeEvent e) {
285
            BuildExecutionSupport.Item lastItem = BuildExecutionSupport.getLastFinishedItem();
286
            if (lastItem instanceof BuildExecutionSupport.ActionItem) {
287
                BuildExecutionSupport.ActionItem ai = (BuildExecutionSupport.ActionItem) lastItem;
288
                String action = ai.getAction();
289
                if (ActionProvider.COMMAND_DEBUG.equals(action)) { // Track debug items only
290
                    boolean changed = false;
291
                    synchronized (debugItems) {
292
                        if (debugItems.isEmpty() || ai != debugItems.getFirst()) {
293
                            debugItems.remove(ai); // Remove it if it's there
294
                            debugItems.addFirst(ai);
295
                            if (debugItems.size() > MAX_ITEMS_COUNT) {
296
                                debugItems.removeLast();
297
                            }
298
                            changed = true;
299
                        }
300
                    }
301
                    if (changed) {
302
                        computeItems();
303
                    }
304
                }
305
            }
306
        }
307
    }
308
    
309
    private static class BuildExecutionSupportChangeSupport {
310
        
311
        public void addChangeListener(ChangeListener listener) {
312
            BuildExecutionSupport.addChangeListener(listener);
313
        }
314
        
315
        public void removeChangeListener(ChangeListener listener) {
316
            BuildExecutionSupport.removeChangeListener(listener);
317
        }
318
    }
200
319
201
    // AttachHistorySupport .....................................................
320
    // AttachHistorySupport .....................................................
202
321

Return to bug 193872
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo