Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 284363 | Differences between
and this patch

Collapse All | Expand All

(-)core/org/eclipse/debug/internal/core/commands/DebugCommand.java (-324 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.core.commands;
12
13
import java.util.LinkedHashSet;
14
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
20
import org.eclipse.core.runtime.jobs.IJobChangeListener;
21
import org.eclipse.core.runtime.jobs.ISchedulingRule;
22
import org.eclipse.core.runtime.jobs.Job;
23
import org.eclipse.debug.core.DebugPlugin;
24
import org.eclipse.debug.core.IRequest;
25
import org.eclipse.debug.core.commands.IDebugCommandHandler;
26
import org.eclipse.debug.core.commands.IDebugCommandRequest;
27
import org.eclipse.debug.core.commands.IEnabledStateRequest;
28
import org.eclipse.debug.internal.core.DebugOptions;
29
30
/**
31
 * Common function for standard debug commands.
32
 * 
33
 * @since 3.3
34
 *
35
 */
36
public abstract class DebugCommand implements IDebugCommandHandler {
37
	
38
	/**
39
	 * Job to update enabled state of action.
40
	 */
41
	class UpdateJob extends Job implements IJobChangeListener {
42
		
43
		/**
44
		 * The request to update
45
		 */
46
		private IEnabledStateRequest request;
47
		
48
		/**
49
		 * Whether this job has been run
50
		 */
51
		private boolean run = false;
52
		
53
		/**
54
		 * Creates a new job to update the specified request
55
		 * 
56
		 * @param stateRequest
57
		 */
58
		UpdateJob(IEnabledStateRequest stateRequest) {
59
			super(getEnablementTaskName());
60
			request = stateRequest;
61
			setSystem(true);
62
			setRule(createUpdateSchedulingRule(request));
63
			getJobManager().addJobChangeListener(this);
64
		}
65
		
66
		protected IStatus run(IProgressMonitor monitor) {
67
			run = true;
68
			if (DebugOptions.DEBUG_COMMANDS) {
69
				System.out.print("can execute command: " + DebugCommand.this); //$NON-NLS-1$
70
			}
71
			if (monitor.isCanceled()) {
72
				if (DebugOptions.DEBUG_COMMANDS) {
73
					System.out.println(" >> *CANCELED* <<"); //$NON-NLS-1$
74
				}
75
				request.cancel();
76
			}
77
			Object[] elements = request.getElements();
78
			Object[] targets = new Object[elements.length];
79
			if (!request.isCanceled()) {
80
				for (int i = 0; i < elements.length; i++) {
81
					targets[i] = getTarget(elements[i]);
82
					if (targets[i] == null) {
83
						request.setEnabled(false);
84
						request.cancel();
85
						if (DebugOptions.DEBUG_COMMANDS) {
86
							System.out.println(" >> false (no adapter)"); //$NON-NLS-1$
87
						}
88
					}
89
				}
90
				if (monitor.isCanceled()) {
91
					request.cancel();
92
				}
93
			}
94
			if (!request.isCanceled()) {
95
				targets = coalesce(targets);
96
				monitor.beginTask(getEnablementTaskName(), targets.length);
97
				try {
98
					boolean executable = isExecutable(targets, monitor, request);
99
					if (DebugOptions.DEBUG_COMMANDS) {
100
						System.out.println(" >> " + executable); //$NON-NLS-1$
101
					}
102
					request.setEnabled(executable);
103
				} catch (CoreException e) {
104
					request.setStatus(e.getStatus());
105
					request.setEnabled(false);
106
					if (DebugOptions.DEBUG_COMMANDS) {
107
						System.out.println(" >> ABORTED"); //$NON-NLS-1$
108
						System.out.println("\t" + e.getStatus().getMessage()); //$NON-NLS-1$
109
					}
110
				}
111
			}
112
			monitor.setCanceled(request.isCanceled());
113
			request.done();
114
			monitor.done();
115
			return Status.OK_STATUS;
116
		}
117
		
118
		/* (non-Javadoc)
119
		 * @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
120
		 */
121
		public boolean belongsTo(Object family) {
122
			return getUpdateJobFamily().equals(family);
123
		}
124
125
		public void aboutToRun(IJobChangeEvent event) {
126
		}
127
128
		public void awake(IJobChangeEvent event) {
129
		}
130
131
		public void done(IJobChangeEvent event) {
132
			if (event.getJob() == this) {
133
				if (!run) {
134
					request.cancel();
135
					request.done();
136
					if (DebugOptions.DEBUG_COMMANDS) {
137
						System.out.println(" >> *CANCELED* <<" + DebugCommand.this); //$NON-NLS-1$
138
					}
139
				}
140
				getJobManager().removeJobChangeListener(this);
141
			}
142
		}
143
144
		public void running(IJobChangeEvent event) {
145
		}
146
147
		public void scheduled(IJobChangeEvent event) {
148
		}
149
150
		public void sleeping(IJobChangeEvent event) {
151
		}
152
				
153
	}
154
	
155
	/**
156
	 * Scheduling rule to serialize commands on an object
157
	 */
158
   class SerialPerObjectRule implements ISchedulingRule {
159
160
		private Object fObject = null;
161
162
		public SerialPerObjectRule(Object lock) {
163
			fObject = lock;
164
		}
165
166
		/*
167
		 * (non-Javadoc)
168
		 * 
169
		 * @see org.eclipse.core.runtime.jobs.ISchedulingRule#contains(org.eclipse.core.runtime.jobs.ISchedulingRule)
170
		 */
171
		public boolean contains(ISchedulingRule rule) {
172
			return rule == this;
173
		}
174
175
		/*
176
		 * (non-Javadoc)
177
		 * 
178
		 * @see org.eclipse.core.runtime.jobs.ISchedulingRule#isConflicting(org.eclipse.core.runtime.jobs.ISchedulingRule)
179
		 */
180
		public boolean isConflicting(ISchedulingRule rule) {
181
			if (rule instanceof SerialPerObjectRule) {
182
				SerialPerObjectRule vup = (SerialPerObjectRule) rule;
183
				return fObject == vup.fObject;
184
			}
185
			return false;
186
		}
187
188
	}
189
   
190
	public boolean execute(final IDebugCommandRequest request) {
191
		Job job = new Job(getExecuteTaskName()) {
192
			protected IStatus run(IProgressMonitor monitor) {
193
				if (DebugOptions.DEBUG_COMMANDS) {
194
					System.out.println("execute: " + DebugCommand.this); //$NON-NLS-1$
195
				}
196
				Object[] elements = request.getElements();
197
				Object[] targets = new Object[elements.length];
198
				for (int i = 0; i < elements.length; i++) {
199
					targets[i]= getTarget(elements[i]);
200
				}
201
				targets = coalesce(targets);
202
				monitor.beginTask(getExecuteTaskName(), targets.length);
203
				try {
204
					doExecute(targets, monitor, request);
205
				} catch (CoreException e) {
206
					request.setStatus(e.getStatus());
207
					if (DebugOptions.DEBUG_COMMANDS) {
208
						System.out.println("\t" + e.getStatus().getMessage()); //$NON-NLS-1$
209
					}
210
				}
211
				request.done();
212
				monitor.setCanceled(request.isCanceled());
213
				monitor.done();
214
				return Status.OK_STATUS;
215
			}
216
		};
217
		job.setSystem(true);
218
		job.schedule();
219
		return isRemainEnabled();
220
	}	
221
	
222
	/**
223
	 * Returns whether this command should remain enabled after execution is invoked.
224
	 * 
225
	 * @return whether to remain enabled
226
	 */
227
	protected boolean isRemainEnabled() {
228
		return false;
229
	}
230
	
231
	public void canExecute(final IEnabledStateRequest request) {
232
		Job job = new UpdateJob(request);
233
		job.schedule();
234
	}
235
	
236
	/**
237
	 * Returns the name to use for jobs and progress monitor task names when checking
238
	 * enabled state.
239
	 * 
240
	 * @return task name
241
	 */
242
	protected String getEnablementTaskName() {
243
		// this is a system job name and does not need to be NLS'd
244
		return "Check Debug Command"; //$NON-NLS-1$
245
	}
246
	
247
	/**
248
	 * Returns the name to use for jobs and progress monitor task names when executing
249
	 * a debug command
250
	 * 
251
	 * @return task name
252
	 */
253
	protected String getExecuteTaskName() {
254
		// this is a system job name and does not need to be NLS'd
255
		return "Execute Debug Command"; //$NON-NLS-1$
256
	}	
257
258
	/**
259
	 * Executes the actual operation.
260
	 * 
261
	 * @param targets objects to perform on
262
	 * @param request request
263
	 */
264
	protected abstract void doExecute(Object[] targets, IProgressMonitor monitor, IRequest request) throws CoreException;
265
266
	/**
267
	 * Returns whether this command is executable.
268
	 * 
269
	 * @param targets objects to check command for
270
	 * @param monitor progress monitor
271
	 * @param request request
272
	 * @return whether this command can be executed
273
	 */
274
	protected abstract boolean isExecutable(Object[] targets, IProgressMonitor monitor, IEnabledStateRequest request) throws CoreException;
275
	
276
	/**
277
	 * Returns the appropriate command adapter from the given object.
278
	 * 
279
	 * @param element object to obtain adapter from
280
	 * @return adapter
281
	 */
282
	protected abstract Object getTarget(Object element); 
283
	
284
	/**
285
	 * Returns an adapter of the specified type for the given object or <code>null</code>
286
	 * if none. The object itself is returned if it is an instance of the specified type.
287
	 * 
288
	 * @param element element to retrieve adapter for
289
	 * @param type adapter type
290
	 * @return adapter or <code>null</code>
291
	 */
292
	protected Object getAdapter(Object element, Class type) {
293
    	return DebugPlugin.getAdapter(element, type);	
294
	}	
295
	
296
	/**
297
	 * Scheduling rule for updating command enabled state.
298
	 * 
299
	 * @return scheduling rule or <code>null</code>
300
	 */
301
	protected ISchedulingRule createUpdateSchedulingRule(IDebugCommandRequest request) {
302
		return new SerialPerObjectRule(request.getElements()[0]);
303
	}
304
	
305
	private Object[] coalesce(Object[] objects) {
306
		if (objects.length == 1) {
307
			return objects;
308
		} else {
309
			LinkedHashSet set = new LinkedHashSet(objects.length);
310
			for (int i = 0; i < objects.length; i++) {
311
				set.add(objects[i]);
312
			}
313
			return set.toArray();
314
		}
315
	}
316
	
317
	/**
318
	 * Returns the job family for this command's "can execute" job.
319
	 * 
320
	 * @return the job family for this command's "can execute" job
321
	 */
322
	protected abstract Object getUpdateJobFamily();
323
	
324
}
(-)core/org/eclipse/debug/internal/core/commands/ForEachCommand.java (-1 / +2 lines)
Lines 13-18 Link Here
13
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.debug.core.IRequest;
15
import org.eclipse.debug.core.IRequest;
16
import org.eclipse.debug.core.commands.AbstractDebugCommand;
16
import org.eclipse.debug.core.commands.IEnabledStateRequest;
17
import org.eclipse.debug.core.commands.IEnabledStateRequest;
17
18
18
/**
19
/**
Lines 20-26 Link Here
20
 * 
21
 * 
21
 * @since 3.3
22
 * @since 3.3
22
 */
23
 */
23
public abstract class ForEachCommand extends DebugCommand {
24
public abstract class ForEachCommand extends AbstractDebugCommand {
24
25
25
	/* (non-Javadoc)
26
	/* (non-Javadoc)
26
	 * @see org.eclipse.debug.internal.core.commands.DebugCommand#doExecute(java.lang.Object[], org.eclipse.core.runtime.IProgressMonitor, org.eclipse.debug.core.IRequest)
27
	 * @see org.eclipse.debug.internal.core.commands.DebugCommand#doExecute(java.lang.Object[], org.eclipse.core.runtime.IProgressMonitor, org.eclipse.debug.core.IRequest)
(-)core/org/eclipse/debug/internal/core/commands/StepCommand.java (-1 / +2 lines)
Lines 17-22 Link Here
17
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.debug.core.IRequest;
19
import org.eclipse.debug.core.IRequest;
20
import org.eclipse.debug.core.commands.AbstractDebugCommand;
20
import org.eclipse.debug.core.commands.IEnabledStateRequest;
21
import org.eclipse.debug.core.commands.IEnabledStateRequest;
21
import org.eclipse.debug.core.model.IStackFrame;
22
import org.eclipse.debug.core.model.IStackFrame;
22
import org.eclipse.debug.core.model.IStep;
23
import org.eclipse.debug.core.model.IStep;
Lines 26-32 Link Here
26
 * 
27
 * 
27
 * @since 3.3
28
 * @since 3.3
28
 */
29
 */
29
public abstract class StepCommand extends DebugCommand {
30
public abstract class StepCommand extends AbstractDebugCommand {
30
31
31
	protected void doExecute(Object[] targets, IProgressMonitor monitor, IRequest request) throws CoreException {
32
	protected void doExecute(Object[] targets, IProgressMonitor monitor, IRequest request) throws CoreException {
32
		for (int i = 0; i < targets.length; i++) {
33
		for (int i = 0; i < targets.length; i++) {
(-)core/org/eclipse/debug/core/commands/AbstractDebugCommand.java (+322 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.core.commands;
12
13
import java.util.LinkedHashSet;
14
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
20
import org.eclipse.core.runtime.jobs.IJobChangeListener;
21
import org.eclipse.core.runtime.jobs.ISchedulingRule;
22
import org.eclipse.core.runtime.jobs.Job;
23
import org.eclipse.debug.core.DebugPlugin;
24
import org.eclipse.debug.core.IRequest;
25
import org.eclipse.debug.internal.core.DebugOptions;
26
27
/**
28
 * Common function for standard debug commands.
29
 * 
30
 * @since 3.6 This class was in the internal package 
31
 * <code>org.eclipse.debug.internal.core.commands</code> since 3.3.
32
 *
33
 */
34
public abstract class AbstractDebugCommand implements IDebugCommandHandler {
35
	
36
	/**
37
	 * Job to update enabled state of action.
38
	 */
39
	private class UpdateJob extends Job implements IJobChangeListener {
40
		
41
		/**
42
		 * The request to update
43
		 */
44
		private IEnabledStateRequest request;
45
		
46
		/**
47
		 * Whether this job has been run
48
		 */
49
		private boolean run = false;
50
		
51
		/**
52
		 * Creates a new job to update the specified request
53
		 * 
54
		 * @param stateRequest
55
		 */
56
		UpdateJob(IEnabledStateRequest stateRequest) {
57
			super(getEnablementTaskName());
58
			request = stateRequest;
59
			setSystem(true);
60
			setRule(createUpdateSchedulingRule(request));
61
			getJobManager().addJobChangeListener(this);
62
		}
63
		
64
		protected IStatus run(IProgressMonitor monitor) {
65
			run = true;
66
			if (DebugOptions.DEBUG_COMMANDS) {
67
				System.out.print("can execute command: " + AbstractDebugCommand.this); //$NON-NLS-1$
68
			}
69
			if (monitor.isCanceled()) {
70
				if (DebugOptions.DEBUG_COMMANDS) {
71
					System.out.println(" >> *CANCELED* <<"); //$NON-NLS-1$
72
				}
73
				request.cancel();
74
			}
75
			Object[] elements = request.getElements();
76
			Object[] targets = new Object[elements.length];
77
			if (!request.isCanceled()) {
78
				for (int i = 0; i < elements.length; i++) {
79
					targets[i] = getTarget(elements[i]);
80
					if (targets[i] == null) {
81
						request.setEnabled(false);
82
						request.cancel();
83
						if (DebugOptions.DEBUG_COMMANDS) {
84
							System.out.println(" >> false (no adapter)"); //$NON-NLS-1$
85
						}
86
					}
87
				}
88
				if (monitor.isCanceled()) {
89
					request.cancel();
90
				}
91
			}
92
			if (!request.isCanceled()) {
93
				targets = coalesce(targets);
94
				monitor.beginTask(getEnablementTaskName(), targets.length);
95
				try {
96
					boolean executable = isExecutable(targets, monitor, request);
97
					if (DebugOptions.DEBUG_COMMANDS) {
98
						System.out.println(" >> " + executable); //$NON-NLS-1$
99
					}
100
					request.setEnabled(executable);
101
				} catch (CoreException e) {
102
					request.setStatus(e.getStatus());
103
					request.setEnabled(false);
104
					if (DebugOptions.DEBUG_COMMANDS) {
105
						System.out.println(" >> ABORTED"); //$NON-NLS-1$
106
						System.out.println("\t" + e.getStatus().getMessage()); //$NON-NLS-1$
107
					}
108
				}
109
			}
110
			monitor.setCanceled(request.isCanceled());
111
			request.done();
112
			monitor.done();
113
			return Status.OK_STATUS;
114
		}
115
		
116
		/* (non-Javadoc)
117
		 * @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
118
		 */
119
		public boolean belongsTo(Object family) {
120
			return getUpdateJobFamily().equals(family);
121
		}
122
123
		public void aboutToRun(IJobChangeEvent event) {
124
		}
125
126
		public void awake(IJobChangeEvent event) {
127
		}
128
129
		public void done(IJobChangeEvent event) {
130
			if (event.getJob() == this) {
131
				if (!run) {
132
					request.cancel();
133
					request.done();
134
					if (DebugOptions.DEBUG_COMMANDS) {
135
						System.out.println(" >> *CANCELED* <<" + AbstractDebugCommand.this); //$NON-NLS-1$
136
					}
137
				}
138
				getJobManager().removeJobChangeListener(this);
139
			}
140
		}
141
142
		public void running(IJobChangeEvent event) {
143
		}
144
145
		public void scheduled(IJobChangeEvent event) {
146
		}
147
148
		public void sleeping(IJobChangeEvent event) {
149
		}
150
				
151
	}
152
	
153
	/**
154
	 * Scheduling rule to serialize commands on an object
155
	 */
156
   private class SerialPerObjectRule implements ISchedulingRule {
157
158
		private Object fObject = null;
159
160
		public SerialPerObjectRule(Object lock) {
161
			fObject = lock;
162
		}
163
164
		/*
165
		 * (non-Javadoc)
166
		 * 
167
		 * @see org.eclipse.core.runtime.jobs.ISchedulingRule#contains(org.eclipse.core.runtime.jobs.ISchedulingRule)
168
		 */
169
		public boolean contains(ISchedulingRule rule) {
170
			return rule == this;
171
		}
172
173
		/*
174
		 * (non-Javadoc)
175
		 * 
176
		 * @see org.eclipse.core.runtime.jobs.ISchedulingRule#isConflicting(org.eclipse.core.runtime.jobs.ISchedulingRule)
177
		 */
178
		public boolean isConflicting(ISchedulingRule rule) {
179
			if (rule instanceof SerialPerObjectRule) {
180
				SerialPerObjectRule vup = (SerialPerObjectRule) rule;
181
				return fObject == vup.fObject;
182
			}
183
			return false;
184
		}
185
186
	}
187
   
188
	public boolean execute(final IDebugCommandRequest request) {
189
		Job job = new Job(getExecuteTaskName()) {
190
			protected IStatus run(IProgressMonitor monitor) {
191
				if (DebugOptions.DEBUG_COMMANDS) {
192
					System.out.println("execute: " + AbstractDebugCommand.this); //$NON-NLS-1$
193
				}
194
				Object[] elements = request.getElements();
195
				Object[] targets = new Object[elements.length];
196
				for (int i = 0; i < elements.length; i++) {
197
					targets[i]= getTarget(elements[i]);
198
				}
199
				targets = coalesce(targets);
200
				monitor.beginTask(getExecuteTaskName(), targets.length);
201
				try {
202
					doExecute(targets, monitor, request);
203
				} catch (CoreException e) {
204
					request.setStatus(e.getStatus());
205
					if (DebugOptions.DEBUG_COMMANDS) {
206
						System.out.println("\t" + e.getStatus().getMessage()); //$NON-NLS-1$
207
					}
208
				}
209
				request.done();
210
				monitor.setCanceled(request.isCanceled());
211
				monitor.done();
212
				return Status.OK_STATUS;
213
			}
214
		};
215
		job.setSystem(true);
216
		job.schedule();
217
		return isRemainEnabled();
218
	}	
219
	
220
	/**
221
	 * Returns whether this command should remain enabled after execution is invoked.
222
	 * 
223
	 * @return whether to remain enabled
224
	 */
225
	protected boolean isRemainEnabled() {
226
		return false;
227
	}
228
	
229
	public void canExecute(final IEnabledStateRequest request) {
230
		Job job = new UpdateJob(request);
231
		job.schedule();
232
	}
233
	
234
	/**
235
	 * Returns the name to use for jobs and progress monitor task names when checking
236
	 * enabled state.
237
	 * 
238
	 * @return task name
239
	 */
240
	protected String getEnablementTaskName() {
241
		// this is a system job name and does not need to be NLS'd
242
		return "Check Debug Command"; //$NON-NLS-1$
243
	}
244
	
245
	/**
246
	 * Returns the name to use for jobs and progress monitor task names when executing
247
	 * a debug command
248
	 * 
249
	 * @return task name
250
	 */
251
	protected String getExecuteTaskName() {
252
		// this is a system job name and does not need to be NLS'd
253
		return "Execute Debug Command"; //$NON-NLS-1$
254
	}	
255
256
	/**
257
	 * Executes the actual operation.
258
	 * 
259
	 * @param targets objects to perform on
260
	 * @param request request
261
	 */
262
	protected abstract void doExecute(Object[] targets, IProgressMonitor monitor, IRequest request) throws CoreException;
263
264
	/**
265
	 * Returns whether this command is executable.
266
	 * 
267
	 * @param targets objects to check command for
268
	 * @param monitor progress monitor
269
	 * @param request request
270
	 * @return whether this command can be executed
271
	 */
272
	protected abstract boolean isExecutable(Object[] targets, IProgressMonitor monitor, IEnabledStateRequest request) throws CoreException;
273
	
274
	/**
275
	 * Returns the appropriate command adapter from the given object.
276
	 * 
277
	 * @param element object to obtain adapter from
278
	 * @return adapter
279
	 */
280
	protected abstract Object getTarget(Object element); 
281
	
282
	/**
283
	 * Returns an adapter of the specified type for the given object or <code>null</code>
284
	 * if none. The object itself is returned if it is an instance of the specified type.
285
	 * 
286
	 * @param element element to retrieve adapter for
287
	 * @param type adapter type
288
	 * @return adapter or <code>null</code>
289
	 */
290
	protected Object getAdapter(Object element, Class type) {
291
    	return DebugPlugin.getAdapter(element, type);	
292
	}	
293
	
294
	/**
295
	 * Scheduling rule for updating command enabled state.
296
	 * 
297
	 * @return scheduling rule or <code>null</code>
298
	 */
299
	protected ISchedulingRule createUpdateSchedulingRule(IDebugCommandRequest request) {
300
		return new SerialPerObjectRule(request.getElements()[0]);
301
	}
302
	
303
	private Object[] coalesce(Object[] objects) {
304
		if (objects.length == 1) {
305
			return objects;
306
		} else {
307
			LinkedHashSet set = new LinkedHashSet(objects.length);
308
			for (int i = 0; i < objects.length; i++) {
309
				set.add(objects[i]);
310
			}
311
			return set.toArray();
312
		}
313
	}
314
	
315
	/**
316
	 * Returns the job family for this command's "can execute" job.
317
	 * 
318
	 * @return the job family for this command's "can execute" job
319
	 */
320
	protected abstract Object getUpdateJobFamily();
321
	
322
}
(-)ui/org/eclipse/debug/internal/ui/commands/actions/StepReturnCommandActionDelegate.java (+1 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.debug.internal.ui.commands.actions;
12
package org.eclipse.debug.internal.ui.commands.actions;
13
13
14
14
/**
15
/**
15
 * Step return action delegate.
16
 * Step return action delegate.
16
 * 
17
 * 
(-)ui/org/eclipse/debug/internal/ui/commands/actions/DropToFrameCommandAction.java (+1 lines)
Lines 14-19 Link Here
14
import org.eclipse.debug.internal.ui.DebugPluginImages;
14
import org.eclipse.debug.internal.ui.DebugPluginImages;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
17
import org.eclipse.debug.ui.actions.DebugCommandAction;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.resource.ImageDescriptor;
18
19
19
/**
20
/**
(-)ui/org/eclipse/debug/internal/ui/commands/actions/StepReturnCommandAction.java (+1 lines)
Lines 14-19 Link Here
14
import org.eclipse.debug.internal.ui.DebugPluginImages;
14
import org.eclipse.debug.internal.ui.DebugPluginImages;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
17
import org.eclipse.debug.ui.actions.DebugCommandAction;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.resource.ImageDescriptor;
18
19
19
/**
20
/**
(-)ui/org/eclipse/debug/internal/ui/commands/actions/UpdateActionsRequest.java (-3 / +2 lines)
Lines 12-18 Link Here
12
12
13
import org.eclipse.debug.core.commands.IEnabledStateRequest;
13
import org.eclipse.debug.core.commands.IEnabledStateRequest;
14
import org.eclipse.debug.internal.core.commands.DebugCommandRequest;
14
import org.eclipse.debug.internal.core.commands.DebugCommandRequest;
15
import org.eclipse.jface.action.IAction;
16
15
17
/**
16
/**
18
 * Boolean collector that collects boolean results from a number of voters.
17
 * Boolean collector that collects boolean results from a number of voters.
Lines 23-32 Link Here
23
 */
22
 */
24
public class UpdateActionsRequest extends DebugCommandRequest implements IEnabledStateRequest {
23
public class UpdateActionsRequest extends DebugCommandRequest implements IEnabledStateRequest {
25
	
24
	
26
	private IAction[] fActions;
25
	private IEnabledTarget[] fActions;
27
	private boolean fEnabled = false;
26
	private boolean fEnabled = false;
28
	
27
	
29
	public UpdateActionsRequest(Object[] elements, IAction[] actions) {
28
	public UpdateActionsRequest(Object[] elements, IEnabledTarget[] actions) {
30
		super(elements);
29
		super(elements);
31
		fActions = actions;
30
		fActions = actions;
32
	}
31
	}
(-)ui/org/eclipse/debug/internal/ui/commands/actions/ICommandParticipant.java (-1 / +1 lines)
Lines 15-21 Link Here
15
/**
15
/**
16
 * Adds function to a command on completion.
16
 * Adds function to a command on completion.
17
 *
17
 *
18
 * @since 3.3
18
 * @since 3.3.
19
 */
19
 */
20
public interface ICommandParticipant {
20
public interface ICommandParticipant {
21
	
21
	
(-)ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandActionDelegate.java (-50 / +6 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.debug.internal.ui.commands.actions;
12
package org.eclipse.debug.internal.ui.commands.actions;
13
13
14
import org.eclipse.debug.ui.actions.DebugCommandAction;
14
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.viewers.ISelection;
16
import org.eclipse.jface.viewers.ISelection;
16
import org.eclipse.swt.widgets.Event;
17
import org.eclipse.swt.widgets.Event;
Lines 21-27 Link Here
21
/**
22
/**
22
 * Abstract base class for debug action delegates performing debug commands.
23
 * Abstract base class for debug action delegates performing debug commands.
23
 * 
24
 * 
24
 * @since 3.3
25
 * @since 3.3.
25
 */
26
 */
26
public abstract class DebugCommandActionDelegate implements IWorkbenchWindowActionDelegate, IActionDelegate2 {
27
public abstract class DebugCommandActionDelegate implements IWorkbenchWindowActionDelegate, IActionDelegate2 {
27
28
Lines 30-56 Link Here
30
	 */
31
	 */
31
	private DebugCommandAction fDebugAction;
32
	private DebugCommandAction fDebugAction;
32
    
33
    
33
    /**
34
	protected void setAction(DebugCommandAction action) {
34
     * The underlying action for this delegate
35
	    fDebugAction = action;
35
     */
36
    private IAction fWindowAction;
37
    
38
    /**
39
     * Whether this action has been initialized before it has been run
40
     * (ensures enablement state is up to date when lazily instantiated)
41
     */
42
    private boolean fInitialized = false;
43
44
	public DebugCommandActionDelegate() {
45
	}
36
	}
46
37
	
47
	/*
38
	/*
48
     * (non-Javadoc)
39
     * (non-Javadoc)
49
     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
40
     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
50
	 */
41
	 */
51
	public void dispose() {
42
	public void dispose() {
52
        fDebugAction.dispose();
43
        fDebugAction.dispose();
53
54
	}
44
	}
55
45
56
    /*
46
    /*
Lines 58-64 Link Here
58
     * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
48
     * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
59
     */
49
     */
60
    public void init(IAction action) {
50
    public void init(IAction action) {
61
        fWindowAction = action;
51
        fDebugAction.setAction(action);
62
    }
52
    }
63
    
53
    
64
    /*
54
    /*
Lines 74-87 Link Here
74
     * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
64
     * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
75
     */
65
     */
76
	public void run(IAction action) {
66
	public void run(IAction action) {
77
		synchronized (this) {
78
			if (!fInitialized) {
79
				try {
80
					wait();
81
				} catch (InterruptedException e) {
82
				}
83
			}			
84
		}
85
        fDebugAction.run();
67
        fDebugAction.run();
86
	}
68
	}
87
69
Lines 105-134 Link Here
105
	protected DebugCommandAction getAction() {
87
	protected DebugCommandAction getAction() {
106
		return fDebugAction;
88
		return fDebugAction;
107
	}
89
	}
108
    
109
    protected void setAction(DebugCommandAction action) {
110
        fDebugAction = action;
111
        action.setDelegate(this);
112
    }
113
114
    public void setEnabled(boolean enabled) {
115
    	synchronized (this) {
116
	    	if (!fInitialized) {
117
	    		fInitialized = true;
118
	    		notifyAll();
119
	    	}
120
    	}
121
        fWindowAction.setEnabled(enabled);
122
    }
123
    
124
    public void setChecked(boolean checked) {
125
    	fWindowAction.setChecked(checked);
126
    }
127
    
128
    protected IAction getWindowAction()
129
    {
130
    	return fWindowAction;
131
    }
132
    
133
    
134
}
90
}
(-)ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandAction.java (-269 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.debug.internal.ui.commands.actions;
13
14
import org.eclipse.debug.ui.DebugUITools;
15
import org.eclipse.debug.ui.contexts.DebugContextEvent;
16
import org.eclipse.debug.ui.contexts.IDebugContextListener;
17
import org.eclipse.debug.ui.contexts.IDebugContextService;
18
import org.eclipse.jface.action.Action;
19
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.swt.widgets.Event;
23
import org.eclipse.ui.IWorkbenchPart;
24
import org.eclipse.ui.IWorkbenchWindow;
25
import org.eclipse.ui.PlatformUI;
26
27
/**
28
 * Abstract base class for actions performing debug commands
29
 *
30
 * @since 3.3
31
 */
32
public abstract class DebugCommandAction extends Action implements IDebugContextListener {
33
34
	/**
35
	 * The window this action is working for.
36
	 */
37
    private IWorkbenchWindow fWindow;
38
    
39
    /**
40
     * The part this action is working for, or <code>null</code> if global to
41
     * a window.
42
     */
43
    private IWorkbenchPart fPart;
44
    
45
    /**
46
     * Command service.
47
     */
48
    private DebugCommandService fUpdateService;
49
    
50
    /**
51
     * Delegate this action is working for or <code>null</code> if none.
52
     */
53
    private DebugCommandActionDelegate fDelegate;
54
55
    /**
56
     * Constructor
57
     */
58
    public DebugCommandAction() {
59
        super();
60
        String helpContextId = getHelpContextId();
61
        if (helpContextId != null)
62
            PlatformUI.getWorkbench().getHelpSystem().setHelp(this, helpContextId);
63
        setEnabled(false);
64
    }
65
66
	/**
67
     * Set the current delegate
68
     * @param delegate
69
     */
70
    public void setDelegate(DebugCommandActionDelegate delegate) {
71
        fDelegate = delegate;
72
    }
73
74
    /**
75
     * Executes this action on the given target object
76
     * 
77
     * @param target the target to perform the action on
78
     */
79
    protected boolean execute(Object[] targets) {
80
    	return fUpdateService.executeCommand(getCommandType(), targets, getCommandParticipant(targets));
81
    }
82
    
83
    /**
84
     * Creates and returns the command participant or <code>null</code>.
85
     * 
86
     * @return command participant to use on command completion
87
     */
88
    protected ICommandParticipant getCommandParticipant(Object[] targets) {
89
    	return null;
90
    }
91
    
92
    /**
93
     * Returns the command type this action executes.
94
     * 
95
     * @return command class.
96
     */
97
    abstract protected Class getCommandType();  
98
99
    /**
100
     * @see org.eclipse.debug.ui.contexts.IDebugContextListener#debugContextChanged(org.eclipse.debug.ui.contexts.DebugContextEvent)
101
     */
102
    public void debugContextChanged(DebugContextEvent event) {
103
    	fUpdateService.postUpdateCommand(getCommandType(), this);
104
	}
105
106
    /**
107
     * @see org.eclipse.jface.action.Action#setEnabled(boolean)
108
     */
109
    public void setEnabled(boolean enabled) {
110
        super.setEnabled(enabled);
111
        if (fDelegate != null) {
112
            fDelegate.setEnabled(enabled);
113
        }
114
    }
115
116
    /**
117
     * Initializes this action for a specific part.
118
     * 
119
     * @param part workbench part
120
     */
121
    public void init(IWorkbenchPart part) {
122
        fPart = part;
123
        fWindow = part.getSite().getWorkbenchWindow();
124
        fUpdateService = DebugCommandService.getService(fWindow);
125
        IDebugContextService service = getDebugContextService();
126
		String partId = part.getSite().getId();
127
		service.addDebugContextListener(this, partId);
128
        ISelection activeContext = service.getActiveContext(partId);
129
        if (activeContext != null) {
130
        	fUpdateService.updateCommand(getCommandType(), this);
131
        } else {
132
        	setEnabled(getInitialEnablement());
133
        }
134
    }
135
    
136
    /**
137
     * Initializes the context action
138
     * @param window the window
139
     */
140
    public void init(IWorkbenchWindow window) {
141
        fWindow = window;
142
        fUpdateService = DebugCommandService.getService(fWindow);
143
        IDebugContextService contextService = getDebugContextService();
144
		contextService.addDebugContextListener(this);
145
        ISelection activeContext = contextService.getActiveContext();
146
        if (activeContext != null) {
147
        	fUpdateService.updateCommand(getCommandType(), this);
148
        } else {
149
        	setEnabled(getInitialEnablement());
150
        }
151
    }
152
    
153
    /**
154
     * Returns whether this action should be enabled when initialized
155
     * and there is no active debug context.
156
     * 
157
     * @return false, by default
158
     */
159
    protected boolean getInitialEnablement() {
160
    	return false;
161
    }
162
163
    /**
164
     * Returns the most recent selection
165
     * 
166
     * @return structured selection
167
     */
168
    protected ISelection getContext() {
169
		if (fPart != null) {
170
			getDebugContextService().getActiveContext(fPart.getSite().getId());
171
    	}
172
        return getDebugContextService().getActiveContext();
173
    }
174
175
    /*
176
     * (non-Javadoc)
177
     * @see org.eclipse.jface.action.Action#run()
178
     */
179
    public void run() {
180
        ISelection selection = getContext();
181
        if (selection instanceof IStructuredSelection && isEnabled()) {
182
            IStructuredSelection ss = (IStructuredSelection) selection;
183
            boolean enabled = execute(ss.toArray());
184
            // disable the action according to the command
185
            setEnabled(enabled);
186
        }
187
    }
188
189
    /*
190
     * (non-Javadoc)
191
     * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event)
192
     */
193
    public void runWithEvent(Event event) {
194
        run();
195
    }
196
197
    /**
198
     * Clean up when removing
199
     */
200
    public void dispose() {
201
        IDebugContextService service = getDebugContextService();
202
        if (fPart != null) {
203
        	service.removeDebugContextListener(this, fPart.getSite().getId());
204
        } else {
205
            service.removeDebugContextListener(this);
206
        }
207
        fWindow = null;
208
        fPart = null;
209
    }
210
    
211
    /**
212
     * Returns the context service this action linked to.
213
     * @return
214
     */
215
    protected IDebugContextService getDebugContextService() {
216
    	return DebugUITools.getDebugContextManager().getContextService(fWindow);
217
    }
218
219
    /**
220
     * @return The help context id for this action
221
     */ 
222
    public abstract String getHelpContextId();
223
224
    /*
225
     * (non-Javadoc)
226
     * @see org.eclipse.jface.action.Action#getId()
227
     */
228
    public abstract String getId();
229
230
    /*
231
     * (non-Javadoc)
232
     * @see org.eclipse.jface.action.Action#getText()
233
     */
234
    public abstract String getText();
235
236
    /*
237
     * (non-Javadoc)
238
     * @see org.eclipse.jface.action.Action#getToolTipText()
239
     */
240
    public abstract String getToolTipText();
241
242
    /*
243
     * (non-Javadoc)
244
     * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor()
245
     */
246
    public abstract ImageDescriptor getDisabledImageDescriptor();
247
248
    /*
249
     * (non-Javadoc)
250
     * @see org.eclipse.jface.action.Action#getHoverImageDescriptor()
251
     */
252
    public abstract ImageDescriptor getHoverImageDescriptor();
253
254
    /*
255
     * (non-Javadoc)
256
     * @see org.eclipse.jface.action.Action#getImageDescriptor()
257
     */
258
    public abstract ImageDescriptor getImageDescriptor();
259
    
260
    /**
261
     * Returns the delegate associated with this action or <code>null</code>
262
     * if none.
263
     * 
264
     * @return delegate or <code>null</code>
265
     */
266
    protected DebugCommandActionDelegate getDelegate() {
267
    	return fDelegate;
268
    }
269
}
(-)ui/org/eclipse/debug/internal/ui/commands/actions/SuspendCommandActionDelegate.java (+1 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.debug.internal.ui.commands.actions;
12
package org.eclipse.debug.internal.ui.commands.actions;
13
13
14
14
/**
15
/**
15
 * Suspend action delegate.
16
 * Suspend action delegate.
16
 * 
17
 * 
(-)ui/org/eclipse/debug/internal/ui/commands/actions/ActionsUpdater.java (-3 / +2 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.ui.commands.actions;
11
package org.eclipse.debug.internal.ui.commands.actions;
12
12
13
import org.eclipse.jface.action.IAction;
14
13
15
/**
14
/**
16
 * Collects votes from handler update requests.
15
 * Collects votes from handler update requests.
Lines 20-32 Link Here
20
 */
19
 */
21
public class ActionsUpdater {
20
public class ActionsUpdater {
22
	
21
	
23
	private IAction[] fActions;
22
	private IEnabledTarget[] fActions;
24
	private int fNumVoters;
23
	private int fNumVoters;
25
	private int fNumOfVotes = 0;
24
	private int fNumOfVotes = 0;
26
	private boolean fDone = false;
25
	private boolean fDone = false;
27
	private boolean fEnabled = true;
26
	private boolean fEnabled = true;
28
	
27
	
29
	public ActionsUpdater(IAction[] actions, int numVoters) {
28
	public ActionsUpdater(IEnabledTarget[] actions, int numVoters) {
30
		fActions = actions;
29
		fActions = actions;
31
		fNumVoters = numVoters;
30
		fNumVoters = numVoters;
32
	}
31
	}
(-)ui/org/eclipse/debug/internal/ui/commands/actions/StepOverCommandActionDelegate.java (+1 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.debug.internal.ui.commands.actions;
12
package org.eclipse.debug.internal.ui.commands.actions;
13
13
14
14
/**
15
/**
15
 * Step over action delegate.
16
 * Step over action delegate.
16
 * 
17
 * 
(-)ui/org/eclipse/debug/internal/ui/commands/actions/ResumeCommandActionDelegate.java (-5 / +33 lines)
Lines 11-27 Link Here
11
11
12
package org.eclipse.debug.internal.ui.commands.actions;
12
package org.eclipse.debug.internal.ui.commands.actions;
13
13
14
import org.eclipse.debug.ui.actions.DebugCommandAction;
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.swt.widgets.Event;
18
import org.eclipse.ui.IActionDelegate2;
19
import org.eclipse.ui.IWorkbenchWindow;
20
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
21
14
/**
22
/**
15
 * Resume action delegate.
23
 * Resume action delegate.
16
 * 
24
 * 
17
 * @since 3.3
25
 * @since 3.3
18
 */
26
 */
19
public class ResumeCommandActionDelegate extends DebugCommandActionDelegate {
27
public class ResumeCommandActionDelegate implements IWorkbenchWindowActionDelegate, IActionDelegate2 {
20
28
21
    public ResumeCommandActionDelegate() {
29
    private DebugCommandAction fDebugAction = new ResumeCommandAction();
22
        super();
30
    
23
        setAction(new ResumeCommandAction());
31
    public void dispose() {
32
        fDebugAction.dispose();
24
    }
33
    }
25
34
26
    
35
    public void init(IWorkbenchWindow window) {
36
        fDebugAction.init(window);
37
    }
38
39
    public void run(IAction action) {
40
        fDebugAction.run();
41
    }
42
43
    public void selectionChanged(IAction action, ISelection selection) {
44
        // do nothing
45
    }
46
47
    public void init(IAction action) {
48
        fDebugAction.setAction(action);
49
        
50
    }
51
52
    public void runWithEvent(IAction action, Event event) {
53
        run(action);
54
    }
27
}
55
}
(-)ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAndRelaunchAction.java (+1 lines)
Lines 20-25 Link Here
20
import org.eclipse.debug.internal.ui.actions.ActionMessages;
20
import org.eclipse.debug.internal.ui.actions.ActionMessages;
21
import org.eclipse.debug.internal.ui.actions.RelaunchActionDelegate;
21
import org.eclipse.debug.internal.ui.actions.RelaunchActionDelegate;
22
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
22
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
23
import org.eclipse.debug.ui.actions.DebugCommandAction;
23
import org.eclipse.debug.ui.contexts.DebugContextEvent;
24
import org.eclipse.debug.ui.contexts.DebugContextEvent;
24
import org.eclipse.jface.resource.ImageDescriptor;
25
import org.eclipse.jface.resource.ImageDescriptor;
25
import org.eclipse.jface.viewers.ISelection;
26
import org.eclipse.jface.viewers.ISelection;
(-)ui/org/eclipse/debug/internal/ui/commands/actions/ToggleStepFiltersAction.java (-3 / +5 lines)
Lines 19-25 Link Here
19
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
19
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
20
import org.eclipse.debug.internal.ui.actions.ActionMessages;
20
import org.eclipse.debug.internal.ui.actions.ActionMessages;
21
import org.eclipse.debug.ui.DebugUITools;
21
import org.eclipse.debug.ui.DebugUITools;
22
import org.eclipse.debug.ui.actions.DebugCommandAction;
22
import org.eclipse.debug.ui.contexts.DebugContextEvent;
23
import org.eclipse.debug.ui.contexts.DebugContextEvent;
24
import org.eclipse.jface.action.IAction;
23
import org.eclipse.jface.resource.ImageDescriptor;
25
import org.eclipse.jface.resource.ImageDescriptor;
24
import org.eclipse.jface.viewers.ISelection;
26
import org.eclipse.jface.viewers.ISelection;
25
import org.eclipse.ui.IWorkbenchPart;
27
import org.eclipse.ui.IWorkbenchPart;
Lines 166-174 Link Here
166
		if (event.getProperty().equals(StepFilterManager.PREF_USE_STEP_FILTERS)) {
168
		if (event.getProperty().equals(StepFilterManager.PREF_USE_STEP_FILTERS)) {
167
			boolean checked = DebugUITools.isUseStepFilters();
169
			boolean checked = DebugUITools.isUseStepFilters();
168
			setChecked(checked);
170
			setChecked(checked);
169
			DebugCommandActionDelegate delegate = getDelegate();
171
			IAction action = getAction();
170
			if (delegate != null) {
172
			if (action != null) {
171
				delegate.setChecked(checked);
173
				action.setChecked(checked);
172
			}
174
			}
173
		}		
175
		}		
174
	}
176
	}
(-)ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAndRemoveAction.java (-35 / +19 lines)
Lines 20-25 Link Here
20
import org.eclipse.debug.internal.ui.DebugPluginImages;
20
import org.eclipse.debug.internal.ui.DebugPluginImages;
21
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
21
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
22
import org.eclipse.debug.internal.ui.actions.ActionMessages;
22
import org.eclipse.debug.internal.ui.actions.ActionMessages;
23
import org.eclipse.debug.ui.actions.DebugCommandAction;
23
import org.eclipse.jface.resource.ImageDescriptor;
24
import org.eclipse.jface.resource.ImageDescriptor;
24
25
25
/**
26
/**
Lines 29-66 Link Here
29
 */
30
 */
30
public class TerminateAndRemoveAction extends DebugCommandAction {
31
public class TerminateAndRemoveAction extends DebugCommandAction {
31
32
32
    
33
    class TerminateAndRemoveParticipant implements ICommandParticipant {
34
        private Object[] fElements;
35
        
36
        TerminateAndRemoveParticipant(Object[] elements) {
37
            fElements = elements;
38
        }
39
        
40
		/* (non-Javadoc)
41
		 * @see org.eclipse.debug.internal.ui.commands.actions.ICommandParticipant#requestDone(org.eclipse.debug.core.commands.IRequest)
42
		 */
43
		public void requestDone(IRequest request) {
44
			IStatus status = request.getStatus();
45
			if(status == null || status.isOK()) {
46
				for (int i = 0; i < fElements.length; i++) {
47
					Object element = fElements[i];
48
	                ILaunch launch= null;
49
	                if (element instanceof ILaunch) {
50
	                    launch= (ILaunch) element;
51
	                } else if (element instanceof IDebugElement) {
52
	                    launch= ((IDebugElement) element).getLaunch();
53
	                } else if (element instanceof IProcess) {
54
	                    launch= ((IProcess) element).getLaunch();
55
	                }   
56
	                if (launch != null)
57
	                    DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);					
58
				}
59
            }
60
		}
61
        
62
    }
63
64
    public String getText() {
33
    public String getText() {
65
        return ActionMessages.TerminateAndRemoveAction_0;
34
        return ActionMessages.TerminateAndRemoveAction_0;
66
    }
35
    }
Lines 93-101 Link Here
93
		return ITerminateHandler.class;
62
		return ITerminateHandler.class;
94
	}
63
	}
95
64
96
	protected ICommandParticipant getCommandParticipant(Object[] targets) {
65
    protected void requestDone(Object[] elements, IRequest request) {
97
		return new TerminateAndRemoveParticipant(targets);
66
        IStatus status = request.getStatus();
98
	}
67
        if(status == null || status.isOK()) {
68
            for (int i = 0; i < elements.length; i++) {
69
                Object element = elements[i];
70
                ILaunch launch= null;
71
                if (element instanceof ILaunch) {
72
                    launch= (ILaunch) element;
73
                } else if (element instanceof IDebugElement) {
74
                    launch= ((IDebugElement) element).getLaunch();
75
                } else if (element instanceof IProcess) {
76
                    launch= ((IProcess) element).getLaunch();
77
                }   
78
                if (launch != null)
79
                    DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);                   
80
            }
81
        }
82
    }
99
83
100
    
84
    
101
}
85
}
(-)ui/org/eclipse/debug/internal/ui/commands/actions/StepIntoCommandAction.java (+1 lines)
Lines 14-19 Link Here
14
import org.eclipse.debug.internal.ui.DebugPluginImages;
14
import org.eclipse.debug.internal.ui.DebugPluginImages;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
17
import org.eclipse.debug.ui.actions.DebugCommandAction;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.resource.ImageDescriptor;
18
19
19
/**
20
/**
(-)ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAllAction.java (+1 lines)
Lines 18-23 Link Here
18
import org.eclipse.debug.internal.ui.DebugPluginImages;
18
import org.eclipse.debug.internal.ui.DebugPluginImages;
19
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
19
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
20
import org.eclipse.debug.internal.ui.actions.ActionMessages;
20
import org.eclipse.debug.internal.ui.actions.ActionMessages;
21
import org.eclipse.debug.ui.actions.DebugCommandAction;
21
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.jface.viewers.ISelection;
23
import org.eclipse.jface.viewers.ISelection;
23
import org.eclipse.jface.viewers.StructuredSelection;
24
import org.eclipse.jface.viewers.StructuredSelection;
(-)ui/org/eclipse/debug/internal/ui/commands/actions/DisconnectCommandAction.java (+1 lines)
Lines 15-20 Link Here
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
17
import org.eclipse.debug.ui.IDebugUIConstants;
17
import org.eclipse.debug.ui.IDebugUIConstants;
18
import org.eclipse.debug.ui.actions.DebugCommandAction;
18
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.jface.resource.ImageDescriptor;
19
/**
20
/**
20
 * Disconnect action.
21
 * Disconnect action.
(-)ui/org/eclipse/debug/internal/ui/commands/actions/SuspendCommandAction.java (+1 lines)
Lines 14-19 Link Here
14
import org.eclipse.debug.internal.ui.DebugPluginImages;
14
import org.eclipse.debug.internal.ui.DebugPluginImages;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
17
import org.eclipse.debug.ui.actions.DebugCommandAction;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.resource.ImageDescriptor;
18
19
19
/**
20
/**
(-)ui/org/eclipse/debug/internal/ui/commands/actions/StepIntoCommandActionDelegate.java (+1 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.debug.internal.ui.commands.actions;
12
package org.eclipse.debug.internal.ui.commands.actions;
13
13
14
14
/**
15
/**
15
 * Step into action delegate.
16
 * Step into action delegate.
16
 * 
17
 * 
(-)ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandService.java (-6 / +5 lines)
Lines 24-30 Link Here
24
import org.eclipse.debug.ui.contexts.DebugContextEvent;
24
import org.eclipse.debug.ui.contexts.DebugContextEvent;
25
import org.eclipse.debug.ui.contexts.IDebugContextListener;
25
import org.eclipse.debug.ui.contexts.IDebugContextListener;
26
import org.eclipse.debug.ui.contexts.IDebugContextService;
26
import org.eclipse.debug.ui.contexts.IDebugContextService;
27
import org.eclipse.jface.action.Action;
28
import org.eclipse.jface.action.IAction;
27
import org.eclipse.jface.action.IAction;
29
import org.eclipse.jface.viewers.ISelection;
28
import org.eclipse.jface.viewers.ISelection;
30
import org.eclipse.jface.viewers.IStructuredSelection;
29
import org.eclipse.jface.viewers.IStructuredSelection;
Lines 111-117 Link Here
111
	 * @param commandType
110
	 * @param commandType
112
	 * @param monitor
111
	 * @param monitor
113
	 */
112
	 */
114
	public void postUpdateCommand(Class commandType, Action action) {
113
	public void postUpdateCommand(Class commandType, IEnabledTarget action) {
115
		synchronized (fCommandUpdates) {
114
		synchronized (fCommandUpdates) {
116
			Job.getJobManager().cancel(commandType);
115
			Job.getJobManager().cancel(commandType);
117
			List actions = (List) fCommandUpdates.get(commandType);
116
			List actions = (List) fCommandUpdates.get(commandType);
Lines 129-139 Link Here
129
	 * @param commandType
128
	 * @param commandType
130
	 * @param requestMonitor
129
	 * @param requestMonitor
131
	 */
130
	 */
132
	public void updateCommand(Class commandType, IAction action) {
131
	public void updateCommand(Class commandType, IEnabledTarget action) {
133
		ISelection context = fContextService.getActiveContext();
132
		ISelection context = fContextService.getActiveContext();
134
		if (context instanceof IStructuredSelection && !context.isEmpty()) {
133
		if (context instanceof IStructuredSelection && !context.isEmpty()) {
135
			Object[] elements = ((IStructuredSelection)context).toArray();
134
			Object[] elements = ((IStructuredSelection)context).toArray();
136
			updateCommand(commandType, elements, new IAction[]{action});
135
			updateCommand(commandType, elements, new IEnabledTarget[]{action});
137
		} else {
136
		} else {
138
			action.setEnabled(false);
137
			action.setEnabled(false);
139
		}
138
		}
Lines 152-158 Link Here
152
				Entry entry = (Entry) iterator.next();
151
				Entry entry = (Entry) iterator.next();
153
				Class commandType = (Class)entry.getKey();
152
				Class commandType = (Class)entry.getKey();
154
				List actions = (List) entry.getValue();
153
				List actions = (List) entry.getValue();
155
				updateCommand(commandType, elements, (IAction[]) actions.toArray(new IAction[actions.size()]));
154
				updateCommand(commandType, elements, (IEnabledTarget[]) actions.toArray(new IEnabledTarget[actions.size()]));
156
			}
155
			}
157
		} else {
156
		} else {
158
			Iterator iterator = commands.values().iterator();
157
			Iterator iterator = commands.values().iterator();
Lines 174-180 Link Here
174
	 * @param elements elements to update for
173
	 * @param elements elements to update for
175
	 * @param monitor status monitor
174
	 * @param monitor status monitor
176
	 */
175
	 */
177
	private void updateCommand(Class handlerType, Object[] elements, IAction[] actions) {
176
	private void updateCommand(Class handlerType, Object[] elements, IEnabledTarget[] actions) {
178
		if (elements.length == 1) {
177
		if (elements.length == 1) {
179
			// usual case - one element
178
			// usual case - one element
180
			Object element = elements[0];
179
			Object element = elements[0];
(-)ui/org/eclipse/debug/internal/ui/commands/actions/ResumeCommandAction.java (+1 lines)
Lines 14-19 Link Here
14
import org.eclipse.debug.internal.ui.DebugPluginImages;
14
import org.eclipse.debug.internal.ui.DebugPluginImages;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
17
import org.eclipse.debug.ui.actions.DebugCommandAction;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.resource.ImageDescriptor;
18
19
19
/**
20
/**
(-)ui/org/eclipse/debug/internal/ui/commands/actions/StepOverCommandAction.java (+1 lines)
Lines 15-20 Link Here
15
import org.eclipse.debug.internal.ui.DebugPluginImages;
15
import org.eclipse.debug.internal.ui.DebugPluginImages;
16
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
16
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
17
import org.eclipse.debug.internal.ui.actions.ActionMessages;
17
import org.eclipse.debug.internal.ui.actions.ActionMessages;
18
import org.eclipse.debug.ui.actions.DebugCommandAction;
18
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.jface.resource.ImageDescriptor;
19
20
20
/**
21
/**
(-)ui/org/eclipse/debug/internal/ui/commands/actions/ToggleStepFiltersCommandActionDelegate.java (-8 / +5 lines)
Lines 12-18 Link Here
12
package org.eclipse.debug.internal.ui.commands.actions;
12
package org.eclipse.debug.internal.ui.commands.actions;
13
13
14
import org.eclipse.debug.ui.DebugUITools;
14
import org.eclipse.debug.ui.DebugUITools;
15
import org.eclipse.ui.IWorkbenchWindow;
15
import org.eclipse.jface.action.IAction;
16
16
17
/**
17
/**
18
 * Toggle step filters action delegate.
18
 * Toggle step filters action delegate.
Lines 29-39 Link Here
29
        setAction(new ToggleStepFiltersAction());
29
        setAction(new ToggleStepFiltersAction());
30
    }
30
    }
31
31
32
	/**
32
    public void init(IAction action) {
33
	 * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
33
        super.init(action);
34
	 */
34
        action.setChecked(DebugUITools.isUseStepFilters());
35
	public void init(IWorkbenchWindow window) {
35
    }
36
		super.init(window);
37
		setChecked(DebugUITools.isUseStepFilters());
38
	}
39
}
36
}
(-)ui/org/eclipse/debug/internal/ui/commands/actions/TerminateCommandAction.java (+1 lines)
Lines 14-19 Link Here
14
import org.eclipse.debug.internal.ui.DebugPluginImages;
14
import org.eclipse.debug.internal.ui.DebugPluginImages;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
15
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
17
import org.eclipse.debug.ui.actions.DebugCommandAction;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.resource.ImageDescriptor;
18
19
19
/**
20
/**
(-)ui/org/eclipse/debug/internal/ui/commands/actions/TerminateCommandActionDelegate.java (+1 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.debug.internal.ui.commands.actions;
12
package org.eclipse.debug.internal.ui.commands.actions;
13
13
14
14
/**
15
/**
15
 * Terminate action delegate.
16
 * Terminate action delegate.
16
 * 
17
 * 
(-)ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java (-1 / +1 lines)
Lines 41-47 Link Here
41
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
41
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
42
import org.eclipse.debug.internal.ui.actions.AddToFavoritesAction;
42
import org.eclipse.debug.internal.ui.actions.AddToFavoritesAction;
43
import org.eclipse.debug.internal.ui.actions.EditLaunchConfigurationAction;
43
import org.eclipse.debug.internal.ui.actions.EditLaunchConfigurationAction;
44
import org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction;
45
import org.eclipse.debug.internal.ui.commands.actions.DisconnectCommandAction;
44
import org.eclipse.debug.internal.ui.commands.actions.DisconnectCommandAction;
46
import org.eclipse.debug.internal.ui.commands.actions.DropToFrameCommandAction;
45
import org.eclipse.debug.internal.ui.commands.actions.DropToFrameCommandAction;
47
import org.eclipse.debug.internal.ui.commands.actions.ResumeCommandAction;
46
import org.eclipse.debug.internal.ui.commands.actions.ResumeCommandAction;
Lines 72-77 Link Here
72
import org.eclipse.debug.ui.DebugUITools;
71
import org.eclipse.debug.ui.DebugUITools;
73
import org.eclipse.debug.ui.IDebugModelPresentation;
72
import org.eclipse.debug.ui.IDebugModelPresentation;
74
import org.eclipse.debug.ui.IDebugUIConstants;
73
import org.eclipse.debug.ui.IDebugUIConstants;
74
import org.eclipse.debug.ui.actions.DebugCommandAction;
75
import org.eclipse.debug.ui.contexts.AbstractDebugContextProvider;
75
import org.eclipse.debug.ui.contexts.AbstractDebugContextProvider;
76
import org.eclipse.debug.ui.contexts.DebugContextEvent;
76
import org.eclipse.debug.ui.contexts.DebugContextEvent;
77
import org.eclipse.debug.ui.contexts.IDebugContextListener;
77
import org.eclipse.debug.ui.contexts.IDebugContextListener;
(-)ui/org/eclipse/debug/ui/actions/DebugCommandHandler.java (+250 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Wind River Systems - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.debug.ui.actions;
13
14
import java.util.Iterator;
15
import java.util.Map;
16
import java.util.WeakHashMap;
17
18
import org.eclipse.core.commands.AbstractHandler;
19
import org.eclipse.core.commands.ExecutionEvent;
20
import org.eclipse.core.commands.ExecutionException;
21
import org.eclipse.core.commands.HandlerEvent;
22
import org.eclipse.core.expressions.IEvaluationContext;
23
import org.eclipse.debug.internal.ui.commands.actions.DebugCommandService;
24
import org.eclipse.debug.internal.ui.commands.actions.ICommandParticipant;
25
import org.eclipse.debug.internal.ui.commands.actions.IEnabledTarget;
26
import org.eclipse.debug.ui.DebugUITools;
27
import org.eclipse.debug.ui.contexts.DebugContextEvent;
28
import org.eclipse.debug.ui.contexts.IDebugContextListener;
29
import org.eclipse.debug.ui.contexts.IDebugContextService;
30
import org.eclipse.jface.viewers.ISelection;
31
import org.eclipse.jface.viewers.IStructuredSelection;
32
import org.eclipse.ui.ISources;
33
import org.eclipse.ui.IWindowListener;
34
import org.eclipse.ui.IWorkbenchWindow;
35
import org.eclipse.ui.PlatformUI;
36
import org.eclipse.ui.handlers.HandlerUtil;
37
38
/**
39
 * Abstract base class for re-targeting command framework handlers, which 
40
 * delegate execution to {@link org.eclipse.debug.core.commands.IDebugCommandHandler} 
41
 * handlers. The specific type of <code>IDebugCommandHandler</code> is 
42
 * determined by the abstract {@link #getCommandType()} method.    
43
 * 
44
 * <p> Note: This class is not an implementation of the <code>IDebugCommandHandler</code>
45
 * interface, which was somewhat unfortunately named.  <code>IDebugCommandHandler</code> 
46
 * is an interface that is internal to the debugger plugins.  This class implements 
47
 * {@link org.eclipse.core.commands.IHandler} interface and is to be used with the 
48
 * platform commands framework. </p>
49
 * 
50
 * @see org.eclipse.debug.core.commands.IDebugCommandHandler
51
 * @see org.eclipse.core.commands.IHandler
52
 *
53
 * @since 3.6
54
 */
55
public abstract class DebugCommandHandler extends AbstractHandler {
56
57
    private class EnabledTarget implements IEnabledTarget, IDebugContextListener, IWindowListener {
58
        boolean fEnabled = getInitialEnablement();
59
        IWorkbenchWindow fWindow;
60
        
61
        EnabledTarget(IWorkbenchWindow window) {
62
            fWindow = window;
63
            DebugCommandService.getService(fWindow).updateCommand(getCommandType(), this);
64
            getContextService(fWindow).addDebugContextListener(this);
65
            PlatformUI.getWorkbench().addWindowListener(this);
66
        }
67
        
68
        public void setEnabled(boolean enabled) {
69
            boolean oldEnabled = fEnabled;
70
            fEnabled = enabled;
71
            if (fEnabled != oldEnabled) {
72
                fireHandlerChanged(new HandlerEvent(DebugCommandHandler.this, true, false));
73
            }
74
        }
75
        
76
        public void debugContextChanged(DebugContextEvent event) {
77
            DebugCommandService.getService(fWindow).postUpdateCommand(getCommandType(), this);
78
        }
79
        
80
        public void windowOpened(IWorkbenchWindow w) {
81
        }
82
    
83
        public void windowDeactivated(IWorkbenchWindow w) {
84
        }
85
    
86
        public void windowClosed(IWorkbenchWindow w) {
87
            if (w.equals(fWindow)) {
88
                dispose();
89
            }
90
        }
91
    
92
        public void windowActivated(IWorkbenchWindow w) {
93
        }
94
        
95
        void dispose() {
96
            if (isDisposed()) {
97
                return;
98
            }
99
            PlatformUI.getWorkbench().removeWindowListener(this);
100
            getContextService(fWindow).removeDebugContextListener(this);
101
            fWindow = null;
102
        }
103
        
104
        boolean isDisposed() {
105
            return fWindow == null;
106
        }
107
    }
108
109
    private Map fEnabledTargetsMap = new WeakHashMap();
110
111
    private EnabledTarget fCurrentEnabledTarget = null;
112
    
113
    /**
114
     * Constructor
115
     */
116
    public DebugCommandHandler() {
117
        super();
118
        PlatformUI.getWorkbench().addWindowListener(new IWindowListener() {
119
            
120
            public void windowOpened(IWorkbenchWindow w) {
121
            }
122
        
123
            public void windowDeactivated(IWorkbenchWindow w) {
124
            }
125
        
126
            public void windowClosed(IWorkbenchWindow w) {
127
                EnabledTarget enabledTarget = (EnabledTarget)fEnabledTargetsMap.get(w);
128
                if (enabledTarget != null) {
129
                    enabledTarget.dispose();
130
                }
131
            }
132
        
133
            public void windowActivated(IWorkbenchWindow w) {
134
            }
135
        });
136
    }
137
    
138
    public void setEnabled(Object evaluationContext) {
139
        fCurrentEnabledTarget = null;
140
        
141
        if (!(evaluationContext instanceof IEvaluationContext)) {
142
            return;
143
        }
144
        IEvaluationContext context = (IEvaluationContext) evaluationContext;
145
        Object _window = context.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME);
146
        if (_window instanceof IWorkbenchWindow) {
147
            IWorkbenchWindow window = (IWorkbenchWindow)_window;
148
            fCurrentEnabledTarget = getEnabledTarget(window);
149
        }
150
    }
151
    
152
    public boolean isEnabled() {
153
        if (fCurrentEnabledTarget == null) {
154
            return false;
155
        }
156
        return fCurrentEnabledTarget.fEnabled;
157
    }
158
    
159
    private EnabledTarget getEnabledTarget(IWorkbenchWindow window) {
160
        EnabledTarget target = (EnabledTarget)fEnabledTargetsMap.get(window);
161
        if (target == null) {
162
            target = new EnabledTarget(window);
163
            DebugCommandService service = DebugCommandService.getService(window);
164
            service.updateCommand(getCommandType(), target);
165
            
166
            DebugUITools.getDebugContextManager().getContextService(window).addDebugContextListener(target);
167
            
168
            fEnabledTargetsMap.put(window, target);
169
        }
170
        return target;
171
    }
172
    
173
    public Object execute(ExecutionEvent event) throws ExecutionException {
174
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
175
        if (window == null) {
176
            throw new ExecutionException("No active workbench window.");
177
        }
178
        fCurrentEnabledTarget = getEnabledTarget(window);
179
180
        ISelection selection = getContextService(window).getActiveContext();
181
        if (selection instanceof IStructuredSelection && isEnabled()) {
182
            IStructuredSelection ss = (IStructuredSelection) selection;
183
            boolean enabledAfterExecute = execute(window, ss.toArray());
184
            
185
            // enable/disable the action according to the command
186
            fCurrentEnabledTarget.setEnabled(enabledAfterExecute);
187
        }
188
189
        return null;
190
    }
191
    
192
    private IDebugContextService getContextService(IWorkbenchWindow window) {
193
        return DebugUITools.getDebugContextManager().getContextService(window);
194
    }
195
    
196
    /**
197
     * Executes this action on the given target object
198
     * 
199
     * @param target the target to perform the action on
200
     */
201
    private boolean execute(IWorkbenchWindow window, Object[] targets) {
202
        DebugCommandService service = DebugCommandService.getService(window); 
203
    	return service.executeCommand(getCommandType(), targets, getCommandParticipant(targets));
204
    }
205
    
206
    /**
207
     * Creates and returns the command participant or <code>null</code>.
208
     * 
209
     * @return command participant to use on command completion
210
     */
211
    protected ICommandParticipant getCommandParticipant(Object[] targets) {
212
    	return null;
213
    }
214
    
215
    /**
216
     * Returns the {@link org.eclipse.debug.core.commands.IDebugCommandHandler} 
217
     * command handler that type this action executes.
218
     * 
219
     * @return command class.
220
     * 
221
     * @see org.eclipse.debug.core.commands.IDebugCommandHandler
222
     */
223
    abstract protected Class getCommandType();  
224
225
    
226
    /**
227
     * Returns whether this action should be enabled when initialized
228
     * and there is no active debug context.
229
     * 
230
     * @return false, by default
231
     */
232
    protected boolean getInitialEnablement() {
233
    	return false;
234
    }
235
236
237
    /**
238
     * Clean up when removing
239
     */
240
    public void dispose() {
241
        for (Iterator itr = fEnabledTargetsMap.values().iterator(); itr.hasNext();) {
242
            EnabledTarget target = (EnabledTarget)itr.next();
243
            if (!target.isDisposed()) {
244
                target.dispose();
245
            }
246
        }
247
        fEnabledTargetsMap.clear();
248
        fCurrentEnabledTarget = null;
249
    }
250
}
(-)ui/org/eclipse/debug/internal/ui/commands/actions/IEnabledTarget.java (+18 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Wind River Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     Wind River Systems - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.ui.commands.actions;
12
13
/**
14
 * 
15
 */
16
public interface IEnabledTarget {
17
    public void setEnabled(boolean enabled);
18
}
(-)ui/org/eclipse/debug/ui/actions/DebugCommandAction.java (+308 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.debug.ui.actions;
13
14
import org.eclipse.debug.core.IRequest;
15
import org.eclipse.debug.internal.ui.commands.actions.DebugCommandService;
16
import org.eclipse.debug.internal.ui.commands.actions.ICommandParticipant;
17
import org.eclipse.debug.internal.ui.commands.actions.IEnabledTarget;
18
import org.eclipse.debug.ui.DebugUITools;
19
import org.eclipse.debug.ui.contexts.DebugContextEvent;
20
import org.eclipse.debug.ui.contexts.IDebugContextListener;
21
import org.eclipse.debug.ui.contexts.IDebugContextService;
22
import org.eclipse.jface.action.Action;
23
import org.eclipse.jface.action.IAction;
24
import org.eclipse.jface.resource.ImageDescriptor;
25
import org.eclipse.jface.viewers.ISelection;
26
import org.eclipse.jface.viewers.IStructuredSelection;
27
import org.eclipse.swt.widgets.Event;
28
import org.eclipse.ui.IWorkbenchPart;
29
import org.eclipse.ui.IWorkbenchWindow;
30
import org.eclipse.ui.PlatformUI;
31
32
/**
33
 * Abstract base class for re-targeting actions which delegate execution to 
34
 * {@link org.eclipse.debug.core.commands.IDebugCommandHandler} handlers.  
35
 * The specific type of <code>IDebugCommandHandler</code> is determined by the 
36
 * abstract {@link #getCommandType()} method.    
37
 * 
38
 * @see org.eclipse.debug.core.commands.IDebugCommandHandler
39
 *
40
 * @since 3.6 This class was in the internal package 
41
 * <code>org.eclipse.debug.internal.ui.commands.actions</code> since 3.3.
42
 */
43
public abstract class DebugCommandAction extends Action implements IDebugContextListener {
44
45
    private boolean fInitialized = false;
46
    
47
	/**
48
	 * The window this action is working for.
49
	 */
50
    private IWorkbenchWindow fWindow;
51
    
52
    /**
53
     * The part this action is working for, or <code>null</code> if global to
54
     * a window.
55
     */
56
    private IWorkbenchPart fPart;
57
    
58
    /**
59
     * Command service.
60
     */
61
    private DebugCommandService fUpdateService;
62
    
63
    /**
64
     * Delegate this action is working for or <code>null</code> if none.
65
     */
66
    private IAction fAction;
67
68
    private IEnabledTarget fEnabledTarget = new IEnabledTarget() {
69
        public void setEnabled(boolean enabled) {
70
            DebugCommandAction.this.setEnabled(enabled);
71
        }
72
    };
73
    
74
    /**
75
     * Constructor
76
     */
77
    public DebugCommandAction() {
78
        super();
79
        String helpContextId = getHelpContextId();
80
        if (helpContextId != null)
81
            PlatformUI.getWorkbench().getHelpSystem().setHelp(this, helpContextId);
82
        setEnabled(false);
83
    }
84
85
	/**
86
     * Set the current delegate
87
     * @param delegate
88
     */
89
    public void setAction(IAction action) {
90
        fAction = action;
91
        fAction.setEnabled(isEnabled());
92
    }
93
94
    /**
95
     * Executes this action on the given target object
96
     * 
97
     * @param target the target to perform the action on
98
     */
99
    private boolean execute(final Object[] targets) {
100
    	return fUpdateService.executeCommand(
101
    	    getCommandType(), targets, 
102
    	    new ICommandParticipant() {
103
    	        public void requestDone(org.eclipse.debug.core.IRequest request) {
104
    	            DebugCommandAction.this.requestDone(targets, request);
105
    	        }    	      
106
    	    });
107
    }
108
        
109
    protected void requestDone(Object[] targets, IRequest request) {
110
        // do nothing by default
111
    }
112
    
113
    /**
114
     * Returns the {@link org.eclipse.debug.core.commands.IDebugCommandHandler} 
115
     * command handler that type this action executes.
116
     * 
117
     * @return command class.
118
     * 
119
     * @see org.eclipse.debug.core.commands.IDebugCommandHandler
120
     */
121
    abstract protected Class getCommandType();  
122
123
    /**
124
     * @see org.eclipse.debug.ui.contexts.IDebugContextListener#debugContextChanged(org.eclipse.debug.ui.contexts.DebugContextEvent)
125
     */
126
    public void debugContextChanged(DebugContextEvent event) {
127
    	fUpdateService.postUpdateCommand(getCommandType(), fEnabledTarget);
128
	}
129
130
    /**
131
     * @see org.eclipse.jface.action.Action#setEnabled(boolean)
132
     */
133
    public void setEnabled(boolean enabled) {
134
        synchronized (this) {
135
            if (!fInitialized) {
136
                fInitialized = true;
137
                notifyAll();
138
            }
139
        }        
140
        super.setEnabled(enabled);
141
        if (fAction != null) {
142
            fAction.setEnabled(enabled);
143
        }
144
    }
145
146
    /**
147
     * Initializes this action for a specific part.
148
     * 
149
     * @param part workbench part
150
     */
151
    public void init(IWorkbenchPart part) {
152
        fPart = part;
153
        fWindow = part.getSite().getWorkbenchWindow();
154
        fUpdateService = DebugCommandService.getService(fWindow);
155
        IDebugContextService service = getDebugContextService();
156
		String partId = part.getSite().getId();
157
		service.addDebugContextListener(this, partId);
158
        ISelection activeContext = service.getActiveContext(partId);
159
        if (activeContext != null) {
160
        	fUpdateService.updateCommand(getCommandType(), fEnabledTarget);
161
        } else {
162
        	setEnabled(getInitialEnablement());
163
        }
164
    }
165
    
166
    /**
167
     * Initializes the context action
168
     * @param window the window
169
     */
170
    public void init(IWorkbenchWindow window) {
171
        fWindow = window;
172
        fUpdateService = DebugCommandService.getService(fWindow);
173
        IDebugContextService contextService = getDebugContextService();
174
		contextService.addDebugContextListener(this);
175
        ISelection activeContext = contextService.getActiveContext();
176
        if (activeContext != null) {
177
        	fUpdateService.updateCommand(getCommandType(), fEnabledTarget);
178
        } else {
179
        	setEnabled(getInitialEnablement());
180
        }
181
    }
182
    
183
    /**
184
     * Returns whether this action should be enabled when initialized
185
     * and there is no active debug context.
186
     * 
187
     * @return false, by default
188
     */
189
    protected boolean getInitialEnablement() {
190
    	return false;
191
    }
192
193
    /**
194
     * Returns the most recent selection
195
     * 
196
     * @return structured selection
197
     */
198
    private ISelection getContext() {
199
		if (fPart != null) {
200
			getDebugContextService().getActiveContext(fPart.getSite().getId());
201
    	}
202
        return getDebugContextService().getActiveContext();
203
    }
204
205
    /*
206
     * (non-Javadoc)
207
     * @see org.eclipse.jface.action.Action#run()
208
     */
209
    public void run() {
210
        synchronized (this) {
211
            if (!fInitialized) {
212
                try {
213
                    wait();
214
                } catch (InterruptedException e) {
215
                }
216
            }           
217
        }        
218
        
219
        ISelection selection = getContext();
220
        if (selection instanceof IStructuredSelection && isEnabled()) {
221
            IStructuredSelection ss = (IStructuredSelection) selection;
222
            boolean enabled = execute(ss.toArray());
223
            // disable the action according to the command
224
            setEnabled(enabled);
225
        }
226
    }
227
228
    /*
229
     * (non-Javadoc)
230
     * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event)
231
     */
232
    public void runWithEvent(Event event) {
233
        run();
234
    }
235
236
    /**
237
     * Clean up when removing
238
     */
239
    public void dispose() {
240
        IDebugContextService service = getDebugContextService();
241
        if (fPart != null) {
242
        	service.removeDebugContextListener(this, fPart.getSite().getId());
243
        } else {
244
            service.removeDebugContextListener(this);
245
        }
246
        fWindow = null;
247
        fPart = null;
248
    }
249
    
250
    /**
251
     * Returns the context service this action linked to.
252
     * @return
253
     */
254
    protected IDebugContextService getDebugContextService() {
255
    	return DebugUITools.getDebugContextManager().getContextService(fWindow);
256
    }
257
258
    /**
259
     * @return The help context id for this action
260
     */ 
261
    public abstract String getHelpContextId();
262
263
    /*
264
     * (non-Javadoc)
265
     * @see org.eclipse.jface.action.Action#getId()
266
     */
267
    public abstract String getId();
268
269
    /*
270
     * (non-Javadoc)
271
     * @see org.eclipse.jface.action.Action#getText()
272
     */
273
    public abstract String getText();
274
275
    /*
276
     * (non-Javadoc)
277
     * @see org.eclipse.jface.action.Action#getToolTipText()
278
     */
279
    public abstract String getToolTipText();
280
281
    /*
282
     * (non-Javadoc)
283
     * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor()
284
     */
285
    public abstract ImageDescriptor getDisabledImageDescriptor();
286
287
    /*
288
     * (non-Javadoc)
289
     * @see org.eclipse.jface.action.Action#getHoverImageDescriptor()
290
     */
291
    public abstract ImageDescriptor getHoverImageDescriptor();
292
293
    /*
294
     * (non-Javadoc)
295
     * @see org.eclipse.jface.action.Action#getImageDescriptor()
296
     */
297
    public abstract ImageDescriptor getImageDescriptor();
298
    
299
    /**
300
     * Returns the delegate associated with this action or <code>null</code>
301
     * if none.
302
     * 
303
     * @return delegate or <code>null</code>
304
     */
305
    protected IAction getAction() {
306
    	return fAction;
307
    }
308
}

Return to bug 284363