Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7673f759f908554120fa1ddc35fa95d73bc516f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*******************************************************************************
 * Copyright (c) 2008, 2013 Wind River Systems and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *     IBM Corporation - bug fixing
 *******************************************************************************/
package org.eclipse.debug.examples.ui.pda.views;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.debug.examples.core.pda.model.PDAStackFrame;
import org.eclipse.debug.examples.core.pda.model.PDAThread;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;

/**
 * Base class for command handlers for data stack view.
 */
abstract public class AbstractDataStackViewHandler extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
		if (part instanceof DataStackView) {
			DataStackView view = (DataStackView)part;

			ISelection selection = DebugUITools.getDebugContextForEventChecked(event);
			if (selection instanceof IStructuredSelection) {
				Object element = ((IStructuredSelection)selection).getFirstElement();

				PDAThread thread = null;
				if (element instanceof PDAThread) {
					thread = (PDAThread)element;
				} else if (element instanceof PDAStackFrame) {
					thread = (PDAThread)((PDAStackFrame)element).getThread();
				}

				if (element != null) {
					doExecute(
						view,
						thread,
						HandlerUtil.getCurrentSelectionChecked(event));
				}
			}
		} else {
			throw new ExecutionException("Handler must be with DataStackView only"); //$NON-NLS-1$
		}
		return null;
	}

	/**
	 * Performs the actual handler operation.
	 *
	 * @param view The view that the handler was invoked in.
	 * @param target The current active debug target.
	 * @param selection The current selection in view.
	 */
	abstract protected void doExecute(DataStackView view, PDAThread target, ISelection selection) throws ExecutionException;
}

Back to the top