1
/*******************************************************************************
2
* Copyright (c) 2009 Ericsson 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
9
* Ericsson - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.dsf.gdb.internal.ui.actions;
13
import org.eclipse.cdt.dsf.datamodel.DMContexts;
14
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
15
import org.eclipse.cdt.dsf.gdb.actions.IReverseToggleHandler;
16
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
17
import org.eclipse.core.expressions.PropertyTester;
18
import org.eclipse.debug.ui.DebugUITools;
19
import org.eclipse.debug.ui.contexts.IDebugContextService;
20
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.ui.IViewPart;
23
import org.eclipse.ui.IViewSite;
24
import org.eclipse.ui.IWorkbenchPart;
27
* Property tester for reverse debugging information available through the given
28
* object. The object being tested could either be a {@link IWorkbenchPart} or
29
* a {@link IDMVMContext}.
31
* One property is supported:
33
* <li> "isReverseDebuggingEnabled" - Checks whether reverse debugging is currently
34
* enabled given the receiver.</li>
38
public class ReverseDebuggingPropertyTester extends PropertyTester {
40
private static final String ENABLED = "isReverseDebuggingEnabled"; //$NON-NLS-1$
42
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
43
if (ENABLED.equals(property)) {
44
if (receiver instanceof IWorkbenchPart) {
45
Object selection = getContextSelectionForPart((IWorkbenchPart)receiver);
46
if (selection instanceof IDMVMContext) {
47
return test((IDMVMContext)selection);
49
} else if (receiver instanceof IDMVMContext) {
50
return test((IDMVMContext)receiver);
56
private boolean test(IDMVMContext context) {
57
ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(context.getDMContext(), ICommandControlDMContext.class);
58
if (controlDmc != null) {
59
IReverseToggleHandler toggle = (IReverseToggleHandler)(controlDmc.getAdapter(IReverseToggleHandler.class));
61
boolean t= toggle.isReverseToggled(controlDmc);
68
private static Object getContextSelectionForPart(IWorkbenchPart part) {
69
IDebugContextService contextService =
70
DebugUITools.getDebugContextManager().getContextService(part.getSite().getWorkbenchWindow());
72
ISelection debugContext = contextService.getActiveContext(getPartId(part));
73
if (debugContext == null) {
74
debugContext = contextService.getActiveContext();
77
if (debugContext instanceof IStructuredSelection) {
78
return ((IStructuredSelection)debugContext).getFirstElement();
83
private static String getPartId(IWorkbenchPart part) {
84
if (part instanceof IViewPart) {
85
IViewSite site = (IViewSite)part.getSite();
86
return site.getId() + (site.getSecondaryId() != null ? (":" + site.getSecondaryId()) : ""); //$NON-NLS-1$ //$NON-NLS-2$
88
return part.getSite().getId();