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-75
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; |
67 |
import org.netbeans.api.debugger.Properties; |
70 |
import org.netbeans.api.debugger.Properties; |
68 |
import org.netbeans.api.project.Project; |
71 |
import org.netbeans.api.project.Project; |
69 |
import org.netbeans.api.project.ui.OpenProjects; |
72 |
import org.netbeans.api.project.ui.OpenProjects; |
|
|
73 |
import org.netbeans.modules.project.uiapi.BuildExecutionSupportImplementation; |
74 |
import org.netbeans.modules.project.uiapi.Utilities; |
70 |
import org.netbeans.spi.debugger.ui.AttachType; |
75 |
import org.netbeans.spi.debugger.ui.AttachType; |
71 |
import org.netbeans.spi.debugger.ui.Controller; |
76 |
import org.netbeans.spi.debugger.ui.Controller; |
72 |
import org.netbeans.spi.project.ActionProvider; |
77 |
import org.netbeans.spi.project.ActionProvider; |
|
|
78 |
import org.netbeans.spi.project.ui.support.BuildExecutionSupport; |
73 |
import org.netbeans.spi.project.ui.support.MainProjectSensitiveActions; |
79 |
import org.netbeans.spi.project.ui.support.MainProjectSensitiveActions; |
74 |
import org.openide.awt.Actions; |
80 |
import org.openide.awt.Actions; |
75 |
import org.openide.awt.DropDownButtonFactory; |
81 |
import org.openide.awt.DropDownButtonFactory; |
Lines 78-83
Link Here
|
78 |
import org.openide.util.ImageUtilities; |
84 |
import org.openide.util.ImageUtilities; |
79 |
import org.openide.util.NbBundle; |
85 |
import org.openide.util.NbBundle; |
80 |
import org.openide.util.RequestProcessor; |
86 |
import org.openide.util.RequestProcessor; |
|
|
87 |
import org.openide.util.WeakListeners; |
81 |
import org.openide.util.WeakSet; |
88 |
import org.openide.util.WeakSet; |
82 |
import org.openide.util.actions.Presenter; |
89 |
import org.openide.util.actions.Presenter; |
83 |
|
90 |
|
Lines 89-96
Link Here
|
89 |
|
96 |
|
90 |
private static WeakSet<AttachHistorySupport> ahs = null; |
97 |
private static WeakSet<AttachHistorySupport> ahs = null; |
91 |
|
98 |
|
92 |
private Action delegate; |
99 |
private final Action delegate; |
93 |
private AttachHistorySupport attachHistorySupport; |
100 |
private final DebugHistorySupport debugHistorySupport; |
|
|
101 |
private final AttachHistorySupport attachHistorySupport; |
94 |
|
102 |
|
95 |
/** Creates a new instance of DebugMainProjectAction */ |
103 |
/** Creates a new instance of DebugMainProjectAction */ |
96 |
public DebugMainProjectAction() { |
104 |
public DebugMainProjectAction() { |
Lines 98-103
Link Here
|
98 |
ActionProvider.COMMAND_DEBUG, |
106 |
ActionProvider.COMMAND_DEBUG, |
99 |
NbBundle.getMessage(DebugMainProjectAction.class, "LBL_DebugMainProjectAction_Name" ),ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debugProject.png", false)); // NOI18N |
107 |
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 |
108 |
delegate.putValue("iconBase","org/netbeans/modules/debugger/resources/debugProject.png"); //NOI18N |
|
|
109 |
//BuildExecutionSupport.registerFinishedItem(null); |
110 |
//Utilities.getBuildExecutionSupportImplementation().getRunningItems(); |
111 |
debugHistorySupport = new DebugHistorySupport(); |
101 |
attachHistorySupport = new AttachHistorySupport(); |
112 |
attachHistorySupport = new AttachHistorySupport(); |
102 |
} |
113 |
} |
103 |
|
114 |
|
Lines 188-193
Link Here
|
188 |
|
199 |
|
189 |
@Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
200 |
@Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
190 |
JPopupMenu menu = (JPopupMenu)e.getSource(); |
201 |
JPopupMenu menu = (JPopupMenu)e.getSource(); |
|
|
202 |
debugHistorySupport.init(menu); |
191 |
attachHistorySupport.init(menu); |
203 |
attachHistorySupport.init(menu); |
192 |
menu.removePopupMenuListener(this); |
204 |
menu.removePopupMenuListener(this); |
193 |
} |
205 |
} |
Lines 199-204
Link Here
|
199 |
} |
211 |
} |
200 |
|
212 |
|
201 |
// AttachHistorySupport ..................................................... |
213 |
// AttachHistorySupport ..................................................... |
|
|
214 |
|
215 |
private static class DebugHistorySupport implements ActionListener, ChangeListener { |
216 |
|
217 |
private JPopupMenu menu; |
218 |
private JMenuItem[] items = new JMenuItem[0]; |
219 |
private final JSeparator separator1 = new JPopupMenu.Separator(); |
220 |
private final JSeparator separator2 = new JPopupMenu.Separator(); |
221 |
private final BuildExecutionSupportImplementation besi; |
222 |
private final LinkedList<BuildExecutionSupport.ActionItem> debugItems = new LinkedList<BuildExecutionSupport.ActionItem>(); |
223 |
|
224 |
private static final String DEBUG_ACTION_ITEM_PROP_NAME = "debug action item"; |
225 |
private static final RequestProcessor RP = new RequestProcessor(DebugHistorySupport.class.getName()); |
226 |
|
227 |
public DebugHistorySupport() { |
228 |
besi = Utilities.getBuildExecutionSupportImplementation(); |
229 |
besi.addChangeListener(WeakListeners.change(this, besi)); |
230 |
} |
231 |
|
232 |
void init(JPopupMenu menu) { |
233 |
this.menu = menu; |
234 |
computeItems(); |
235 |
} |
236 |
|
237 |
private void computeItems() { |
238 |
boolean wasSeparator = items.length > 0; |
239 |
for (int i = 0; i < items.length; i++) { |
240 |
menu.remove(items[i]); |
241 |
} |
242 |
synchronized (debugItems) { |
243 |
if (debugItems.isEmpty()) { |
244 |
items = new JMenuItem[0]; |
245 |
} else { |
246 |
int n = debugItems.size(); |
247 |
items = new JMenuItem[n]; |
248 |
int i = 0; |
249 |
for (BuildExecutionSupport.ActionItem ai : debugItems) { |
250 |
String dispName = ai.getDisplayName(); |
251 |
items[i] = new JMenuItem(dispName); |
252 |
items[i].putClientProperty(DEBUG_ACTION_ITEM_PROP_NAME, ai); |
253 |
items[i].addActionListener(this); |
254 |
i++; |
255 |
} |
256 |
} |
257 |
} |
258 |
if (items.length == 0) { |
259 |
if (wasSeparator) { |
260 |
menu.remove(separator1); |
261 |
menu.remove(separator2); |
262 |
} |
263 |
} else { |
264 |
if (!wasSeparator) { |
265 |
menu.insert(separator1, 1); |
266 |
} |
267 |
int i; |
268 |
for (i = 0; i < items.length; i++) { |
269 |
menu.insert(items[i], i + 2); |
270 |
} |
271 |
menu.insert(separator2, i + 2); |
272 |
} |
273 |
} |
274 |
|
275 |
@Override |
276 |
public void actionPerformed(ActionEvent e) { |
277 |
JMenuItem item = (JMenuItem)e.getSource(); |
278 |
final BuildExecutionSupport.ActionItem ai = |
279 |
(BuildExecutionSupport.ActionItem) item.getClientProperty(DEBUG_ACTION_ITEM_PROP_NAME); |
280 |
RP.post(new Runnable() { |
281 |
@Override |
282 |
public void run() { |
283 |
ai.repeatExecution(); |
284 |
} |
285 |
}); |
286 |
} |
287 |
|
288 |
@Override |
289 |
public void stateChanged(ChangeEvent e) { |
290 |
BuildExecutionSupport.Item lastItem = besi.getLastItem(); |
291 |
if (lastItem instanceof BuildExecutionSupport.ActionItem) { |
292 |
BuildExecutionSupport.ActionItem ai = (BuildExecutionSupport.ActionItem) lastItem; |
293 |
String action = ai.getAction(); |
294 |
if (ActionProvider.COMMAND_DEBUG.equals(action)) { // Track debug items only |
295 |
boolean changed = false; |
296 |
synchronized (debugItems) { |
297 |
if (debugItems.isEmpty() || ai != debugItems.getFirst()) { |
298 |
debugItems.remove(ai); // Remove it if it's there |
299 |
debugItems.addFirst(ai); |
300 |
changed = true; |
301 |
} |
302 |
} |
303 |
if (changed) { |
304 |
computeItems(); |
305 |
} |
306 |
} |
307 |
} |
308 |
} |
309 |
} |
202 |
|
310 |
|
203 |
static class AttachHistorySupport implements ActionListener { |
311 |
static class AttachHistorySupport implements ActionListener { |
204 |
|
312 |
|