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

(-)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/TerminateAndRelaunchAction.java (-30 / +15 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;
Lines 30-66 Link Here
30
 */
31
 */
31
public class TerminateAndRelaunchAction extends DebugCommandAction {
32
public class TerminateAndRelaunchAction extends DebugCommandAction {
32
	
33
	
33
	class Participant implements ICommandParticipant {
34
    public void postExecute(IRequest request, final Object[] targets) {
34
		
35
        if (request.getStatus() == null || request.getStatus().isOK()) {
35
		private Object[] fTargets;
36
            DebugUIPlugin.getStandardDisplay().asyncExec(new Runnable() {
36
37
                public void run() {
37
		public Participant(Object[] targets) {
38
                    // Must be run in the UI thread since the launch can require
38
			fTargets = targets;
39
                    // prompting to proceed
39
		}
40
                    for (int i = 0; i < targets.length; i++) {
40
41
                        ILaunch launch = RelaunchActionDelegate.getLaunch(targets[i]);
41
		/* (non-Javadoc)
42
                        RelaunchActionDelegate.relaunch(launch.getLaunchConfiguration(), launch.getLaunchMode());
42
		 * @see org.eclipse.debug.internal.ui.commands.actions.ICommandParticipant#requestDone(org.eclipse.debug.core.commands.IRequest)
43
                    }
43
		 */
44
                }
44
		public void requestDone(IRequest request) {
45
            }); 
45
			if (request.getStatus() == null || request.getStatus().isOK()) {
46
        }
46
				DebugUIPlugin.getStandardDisplay().asyncExec(new Runnable() {
47
    }
47
		            public void run() {
48
		                // Must be run in the UI thread since the launch can require
49
		                // prompting to proceed
50
		            	for (int i = 0; i < fTargets.length; i++) {
51
		            		ILaunch launch = RelaunchActionDelegate.getLaunch(fTargets[i]);
52
		            		RelaunchActionDelegate.relaunch(launch.getLaunchConfiguration(), launch.getLaunchMode());
53
						}
54
		            }
55
		        });	
56
			}
57
		}
58
		
59
	}
60
48
61
	protected ICommandParticipant getCommandParticipant(Object[] targets) {
62
		return new Participant(targets);
63
	}
64
49
65
	protected Class getCommandType() {
50
	protected Class getCommandType() {
66
		return ITerminateHandler.class;
51
		return ITerminateHandler.class;
(-)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/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/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/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/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/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/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 (+267 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.core.IRequest;
24
import org.eclipse.debug.internal.ui.commands.actions.DebugCommandService;
25
import org.eclipse.debug.internal.ui.commands.actions.ICommandParticipant;
26
import org.eclipse.debug.internal.ui.commands.actions.IEnabledTarget;
27
import org.eclipse.debug.ui.DebugUITools;
28
import org.eclipse.debug.ui.contexts.DebugContextEvent;
29
import org.eclipse.debug.ui.contexts.IDebugContextListener;
30
import org.eclipse.debug.ui.contexts.IDebugContextService;
31
import org.eclipse.jface.viewers.ISelection;
32
import org.eclipse.jface.viewers.IStructuredSelection;
33
import org.eclipse.ui.ISources;
34
import org.eclipse.ui.IWindowListener;
35
import org.eclipse.ui.IWorkbenchWindow;
36
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.ui.handlers.HandlerUtil;
38
39
/**
40
 * Abstract base class for re-targeting command framework handlers, which 
41
 * delegate execution to {@link org.eclipse.debug.core.commands.IDebugCommandHandler} 
42
 * handlers. The specific type of <code>IDebugCommandHandler</code> is 
43
 * determined by the abstract {@link #getCommandType()} method.    
44
 * 
45
 * <p> Note: This class is not an implementation of the <code>IDebugCommandHandler</code>
46
 * interface, which was somewhat unfortunately named.  <code>IDebugCommandHandler</code> 
47
 * is an interface that used only by thedebugger plugins.  This class implements 
48
 * {@link org.eclipse.core.commands.IHandler} interface and is to be used with the 
49
 * platform commands framework. </p>
50
 * 
51
 * @see org.eclipse.debug.core.commands.IDebugCommandHandler
52
 * @see org.eclipse.core.commands.IHandler
53
 *
54
 * @since 3.6
55
 */
56
public abstract class DebugCommandHandler extends AbstractHandler {
57
58
    /**
59
     * The DebugCommandService is able to evaluate the command handler 
60
     * enablement in each workbench window separately, however the workbench
61
     * command framework uses only a single handler instance for all windows.
62
     * This IEnabledTarget implementation tracks enablement of the command
63
     * for a given window.  When the handler enablement is tested, the 
64
     * currently active window is used to determine which enabled target 
65
     * to use.  
66
     */
67
    private class EnabledTarget implements IEnabledTarget, IDebugContextListener {
68
        boolean fEnabled = getInitialEnablement();
69
        IWorkbenchWindow fWindow;
70
        
71
        EnabledTarget(IWorkbenchWindow window) {
72
            fWindow = window;
73
            DebugCommandService.getService(fWindow).updateCommand(getCommandType(), this);
74
            getContextService(fWindow).addDebugContextListener(this);
75
        }
76
        
77
        public void setEnabled(boolean enabled) {
78
            boolean oldEnabled = fEnabled;
79
            fEnabled = enabled;
80
            if (fEnabled != oldEnabled && fCurrentEnabledTarget == this) {
81
                fireHandlerChanged(new HandlerEvent(DebugCommandHandler.this, true, false));
82
            }
83
        }
84
        
85
        public void debugContextChanged(DebugContextEvent event) {
86
            DebugCommandService.getService(fWindow).postUpdateCommand(getCommandType(), this);
87
        }
88
        
89
        void dispose() {
90
            if (isDisposed()) {
91
                return;
92
            }
93
            getContextService(fWindow).removeDebugContextListener(this);
94
            fWindow = null;
95
        }
96
        
97
        boolean isDisposed() {
98
            return fWindow == null;
99
        }
100
    }
101
102
    /**
103
     * Window listener is used to make sure that the handler enablement 
104
     * is updated when the active workbench window is changed.
105
     */
106
    private IWindowListener fWindowListener =  new IWindowListener() {
107
        
108
        public void windowOpened(IWorkbenchWindow w) {
109
        }
110
    
111
        public void windowDeactivated(IWorkbenchWindow w) {
112
        }
113
    
114
        public void windowClosed(IWorkbenchWindow w) {
115
            EnabledTarget enabledTarget = (EnabledTarget)fEnabledTargetsMap.get(w);
116
            if (enabledTarget != null) {
117
                enabledTarget.dispose();
118
            }
119
        }
120
    
121
        public void windowActivated(IWorkbenchWindow w) {
122
            fCurrentEnabledTarget = (EnabledTarget)fEnabledTargetsMap.get(w);
123
            fireHandlerChanged(new HandlerEvent(DebugCommandHandler.this, true, false));
124
        }
125
    };
126
    
127
    /**
128
     * Map of enabled targets keyed by workbench window.
129
     */
130
    private Map fEnabledTargetsMap = new WeakHashMap();
131
132
    /**
133
     * The current enabled target, based on the active
134
     * workbench window.
135
     */
136
    private EnabledTarget fCurrentEnabledTarget = null;
137
    
138
    /**
139
      * The constructor adds the handler as the 
140
     */
141
    public DebugCommandHandler() {
142
        super();
143
        PlatformUI.getWorkbench().addWindowListener(fWindowListener);
144
    }
145
    
146
    public void setEnabled(Object evaluationContext) {
147
        // This method is called with the current evaluation context
148
        // just prior to the isEnabled() being called.  Check the active
149
        // window and update the current enabled target based on it 
150
        fCurrentEnabledTarget = null;
151
        
152
        if (!(evaluationContext instanceof IEvaluationContext)) {
153
            return;
154
        }
155
        IEvaluationContext context = (IEvaluationContext) evaluationContext;
156
        Object _window = context.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME);
157
        if (_window instanceof IWorkbenchWindow) {
158
            IWorkbenchWindow window = (IWorkbenchWindow)_window;
159
            fCurrentEnabledTarget = getEnabledTarget(window);
160
        }
161
    }
162
    
163
    public boolean isEnabled() {
164
        if (fCurrentEnabledTarget == null) {
165
            return false;
166
        }
167
        return fCurrentEnabledTarget.fEnabled;
168
    }
169
    
170
    private EnabledTarget getEnabledTarget(IWorkbenchWindow window) {
171
        EnabledTarget target = (EnabledTarget)fEnabledTargetsMap.get(window);
172
        if (target == null) {
173
            target = new EnabledTarget(window);
174
            fEnabledTargetsMap.put(window, target);
175
        }
176
        return target;
177
    }
178
    
179
    public Object execute(ExecutionEvent event) throws ExecutionException {
180
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
181
        if (window == null) {
182
            throw new ExecutionException("No active workbench window.");
183
        }
184
        fCurrentEnabledTarget = getEnabledTarget(window);
185
186
        ISelection selection = getContextService(window).getActiveContext();
187
        if (selection instanceof IStructuredSelection && isEnabled()) {
188
            IStructuredSelection ss = (IStructuredSelection) selection;
189
            boolean enabledAfterExecute = execute(window, ss.toArray());
190
            
191
            // enable/disable the action according to the command
192
            fCurrentEnabledTarget.setEnabled(enabledAfterExecute);
193
        }
194
195
        return null;
196
    }
197
    
198
    private IDebugContextService getContextService(IWorkbenchWindow window) {
199
        return DebugUITools.getDebugContextManager().getContextService(window);
200
    }
201
    
202
    /**
203
     * Executes this action on the given target object
204
     * 
205
     * @param target the target to perform the action on
206
     */
207
    private boolean execute(IWorkbenchWindow window, final Object[] targets) {
208
        DebugCommandService service = DebugCommandService.getService(window); 
209
    	return service.executeCommand(
210
    	    getCommandType(), targets, 
211
            new ICommandParticipant() {
212
                public void requestDone(org.eclipse.debug.core.IRequest request) {
213
                    DebugCommandHandler.this.postExecute(request, targets);
214
                }             
215
            });
216
    }
217
218
    /**
219
     * This method is called after the completion of the execution of this 
220
     * command.  Extending classes may override this method to perform additional
221
     * operation after command execution. 
222
     * 
223
     * @param request The completed request object which was given the the 
224
     * debug command handler.
225
     * @param targets Objects which were the targets of this action
226
     */
227
    protected void postExecute(IRequest request, Object[] targets) {
228
        // do nothing by default
229
    }
230
231
    /**
232
     * Returns the {@link org.eclipse.debug.core.commands.IDebugCommandHandler} 
233
     * command handler that type this action executes.
234
     * 
235
     * @return command class.
236
     * 
237
     * @see org.eclipse.debug.core.commands.IDebugCommandHandler
238
     */
239
    abstract protected Class getCommandType();  
240
241
    
242
    /**
243
     * Returns whether this action should be enabled when initialized
244
     * and there is no active debug context.
245
     * 
246
     * @return false, by default
247
     */
248
    protected boolean getInitialEnablement() {
249
    	return false;
250
    }
251
252
253
    /**
254
     * Clean up when removing
255
     */
256
    public void dispose() {
257
        PlatformUI.getWorkbench().removeWindowListener(fWindowListener);        
258
        for (Iterator itr = fEnabledTargetsMap.values().iterator(); itr.hasNext();) {
259
            EnabledTarget target = (EnabledTarget)itr.next();
260
            if (!target.isDisposed()) {
261
                target.dispose();
262
            }
263
        }
264
        fEnabledTargetsMap.clear();
265
        fCurrentEnabledTarget = null;
266
    }
267
}
(-)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 (+329 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
 * <p>
38
 * This base class is an action which can be instantiated directly by views, 
39
 * etc.  In order to contribute an action using an extension point, a class 
40
 * implementing {@link org.eclipse.ui.IActionDelegate} should be created first.
41
 * The delegate should then use the <code>DebugCommandAction</code> implement 
42
 * the needed delegate functionality. <br>
43
 * Note: <code>IDebugCommandHandler</code> command typically act on the active
44
 * debug context as opposed to the active selection in view or window.  The 
45
 * action delegate should ignore the active window selection, and instead allow 
46
 * the <code>DebugCommandAction</code> to update itself based on the active 
47
 * debug context. 
48
 * </p>
49
 * 
50
 * @see org.eclipse.debug.core.commands.IDebugCommandHandler
51
 *
52
 * @since 3.6 This class was in the internal package 
53
 * <code>org.eclipse.debug.internal.ui.commands.actions</code> since 3.3.
54
 */
55
public abstract class DebugCommandAction extends Action implements IDebugContextListener {
56
57
    private boolean fInitialized = false;
58
    
59
	/**
60
	 * The window this action is working for.
61
	 */
62
    private IWorkbenchWindow fWindow;
63
    
64
    /**
65
     * The part this action is working for, or <code>null</code> if global to
66
     * a window.
67
     */
68
    private IWorkbenchPart fPart;
69
    
70
    /**
71
     * Command service.
72
     */
73
    private DebugCommandService fUpdateService;
74
    
75
    /**
76
     * Delegate this action is working for or <code>null</code> if none.
77
     */
78
    private IAction fAction;
79
80
    private IEnabledTarget fEnabledTarget = new IEnabledTarget() {
81
        public void setEnabled(boolean enabled) {
82
            DebugCommandAction.this.setEnabled(enabled);
83
        }
84
    };
85
    
86
    /**
87
     * Constructor
88
     */
89
    public DebugCommandAction() {
90
        super();
91
        String helpContextId = getHelpContextId();
92
        if (helpContextId != null)
93
            PlatformUI.getWorkbench().getHelpSystem().setHelp(this, helpContextId);
94
        setEnabled(false);
95
    }
96
97
	/**
98
     * Set the current delegate
99
     * @param delegate
100
     */
101
    public void setAction(IAction action) {
102
        fAction = action;
103
        fAction.setEnabled(isEnabled());
104
    }
105
106
    /**
107
     * Executes this action on the given target object
108
     * 
109
     * @param target the target to perform the action on
110
     */
111
    private boolean execute(final Object[] targets) {
112
    	return fUpdateService.executeCommand(
113
    	    getCommandType(), targets, 
114
    	    new ICommandParticipant() {
115
    	        public void requestDone(org.eclipse.debug.core.IRequest request) {
116
    	            DebugCommandAction.this.postExecute(request, targets);
117
    	        }    	      
118
    	    });
119
    }
120
        
121
    /**
122
     * This method is called after the completion of the execution of this 
123
     * command.  Extending classes may override this method to perform additional
124
     * operation after command execution. 
125
     * 
126
     * @param targets Objects which were the targets of this action
127
     * @param request The completed request object which was given the the 
128
     * debug command handler.
129
     */
130
    protected void postExecute(IRequest request, Object[] targets) {
131
        // do nothing by default
132
    }
133
    
134
    /**
135
     * Returns the {@link org.eclipse.debug.core.commands.IDebugCommandHandler} 
136
     * command handler that type this action executes.
137
     * 
138
     * @return command class.
139
     * 
140
     * @see org.eclipse.debug.core.commands.IDebugCommandHandler
141
     */
142
    abstract protected Class getCommandType();  
143
144
    /**
145
     * @see org.eclipse.debug.ui.contexts.IDebugContextListener#debugContextChanged(org.eclipse.debug.ui.contexts.DebugContextEvent)
146
     */
147
    public void debugContextChanged(DebugContextEvent event) {
148
    	fUpdateService.postUpdateCommand(getCommandType(), fEnabledTarget);
149
	}
150
151
    /**
152
     * @see org.eclipse.jface.action.Action#setEnabled(boolean)
153
     */
154
    public void setEnabled(boolean enabled) {
155
        synchronized (this) {
156
            if (!fInitialized) {
157
                fInitialized = true;
158
                notifyAll();
159
            }
160
        }        
161
        super.setEnabled(enabled);
162
        if (fAction != null) {
163
            fAction.setEnabled(enabled);
164
        }
165
    }
166
167
    /**
168
     * Initializes this action for a specific part.
169
     * 
170
     * @param part workbench part
171
     */
172
    public void init(IWorkbenchPart part) {
173
        fPart = part;
174
        fWindow = part.getSite().getWorkbenchWindow();
175
        fUpdateService = DebugCommandService.getService(fWindow);
176
        IDebugContextService service = getDebugContextService();
177
		String partId = part.getSite().getId();
178
		service.addDebugContextListener(this, partId);
179
        ISelection activeContext = service.getActiveContext(partId);
180
        if (activeContext != null) {
181
        	fUpdateService.updateCommand(getCommandType(), fEnabledTarget);
182
        } else {
183
        	setEnabled(getInitialEnablement());
184
        }
185
    }
186
    
187
    /**
188
     * Initializes the context action
189
     * @param window the window
190
     */
191
    public void init(IWorkbenchWindow window) {
192
        fWindow = window;
193
        fUpdateService = DebugCommandService.getService(fWindow);
194
        IDebugContextService contextService = getDebugContextService();
195
		contextService.addDebugContextListener(this);
196
        ISelection activeContext = contextService.getActiveContext();
197
        if (activeContext != null) {
198
        	fUpdateService.updateCommand(getCommandType(), fEnabledTarget);
199
        } else {
200
        	setEnabled(getInitialEnablement());
201
        }
202
    }
203
    
204
    /**
205
     * Returns whether this action should be enabled when initialized
206
     * and there is no active debug context.
207
     * 
208
     * @return false, by default
209
     */
210
    protected boolean getInitialEnablement() {
211
    	return false;
212
    }
213
214
    /**
215
     * Returns the most recent selection
216
     * 
217
     * @return structured selection
218
     */
219
    private ISelection getContext() {
220
		if (fPart != null) {
221
			getDebugContextService().getActiveContext(fPart.getSite().getId());
222
    	}
223
        return getDebugContextService().getActiveContext();
224
    }
225
226
    /*
227
     * (non-Javadoc)
228
     * @see org.eclipse.jface.action.Action#run()
229
     */
230
    public void run() {
231
        synchronized (this) {
232
            if (!fInitialized) {
233
                try {
234
                    wait();
235
                } catch (InterruptedException e) {
236
                }
237
            }           
238
        }        
239
        
240
        ISelection selection = getContext();
241
        if (selection instanceof IStructuredSelection && isEnabled()) {
242
            IStructuredSelection ss = (IStructuredSelection) selection;
243
            boolean enabled = execute(ss.toArray());
244
            // disable the action according to the command
245
            setEnabled(enabled);
246
        }
247
    }
248
249
    /*
250
     * (non-Javadoc)
251
     * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event)
252
     */
253
    public void runWithEvent(Event event) {
254
        run();
255
    }
256
257
    /**
258
     * Clean up when removing
259
     */
260
    public void dispose() {
261
        IDebugContextService service = getDebugContextService();
262
        if (fPart != null) {
263
        	service.removeDebugContextListener(this, fPart.getSite().getId());
264
        } else {
265
            service.removeDebugContextListener(this);
266
        }
267
        fWindow = null;
268
        fPart = null;
269
    }
270
    
271
    /**
272
     * Returns the context service this action linked to.
273
     * @return
274
     */
275
    protected IDebugContextService getDebugContextService() {
276
    	return DebugUITools.getDebugContextManager().getContextService(fWindow);
277
    }
278
279
    /**
280
     * @return The help context id for this action
281
     */ 
282
    public abstract String getHelpContextId();
283
284
    /*
285
     * (non-Javadoc)
286
     * @see org.eclipse.jface.action.Action#getId()
287
     */
288
    public abstract String getId();
289
290
    /*
291
     * (non-Javadoc)
292
     * @see org.eclipse.jface.action.Action#getText()
293
     */
294
    public abstract String getText();
295
296
    /*
297
     * (non-Javadoc)
298
     * @see org.eclipse.jface.action.Action#getToolTipText()
299
     */
300
    public abstract String getToolTipText();
301
302
    /*
303
     * (non-Javadoc)
304
     * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor()
305
     */
306
    public abstract ImageDescriptor getDisabledImageDescriptor();
307
308
    /*
309
     * (non-Javadoc)
310
     * @see org.eclipse.jface.action.Action#getHoverImageDescriptor()
311
     */
312
    public abstract ImageDescriptor getHoverImageDescriptor();
313
314
    /*
315
     * (non-Javadoc)
316
     * @see org.eclipse.jface.action.Action#getImageDescriptor()
317
     */
318
    public abstract ImageDescriptor getImageDescriptor();
319
    
320
    /**
321
     * Returns the delegate associated with this action or <code>null</code>
322
     * if none.
323
     * 
324
     * @return delegate or <code>null</code>
325
     */
326
    protected IAction getAction() {
327
    	return fAction;
328
    }
329
}
(-)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++) {
(-)buildnotes_platform-debug.html (+10 lines)
Lines 11-16 Link Here
11
11
12
<h2>Summary of API changes in 3.6</h2>
12
<h2>Summary of API changes in 3.6</h2>
13
13
14
<h3>DebugCommandAction base class</h3>
15
<p><strong>What is affected:</strong>
16
<ul>
17
  <li>Class addition: <code>org.eclipse.debug.ui.actions.DebugCommandAction</code> </li>
18
  <li>Class addition: <code>org.eclipse.debug.ui.actions.DebugCommandHandler</code> </li>
19
</ul>
20
</p>
21
<p><strong>Description:</strong>The <code>IDebugCommandHandler</code> interface allows debugger to implement debug action handlers which execute asynchronously.  Most of the debugger actions user this interface to communicate with the debug model.  However, debuggers which need to add their own asynchronous actions had to duplicate the debug framework actions which invoke the <code>IDebugCommandHandler</code> handlers.  <code>DebugCommandAction</code> and <code>DebugCommandHandler</code> are base classes which can be extended by debuggers to implement new types of actions with asynchronous execution handlers.</p>
22
<p><strong>Action required:</strong> This is a backwards compatible change. No action required. </p>
23
14
<p>&nbsp;</p>
24
<p>&nbsp;</p>
15
</body>
25
</body>
16
</html>
26
</html>
(-)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
}

Return to bug 284363