mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 483234: Add a command example to the example plug-in
A new command, ShowVersionHandler, has been added to the plug-in to demonstrate all the pieces that need to be put in place to connect a command to a DSF session. Change-Id: Iefde0ba144c12ce2e580da7717b390258c0d3675 Signed-off-by: Jonah Graham <jonah@kichwacoders.com>
This commit is contained in:
parent
ec9a9fb5c7
commit
e9d5637eca
13 changed files with 328 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#Tue Jun 24 11:04:03 PDT 2008
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
|
@ -67,4 +66,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
|
|||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
|
|
|
@ -16,7 +16,7 @@ Require-Bundle: org.eclipse.ui,
|
|||
org.eclipse.cdt.ui,
|
||||
org.eclipse.cdt.debug.core,
|
||||
org.eclipse.cdt.debug.ui
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-Vendor: Eclipse CDT
|
||||
Export-Package: org.eclipse.cdt.examples.dsf.gdb;x-internal:=true,
|
||||
|
|
BIN
dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/icons/sample.gif
Normal file
BIN
dsf-gdb/org.eclipse.cdt.examples.dsf.gdb/icons/sample.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 983 B |
|
@ -83,4 +83,114 @@
|
|||
<adapter type="org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactory"/>
|
||||
</factory>
|
||||
</extension>
|
||||
|
||||
<!-- Example showing how to add a custom command with toolbar/menu contributions with DSF.
|
||||
The example command id is org.eclipse.cdt.examples.dsf.gdb.command.showVersion.
|
||||
In this example, when run it will display the version of GDB that is connected. -->
|
||||
<extension point="org.eclipse.ui.commands">
|
||||
<command
|
||||
categoryId="org.eclipse.cdt.debug.ui.category.debugViewLayout"
|
||||
description="Show the GDB Version in a pop-up"
|
||||
id="org.eclipse.cdt.examples.dsf.gdb.command.showVersion"
|
||||
name="Show GDB Version">
|
||||
</command>
|
||||
</extension>
|
||||
|
||||
<!-- Contribute Show GDB Version command to various places in the UI -->
|
||||
<extension
|
||||
point="org.eclipse.ui.menus">
|
||||
|
||||
<!-- Contribute Show GDB Version to the toolbar at the top of the Debug View
|
||||
NOTE: due to platform issues, the org.eclipse.debug.ui.debugViewToolbarVisible does
|
||||
not work reliably, further tied to the org.eclipse.core.runtime.bundleState test
|
||||
it means that this contribution does not show up reliabliy. Closing and re-opening
|
||||
the debug view resolves the issue fully. See Bug 378554 and 378892 (which is
|
||||
a similar issue for reverse debugging buttons).
|
||||
-->
|
||||
<menuContribution
|
||||
locationURI="toolbar:org.eclipse.debug.ui.DebugView?before=stepGroup">
|
||||
<command
|
||||
commandId="org.eclipse.cdt.examples.dsf.gdb.command.showVersion"
|
||||
icon="icons/sample.gif"
|
||||
label="Show GDB Version"
|
||||
style="push"
|
||||
tooltip="Show the GDB Version in a pop-up">
|
||||
<visibleWhen checkEnabled="false">
|
||||
<and>
|
||||
<systemTest property="org.eclipse.debug.ui.debugViewToolbarVisible" value="true"/>
|
||||
<with variable="org.eclipse.core.runtime.Platform">
|
||||
<test property="org.eclipse.core.runtime.bundleState"
|
||||
args="org.eclipse.cdt.examples.dsf.gdb"
|
||||
value="ACTIVE">
|
||||
</test>
|
||||
</with>
|
||||
</and>
|
||||
</visibleWhen>
|
||||
</command>
|
||||
</menuContribution>
|
||||
|
||||
<!-- Contribute Show GDB Version to the popup menu of the Debug View -->
|
||||
<menuContribution
|
||||
locationURI="popup:org.eclipse.debug.ui.DebugView?before=stepGroup">
|
||||
<command
|
||||
commandId="org.eclipse.cdt.examples.dsf.gdb.command.showVersion"
|
||||
icon="icons/sample.gif"
|
||||
label="Show GDB Version"
|
||||
style="push"
|
||||
tooltip="Show the GDB Version in a pop-up">
|
||||
<visibleWhen
|
||||
checkEnabled="false">
|
||||
<with variable="org.eclipse.core.runtime.Platform">
|
||||
<test property="org.eclipse.core.runtime.bundleState"
|
||||
args="org.eclipse.cdt.examples.dsf.gdb"
|
||||
value="ACTIVE">
|
||||
</test>
|
||||
</with>
|
||||
</visibleWhen>
|
||||
</command>
|
||||
</menuContribution>
|
||||
|
||||
<!-- Contribute Show GDB Version to the Main toolbar -->
|
||||
<menuContribution
|
||||
locationURI="toolbar:org.eclipse.debug.ui.main.toolbar?before=stepGroup">
|
||||
<command
|
||||
commandId="org.eclipse.cdt.examples.dsf.gdb.command.showVersion"
|
||||
icon="icons/sample.gif"
|
||||
label="Show GDB Version"
|
||||
style="push"
|
||||
tooltip="Show the GDB Version in a pop-up">
|
||||
<visibleWhen
|
||||
checkEnabled="false">
|
||||
<and>
|
||||
<reference
|
||||
definitionId="org.eclipse.cdt.debug.ui.testIsDebugActionSetActive">
|
||||
</reference>
|
||||
<with variable="org.eclipse.core.runtime.Platform">
|
||||
<test property="org.eclipse.core.runtime.bundleState"
|
||||
args="org.eclipse.cdt.examples.dsf.gdb"
|
||||
value="ACTIVE">
|
||||
</test>
|
||||
</with>
|
||||
</and>
|
||||
</visibleWhen>
|
||||
</command>
|
||||
</menuContribution>
|
||||
|
||||
</extension>
|
||||
|
||||
<!-- Connect the Show GDB Version command ID to its handler -->
|
||||
<extension point="org.eclipse.ui.handlers">
|
||||
<handler
|
||||
class="org.eclipse.cdt.examples.dsf.gdb.commands.ShowVersionHandler"
|
||||
commandId="org.eclipse.cdt.examples.dsf.gdb.command.showVersion">
|
||||
<enabledWhen>
|
||||
<with variable="org.eclipse.core.runtime.Platform">
|
||||
<test property="org.eclipse.core.runtime.bundleState"
|
||||
args="org.eclipse.cdt.examples.dsf.gdb"
|
||||
value="ACTIVE">
|
||||
</test>
|
||||
</with>
|
||||
</enabledWhen>
|
||||
</handler>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
*
|
||||
* Contributors:
|
||||
* Marc Khouzam (Ericsson) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
@ -19,8 +19,8 @@ import org.eclipse.debug.core.ILaunch;
|
|||
@SuppressWarnings("restriction")
|
||||
@ThreadSafe
|
||||
public class GdbExtendedAdapterFactory extends GdbAdapterFactory {
|
||||
@Override
|
||||
protected GdbSessionAdapters createGdbSessionAdapters(ILaunch launch, DsfSession session) {
|
||||
return new GdbExtendedSessionAdapters(launch, session, getAdapterList());
|
||||
}
|
||||
@Override
|
||||
protected GdbSessionAdapters createGdbSessionAdapters(ILaunch launch, DsfSession session) {
|
||||
return new GdbExtendedSessionAdapters(launch, session, getAdapterList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,13 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.examples.dsf.gdb;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbSessionAdapters;
|
||||
import org.eclipse.cdt.dsf.service.DsfSession;
|
||||
import org.eclipse.cdt.examples.dsf.gdb.actions.DsfExtendedTerminateCommand;
|
||||
import org.eclipse.cdt.examples.dsf.gdb.actions.GdbShowVersionHandler;
|
||||
import org.eclipse.cdt.examples.dsf.gdb.commands.IShowVersionHandler;
|
||||
import org.eclipse.cdt.examples.dsf.gdb.viewmodel.GdbExtendedViewModelAdapter;
|
||||
import org.eclipse.debug.core.ILaunch;
|
||||
import org.eclipse.debug.core.commands.ITerminateHandler;
|
||||
|
@ -34,7 +38,17 @@ public class GdbExtendedSessionAdapters extends GdbSessionAdapters {
|
|||
if (IViewerInputProvider.class.equals(adapterType)) {
|
||||
return (T)new GdbExtendedViewModelAdapter(session, getSteppingController());
|
||||
}
|
||||
if (IShowVersionHandler.class.equals(adapterType)) {
|
||||
return (T)new GdbShowVersionHandler(session);
|
||||
}
|
||||
|
||||
return super.createModelAdapter(adapterType, launch, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Class<?>> getModelAdapters() {
|
||||
List<Class<?>> modelAdapters = super.getModelAdapters();
|
||||
modelAdapters.add(IShowVersionHandler.class);
|
||||
return modelAdapters;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Kichwa Coders 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Jonah Graham (Kichwa Coders) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.examples.dsf.gdb.actions;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
|
||||
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
|
||||
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
|
||||
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
|
||||
import org.eclipse.cdt.dsf.datamodel.DMContexts;
|
||||
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
|
||||
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
|
||||
import org.eclipse.cdt.dsf.service.DsfSession;
|
||||
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
|
||||
import org.eclipse.cdt.examples.dsf.gdb.GDBExamplePlugin;
|
||||
import org.eclipse.cdt.examples.dsf.gdb.commands.IShowVersionHandler;
|
||||
import org.eclipse.cdt.examples.dsf.gdb.service.IGDBExtendedFunctions;
|
||||
import org.eclipse.debug.core.commands.IDebugCommandRequest;
|
||||
import org.eclipse.debug.core.commands.IEnabledStateRequest;
|
||||
|
||||
public class GdbShowVersionHandler implements IShowVersionHandler {
|
||||
private final DsfExecutor fExecutor;
|
||||
private final DsfServicesTracker fTracker;
|
||||
|
||||
public GdbShowVersionHandler(DsfSession session) {
|
||||
fExecutor = session.getExecutor();
|
||||
fTracker = new DsfServicesTracker(GDBExamplePlugin.getBundleContext(), session.getId());
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
fTracker.dispose();
|
||||
}
|
||||
|
||||
private Optional<ICommandControlDMContext> getContext(final IDebugCommandRequest request) {
|
||||
if (request.getElements().length != 1 || !(request.getElements()[0] instanceof IDMVMContext)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
final IDMVMContext context = (IDMVMContext) request.getElements()[0];
|
||||
ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(context.getDMContext(),
|
||||
ICommandControlDMContext.class);
|
||||
if (controlDmc != null)
|
||||
return Optional.of(controlDmc);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void canExecute(final IEnabledStateRequest request) {
|
||||
final Optional<ICommandControlDMContext> context = getContext(request);
|
||||
if (!context.isPresent()) {
|
||||
request.setEnabled(false);
|
||||
request.done();
|
||||
return;
|
||||
}
|
||||
|
||||
fExecutor.execute(new DsfRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final IGDBExtendedFunctions funcService = fTracker.getService(IGDBExtendedFunctions.class);
|
||||
if (funcService == null) {
|
||||
request.setEnabled(false);
|
||||
request.done();
|
||||
} else {
|
||||
funcService.canGetVersion(context.get(), new DataRequestMonitor<Boolean>(fExecutor, null) {
|
||||
@Override
|
||||
protected void handleCompleted() {
|
||||
if (!isSuccess()) {
|
||||
request.setEnabled(false);
|
||||
} else {
|
||||
request.setEnabled(getData());
|
||||
}
|
||||
request.done();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final IDebugCommandRequest request) {
|
||||
final Optional<ICommandControlDMContext> context = getContext(request);
|
||||
if (!context.isPresent()) {
|
||||
request.done();
|
||||
return false;
|
||||
}
|
||||
|
||||
fExecutor.execute(new DsfRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final IGDBExtendedFunctions funcService = fTracker.getService(IGDBExtendedFunctions.class);
|
||||
if (funcService == null) {
|
||||
request.done();
|
||||
} else {
|
||||
funcService.getVersion(context.get(), new DataRequestMonitor<String>(fExecutor, null) {
|
||||
@Override
|
||||
protected void handleCompleted() {
|
||||
String str;
|
||||
if (isSuccess()) {
|
||||
str = "======= GDB version: " + getData() + " ======="; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} else {
|
||||
str = "Could not obtain GDB version. Error: " + //$NON-NLS-1$
|
||||
getStatus();
|
||||
}
|
||||
funcService.notify(context.get(), str, new RequestMonitor(fExecutor, null) {
|
||||
@Override
|
||||
protected void handleCompleted() {
|
||||
request.done();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Return true so that the show version pop-up command is immediately
|
||||
* reenabled, this allows users to run the command multiple times
|
||||
* without any other operations in between. There is a small chance the
|
||||
* command may be issued again while it is still running, however with
|
||||
* this particular command it is very fast so that is unlikely. In
|
||||
* addition for this command no harm comes if it is issued twice.
|
||||
*
|
||||
* Most commands return false here because they need to be reenabled by
|
||||
* some operation. For example continue would only be reenabled by the
|
||||
* state change in the backend to being suspended again.
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Kichwa Coders 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Jonah Graham (Kichwa Coders) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.examples.dsf.gdb.commands;
|
||||
|
||||
import org.eclipse.debug.core.commands.IDebugCommandHandler;
|
||||
|
||||
public interface IShowVersionHandler extends IDebugCommandHandler {
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Kichwa Coders 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Jonah Graham (Kichwa Coders) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.examples.dsf.gdb.commands;
|
||||
|
||||
import org.eclipse.debug.ui.actions.DebugCommandHandler;
|
||||
|
||||
public class ShowVersionHandler extends DebugCommandHandler {
|
||||
|
||||
@Override
|
||||
protected Class<IShowVersionHandler> getCommandType() {
|
||||
return IShowVersionHandler.class;
|
||||
}
|
||||
}
|
|
@ -118,4 +118,9 @@ public class GDBExtendedService extends AbstractDsfService implements IGDBExtend
|
|||
NOT_SUPPORTED, "Not supported", null)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void canGetVersion(ICommandControlDMContext ctx, DataRequestMonitor<Boolean> rm) {
|
||||
rm.done(fCommandFactory instanceof GdbExtendedCommandFactory_6_8);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,4 +27,9 @@ public interface IGDBExtendedFunctions extends IDsfService {
|
|||
*/
|
||||
void getVersion(ICommandControlDMContext ctx, DataRequestMonitor<String> rm);
|
||||
|
||||
/**
|
||||
* Can get the version of the debugger
|
||||
*/
|
||||
void canGetVersion(ICommandControlDMContext ctx, DataRequestMonitor<Boolean> rm);
|
||||
|
||||
}
|
||||
|
|
|
@ -72,7 +72,8 @@ Export-Package: org.eclipse.cdt.dsf.debug.internal.ui;x-internal:=true,
|
|||
x-friends:="org.eclipse.cdt.dsf.gdb.ui,
|
||||
org.eclipse.cdt.examples.dsf,
|
||||
org.eclipse.cdt.examples.dsf.pda.ui,
|
||||
org.eclipse.cdt.debug.edc.ui",
|
||||
org.eclipse.cdt.debug.edc.ui,
|
||||
org.eclipse.cdt.examples.dsf.gdb",
|
||||
org.eclipse.cdt.dsf.ui.viewmodel.properties;
|
||||
x-friends:="org.eclipse.cdt.dsf.gdb.ui,
|
||||
org.eclipse.cdt.examples.dsf,
|
||||
|
|
Loading…
Add table
Reference in a new issue