Bug 303808: Example of ConsolePageParticipant for Debugger Console

This commit also enables a richer set of enablement checks when
contributing ConsolePageParticipants to the Debugger Console view.

Change-Id: I34aa010fd9cfa91f24781e2bef5ba41b9525eab0
This commit is contained in:
Marc Khouzam 2016-12-21 21:58:42 -05:00
parent c8ce2587e8
commit bfea9deb90
10 changed files with 248 additions and 5 deletions

View file

@ -17,6 +17,9 @@ import java.util.List;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.debug.ui.debuggerconsole.IDebuggerConsole;
import org.eclipse.cdt.debug.ui.debuggerconsole.IDebuggerConsoleManager;
import org.eclipse.core.expressions.EvaluationResult;
import org.eclipse.core.expressions.Expression;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
@ -26,6 +29,7 @@ import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
@ -114,7 +118,26 @@ public class DebuggerConsoleManager implements IDebuggerConsoleManager {
IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
IConfigurationElement config = elements[i];
ConsolePageParticipantExtension extension = new ConsolePageParticipantExtension(config);
ConsolePageParticipantExtension extension = new ConsolePageParticipantExtension(config) {
@Override
public boolean isEnabledFor(IConsole console) throws CoreException {
// Override to provide more information to the evaluation context
// than what the base class provides. This allows richer enablement
// conditions to be used. For example, org.eclipse.cdt.examples.dsf.gdb
// limits the enablement of its GdbExtendedConsolePageParticipant to
// when the plugin has been activated.
// Without this richer EvaluationContext, the information about
// plugin activation is not available and all that can be checked is
// the type of console.
IEvaluationContext context = DebugUIPlugin.createEvaluationContext(console);
Expression expression = getEnablementExpression();
if (expression != null){
EvaluationResult evaluationResult = expression.evaluate(context);
return evaluationResult == EvaluationResult.TRUE;
}
return true;
}
};
fPageParticipants.add(extension);
}
}

View file

@ -33,7 +33,7 @@ Export-Package: org.eclipse.cdt.dsf.gdb.internal.ui;x-friends:="org.eclipse.cdt.
org.eclipse.cdt.dsf.gdb.internal.ui.actions;x-friends:="org.eclipse.cdt.examples.dsf.gdb",
org.eclipse.cdt.dsf.gdb.internal.ui.breakpoints;x-internal:=true,
org.eclipse.cdt.dsf.gdb.internal.ui.commands;x-internal:=true,
org.eclipse.cdt.dsf.gdb.internal.ui.console;x-internal:=true,
org.eclipse.cdt.dsf.gdb.internal.ui.console;x-friends:="org.eclipse.cdt.examples.dsf.gdb",
org.eclipse.cdt.dsf.gdb.internal.ui.console.actions;x-internal:=true,
org.eclipse.cdt.dsf.gdb.internal.ui.disassembly;x-internal:=true,
org.eclipse.cdt.dsf.gdb.internal.ui.launching;x-friends:="org.eclipse.cdt.debug.gdbjtag.ui,org.eclipse.cdt.examples.dsf.gdb,org.eclipse.cdt.docker.launcher",

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: GDB DSF Debugger Extension Example
Bundle-SymbolicName: org.eclipse.cdt.examples.dsf.gdb;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Version: 1.1.0.qualifier
Bundle-Activator: org.eclipse.cdt.examples.dsf.gdb.GDBExamplePlugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
@ -15,7 +15,9 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.cdt.dsf.ui,
org.eclipse.cdt.ui,
org.eclipse.cdt.debug.core,
org.eclipse.cdt.debug.ui
org.eclipse.cdt.debug.ui,
org.eclipse.ui.console,
org.eclipse.tm.terminal.control
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-Vendor: Eclipse CDT

View file

@ -239,4 +239,27 @@
</enabledWhen>
</handler>
</extension>
<!-- Add a console page participant to the debugger console pages -->
<extension
point="org.eclipse.ui.console.consolePageParticipants">
<consolePageParticipant
class="org.eclipse.cdt.examples.dsf.gdb.ui.console.GdbExtendedConsolePageParticipant"
id="org.eclipse.cdt.examples.dsf.gdb.debuggerConsolePageParticipant">
<enablement>
<and>
<instanceof value="org.eclipse.cdt.debug.ui.debuggerconsole.IDebuggerConsole"/>
<!-- The below check only works with the Debugger Console view and not the
standard console view. But that is ok since this contribution is
for the Debugger Console views only. -->
<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>
</enablement>
</consolePageParticipant>
</extension>
</plugin>

View file

@ -11,7 +11,7 @@
<relativePath>../../pom.xml</relativePath>
</parent>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.examples.dsf.gdb</artifactId>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2016 Ericsson 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
*******************************************************************************/
package org.eclipse.cdt.examples.dsf.gdb.ui.console;
import org.eclipse.osgi.util.NLS;
/**
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public class GdbExtendedConsoleMessages extends NLS {
public static String Request_Thread_Info;
public static String Request_Thread_Info_Tip;
public static String Set_Special_Background;
public static String Set_Special_Background_Tip;
static {
// initialize resource bundle
NLS.initializeMessages(GdbExtendedConsoleMessages.class.getName(), GdbExtendedConsoleMessages.class);
}
private GdbExtendedConsoleMessages() {
}
}

View file

@ -0,0 +1,12 @@
###############################################################################
# Copyright (c) 2016 Ericsson 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
###############################################################################
Request_Thread_Info=Info
Request_Thread_Info_Tip=Request information about threads
Set_Special_Background=Background
Set_Special_Background_Tip=Toggle background color

View file

@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2016 Ericsson 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
*******************************************************************************/
package org.eclipse.cdt.examples.dsf.gdb.ui.console;
import org.eclipse.cdt.dsf.gdb.internal.ui.console.GdbBasicCliConsole;
import org.eclipse.cdt.dsf.gdb.internal.ui.console.GdbFullCliConsolePage;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleConstants;
import org.eclipse.ui.console.IConsolePageParticipant;
import org.eclipse.ui.part.IPageBookViewPage;
/**
* An example console page participant for both standard console pages of the Debugger
* Console view.
* It adds a button to the GdbBasicCliConsolePage and different one to the GdbFullCliConsolePage.
*/
public class GdbExtendedConsolePageParticipant implements IConsolePageParticipant {
private IPageBookViewPage fPage;
private IConsole fConsole;
@Override
public void init(IPageBookViewPage page, IConsole console) {
fPage = page;
fConsole = console;
addButtons();
}
private void addButtons() {
IToolBarManager toolBarManager = fPage.getSite().getActionBars().getToolBarManager();
IAction action = null;
if (fConsole instanceof GdbBasicCliConsole) {
action = new GdbExtendedSpecialBackgroundToggle(fConsole);
} else if (fPage instanceof GdbFullCliConsolePage) {
ITerminalViewControl terminalControl = ((GdbFullCliConsolePage)fPage).getTerminalViewControl();
action = new GdbExtendedInfoThreadsAction(terminalControl);
}
toolBarManager.appendToGroup(IConsoleConstants.OUTPUT_GROUP, action);
}
@Override
public <T> T getAdapter(Class<T> adapter) {
return null;
}
@Override
public void dispose() {
}
@Override
public void activated() {
}
@Override
public void deactivated() {
}
}

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2016 Ericsson 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
*******************************************************************************/
package org.eclipse.cdt.examples.dsf.gdb.ui.console;
import org.eclipse.jface.action.Action;
import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
/**
* Action to requests threads info from the full GDB console
*/
public class GdbExtendedInfoThreadsAction extends Action {
private final ITerminalViewControl fTerminalCtrl;
public GdbExtendedInfoThreadsAction(ITerminalViewControl terminalControl) {
fTerminalCtrl = terminalControl;
if (fTerminalCtrl == null || fTerminalCtrl.isDisposed()) {
setEnabled(false);
}
setText(GdbExtendedConsoleMessages.Request_Thread_Info);
setToolTipText(GdbExtendedConsoleMessages.Request_Thread_Info_Tip);
}
@Override
public void run() {
fTerminalCtrl.pasteString("info threads\n"); //$NON-NLS-1$
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2016 Ericsson 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
*******************************************************************************/
package org.eclipse.cdt.examples.dsf.gdb.ui.console;
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.TextConsole;
/**
* Action to toggle a special background color for the basic GDB console
*/
public class GdbExtendedSpecialBackgroundToggle extends Action {
private static final int SPECIAL_BACKGROUND_COLOR = SWT.COLOR_DARK_GREEN;
private TextConsole fConsole;
public GdbExtendedSpecialBackgroundToggle(IConsole console) {
if (console instanceof TextConsole) {
fConsole = (TextConsole)console;
} else {
setEnabled(false);
}
setText(GdbExtendedConsoleMessages.Set_Special_Background);
setToolTipText(GdbExtendedConsoleMessages.Set_Special_Background_Tip);
}
@Override
public void run() {
int newColor = SPECIAL_BACKGROUND_COLOR;
Color background = fConsole.getBackground();
if (background.equals(Display.getDefault().getSystemColor(SPECIAL_BACKGROUND_COLOR))) {
boolean enabled = Platform.getPreferencesService().getBoolean(GdbPlugin.PLUGIN_ID,
IGdbDebugPreferenceConstants.PREF_CONSOLE_INVERTED_COLORS,
false, null);
if (enabled) {
newColor = SWT.COLOR_BLACK;
} else {
newColor = SWT.COLOR_WHITE;
}
}
fConsole.setBackground(Display.getDefault().getSystemColor(newColor));
}
}