diff options
author | Marc Khouzam | 2012-04-25 02:58:22 +0000 |
---|---|---|
committer | Marc Khouzam | 2012-04-25 13:57:37 +0000 |
commit | efe3dd4be6ab048411a623112dcae093d78fd329 (patch) | |
tree | da943aeef0480055abd7119309f84dc751eb3333 /dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug | |
parent | c7be1163514fee663d90df4ff3b6a37a8c1968fa (diff) | |
download | org.eclipse.cdt-efe3dd4be6ab048411a623112dcae093d78fd329.tar.gz org.eclipse.cdt-efe3dd4be6ab048411a623112dcae093d78fd329.tar.xz org.eclipse.cdt-efe3dd4be6ab048411a623112dcae093d78fd329.zip |
Bug 330974: If the user selects multiple nodes in the debug view most debug commands are disabled
Change-Id: I51d15347fd28ee550e9bd2b75c61e904e75b4c8b
Reviewed-on: https://git.eclipse.org/r/5650
Reviewed-by: Marc Khouzam <marc.khouzam@ericsson.com>
IP-Clean: Marc Khouzam <marc.khouzam@ericsson.com>
Tested-by: Marc Khouzam <marc.khouzam@ericsson.com>
Diffstat (limited to 'dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug')
3 files changed, 154 insertions, 41 deletions
diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/actions/DsfCommandRunnable.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/actions/DsfCommandRunnable.java index a79fa6e4f5e..7b1426fee03 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/actions/DsfCommandRunnable.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/actions/DsfCommandRunnable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 Wind River Systems and others. + * Copyright (c) 2006, 2012 Wind River Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,9 +7,13 @@ * * Contributors: * Wind River Systems - initial API and implementation + * Marc Khouzam (Ericsson) - Added support for multiple selection (bug 330974) *******************************************************************************/ package org.eclipse.cdt.dsf.debug.ui.actions; +import java.util.HashSet; +import java.util.Set; + import org.eclipse.cdt.dsf.concurrent.DsfRunnable; import org.eclipse.cdt.dsf.concurrent.Immutable; import org.eclipse.cdt.dsf.datamodel.DMContexts; @@ -29,11 +33,18 @@ import org.eclipse.debug.core.commands.IDebugCommandRequest; */ @Immutable public abstract class DsfCommandRunnable extends DsfRunnable { - private final IExecutionDMContext fContext; + private final IExecutionDMContext[] fContexts; private final DsfServicesTracker fTracker; private final IDebugCommandRequest fRequest; - public IExecutionDMContext getContext() { return fContext; } + // For backwards compatibility, keep this method that returns the first selection. This method + // is meaningful when we only support a single selection. + public IExecutionDMContext getContext() { return (fContexts != null && fContexts.length > 0) ? fContexts[0] : null; } + /** + * Return all selected contexts. + * @since 2.3 + */ + public IExecutionDMContext[] getContexts() { return fContexts; } public IRunControl getRunControl() { return fTracker.getService(IRunControl.class); } @@ -42,8 +53,8 @@ public abstract class DsfCommandRunnable extends DsfRunnable { * @since 1.1 */ public SteppingController getSteppingController() { - if (fContext != null) { - return (SteppingController) fContext.getAdapter(SteppingController.class); + if (fContexts != null && fContexts.length > 0) { + return (SteppingController) fContexts[0].getAdapter(SteppingController.class); } return null; } @@ -56,15 +67,33 @@ public abstract class DsfCommandRunnable extends DsfRunnable { } public DsfCommandRunnable(DsfServicesTracker servicesTracker, Object element, IDebugCommandRequest request) { - fTracker = servicesTracker; - if (element instanceof IDMVMContext) { - IDMVMContext vmc = (IDMVMContext)element; - fContext = DMContexts.getAncestorOfType(vmc.getDMContext(), IExecutionDMContext.class); - } else { - fContext = null; - } - - fRequest = request; + this(servicesTracker, new Object[] { element }, request); + } + + /** @since 2.3 */ + public DsfCommandRunnable(DsfServicesTracker servicesTracker, Object[] elements, IDebugCommandRequest request) { + fTracker = servicesTracker; + fRequest = request; + + // Extract all selected execution contexts, using a set to avoid duplicates. Duplicates will + // happen if multiple stack frames of the same thread are selected. + Set<IExecutionDMContext> execDmcSet = new HashSet<IExecutionDMContext>(request.getElements().length); + for (Object element : request.getElements()) { + if (element instanceof IDMVMContext) { + IDMVMContext vmc = (IDMVMContext)element; + IExecutionDMContext execDmc = DMContexts.getAncestorOfType(vmc.getDMContext(), IExecutionDMContext.class); + if (execDmc != null) { + // We have a thread or a process + execDmcSet.add(execDmc); + } + } + } + + if (execDmcSet.size() == 0) { + fContexts = null; + } else { + fContexts = execDmcSet.toArray(new IExecutionDMContext[execDmcSet.size()]); + } } @Override @@ -73,8 +102,8 @@ public abstract class DsfCommandRunnable extends DsfRunnable { fRequest.done(); return; } - if (getContext() == null) { - fRequest.setStatus(makeError("Selected object does not support run control.", null)); //$NON-NLS-1$ + if (getContexts() == null || getContexts().length == 0) { + fRequest.setStatus(makeError("Selected objects do not support run control.", null)); //$NON-NLS-1$ } else if (getRunControl() == null || getSteppingController() == null) { fRequest.setStatus(makeError("Run Control not available", null)); //$NON-NLS-1$ } else { diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/actions/DsfResumeCommand.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/actions/DsfResumeCommand.java index 10e7c464039..44f089339ca 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/actions/DsfResumeCommand.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/actions/DsfResumeCommand.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 Wind River Systems and others. + * Copyright (c) 2006, 2012 Wind River Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,14 +7,16 @@ * * Contributors: * Wind River Systems - initial API and implementation + * Marc Khouzam (Ericsson) - Added support for multi-selection (Bug 330974) *******************************************************************************/ package org.eclipse.cdt.dsf.debug.ui.actions; -import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DsfExecutor; -import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor; +import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; import org.eclipse.cdt.dsf.concurrent.Immutable; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.debug.service.IMultiRunControl; import org.eclipse.cdt.dsf.internal.ui.DsfUIPlugin; import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.cdt.dsf.service.DsfSession; @@ -43,17 +45,42 @@ public class DsfResumeCommand implements IResumeHandler { @Override public void canExecute(final IEnabledStateRequest request) { - if (request.getElements().length != 1) { - request.setEnabled(false); - request.done(); + if (request.getElements().length == 1) { + canExecuteSingle(request); return; } + // Handle multi-selection + fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements(), request) { + @Override public void doExecute() { + final IMultiRunControl multiRun = fTracker.getService(IMultiRunControl.class); + if (multiRun == null) { + // No multi run control service: multi selection not allowed + request.setEnabled(false); + request.done(); + return; + } + + // Check if some of the selections can be resumed + multiRun.canResumeSome( + getContexts(), + new ImmediateDataRequestMonitor<Boolean>() { + @Override + protected void handleCompleted() { + request.setEnabled(isSuccess() && getData()); + request.done(); + } + }); + } + }); + } + + private void canExecuteSingle(final IEnabledStateRequest request) { fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements()[0], request) { @Override public void doExecute() { getRunControl().canResume( getContext(), - new DataRequestMonitor<Boolean>(ImmediateExecutor.getInstance(), null) { + new ImmediateDataRequestMonitor<Boolean>() { @Override protected void handleCompleted() { request.setEnabled(isSuccess() && getData()); @@ -66,17 +93,32 @@ public class DsfResumeCommand implements IResumeHandler { @Override public boolean execute(final IDebugCommandRequest request) { - if (request.getElements().length != 1) { - request.done(); - return false; + if (request.getElements().length == 1) { + executeSingle(request); + return false; } + + // Handle multi-selection + fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements(), request) { + @Override public void doExecute() { + final IMultiRunControl multiRun = fTracker.getService(IMultiRunControl.class); + if (multiRun == null) { + // No multi run control service: multi selection not allowed + request.done(); + return; + } + multiRun.resume(getContexts(), new ImmediateRequestMonitor()); + } + }); + return false; + } + + private void executeSingle(IDebugCommandRequest request) { fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements()[0], request) { @Override public void doExecute() { getRunControl().resume(getContext(), new RequestMonitor(fExecutor, null)); } }); - return false; } - } diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/actions/DsfSuspendCommand.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/actions/DsfSuspendCommand.java index ebc32610586..30a9f538e4e 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/actions/DsfSuspendCommand.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/actions/DsfSuspendCommand.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 Wind River Systems and others. + * Copyright (c) 2006, 2012 Wind River Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,14 +7,16 @@ * * Contributors: * Wind River Systems - initial API and implementation + * Marc Khouzam (Ericsson) - Added support for multi-selection (Bug 330974) *******************************************************************************/ package org.eclipse.cdt.dsf.debug.ui.actions; -import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DsfExecutor; -import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor; +import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; import org.eclipse.cdt.dsf.concurrent.Immutable; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.debug.service.IMultiRunControl; import org.eclipse.cdt.dsf.internal.ui.DsfUIPlugin; import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.cdt.dsf.service.DsfSession; @@ -42,17 +44,42 @@ public class DsfSuspendCommand implements ISuspendHandler { @Override public void canExecute(final IEnabledStateRequest request) { - if (request.getElements().length != 1) { - request.setEnabled(false); - request.done(); + if (request.getElements().length == 1) { + canExecuteSingle(request); return; } + // Handle multi-selection + fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements(), request) { + @Override public void doExecute() { + final IMultiRunControl multiRun = fTracker.getService(IMultiRunControl.class); + if (multiRun == null) { + // No multi run control service: multi selection not allowed + request.setEnabled(false); + request.done(); + return; + } + + // Check if some of the selections can be suspended + multiRun.canSuspendSome( + getContexts(), + new ImmediateDataRequestMonitor<Boolean>() { + @Override + protected void handleCompleted() { + request.setEnabled(isSuccess() && getData()); + request.done(); + } + }); + } + }); + } + + private void canExecuteSingle(final IEnabledStateRequest request) { fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements()[0], request) { @Override public void doExecute() { getRunControl().canSuspend( getContext(), - new DataRequestMonitor<Boolean>(ImmediateExecutor.getInstance(), null) { + new ImmediateDataRequestMonitor<Boolean>() { @Override protected void handleCompleted() { request.setEnabled(isSuccess() && getData()); @@ -65,17 +92,32 @@ public class DsfSuspendCommand implements ISuspendHandler { @Override public boolean execute(final IDebugCommandRequest request) { - if (request.getElements().length != 1) { - request.done(); - return false; + if (request.getElements().length == 1) { + executeSingle(request); + return false; } - + + // Handle multi-selection + fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements(), request) { + @Override public void doExecute() { + final IMultiRunControl multiRun = fTracker.getService(IMultiRunControl.class); + if (multiRun == null) { + // No multi run control service: multi selection not allowed + request.done(); + return; + } + + multiRun.suspend(getContexts(), new ImmediateRequestMonitor()); + } + }); + return false; + } + + private void executeSingle(IDebugCommandRequest request) { fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements()[0], request) { @Override public void doExecute() { getRunControl().suspend(getContext(), new RequestMonitor(fExecutor, null)); } }); - return false; } - } |