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 (+2 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.DebugCommandActionDelegate;
15
14
/**
16
/**
15
 * Step return action delegate.
17
 * Step return action delegate.
16
 * 
18
 * 
(-)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/ExecuteActionRequest.java (+1 lines)
Lines 14-19 Link Here
14
import org.eclipse.debug.internal.core.commands.DebugCommandRequest;
14
import org.eclipse.debug.internal.core.commands.DebugCommandRequest;
15
import org.eclipse.debug.internal.ui.DebugUIMessages;
15
import org.eclipse.debug.internal.ui.DebugUIMessages;
16
import org.eclipse.debug.internal.ui.DebugUIPlugin;
16
import org.eclipse.debug.internal.ui.DebugUIPlugin;
17
import org.eclipse.debug.ui.actions.ICommandParticipant;
17
import org.eclipse.jface.dialogs.MessageDialog;
18
import org.eclipse.jface.dialogs.MessageDialog;
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 (-23 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
package org.eclipse.debug.internal.ui.commands.actions;
12
13
import org.eclipse.debug.core.IRequest;
14
15
/**
16
 * Adds function to a command on completion.
17
 *
18
 * @since 3.3
19
 */
20
public interface ICommandParticipant {
21
	
22
	public void requestDone(IRequest request);
23
}
(-)ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandActionDelegate.java (-134 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 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.jface.action.IAction;
15
import org.eclipse.jface.viewers.ISelection;
16
import org.eclipse.swt.widgets.Event;
17
import org.eclipse.ui.IActionDelegate2;
18
import org.eclipse.ui.IWorkbenchWindow;
19
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
20
21
/**
22
 * Abstract base class for debug action delegates performing debug commands.
23
 * 
24
 * @since 3.3
25
 */
26
public abstract class DebugCommandActionDelegate implements IWorkbenchWindowActionDelegate, IActionDelegate2 {
27
28
	/**
29
     *The real action for this delegate 
30
	 */
31
	private DebugCommandAction fDebugAction;
32
    
33
    /**
34
     * The underlying action for this delegate
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
	}
46
47
	/*
48
     * (non-Javadoc)
49
     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
50
	 */
51
	public void dispose() {
52
        fDebugAction.dispose();
53
54
	}
55
56
    /*
57
     * (non-Javadoc)
58
     * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
59
     */
60
    public void init(IAction action) {
61
        fWindowAction = action;
62
    }
63
    
64
    /*
65
     * (non-Javadoc)
66
     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
67
     */
68
    public void init(IWorkbenchWindow window) {
69
        fDebugAction.init(window);
70
	}
71
    
72
    /*
73
     * (non-Javadoc)
74
     * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
75
     */
76
	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();
86
	}
87
88
    
89
    /*
90
     * (non-Javadoc)
91
     * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
92
     */
93
	public void runWithEvent(IAction action, Event event) {
94
        run(action);
95
    }
96
97
    /*
98
     * (non-Javadoc)
99
     * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
100
     */
101
    public void selectionChanged(IAction action, ISelection s) {
102
		// do nothing
103
	}
104
105
	protected DebugCommandAction getAction() {
106
		return fDebugAction;
107
	}
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
}
(-)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/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/SuspendCommandActionDelegate.java (+2 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.DebugCommandActionDelegate;
15
14
/**
16
/**
15
 * Suspend action delegate.
17
 * Suspend action delegate.
16
 * 
18
 * 
(-)ui/org/eclipse/debug/internal/ui/commands/actions/StepOverCommandActionDelegate.java (+2 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.DebugCommandActionDelegate;
15
14
/**
16
/**
15
 * Step over action delegate.
17
 * Step over action delegate.
16
 * 
18
 * 
(-)ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAndRelaunchAction.java (+2 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;
24
import org.eclipse.debug.ui.actions.ICommandParticipant;
23
import org.eclipse.debug.ui.contexts.DebugContextEvent;
25
import org.eclipse.debug.ui.contexts.DebugContextEvent;
24
import org.eclipse.jface.resource.ImageDescriptor;
26
import org.eclipse.jface.resource.ImageDescriptor;
25
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.ISelection;
(-)ui/org/eclipse/debug/internal/ui/commands/actions/ResumeCommandActionDelegate.java (+2 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.DebugCommandActionDelegate;
15
14
/**
16
/**
15
 * Resume action delegate.
17
 * Resume action delegate.
16
 * 
18
 * 
(-)ui/org/eclipse/debug/internal/ui/commands/actions/ToggleStepFiltersAction.java (+2 lines)
Lines 19-24 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;
23
import org.eclipse.debug.ui.actions.DebugCommandActionDelegate;
22
import org.eclipse.debug.ui.contexts.DebugContextEvent;
24
import org.eclipse.debug.ui.contexts.DebugContextEvent;
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;
(-)ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAndRemoveAction.java (+2 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;
24
import org.eclipse.debug.ui.actions.ICommandParticipant;
23
import org.eclipse.jface.resource.ImageDescriptor;
25
import org.eclipse.jface.resource.ImageDescriptor;
24
26
25
/**
27
/**
(-)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 (+2 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.DebugCommandActionDelegate;
15
14
/**
16
/**
15
 * Step into action delegate.
17
 * Step into action delegate.
16
 * 
18
 * 
(-)ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandService.java (-6 / +6 lines)
Lines 21-30 Link Here
21
import org.eclipse.debug.core.DebugPlugin;
21
import org.eclipse.debug.core.DebugPlugin;
22
import org.eclipse.debug.core.commands.IDebugCommandHandler;
22
import org.eclipse.debug.core.commands.IDebugCommandHandler;
23
import org.eclipse.debug.ui.DebugUITools;
23
import org.eclipse.debug.ui.DebugUITools;
24
import org.eclipse.debug.ui.actions.ICommandParticipant;
24
import org.eclipse.debug.ui.contexts.DebugContextEvent;
25
import org.eclipse.debug.ui.contexts.DebugContextEvent;
25
import org.eclipse.debug.ui.contexts.IDebugContextListener;
26
import org.eclipse.debug.ui.contexts.IDebugContextListener;
26
import org.eclipse.debug.ui.contexts.IDebugContextService;
27
import org.eclipse.debug.ui.contexts.IDebugContextService;
27
import org.eclipse.jface.action.Action;
28
import org.eclipse.jface.action.IAction;
28
import org.eclipse.jface.action.IAction;
29
import org.eclipse.jface.viewers.ISelection;
29
import org.eclipse.jface.viewers.ISelection;
30
import org.eclipse.jface.viewers.IStructuredSelection;
30
import org.eclipse.jface.viewers.IStructuredSelection;
Lines 111-117 Link Here
111
	 * @param commandType
111
	 * @param commandType
112
	 * @param monitor
112
	 * @param monitor
113
	 */
113
	 */
114
	public void postUpdateCommand(Class commandType, Action action) {
114
	public void postUpdateCommand(Class commandType, IEnabledTarget action) {
115
		synchronized (fCommandUpdates) {
115
		synchronized (fCommandUpdates) {
116
			Job.getJobManager().cancel(commandType);
116
			Job.getJobManager().cancel(commandType);
117
			List actions = (List) fCommandUpdates.get(commandType);
117
			List actions = (List) fCommandUpdates.get(commandType);
Lines 129-139 Link Here
129
	 * @param commandType
129
	 * @param commandType
130
	 * @param requestMonitor
130
	 * @param requestMonitor
131
	 */
131
	 */
132
	public void updateCommand(Class commandType, IAction action) {
132
	public void updateCommand(Class commandType, IEnabledTarget action) {
133
		ISelection context = fContextService.getActiveContext();
133
		ISelection context = fContextService.getActiveContext();
134
		if (context instanceof IStructuredSelection && !context.isEmpty()) {
134
		if (context instanceof IStructuredSelection && !context.isEmpty()) {
135
			Object[] elements = ((IStructuredSelection)context).toArray();
135
			Object[] elements = ((IStructuredSelection)context).toArray();
136
			updateCommand(commandType, elements, new IAction[]{action});
136
			updateCommand(commandType, elements, new IEnabledTarget[]{action});
137
		} else {
137
		} else {
138
			action.setEnabled(false);
138
			action.setEnabled(false);
139
		}
139
		}
Lines 152-158 Link Here
152
				Entry entry = (Entry) iterator.next();
152
				Entry entry = (Entry) iterator.next();
153
				Class commandType = (Class)entry.getKey();
153
				Class commandType = (Class)entry.getKey();
154
				List actions = (List) entry.getValue();
154
				List actions = (List) entry.getValue();
155
				updateCommand(commandType, elements, (IAction[]) actions.toArray(new IAction[actions.size()]));
155
				updateCommand(commandType, elements, (IEnabledTarget[]) actions.toArray(new IEnabledTarget[actions.size()]));
156
			}
156
			}
157
		} else {
157
		} else {
158
			Iterator iterator = commands.values().iterator();
158
			Iterator iterator = commands.values().iterator();
Lines 174-180 Link Here
174
	 * @param elements elements to update for
174
	 * @param elements elements to update for
175
	 * @param monitor status monitor
175
	 * @param monitor status monitor
176
	 */
176
	 */
177
	private void updateCommand(Class handlerType, Object[] elements, IAction[] actions) {
177
	private void updateCommand(Class handlerType, Object[] elements, IEnabledTarget[] actions) {
178
		if (elements.length == 1) {
178
		if (elements.length == 1) {
179
			// usual case - one element
179
			// usual case - one element
180
			Object element = elements[0];
180
			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/ToggleStepFiltersCommandActionDelegate.java (+1 lines)
Lines 12-17 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.debug.ui.actions.DebugCommandActionDelegate;
15
import org.eclipse.ui.IWorkbenchWindow;
16
import org.eclipse.ui.IWorkbenchWindow;
16
17
17
/**
18
/**
(-)ui/org/eclipse/debug/internal/ui/commands/actions/TerminateCommandActionDelegate.java (+2 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.DebugCommandActionDelegate;
15
14
/**
16
/**
15
 * Terminate action delegate.
17
 * Terminate action delegate.
16
 * 
18
 * 
(-)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/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/ICommandParticipant.java (+24 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
package org.eclipse.debug.ui.actions;
12
13
import org.eclipse.debug.core.IRequest;
14
15
/**
16
 * Adds function to a command on completion.
17
 *
18
 * @since 3.6 This interface was in the internal package 
19
 * <code>org.eclipse.debug.internal.ui.commands.actions</code> since 3.3.
20
 */
21
public interface ICommandParticipant {
22
	
23
	public void requestDone(IRequest request);
24
}
(-)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 (+287 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.internal.ui.commands.actions.DebugCommandService;
15
import org.eclipse.debug.internal.ui.commands.actions.IEnabledTarget;
16
import org.eclipse.debug.ui.DebugUITools;
17
import org.eclipse.debug.ui.contexts.DebugContextEvent;
18
import org.eclipse.debug.ui.contexts.IDebugContextListener;
19
import org.eclipse.debug.ui.contexts.IDebugContextService;
20
import org.eclipse.jface.action.Action;
21
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.jface.viewers.ISelection;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.swt.widgets.Event;
25
import org.eclipse.ui.IWorkbenchPart;
26
import org.eclipse.ui.IWorkbenchWindow;
27
import org.eclipse.ui.PlatformUI;
28
29
/**
30
 * Abstract base class for re-targeting actions which delegate execution to 
31
 * {@link org.eclipse.debug.core.commands.IDebugCommandHandler} handlers.  
32
 * The specific type of <code>IDebugCommandHandler</code> is determined by the 
33
 * abstract {@link #getCommandType()} method.    
34
 * 
35
 * @see org.eclipse.debug.core.commands.IDebugCommandHandler
36
 *
37
 * @since 3.6 This class was in the internal package 
38
 * <code>org.eclipse.debug.internal.ui.commands.actions</code> since 3.3.
39
 */
40
public abstract class DebugCommandAction extends Action implements IDebugContextListener {
41
42
	/**
43
	 * The window this action is working for.
44
	 */
45
    private IWorkbenchWindow fWindow;
46
    
47
    /**
48
     * The part this action is working for, or <code>null</code> if global to
49
     * a window.
50
     */
51
    private IWorkbenchPart fPart;
52
    
53
    /**
54
     * Command service.
55
     */
56
    private DebugCommandService fUpdateService;
57
    
58
    /**
59
     * Delegate this action is working for or <code>null</code> if none.
60
     */
61
    private DebugCommandActionDelegate fDelegate;
62
63
    private IEnabledTarget fEnabledTarget = new IEnabledTarget() {
64
        public void setEnabled(boolean enabled) {
65
            DebugCommandAction.this.setEnabled(enabled);
66
        }
67
    };
68
    
69
70
    /**
71
     * Constructor
72
     */
73
    public DebugCommandAction() {
74
        super();
75
        String helpContextId = getHelpContextId();
76
        if (helpContextId != null)
77
            PlatformUI.getWorkbench().getHelpSystem().setHelp(this, helpContextId);
78
        setEnabled(false);
79
    }
80
81
	/**
82
     * Set the current delegate
83
     * @param delegate
84
     */
85
    public void setDelegate(DebugCommandActionDelegate delegate) {
86
        fDelegate = delegate;
87
    }
88
89
    /**
90
     * Executes this action on the given target object
91
     * 
92
     * @param target the target to perform the action on
93
     */
94
    private boolean execute(Object[] targets) {
95
    	return fUpdateService.executeCommand(getCommandType(), targets, getCommandParticipant(targets));
96
    }
97
    
98
    /**
99
     * Creates and returns the command participant or <code>null</code>.
100
     * 
101
     * @return command participant to use on command completion
102
     */
103
    protected ICommandParticipant getCommandParticipant(Object[] targets) {
104
    	return null;
105
    }
106
    
107
    /**
108
     * Returns the {@link org.eclipse.debug.core.commands.IDebugCommandHandler} 
109
     * command handler that type this action executes.
110
     * 
111
     * @return command class.
112
     * 
113
     * @see org.eclipse.debug.core.commands.IDebugCommandHandler
114
     */
115
    abstract protected Class getCommandType();  
116
117
    /**
118
     * @see org.eclipse.debug.ui.contexts.IDebugContextListener#debugContextChanged(org.eclipse.debug.ui.contexts.DebugContextEvent)
119
     */
120
    public void debugContextChanged(DebugContextEvent event) {
121
    	fUpdateService.postUpdateCommand(getCommandType(), fEnabledTarget);
122
	}
123
124
    /**
125
     * @see org.eclipse.jface.action.Action#setEnabled(boolean)
126
     */
127
    public void setEnabled(boolean enabled) {
128
        super.setEnabled(enabled);
129
        if (fDelegate != null) {
130
            fDelegate.setEnabled(enabled);
131
        }
132
    }
133
134
    /**
135
     * Initializes this action for a specific part.
136
     * 
137
     * @param part workbench part
138
     */
139
    public void init(IWorkbenchPart part) {
140
        fPart = part;
141
        fWindow = part.getSite().getWorkbenchWindow();
142
        fUpdateService = DebugCommandService.getService(fWindow);
143
        IDebugContextService service = getDebugContextService();
144
		String partId = part.getSite().getId();
145
		service.addDebugContextListener(this, partId);
146
        ISelection activeContext = service.getActiveContext(partId);
147
        if (activeContext != null) {
148
        	fUpdateService.updateCommand(getCommandType(), fEnabledTarget);
149
        } else {
150
        	setEnabled(getInitialEnablement());
151
        }
152
    }
153
    
154
    /**
155
     * Initializes the context action
156
     * @param window the window
157
     */
158
    public void init(IWorkbenchWindow window) {
159
        fWindow = window;
160
        fUpdateService = DebugCommandService.getService(fWindow);
161
        IDebugContextService contextService = getDebugContextService();
162
		contextService.addDebugContextListener(this);
163
        ISelection activeContext = contextService.getActiveContext();
164
        if (activeContext != null) {
165
        	fUpdateService.updateCommand(getCommandType(), fEnabledTarget);
166
        } else {
167
        	setEnabled(getInitialEnablement());
168
        }
169
    }
170
    
171
    /**
172
     * Returns whether this action should be enabled when initialized
173
     * and there is no active debug context.
174
     * 
175
     * @return false, by default
176
     */
177
    protected boolean getInitialEnablement() {
178
    	return false;
179
    }
180
181
    /**
182
     * Returns the most recent selection
183
     * 
184
     * @return structured selection
185
     */
186
    private ISelection getContext() {
187
		if (fPart != null) {
188
			getDebugContextService().getActiveContext(fPart.getSite().getId());
189
    	}
190
        return getDebugContextService().getActiveContext();
191
    }
192
193
    /*
194
     * (non-Javadoc)
195
     * @see org.eclipse.jface.action.Action#run()
196
     */
197
    public void run() {
198
        ISelection selection = getContext();
199
        if (selection instanceof IStructuredSelection && isEnabled()) {
200
            IStructuredSelection ss = (IStructuredSelection) selection;
201
            boolean enabled = execute(ss.toArray());
202
            // disable the action according to the command
203
            setEnabled(enabled);
204
        }
205
    }
206
207
    /*
208
     * (non-Javadoc)
209
     * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event)
210
     */
211
    public void runWithEvent(Event event) {
212
        run();
213
    }
214
215
    /**
216
     * Clean up when removing
217
     */
218
    public void dispose() {
219
        IDebugContextService service = getDebugContextService();
220
        if (fPart != null) {
221
        	service.removeDebugContextListener(this, fPart.getSite().getId());
222
        } else {
223
            service.removeDebugContextListener(this);
224
        }
225
        fWindow = null;
226
        fPart = null;
227
    }
228
    
229
    /**
230
     * Returns the context service this action linked to.
231
     * @return
232
     */
233
    protected IDebugContextService getDebugContextService() {
234
    	return DebugUITools.getDebugContextManager().getContextService(fWindow);
235
    }
236
237
    /**
238
     * @return The help context id for this action
239
     */ 
240
    public abstract String getHelpContextId();
241
242
    /*
243
     * (non-Javadoc)
244
     * @see org.eclipse.jface.action.Action#getId()
245
     */
246
    public abstract String getId();
247
248
    /*
249
     * (non-Javadoc)
250
     * @see org.eclipse.jface.action.Action#getText()
251
     */
252
    public abstract String getText();
253
254
    /*
255
     * (non-Javadoc)
256
     * @see org.eclipse.jface.action.Action#getToolTipText()
257
     */
258
    public abstract String getToolTipText();
259
260
    /*
261
     * (non-Javadoc)
262
     * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor()
263
     */
264
    public abstract ImageDescriptor getDisabledImageDescriptor();
265
266
    /*
267
     * (non-Javadoc)
268
     * @see org.eclipse.jface.action.Action#getHoverImageDescriptor()
269
     */
270
    public abstract ImageDescriptor getHoverImageDescriptor();
271
272
    /*
273
     * (non-Javadoc)
274
     * @see org.eclipse.jface.action.Action#getImageDescriptor()
275
     */
276
    public abstract ImageDescriptor getImageDescriptor();
277
    
278
    /**
279
     * Returns the delegate associated with this action or <code>null</code>
280
     * if none.
281
     * 
282
     * @return delegate or <code>null</code>
283
     */
284
    protected DebugCommandActionDelegate getDelegate() {
285
    	return fDelegate;
286
    }
287
}
(-)ui/org/eclipse/debug/ui/actions/DebugCommandActionDelegate.java (+135 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 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.jface.action.IAction;
15
import org.eclipse.jface.viewers.ISelection;
16
import org.eclipse.swt.widgets.Event;
17
import org.eclipse.ui.IActionDelegate2;
18
import org.eclipse.ui.IWorkbenchWindow;
19
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
20
21
/**
22
 * Abstract base class for debug action delegates performing debug commands.
23
 * 
24
 * @since 3.6 This class was in the internal package 
25
 * <code>org.eclipse.debug.internal.ui.commands.actions</code> since 3.3.
26
 */
27
public abstract class DebugCommandActionDelegate implements IWorkbenchWindowActionDelegate, IActionDelegate2 {
28
29
	/**
30
     *The real action for this delegate 
31
	 */
32
	private DebugCommandAction fDebugAction;
33
    
34
    /**
35
     * The underlying action for this delegate
36
     */
37
    private IAction fWindowAction;
38
    
39
    /**
40
     * Whether this action has been initialized before it has been run
41
     * (ensures enablement state is up to date when lazily instantiated)
42
     */
43
    private boolean fInitialized = false;
44
45
	public DebugCommandActionDelegate() {
46
	}
47
48
	/*
49
     * (non-Javadoc)
50
     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
51
	 */
52
	public void dispose() {
53
        fDebugAction.dispose();
54
55
	}
56
57
    /*
58
     * (non-Javadoc)
59
     * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
60
     */
61
    public void init(IAction action) {
62
        fWindowAction = action;
63
    }
64
    
65
    /*
66
     * (non-Javadoc)
67
     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
68
     */
69
    public void init(IWorkbenchWindow window) {
70
        fDebugAction.init(window);
71
	}
72
    
73
    /*
74
     * (non-Javadoc)
75
     * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
76
     */
77
	public void run(IAction action) {
78
		synchronized (this) {
79
			if (!fInitialized) {
80
				try {
81
					wait();
82
				} catch (InterruptedException e) {
83
				}
84
			}			
85
		}
86
        fDebugAction.run();
87
	}
88
89
    
90
    /*
91
     * (non-Javadoc)
92
     * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
93
     */
94
	public void runWithEvent(IAction action, Event event) {
95
        run(action);
96
    }
97
98
    /*
99
     * (non-Javadoc)
100
     * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
101
     */
102
    public void selectionChanged(IAction action, ISelection s) {
103
		// do nothing
104
	}
105
106
	protected DebugCommandAction getAction() {
107
		return fDebugAction;
108
	}
109
    
110
    protected void setAction(DebugCommandAction action) {
111
        fDebugAction = action;
112
        action.setDelegate(this);
113
    }
114
115
    public void setEnabled(boolean enabled) {
116
    	synchronized (this) {
117
	    	if (!fInitialized) {
118
	    		fInitialized = true;
119
	    		notifyAll();
120
	    	}
121
    	}
122
        fWindowAction.setEnabled(enabled);
123
    }
124
    
125
    public void setChecked(boolean checked) {
126
    	fWindowAction.setChecked(checked);
127
    }
128
    
129
    protected IAction getWindowAction()
130
    {
131
    	return fWindowAction;
132
    }
133
    
134
    
135
}
(-)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
}

Return to bug 284363