diff options
author | Darin Wright | 2007-10-09 21:03:43 +0000 |
---|---|---|
committer | Darin Wright | 2007-10-09 21:03:43 +0000 |
commit | 07f1e796ae8a43d56d3010bd3e85063b318a0ad3 (patch) | |
tree | 35f7610d1674c644f814f9a8b8bb8a858feffd39 /org.eclipse.debug.examples.ui | |
parent | 50371b66ac350e9f64991048058ad251a191c90d (diff) | |
download | eclipse.platform.debug-07f1e796ae8a43d56d3010bd3e85063b318a0ad3.tar.gz eclipse.platform.debug-07f1e796ae8a43d56d3010bd3e85063b318a0ad3.tar.xz eclipse.platform.debug-07f1e796ae8a43d56d3010bd3e85063b318a0ad3.zip |
release of original PDA code base
Diffstat (limited to 'org.eclipse.debug.examples.ui')
39 files changed, 2678 insertions, 0 deletions
diff --git a/org.eclipse.debug.examples.ui/.classpath b/org.eclipse.debug.examples.ui/.classpath new file mode 100644 index 000000000..b7464f3ca --- /dev/null +++ b/org.eclipse.debug.examples.ui/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/org.eclipse.debug.examples.ui/.cvsignore b/org.eclipse.debug.examples.ui/.cvsignore new file mode 100644 index 000000000..ba077a403 --- /dev/null +++ b/org.eclipse.debug.examples.ui/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/org.eclipse.debug.examples.ui/.project b/org.eclipse.debug.examples.ui/.project new file mode 100644 index 000000000..6b2c66f6d --- /dev/null +++ b/org.eclipse.debug.examples.ui/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>example.debug.ui</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/org.eclipse.debug.examples.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.debug.examples.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..14a594160 --- /dev/null +++ b/org.eclipse.debug.examples.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,37 @@ +#Mon Jan 24 20:23:44 CST 2005 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.emptyStatement=warning +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning diff --git a/org.eclipse.debug.examples.ui/META-INF/MANIFEST.MF b/org.eclipse.debug.examples.ui/META-INF/MANIFEST.MF new file mode 100644 index 000000000..0b61b2dbd --- /dev/null +++ b/org.eclipse.debug.examples.ui/META-INF/MANIFEST.MF @@ -0,0 +1,25 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Example Debug UI Plug-in +Bundle-SymbolicName: org.eclipse.debug.examples.ui;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.eclipse.debug.examples.ui.pda.DebugUIPlugin +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.core.resources, + org.eclipse.debug.core, + org.eclipse.ui, + org.eclipse.debug.ui, + org.eclipse.jface.text, + org.eclipse.ui.editors, + org.eclipse.ui.workbench.texteditor, + org.eclipse.ui.ide, + org.eclipse.debug.examples.core +Eclipse-LazyStart: true +Export-Package: org.eclipse.debug.examples.ui.pda, + org.eclipse.debug.examples.ui.pda.adapters, + org.eclipse.debug.examples.ui.pda.breakpoints, + org.eclipse.debug.examples.ui.pda.editor, + org.eclipse.debug.examples.ui.pda.launcher, + org.eclipse.debug.examples.ui.pda.presentation, + org.eclipse.debug.examples.ui.pda.views +Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/org.eclipse.debug.examples.ui/about.html b/org.eclipse.debug.examples.ui/about.html new file mode 100644 index 000000000..460233046 --- /dev/null +++ b/org.eclipse.debug.examples.ui/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 2, 2006</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/org.eclipse.debug.examples.ui/build.properties b/org.eclipse.debug.examples.ui/build.properties new file mode 100644 index 000000000..3b3d36c80 --- /dev/null +++ b/org.eclipse.debug.examples.ui/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + bin/,\ + about.html,\ + META-INF/,\ + . +src.includes = src/ diff --git a/org.eclipse.debug.examples.ui/icons/full/dlcl16/pop.gif b/org.eclipse.debug.examples.ui/icons/full/dlcl16/pop.gif Binary files differnew file mode 100644 index 000000000..559e46298 --- /dev/null +++ b/org.eclipse.debug.examples.ui/icons/full/dlcl16/pop.gif diff --git a/org.eclipse.debug.examples.ui/icons/full/dlcl16/push.gif b/org.eclipse.debug.examples.ui/icons/full/dlcl16/push.gif Binary files differnew file mode 100644 index 000000000..f7e6cc089 --- /dev/null +++ b/org.eclipse.debug.examples.ui/icons/full/dlcl16/push.gif diff --git a/org.eclipse.debug.examples.ui/icons/full/elcl16/pop.gif b/org.eclipse.debug.examples.ui/icons/full/elcl16/pop.gif Binary files differnew file mode 100644 index 000000000..2cd9c5444 --- /dev/null +++ b/org.eclipse.debug.examples.ui/icons/full/elcl16/pop.gif diff --git a/org.eclipse.debug.examples.ui/icons/full/elcl16/push.gif b/org.eclipse.debug.examples.ui/icons/full/elcl16/push.gif Binary files differnew file mode 100644 index 000000000..a5ac28d4c --- /dev/null +++ b/org.eclipse.debug.examples.ui/icons/full/elcl16/push.gif diff --git a/org.eclipse.debug.examples.ui/icons/full/obj16/pda.gif b/org.eclipse.debug.examples.ui/icons/full/obj16/pda.gif Binary files differnew file mode 100644 index 000000000..04c5052b2 --- /dev/null +++ b/org.eclipse.debug.examples.ui/icons/full/obj16/pda.gif diff --git a/org.eclipse.debug.examples.ui/plugin.xml b/org.eclipse.debug.examples.ui/plugin.xml new file mode 100644 index 000000000..3cc918c18 --- /dev/null +++ b/org.eclipse.debug.examples.ui/plugin.xml @@ -0,0 +1,174 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> +<plugin> +<!--#ifdef ex1 --> +<!--#else --> + <extension + point="org.eclipse.debug.ui.launchConfigurationTabGroups"> + <launchConfigurationTabGroup + class="org.eclipse.debug.examples.ui.pda.launcher.PDATabGroup" + description="Specify and launch a PDA program" + id="pda.tabGroup" + type="pda.launchType"/> + </extension> + <extension + point="org.eclipse.debug.ui.launchConfigurationTypeImages"> + <launchConfigurationTypeImage + icon="icons/full/obj16/pda.gif" + configTypeID="pda.launchType" + id="pda.typeImage"/> + </extension> + <extension + point="org.eclipse.debug.ui.launchShortcuts"> + <shortcut + label="PDA Application" + icon="icons/full/obj16/pda.gif" + class="org.eclipse.debug.examples.ui.pda.launcher.PDALaunchShortcut" + modes="run, debug" + id="pda.launchShortcut"> + <contextualLaunch> + <enablement> + <with variable="selection"> + <count value="1"/> + <iterate> + <instanceof value="org.eclipse.core.resources.IFile"/> + <test + value="*.pda" + property="org.eclipse.debug.ui.matchesPattern"/> + </iterate> + </with> + </enablement> + </contextualLaunch> + </shortcut> + </extension> +<!--#endif --> + <extension + point="org.eclipse.debug.ui.debugModelPresentations"> + <debugModelPresentation + class="org.eclipse.debug.examples.ui.pda.presentation.PDAModelPresentation" + id="pda.debugModel"/> + </extension> + <extension + point="org.eclipse.ui.editors"> + <editor + filenames="*.pda" + class="org.eclipse.debug.examples.ui.pda.editor.PDAEditor" + icon="icons/full/obj16/pda.gif" + default="true" + name="PDA Editor" + id="pda.editor" + extensions="pda"/> + </extension> + <extension + point="org.eclipse.ui.editorActions"> + <editorContribution + targetID="pda.editor" + id="pda.rulerActions"> + <action + label="Not Used" + class="org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate" + style="push" + actionID="RulerDoubleClick" + id="pda.doubleClickBreakpointAction"/> + </editorContribution> + </extension> + <extension + point="org.eclipse.ui.views"> + <view + icon="icons/full/obj16/pda.gif" + class="org.eclipse.debug.examples.ui.pda.views.DataStackView" + name="PDA Data Stack" + id="pda.dataStackView"/> + </extension> + + <extension + point="org.eclipse.ui.perspectiveExtensions"> + <perspectiveExtension targetID="org.eclipse.debug.ui.DebugPerspective"> + <view + visible="false" + relative="org.eclipse.debug.ui.VariableView" + relationship="stack" + id="pda.dataStackView"/> + </perspectiveExtension> + </extension> + <extension + point="org.eclipse.ui.contexts"> + <context + parentId="org.eclipse.debug.ui.debugging" + description="Debugging PDA Programs" + name="Debugging PDA Programs" + id="pda.debugging"/> + </extension> + <extension + point="org.eclipse.debug.ui.debugModelContextBindings"> + <modelContextBinding + contextId="pda.debugging" + debugModelId="pda.debugModel"/> + </extension> + <extension + point="org.eclipse.debug.ui.contextViewBindings"> + <contextViewBinding + contextId="pda.debugging" + viewId="pda.dataStackView"/> + </extension> + + <extension + point="org.eclipse.ui.popupMenus"> + <viewerContribution + targetID="pda.editor.rulerMenu" + id="pda.editor.rulerActions"> + <action + label="Toggle Breakpoint" + class="org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate" + menubarPath="debug" + id="pda.editor.ruler.toggleBreakpointAction"/> + </viewerContribution> + <viewerContribution + targetID="pda.editor.contextMenu" + id="pda.editor.menuActions"> + <action + label="Run to Line" + definitionId="org.eclipse.debug.ui.commands.RunToLine" + class="org.eclipse.debug.ui.actions.RunToLineActionDelegate" + menubarPath="additions" + id="pda.editor.context.runToLineAction"/> + </viewerContribution> +<!--#ifdef ex5 --> +<!--#else --> + <objectContribution + adaptable="false" + id="pda.dropToFrame" + objectClass="org.eclipse.debug.examples.core.pda.model.PDAStackFrame"> + <action + class="org.eclipse.debug.examples.ui.pda.editor.PopFrameActionDelegate" + id="pda.dropToFrame" + label="Pop Frame"/> + </objectContribution> +<!--#endif --> + </extension> + + <extension + point="org.eclipse.core.runtime.adapters"> + <factory + class="org.eclipse.debug.examples.ui.pda.breakpoints.PDAEditorAdapterFactory" + adaptableType="org.eclipse.debug.examples.ui.pda.editor.PDAEditor"> + <adapter type="org.eclipse.debug.ui.actions.IToggleBreakpointsTarget"/> +<!--#ifdef ex7 --> +<!--#else --> + <adapter type="org.eclipse.debug.ui.actions.IRunToLineTarget"/> +<!--#endif --> + </factory> +<!-- FLEXIBLE HIERARCHY EXAMPLE + <factory + adaptableType="org.eclipse.debug.examples.core.pda.model.PDADebugTarget" + class="example.debug.ui.adapters.AdapterFactory"> + <adapter + type="org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider"> + </adapter> + <adapter + type="org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxyFactory"> + </adapter> + </factory> +--> + </extension> +</plugin> diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/DebugUIPlugin.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/DebugUIPlugin.java new file mode 100644 index 000000000..ba635acb7 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/DebugUIPlugin.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda; + +import java.net.URL; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.MissingResourceException; +import java.util.ResourceBundle; +import java.util.Map.Entry; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.internal.util.BundleUtility; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class DebugUIPlugin extends AbstractUIPlugin { + //The shared instance. + private static DebugUIPlugin plugin; + //Resource bundle. + private ResourceBundle resourceBundle; + + private final static String ICONS_PATH = "icons/full/";//$NON-NLS-1$ + private final static String PATH_OBJECT = ICONS_PATH + "obj16/"; //Model object icons //$NON-NLS-1$ + private final static String PATH_ELOCALTOOL = ICONS_PATH + "elcl16/"; //Enabled local toolbar icons //$NON-NLS-1$ + private final static String PATH_DLOCALTOOL = ICONS_PATH + "dlcl16/"; //Disabled local toolbar icons //$NON-NLS-1$ + + /** + * Toolbar action to pop data stack + */ + public final static String IMG_ELCL_POP = "IMG_ELCL_POP"; + public final static String IMG_DLCL_POP = "IMG_DLCL_POP"; + + /** + * Toolbar action to push onto data stack + */ + public final static String IMG_ELCL_PUSH = "IMG_ELCL_PUSH"; + public final static String IMG_DLCL_PUSH = "IMG_DLCL_PUSH"; + + /** + * PDA program image + */ + public final static String IMG_OBJ_PDA = "IMB_OBJ_PDA"; + + /** + * Keyword color + */ + public final static RGB KEYWORD = new RGB(0,0,255); + public final static RGB LABEL = new RGB(128, 128, 0); + + /** + * Managed colors + */ + private Map fColors = new HashMap(); + + /** + * The constructor. + */ + public DebugUIPlugin() { + super(); + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); +// Toggles single threaded adapter example +// IAdapterManager adapterManager = Platform.getAdapterManager(); +// IAdapterFactory factory = new AdapterFactory(); +// adapterManager.registerAdapters(factory, PDADebugTarget.class); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + resourceBundle = null; + Iterator colors = fColors.entrySet().iterator(); + while (colors.hasNext()) { + Map.Entry entry = (Entry) colors.next(); + ((Color)entry.getValue()).dispose(); + } + } + + /** + * Returns the shared instance. + */ + public static DebugUIPlugin getDefault() { + return plugin; + } + + /** + * Returns the string from the plugin's resource bundle, + * or 'key' if not found. + */ + public static String getResourceString(String key) { + ResourceBundle bundle = DebugUIPlugin.getDefault().getResourceBundle(); + try { + return (bundle != null) ? bundle.getString(key) : key; + } catch (MissingResourceException e) { + return key; + } + } + + /** + * Returns the plugin's resource bundle, + */ + public ResourceBundle getResourceBundle() { + try { + if (resourceBundle == null) + resourceBundle = ResourceBundle.getBundle("org.eclipse.debug.examples.ui.pda.DebugUIPluginResources"); + } catch (MissingResourceException x) { + resourceBundle = null; + } + return resourceBundle; + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry) + */ + protected void initializeImageRegistry(ImageRegistry reg) { + declareImage(IMG_OBJ_PDA, PATH_OBJECT + "pda.gif"); + declareImage(IMG_ELCL_POP, PATH_ELOCALTOOL + "pop.gif"); + declareImage(IMG_DLCL_POP, PATH_DLOCALTOOL + "pop.gif"); + declareImage(IMG_ELCL_PUSH, PATH_ELOCALTOOL + "push.gif"); + declareImage(IMG_DLCL_PUSH, PATH_DLOCALTOOL + "push.gif"); + } + + /** + * Declares a workbench image given the path of the image file (relative to + * the workbench plug-in). This is a helper method that creates the image + * descriptor and passes it to the main <code>declareImage</code> method. + * + * @param symbolicName the symbolic name of the image + * @param path the path of the image file relative to the base of the workbench + * plug-ins install directory + * <code>false</code> if this is not a shared image + */ + private void declareImage(String key, String path) { + URL url = BundleUtility.find("org.eclipse.debug.examples.ui.pda", path); + ImageDescriptor desc = ImageDescriptor.createFromURL(url); + getImageRegistry().put(key, desc); + } + + /** + * Returns the color described by the given RGB. + * + * @param rgb + * @return color + */ + public Color getColor(RGB rgb) { + Color color = (Color) fColors.get(rgb); + if (color == null) { + color= new Color(Display.getCurrent(), rgb); + fColors.put(rgb, color); + } + return color; + } + + } diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/AdapterFactory.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/AdapterFactory.java new file mode 100644 index 000000000..3e4153fd5 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/AdapterFactory.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.adapters; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxyFactory; + + +/** + * + * @since 3.2 + * + */ +public class AdapterFactory implements IAdapterFactory { + + private static IElementContentProvider fgTargetAdapter = new PDADebugTargetContentProvider(); + private static IModelProxyFactory fgFactory = new ModelProxyFactory(); + + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (IElementContentProvider.class.equals(adapterType)) { + if (adaptableObject instanceof PDADebugTarget) { + return fgTargetAdapter; + } + } + if (IModelProxyFactory.class.equals(adapterType)) { + if (adaptableObject instanceof PDADebugTarget) { + return fgFactory; + } + } + return null; + } + + public Class[] getAdapterList() { + return new Class[]{IElementContentProvider.class, IModelProxyFactory.class}; + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/ModelProxyFactory.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/ModelProxyFactory.java new file mode 100644 index 000000000..a8e5959f1 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/ModelProxyFactory.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.adapters; + +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxyFactory; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; + + +public class ModelProxyFactory implements IModelProxyFactory { + + public IModelProxy createModelProxy(Object element, IPresentationContext context) { + if (IDebugUIConstants.ID_DEBUG_VIEW.equals(context.getId())) { + if (element instanceof PDADebugTarget){ + return new PDADebugTargetProxy((IDebugTarget) element); + } + } + return null; + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDADebugTargetContentProvider.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDADebugTargetContentProvider.java new file mode 100644 index 000000000..ab33ae4f2 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDADebugTargetContentProvider.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.debug.examples.ui.pda.adapters; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.examples.core.pda.model.PDAThread; +import org.eclipse.debug.internal.ui.model.elements.ElementContentProvider; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; +import org.eclipse.debug.ui.IDebugUIConstants; + + +public class PDADebugTargetContentProvider extends ElementContentProvider { + + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#getChildCount(java.lang.Object, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate) + */ + protected int getChildCount(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { + PDAThread thread = ((PDADebugTarget) element).getThread(); + if (thread != null) { + if (thread.hasStackFrames()) { + return thread.getStackFrames().length; + } + } + return 0; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#hasChildren(java.lang.Object, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate) + */ + protected boolean hasChildren(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { + PDAThread thread = ((PDADebugTarget) element).getThread(); + if (thread != null) { + return thread.hasStackFrames(); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#getChildren(java.lang.Object, int, int, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate) + */ + protected Object[] getChildren(Object parent, int index, int length, IPresentationContext context, IViewerUpdate monitor) throws CoreException { + if (context.getId().equals(IDebugUIConstants.ID_DEBUG_VIEW)) { + PDAThread thread = ((PDADebugTarget) parent).getThread(); + if (thread != null) { + return getElements(thread.getStackFrames(), index, length); + } + } + return EMPTY; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#supportsContextId(java.lang.String) + */ + protected boolean supportsContextId(String id) { + return IDebugUIConstants.ID_DEBUG_VIEW.equals(id); + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDADebugTargetProxy.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDADebugTargetProxy.java new file mode 100644 index 000000000..e905e12fe --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDADebugTargetProxy.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.adapters; + +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.internal.ui.viewers.update.DebugEventHandler; +import org.eclipse.debug.internal.ui.viewers.update.DebugTargetEventHandler; +import org.eclipse.debug.internal.ui.viewers.update.DebugTargetProxy; + +/** + * @since 3.2 + * + */ +public class PDADebugTargetProxy extends DebugTargetProxy { + + /** + * @param target + */ + public PDADebugTargetProxy(IDebugTarget target) { + super(target); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.viewers.update.DebugTargetProxy#createEventHandlers() + */ + protected DebugEventHandler[] createEventHandlers() { + return new DebugEventHandler[] { new DebugTargetEventHandler(this), new PDAThreadEventHandler(this) }; + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDAThreadEventHandler.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDAThreadEventHandler.java new file mode 100644 index 000000000..2af58c7e6 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDAThreadEventHandler.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.adapters; + +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.core.model.IThread; +import org.eclipse.debug.examples.core.pda.model.PDAThread; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta; +import org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy; +import org.eclipse.debug.internal.ui.viewers.update.DebugEventHandler; + + +/** + * @since 3.2 + */ +public class PDAThreadEventHandler extends DebugEventHandler { + + private IStackFrame fPrev = null; + + /** + * Constructs and event handler for a threads in the given viewer. + * + * @param viewer + */ + public PDAThreadEventHandler(AbstractModelProxy proxy) { + super(proxy); + } + + protected void handleSuspend(DebugEvent event) { + IThread thread = (IThread) event.getSource(); + int extras = IModelDelta.STATE; + if (event.getDetail() == DebugEvent.BREAKPOINT | event.getDetail() == DebugEvent.CLIENT_REQUEST) { + extras = IModelDelta.EXPAND; + } + fireDeltaUpdatingTopFrame(thread, IModelDelta.NO_CHANGE | extras); + } + + private boolean isEqual(Object o1, Object o2) { + if (o1 == o2) { + return true; + } + if (o1 == null) { + return false; + } + return o1.equals(o2); + } + + protected void handleResume(DebugEvent event) { + IThread thread = (IThread) event.getSource(); + fireDeltaAndClearTopFrame(thread, IModelDelta.STATE | IModelDelta.CONTENT); + } + + protected void handleCreate(DebugEvent event) { + fireDeltaAndClearTopFrame((IThread) event.getSource(), IModelDelta.ADDED); + } + + protected void handleTerminate(DebugEvent event) { + fireDeltaAndClearTopFrame((IThread) event.getSource(), IModelDelta.REMOVED); + } + + protected void handleChange(DebugEvent event) { + fireDeltaUpdatingTopFrame((IThread) event.getSource(), IModelDelta.STATE); + } + + protected void handleLateSuspend(DebugEvent suspend, DebugEvent resume) { + IThread thread = (IThread) suspend.getSource(); + fireDeltaUpdatingTopFrame(thread, IModelDelta.CONTENT | IModelDelta.EXPAND); + } + + protected void handleSuspendTimeout(DebugEvent event) { + IThread thread = (IThread) event.getSource(); + fireDeltaAndClearTopFrame(thread, IModelDelta.CONTENT); + } + + private ModelDelta buildRootDelta() { + return new ModelDelta(getLaunchManager(), IModelDelta.NO_CHANGE); + } + + private ILaunchManager getLaunchManager() { + return DebugPlugin.getDefault().getLaunchManager(); + } + + protected ModelDelta addTarget(ModelDelta delta, IThread thread) { + ILaunch launch = thread.getLaunch(); + Object[] children = launch.getChildren(); + delta = delta.addNode(launch, indexOf(getLaunchManager().getLaunches(), launch), IModelDelta.NO_CHANGE, children.length); + IDebugTarget debugTarget = thread.getDebugTarget(); + int numFrames = -1; + try { + numFrames = thread.getStackFrames().length; + } catch (DebugException e) { + } + return delta.addNode(debugTarget, indexOf(children, debugTarget), IModelDelta.NO_CHANGE, numFrames); + } + + private void fireDeltaAndClearTopFrame(IThread thread, int flags) { + ModelDelta delta = buildRootDelta(); + ModelDelta node = addTarget(delta, thread); + synchronized (this) { + fPrev = null; + } + fireDelta(delta); + } + + private void fireDeltaUpdatingTopFrame(IThread thread, int flags) { + ModelDelta delta = buildRootDelta(); + ModelDelta node = addTarget(delta, thread); + synchronized (this) { + IStackFrame prev = fPrev; + IStackFrame frame = null; + try { + frame = thread.getTopStackFrame(); + } catch (DebugException e) { + } + if (isEqual(frame, prev)) { + node.setFlags(flags); + } else { + node.setFlags(flags | IModelDelta.CONTENT); + } + if (frame != null) { + node.addNode(frame, 0, IModelDelta.STATE | IModelDelta.SELECT, 0); + } + fPrev = frame; + } + fireDelta(delta); + } + + protected boolean handlesEvent(DebugEvent event) { + return event.getSource() instanceof PDAThread; + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDABreakpointAdapter.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDABreakpointAdapter.java new file mode 100644 index 000000000..38e8f8525 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDABreakpointAdapter.java @@ -0,0 +1,220 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.breakpoints; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.core.model.ILineBreakpoint; +import org.eclipse.debug.examples.core.pda.DebugCorePlugin; +import org.eclipse.debug.examples.core.pda.breakpoints.PDALineBreakpoint; +import org.eclipse.debug.examples.core.pda.breakpoints.PDAWatchpoint; +import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetExtension; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditor; + + +/** + * Adapter to create breakpoints in PDA files. + */ +public class PDABreakpointAdapter implements IToggleBreakpointsTargetExtension { + /* (non-Javadoc) + * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + */ + public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { + ITextEditor textEditor = getEditor(part); + if (textEditor != null) { + IResource resource = (IResource) textEditor.getEditorInput().getAdapter(IResource.class); + ITextSelection textSelection = (ITextSelection) selection; + int lineNumber = textSelection.getStartLine(); + IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(DebugCorePlugin.ID_PDA_DEBUG_MODEL); + for (int i = 0; i < breakpoints.length; i++) { + IBreakpoint breakpoint = breakpoints[i]; + if (breakpoint instanceof ILineBreakpoint && resource.equals(breakpoint.getMarker().getResource())) { + if (((ILineBreakpoint)breakpoint).getLineNumber() == (lineNumber + 1)) { + // remove + breakpoint.delete(); + return; + } + } + } + // create line breakpoint (doc line numbers start at 0) + PDALineBreakpoint lineBreakpoint = new PDALineBreakpoint(resource, lineNumber + 1); + DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint); + } + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + */ + public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) { + return getEditor(part) != null; + } + + /** + * Returns the editor being used to edit a PDA file, associated with the + * given part, or <code>null</code> if none. + * + * @param part workbench part + * @return the editor being used to edit a PDA file, associated with the + * given part, or <code>null</code> if none + */ + private ITextEditor getEditor(IWorkbenchPart part) { + if (part instanceof ITextEditor) { + ITextEditor editorPart = (ITextEditor) part; + IResource resource = (IResource) editorPart.getEditorInput().getAdapter(IResource.class); + if (resource != null) { + String extension = resource.getFileExtension(); + if (extension != null && extension.equals("pda")) { + return editorPart; + } + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + */ + public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + */ + public boolean canToggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) { + return false; + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + */ + public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) throws CoreException { + String[] variableAndFunctionName = getVariableAndFunctionName(part, selection); + if (variableAndFunctionName != null && part instanceof ITextEditor && selection instanceof ITextSelection) { + ITextEditor editorPart = (ITextEditor)part; + int lineNumber = ((ITextSelection)selection).getStartLine(); + IResource resource = (IResource) editorPart.getEditorInput().getAdapter(IResource.class); + String var = variableAndFunctionName[0]; + String fcn = variableAndFunctionName[1]; + // look for existing watchpoint to delete + IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(DebugCorePlugin.ID_PDA_DEBUG_MODEL); + for (int i = 0; i < breakpoints.length; i++) { + IBreakpoint breakpoint = breakpoints[i]; + if (breakpoint instanceof PDAWatchpoint && resource.equals(breakpoint.getMarker().getResource())) { + PDAWatchpoint watchpoint = (PDAWatchpoint)breakpoint; + String otherVar = watchpoint.getVariableName(); + String otherFcn = watchpoint.getFunctionName(); + if (otherVar.equals(var) && otherFcn.equals(fcn)) { + breakpoint.delete(); + return; + } + } + } + // create watchpoint + PDAWatchpoint watchpoint = new PDAWatchpoint(resource, lineNumber + 1, fcn, var, true, true); + DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(watchpoint); + } + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + */ + public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) { + return getVariableAndFunctionName(part, selection) != null; + } + + /** + * Returns the variable and function names at the current line, or <code>null</code> if none. + * + * @param part text editor + * @param selection text selection + * @return the variable and function names at the current line, or <code>null</code> if none. + * The array has two elements, the first is the variable name, the second is the function name. + */ + private String[] getVariableAndFunctionName(IWorkbenchPart part, ISelection selection) { + ITextEditor editor = getEditor(part); + if (editor != null && selection instanceof ITextSelection) { + ITextSelection textSelection = (ITextSelection) selection; + IDocumentProvider documentProvider = editor.getDocumentProvider(); + try { + documentProvider.connect(this); + IDocument document = documentProvider.getDocument(editor.getEditorInput()); + IRegion region = document.getLineInformationOfOffset(textSelection.getOffset()); + String string = document.get(region.getOffset(), region.getLength()).trim(); + if (string.startsWith("var ")) { + String varName = string.substring(4).trim(); + String fcnName = getFunctionName(document, varName, document.getLineOfOffset(textSelection.getOffset())); + return new String[] {varName, fcnName}; + } + } catch (CoreException e) { + } catch (BadLocationException e) { + } finally { + documentProvider.disconnect(this); + } + } + return null; + } + + /** + * Returns the name of the function containing the given variable defined at the given + * line number in the specified document. + * + * @param document PDA source file + * @param varName variable name + * @param line line numbner at which the variable is defined + * @return name of function defining the variable + */ + private String getFunctionName(IDocument document, String varName, int line) { + // This is a simple guess at the function name - look for the labels preceeding + // the variable definition, and then see if there are any 'calls' to that + // label. If none, assumet the variable is in the "_main_" function + String source = document.get(); + int lineIndex = line - 1; + while (lineIndex >= 0) { + try { + IRegion information = document.getLineInformation(lineIndex); + String lineText = document.get(information.getOffset(), information.getLength()); + if (lineText.startsWith(":")) { + String label = lineText.substring(1); + if (source.indexOf("call " + label) >= 0) { + return label; + } + } + lineIndex--; + } catch (BadLocationException e) { + } + } + return "_main_"; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTargetExtension#toggleBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + */ + public void toggleBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { + if (canToggleWatchpoints(part, selection)) { + toggleWatchpoints(part, selection); + } else { + toggleLineBreakpoints(part, selection); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTargetExtension#canToggleBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + */ + public boolean canToggleBreakpoints(IWorkbenchPart part, ISelection selection) { + return canToggleLineBreakpoints(part, selection) || canToggleWatchpoints(part, selection); + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDAEditorAdapterFactory.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDAEditorAdapterFactory.java new file mode 100644 index 000000000..c67200a40 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDAEditorAdapterFactory.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.breakpoints; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.debug.examples.ui.pda.editor.PDAEditor; +import org.eclipse.debug.ui.actions.IRunToLineTarget; +import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; +import org.eclipse.ui.texteditor.ITextEditor; + + +/** + * Creates a toggle breakpoint adapter + */ +public class PDAEditorAdapterFactory implements IAdapterFactory { + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) + */ + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adaptableObject instanceof PDAEditor) { + ITextEditor editorPart = (ITextEditor) adaptableObject; + IResource resource = (IResource) editorPart.getEditorInput().getAdapter(IResource.class); + if (resource != null) { + String extension = resource.getFileExtension(); + if (extension != null && extension.equals("pda")) { + if (adapterType.equals(IToggleBreakpointsTarget.class)) { + return new PDABreakpointAdapter(); + } + //#ifdef ex7 +//# // TODO: Exercise 7 - create run to line adapter + //#else + if (adapterType.equals(IRunToLineTarget.class)) { + return new PDARunToLineAdapter(); + } + //#endif + } + } + } + return null; + } + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() + */ + public Class[] getAdapterList() { + return new Class[]{IToggleBreakpointsTarget.class}; + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDARunToLineAdapter.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDARunToLineAdapter.java new file mode 100644 index 000000000..3d5fa42d0 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/breakpoints/PDARunToLineAdapter.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.breakpoints; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.core.model.IDebugElement; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.core.model.ISuspendResume; +import org.eclipse.debug.examples.core.pda.DebugCorePlugin; +import org.eclipse.debug.examples.core.pda.breakpoints.PDARunToLineBreakpoint; +import org.eclipse.debug.ui.actions.IRunToLineTarget; +import org.eclipse.debug.ui.actions.RunToLineHandler; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.texteditor.ITextEditor; + + +/** + * Run to line target for the Java debugger + */ +public class PDARunToLineAdapter implements IRunToLineTarget { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.actions.IRunToLineTarget#runToLine(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection, org.eclipse.debug.core.model.ISuspendResume) + */ + public void runToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) throws CoreException { + IEditorPart editorPart = (IEditorPart)part; + ITextEditor textEditor = (ITextEditor)editorPart; + ITextSelection textSelection = (ITextSelection) selection; + int lineNumber = textSelection.getStartLine() + 1; + if (lineNumber > 0) { + if (target instanceof IAdaptable) { + IDebugTarget debugTarget = (IDebugTarget) ((IAdaptable)target).getAdapter(IDebugTarget.class); + if (debugTarget != null) { + //#ifdef ex7 +//# // TODO: Exercise 7 - perform the run-to-line with a run-to-line breakpoint and handler + //#else + IFile resource = (IFile) textEditor.getEditorInput().getAdapter(IResource.class); + IBreakpoint breakpoint= new PDARunToLineBreakpoint(resource, lineNumber); + RunToLineHandler handler = new RunToLineHandler(debugTarget, target, breakpoint); + handler.run(new NullProgressMonitor()); + //#endif + } + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.actions.IRunToLineTarget#canRunToLine(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection, org.eclipse.debug.core.model.ISuspendResume) + */ + public boolean canRunToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) { + //#ifdef ex7 +//# // TODO: Exercise 7 - ensure the target is a PDA target +//# return false; + //#else + return target instanceof IDebugElement && + ((IDebugElement)target).getModelIdentifier().equals(DebugCorePlugin.ID_PDA_DEBUG_MODEL); + //#endif + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/AnnotationHover.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/AnnotationHover.java new file mode 100644 index 000000000..6b79056b7 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/AnnotationHover.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.editor; + +import java.util.Iterator; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.IAnnotationHover; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.ISourceViewer; + +/** + * Returns hover for breakpoints. + */ +public class AnnotationHover implements IAnnotationHover { + + public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) { + IAnnotationModel annotationModel = sourceViewer.getAnnotationModel(); + Iterator iterator = annotationModel.getAnnotationIterator(); + while (iterator.hasNext()) { + Annotation annotation = (Annotation) iterator.next(); + Position position = annotationModel.getPosition(annotation); + try { + int lineOfAnnotation = sourceViewer.getDocument().getLineOfOffset(position.getOffset()); + if (lineNumber == lineOfAnnotation) { + return annotation.getText(); + } + } catch (BadLocationException e) { + } + } + return null; + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAContentAssistProcessor.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAContentAssistProcessor.java new file mode 100644 index 000000000..5d7089472 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAContentAssistProcessor.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.editor; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.contentassist.CompletionProposal; +import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.text.contentassist.IContextInformation; +import org.eclipse.jface.text.contentassist.IContextInformationValidator; + +public class PDAContentAssistProcessor implements IContentAssistProcessor { + + public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { + int index = offset - 1; + StringBuffer prefix = new StringBuffer(); + IDocument document = viewer.getDocument(); + while (index > 0) { + try { + char prev = document.getChar(index); + if (Character.isWhitespace(prev)) { + break; + } + prefix.insert(0, prev); + index--; + } catch (BadLocationException e) { + } + } + + List proposals = new ArrayList(); + String[] keywords = PDAScanner.fgKeywords; + if (prefix.length() > 0) { + String word = prefix.toString(); + for (int i = 0; i < keywords.length; i++) { + String keyword = keywords[i]; + if (keyword.startsWith(word) && word.length() < keyword.length()) { + proposals.add(new CompletionProposal(keyword + " ", index + 1, offset - (index + 1), keyword.length() + 1)); + } + } + } else { + // propose all keywords + for (int i = 0; i < keywords.length; i++) { + String keyword = keywords[i]; + proposals.add(new CompletionProposal(keyword + " ", offset, 0, keyword.length() + 1)); + } + } + if (!proposals.isEmpty()) { + return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int) + */ + public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() + */ + public char[] getCompletionProposalAutoActivationCharacters() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters() + */ + public char[] getContextInformationAutoActivationCharacters() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage() + */ + public String getErrorMessage() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator() + */ + public IContextInformationValidator getContextInformationValidator() { + return null; + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAContentAssistant.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAContentAssistant.java new file mode 100644 index 000000000..01f71928e --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAContentAssistant.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.editor; + +import org.eclipse.jface.text.DefaultInformationControl; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IInformationControl; +import org.eclipse.jface.text.IInformationControlCreator; +import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.swt.widgets.Shell; + +public class PDAContentAssistant extends ContentAssistant { + + public PDAContentAssistant() { + super(); + + PDAContentAssistProcessor processor= new PDAContentAssistProcessor(); + setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE); + + enableAutoActivation(false); + enableAutoInsert(false); + + setInformationControlCreator(getInformationControlCreator()); + } + + private IInformationControlCreator getInformationControlCreator() { + return new IInformationControlCreator() { + public IInformationControl createInformationControl(Shell parent) { + return new DefaultInformationControl(parent); + } + }; + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAEditor.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAEditor.java new file mode 100644 index 000000000..3617cb172 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAEditor.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.editor; + +import java.util.ResourceBundle; + +import org.eclipse.jface.action.IAction; +import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor; +import org.eclipse.ui.texteditor.ContentAssistAction; +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; + +/** + * PDA editor + */ +public class PDAEditor extends AbstractDecoratedTextEditor { + + /** + * Creates a PDE editor + */ + public PDAEditor() { + super(); + setSourceViewerConfiguration(new PDASourceViewerConfiguration()); + setRulerContextMenuId("pda.editor.rulerMenu"); + setEditorContextMenuId("pda.editor.editorMenu"); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions() + */ + protected void createActions() { + super.createActions(); + ResourceBundle bundle = ResourceBundle.getBundle("org.eclipse.debug.examples.ui.pda.editor.PDAEditorMessages"); //$NON-NLS-1$ + IAction action = new ContentAssistAction(bundle, "ContentAssistProposal.", this); //$NON-NLS-1$ + action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + setAction("ContentAssistProposal", action); //$NON-NLS-1$ + } + + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAEditorMessages.properties b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAEditorMessages.properties new file mode 100644 index 000000000..3215e8892 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAEditorMessages.properties @@ -0,0 +1,15 @@ +############################################################################### +# Copyright (c) 2000, 2007 IBM Corporation 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: +# IBM Corporation - initial API and implementation +############################################################################### + +ContentAssistProposal.label=Content &Assist +ContentAssistProposal.tooltip=Content Assist +ContentAssistProposal.image= +ContentAssistProposal.description=Content Assist
\ No newline at end of file diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAScanner.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAScanner.java new file mode 100644 index 000000000..b62d0ba45 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDAScanner.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.editor; + +import org.eclipse.debug.examples.ui.pda.DebugUIPlugin; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.rules.BufferedRuleBasedScanner; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IWordDetector; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.rules.WordRule; + + +/** + * PDA editor keyword scanner. + */ +public class PDAScanner extends BufferedRuleBasedScanner { + + /** + * PDA keywods + */ + public static final String[] fgKeywords = new String[] { + "add", "branch_not_zero", "call", "dec", "dup", + "halt", "output", "pop", "push", "return", "var" + }; + + /** + * Detects potential keywords + */ + class PDAWordDetector implements IWordDetector { + + /* (non-Javadoc) + * @see org.eclipse.jface.text.rules.IWordDetector#isWordStart(char) + */ + public boolean isWordStart(char c) { + return Character.isLetter(c); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.rules.IWordDetector#isWordPart(char) + */ + public boolean isWordPart(char c) { + return Character.isLetter(c) || c == '_'; + } + } + + /** + * Detects PDA branch labels + */ + class PDALabelDetector extends PDAWordDetector { + + /* (non-Javadoc) + * @see org.eclipse.jface.text.rules.IWordDetector#isWordStart(char) + */ + public boolean isWordStart(char c) { + return c == ':'; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.rules.IWordDetector#isWordPart(char) + */ + public boolean isWordPart(char c) { + return super.isWordPart(c) || Character.isDigit(c); + } + } + + /** + * Constructs a scanner that identifies PDA keywords. + */ + public PDAScanner() { + // keywords + Token token = new Token(new TextAttribute(DebugUIPlugin.getDefault().getColor(DebugUIPlugin.KEYWORD))); + WordRule keywords = new WordRule(new PDAWordDetector()); + for (int i = 0; i < fgKeywords.length; i++) { + String keyword = fgKeywords[i]; + keywords.addWord(keyword, token); + } + // labels + token = new Token(new TextAttribute(DebugUIPlugin.getDefault().getColor(DebugUIPlugin.LABEL))); + WordRule labels = new WordRule(new PDALabelDetector(), token); + setRules(new IRule[]{keywords, labels}); + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDASourceViewerConfiguration.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDASourceViewerConfiguration.java new file mode 100644 index 000000000..6c24c36a0 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PDASourceViewerConfiguration.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.editor; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextHover; +import org.eclipse.jface.text.contentassist.IContentAssistant; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.source.IAnnotationHover; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; + +/** + * Source view configuration for the PDA editor + */ +public class PDASourceViewerConfiguration extends TextSourceViewerConfiguration { + + /* (non-Javadoc) + * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getTextHover(org.eclipse.jface.text.source.ISourceViewer, java.lang.String) + */ + public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { + return new TextHover(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAnnotationHover(org.eclipse.jface.text.source.ISourceViewer) + */ + public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { + return new AnnotationHover(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer) + */ + public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { + PresentationReconciler reconciler = new PresentationReconciler(); + reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); + DefaultDamagerRepairer dr = new DefaultDamagerRepairer(new PDAScanner()); + reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + return reconciler; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentAssistant(org.eclipse.jface.text.source.ISourceViewer) + */ + public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { + return new PDAContentAssistant(); + } + + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PopFrameActionDelegate.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PopFrameActionDelegate.java new file mode 100644 index 000000000..1c13bac19 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/PopFrameActionDelegate.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.editor; + +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.examples.core.pda.model.PDAStackFrame; +import org.eclipse.debug.examples.core.pda.model.PDAThread; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IActionDelegate2; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; + + +public class PopFrameActionDelegate implements IObjectActionDelegate, IActionDelegate2 { + + private PDAThread fThread = null; + + /* (non-Javadoc) + * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) + */ + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run(IAction action) { + //#ifdef ex5 +//# // TODO: Exercise 5 - pop the top frame + //#else + try { + fThread.pop(); + } catch (DebugException e) { + } + //#endif + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) { + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss = (IStructuredSelection) selection; + Object element = ss.getFirstElement(); + if (element instanceof PDAStackFrame) { + PDAStackFrame frame = (PDAStackFrame) element; + //#ifdef ex5 +//# // TODO: Exercise 5 - enable the action if the frame's thread supports it + //#else + fThread = (PDAThread) frame.getThread(); + try { + action.setEnabled(fThread.canPop() && fThread.getTopStackFrame().equals(frame)); + } catch (DebugException e) { + } + return; + //#endif + } + + } + action.setEnabled(false); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) + */ + public void init(IAction action) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate2#dispose() + */ + public void dispose() { + fThread = null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event) + */ + public void runWithEvent(IAction action, Event event) { + run(action); + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/TextHover.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/TextHover.java new file mode 100644 index 000000000..6b14e4c74 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/TextHover.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.editor; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IThread; +import org.eclipse.debug.core.model.IVariable; +import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +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.text.BadLocationException; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextHover; +import org.eclipse.jface.text.ITextViewer; + + +/** + * Produces debug hover for the PDA debugger. + */ +public class TextHover implements ITextHover { + + /* (non-Javadoc) + * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) + */ + public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { + String varName = null; + try { + varName = textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength()); + } catch (BadLocationException e) { + return null; + } + if (varName.startsWith("$") && varName.length() > 1) { + varName = varName.substring(1); + } + + PDAStackFrame frame = null; + IAdaptable debugContext = DebugUITools.getDebugContext(); + if (debugContext instanceof PDAStackFrame) { + frame = (PDAStackFrame) debugContext; + } else if (debugContext instanceof PDAThread) { + PDAThread thread = (PDAThread) debugContext; + try { + frame = (PDAStackFrame) thread.getTopStackFrame(); + } catch (DebugException e) { + return null; + } + } else if (debugContext instanceof PDADebugTarget) { + PDADebugTarget target = (PDADebugTarget) debugContext; + try { + IThread[] threads = target.getThreads(); + if (threads.length > 0) { + frame = (PDAStackFrame) threads[0].getTopStackFrame(); + } + } catch (DebugException e) { + return null; + } + } + if (frame != null) { + try { + IVariable[] variables = frame.getVariables(); + for (int i = 0; i < variables.length; i++) { + IVariable variable = variables[i]; + if (variable.getName().equals(varName)) { + return varName + " = " + variable.getValue().getValueString(); + } + } + } catch (DebugException e) { + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer, int) + */ + public IRegion getHoverRegion(ITextViewer textViewer, int offset) { + return WordFinder.findWord(textViewer.getDocument(), offset); + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/WordFinder.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/WordFinder.java new file mode 100644 index 000000000..e60d98203 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/editor/WordFinder.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.editor; + + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Region; + +/** + * Looks for an identifier in a source file + */ +public class WordFinder { + + /** + * Returns the region in the given document that contains an identifier, or + * <code>null</code> if none. + * + * @param document document to search + * @param offset offset at which to look for an identifier + * @return region containing an identifier, or <code>null</code> + */ + public static IRegion findWord(IDocument document, int offset) { + + int start= -1; + int end= -1; + + + try { + + int pos= offset; + char c; + + while (pos >= 0) { + c= document.getChar(pos); + if (!Character.isJavaIdentifierPart(c)) + break; + --pos; + } + + start= pos; + + pos= offset; + int length= document.getLength(); + + while (pos < length) { + c= document.getChar(pos); + if (!Character.isJavaIdentifierPart(c)) + break; + ++pos; + } + + end= pos; + + } catch (BadLocationException x) { + } + + if (start > -1 && end > -1) { + if (start == offset && end == offset) + return new Region(offset, 0); + else if (start == offset) + return new Region(start, end - start); + else + return new Region(start + 1, end - start - 1); + } + + return null; + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/launcher/PDALaunchShortcut.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/launcher/PDALaunchShortcut.java new file mode 100644 index 000000000..2bbf75ee2 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/launcher/PDALaunchShortcut.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.launcher; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.examples.core.pda.DebugCorePlugin; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.ILaunchShortcut; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IEditorPart; + + +/** + * Launches a PDA file + */ +public class PDALaunchShortcut implements ILaunchShortcut { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchShortcut#launch(org.eclipse.jface.viewers.ISelection, java.lang.String) + */ + public void launch(ISelection selection, String mode) { + // must be a structured selection with one file selected + IFile file = (IFile) ((IStructuredSelection)selection).getFirstElement(); + + // check for an existing launch config for the pda file + String path = file.getFullPath().toString(); + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); + ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(DebugCorePlugin.ID_PDA_LAUNCH_CONFIGURATION_TYPE); + try { + ILaunchConfiguration[] configurations = launchManager.getLaunchConfigurations(type); + for (int i = 0; i < configurations.length; i++) { + ILaunchConfiguration configuration = configurations[i]; + String attribute = configuration.getAttribute(DebugCorePlugin.ATTR_PDA_PROGRAM, (String)null); + if (path.equals(attribute)) { + DebugUITools.launch(configuration, mode); + return; + } + } + } catch (CoreException e) { + return; + } + + try { + // create a new configuration for the pda file + ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, file.getName()); + workingCopy.setAttribute(DebugCorePlugin.ATTR_PDA_PROGRAM, path); + ILaunchConfiguration configuration = workingCopy.doSave(); + DebugUITools.launch(configuration, mode); + } catch (CoreException e1) { + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchShortcut#launch(org.eclipse.ui.IEditorPart, java.lang.String) + */ + public void launch(IEditorPart editor, String mode) { + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/launcher/PDAMainTab.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/launcher/PDAMainTab.java new file mode 100644 index 000000000..59217fb54 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/launcher/PDAMainTab.java @@ -0,0 +1,185 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.launcher; + + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.examples.core.pda.DebugCorePlugin; +import org.eclipse.debug.examples.ui.pda.DebugUIPlugin; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ResourceListSelectionDialog; + + +/** + * Tab to specify the PDA program to run/debug. + */ +public class PDAMainTab extends AbstractLaunchConfigurationTab { + + private Text fProgramText; + private Button fProgramButton; + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + Font font = parent.getFont(); + + Composite comp = new Composite(parent, SWT.NONE); + setControl(comp); + GridLayout topLayout = new GridLayout(); + topLayout.verticalSpacing = 0; + topLayout.numColumns = 3; + comp.setLayout(topLayout); + comp.setFont(font); + + createVerticalSpacer(comp, 3); + + Label programLabel = new Label(comp, SWT.NONE); + programLabel.setText("&Program:"); + GridData gd = new GridData(GridData.BEGINNING); + programLabel.setLayoutData(gd); + programLabel.setFont(font); + + fProgramText = new Text(comp, SWT.SINGLE | SWT.BORDER); + gd = new GridData(GridData.FILL_HORIZONTAL); + fProgramText.setLayoutData(gd); + fProgramText.setFont(font); + fProgramText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateLaunchConfigurationDialog(); + } + }); + + fProgramButton = createPushButton(comp, "&Browse...", null); //$NON-NLS-1$ + fProgramButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + browsePDAFiles(); + } + }); + } + + /** + * Open a resource chooser to select a PDA program + */ + protected void browsePDAFiles() { + ResourceListSelectionDialog dialog = new ResourceListSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), IResource.FILE); + dialog.setTitle("PDA Program"); + dialog.setMessage("Select PDA Program"); + if (dialog.open() == Window.OK) { + Object[] files = dialog.getResult(); + IFile file = (IFile) files[0]; + fProgramText.setText(file.getFullPath().toString()); + } + + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) + */ + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration) + */ + public void initializeFrom(ILaunchConfiguration configuration) { + //#ifdef ex1 +//# // TODO: Exercise 1 - retrieve the program path attribute from the launch configuration +//# String program = null; +//# if (program != null) { +//# fProgramText.setText(program); +//# } + //#else + try { + String program = null; + program = configuration.getAttribute(DebugCorePlugin.ATTR_PDA_PROGRAM, (String)null); + if (program != null) { + fProgramText.setText(program); + } + } catch (CoreException e) { + setErrorMessage(e.getMessage()); + } + //#endif + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) + */ + public void performApply(ILaunchConfigurationWorkingCopy configuration) { + String program = fProgramText.getText().trim(); + if (program.length() == 0) { + program = null; + } + //#ifdef ex1 +//# // TODO: Exercise 1 - update the launch configuration with the path to +//# // currently specified program + //#else + configuration.setAttribute(DebugCorePlugin.ATTR_PDA_PROGRAM, program); + //#endif + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName() + */ + public String getName() { + return "Main"; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration) + */ + public boolean isValid(ILaunchConfiguration launchConfig) { + setErrorMessage(null); + setMessage(null); + String text = fProgramText.getText(); + //#ifdef ex1 +//# // TODO: Exercise 1 - validate the currently specified program exists and is not +//# // empty, providing the user with feedback. + //#else + if (text.length() > 0) { + IPath path = new Path(text); + if (ResourcesPlugin.getWorkspace().getRoot().findMember(path) == null) { + setErrorMessage("Specified program does not exist"); + return false; + } + } else { + setMessage("Specify a program"); + } + //#endif + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage() + */ + public Image getImage() { + return DebugUIPlugin.getDefault().getImageRegistry().get(DebugUIPlugin.IMG_OBJ_PDA); + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/launcher/PDATabGroup.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/launcher/PDATabGroup.java new file mode 100644 index 000000000..6f1753c45 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/launcher/PDATabGroup.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.launcher; + +import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; +import org.eclipse.debug.ui.CommonTab; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.debug.ui.ILaunchConfigurationTab; +import org.eclipse.debug.ui.sourcelookup.SourceLookupTab; + +/** + * Tab group for a PDA application + */ +public class PDATabGroup extends AbstractLaunchConfigurationTabGroup { + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchConfigurationTabGroup#createTabs(org.eclipse.debug.ui.ILaunchConfigurationDialog, java.lang.String) + */ + public void createTabs(ILaunchConfigurationDialog dialog, String mode) { + //#ifdef ex1 +//# // TODO: Exercise 1 - add the PDA main tab, source lookup tab and common +//# // tab to the tab group + //#else + setTabs(new ILaunchConfigurationTab[] { + new PDAMainTab(), + new SourceLookupTab(), + new CommonTab() + }); + //#endif + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/presentation/PDAModelPresentation.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/presentation/PDAModelPresentation.java new file mode 100644 index 000000000..7d5d3ba91 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/presentation/PDAModelPresentation.java @@ -0,0 +1,192 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.presentation; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.core.model.ILineBreakpoint; +import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.examples.core.pda.DebugCorePlugin; +import org.eclipse.debug.examples.core.pda.breakpoints.PDALineBreakpoint; +import org.eclipse.debug.examples.core.pda.breakpoints.PDAWatchpoint; +import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.examples.core.pda.model.PDAStackFrame; +import org.eclipse.debug.examples.core.pda.model.PDAThread; +import org.eclipse.debug.ui.IDebugModelPresentation; +import org.eclipse.debug.ui.IValueDetailListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.part.FileEditorInput; + + +/** + * Renders PDA debug elements + */ +public class PDAModelPresentation extends LabelProvider implements IDebugModelPresentation { + /* (non-Javadoc) + * @see org.eclipse.debug.ui.IDebugModelPresentation#setAttribute(java.lang.String, java.lang.Object) + */ + public void setAttribute(String attribute, Object value) { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) + */ + public String getText(Object element) { + if (element instanceof PDADebugTarget) { + return getTargetText((PDADebugTarget)element); + } else if (element instanceof PDAThread) { + return getThreadText((PDAThread)element); + } else if (element instanceof PDAStackFrame) { + return getStackFrameText((PDAStackFrame)element); + } else if (element instanceof PDAWatchpoint) { + return getWatchpointText((PDAWatchpoint)element); + } + return null; + } + + /** + * Returns a label for the given watchpoint. + * + * @param watchpoint + * @return a label for the given watchpoint + */ + private String getWatchpointText(PDAWatchpoint watchpoint) { + try { + String label = watchpoint.getVariableName() + " (" + watchpoint.getFunctionName() + ")"; + if (watchpoint.isAccess()) { + label += " [read]"; + } + if (watchpoint.isModification()) { + label += " [write]"; + } + return label; + } catch (CoreException e) { + return null; + } + } + /** + * Returns a label for the given debug target + * + * @param target debug target + * @return a label for the given debug target + */ + private String getTargetText(PDADebugTarget target) { + try { + String pgmPath = target.getLaunch().getLaunchConfiguration().getAttribute(DebugCorePlugin.ATTR_PDA_PROGRAM, (String)null); + if (pgmPath != null) { + IPath path = new Path(pgmPath); + String label = ""; + if (target.isTerminated()) { + label = "<terminated>"; + } + return label + "PDA [" + path.lastSegment() + "]"; + } + } catch (CoreException e) { + } + return "PDA"; + + } + + /** + * Returns a label for the given stack frame + * + * @param frame a stack frame + * @return a label for the given stack frame + */ + private String getStackFrameText(PDAStackFrame frame) { + try { + return frame.getName() + " (line: " + frame.getLineNumber() + ")"; + } catch (DebugException e) { + } + return null; + + } + + /** + * Returns a label for the given thread + * + * @param thread a thread + * @return a label for the given thread + */ + private String getThreadText(PDAThread thread) { + String label = thread.getName(); + if (thread.isStepping()) { + label += " (stepping)"; + } else if (thread.isSuspended()) { + IBreakpoint[] breakpoints = thread.getBreakpoints(); + if (breakpoints.length == 0) { + if (thread.getError() == null) { + label += " (suspended)"; + } else { + label += " (" + thread.getError() + ")"; + } + } else { + IBreakpoint breakpoint = breakpoints[0]; // there can only be one in PDA + if (breakpoint instanceof PDALineBreakpoint) { + PDALineBreakpoint pdaBreakpoint = (PDALineBreakpoint) breakpoint; + if (pdaBreakpoint instanceof PDAWatchpoint) { + try { + PDAWatchpoint watchpoint = (PDAWatchpoint)pdaBreakpoint; + label += " (watchpoint: " + watchpoint.getSuspendType() + " " + watchpoint.getVariableName() + ")"; + } catch (CoreException e) { + } + } else if (pdaBreakpoint.isRunToLineBreakpoint()) { + label += " (run to line)"; + } else { + label += " (suspended at line breakpoint)"; + } + } + } + } else if (thread.isTerminated()) { + label = "<terminated> " + label; + } + return label; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.IDebugModelPresentation#computeDetail(org.eclipse.debug.core.model.IValue, org.eclipse.debug.ui.IValueDetailListener) + */ + public void computeDetail(IValue value, IValueDetailListener listener) { + String detail = ""; + try { + detail = value.getValueString(); + } catch (DebugException e) { + } + listener.detailComputed(value, detail); + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(java.lang.Object) + */ + public IEditorInput getEditorInput(Object element) { + if (element instanceof IFile) { + return new FileEditorInput((IFile)element); + } + if (element instanceof ILineBreakpoint) { + return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource()); + } + return null; + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(org.eclipse.ui.IEditorInput, java.lang.Object) + */ + public String getEditorId(IEditorInput input, Object element) { + if (element instanceof IFile || element instanceof ILineBreakpoint) { + return "pda.editor"; + } + return null; + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/DataStackView.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/DataStackView.java new file mode 100644 index 000000000..234fe30ec --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/DataStackView.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.views; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IDebugElement; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.examples.core.pda.DebugCorePlugin; +import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.ui.AbstractDebugView; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchPart; + + +/** + * View of the PDA VM data stack + */ +public class DataStackView extends AbstractDebugView implements ISelectionListener { + + private PDADebugTarget fTarget; + private PopAction fPopAction; + private PushAction fPushAction; + + class StackViewContentProvider implements ITreeContentProvider { + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) + */ + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof PDADebugTarget) { + try { + return ((PDADebugTarget)parentElement).getDataStack(); + } catch (DebugException e) { + } + } + return new Object[0]; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) + */ + public Object getParent(Object element) { + if (element instanceof IDebugTarget) { + return null; + } else { + return ((IDebugElement)element).getDebugTarget(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) + */ + public boolean hasChildren(Object element) { + if (element instanceof IDebugElement) { + return getChildren(element).length > 0; + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractDebugView#createViewer(org.eclipse.swt.widgets.Composite) + */ + protected Viewer createViewer(Composite parent) { + TreeViewer viewer = new TreeViewer(parent); + viewer.setLabelProvider(DebugUITools.newDebugModelPresentation()); + viewer.setContentProvider(new StackViewContentProvider()); + getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); + getSite().setSelectionProvider(viewer); + return viewer; + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractDebugView#createActions() + */ + protected void createActions() { + fPopAction = new PopAction(this); + fPushAction = new PushAction(this); + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractDebugView#getHelpContextId() + */ + protected String getHelpContextId() { + return null; + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractDebugView#fillContextMenu(org.eclipse.jface.action.IMenuManager) + */ + protected void fillContextMenu(IMenuManager menu) { + menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + menu.add(fPopAction); + menu.add(fPushAction); + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractDebugView#configureToolBar(org.eclipse.jface.action.IToolBarManager) + */ + protected void configureToolBar(IToolBarManager tbm) { + tbm.add(fPopAction); + tbm.add(fPushAction); + } + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPart#dispose() + */ + public void dispose() { + getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); + super.dispose(); + } + /* (non-Javadoc) + * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + update(); + } + + /** + * Updates the view for the selected target (if suspended) + */ + private synchronized void update() { + IAdaptable adaptable = DebugUITools.getDebugContext(); + fTarget = null; + if (adaptable != null) { + IDebugElement element = (IDebugElement) adaptable.getAdapter(IDebugElement.class); + if (element != null) { + if (element.getModelIdentifier().equals(DebugCorePlugin.ID_PDA_DEBUG_MODEL)) { + fTarget = (PDADebugTarget) element.getDebugTarget(); + } + } + } + Object input = null; + if (fTarget != null && fTarget.isSuspended()) { + input = fTarget; + } + getViewer().setInput(input); + fPushAction.setDebugTarget(fTarget); + getViewer().refresh(); + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopAction.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopAction.java new file mode 100644 index 000000000..af21fbcc6 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopAction.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.views; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.examples.ui.pda.DebugUIPlugin; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeViewer; + + +/** + * Pops a selected value off the data stack. The selection does <b>not</b> have to be + * the top element on the stack. + */ +public class PopAction extends Action implements ISelectionChangedListener { + + private DataStackView fView; + + /** + * Constructs an action to pop values off the stack + */ + protected PopAction(DataStackView view) { + super("Pop"); + ImageRegistry imageRegistry = DebugUIPlugin.getDefault().getImageRegistry(); + setImageDescriptor(imageRegistry.getDescriptor(DebugUIPlugin.IMG_ELCL_POP)); + setDisabledImageDescriptor(imageRegistry.getDescriptor(DebugUIPlugin.IMG_DLCL_POP)); + setToolTipText("Pop"); + setEnabled(false); + view.getSite().getSelectionProvider().addSelectionChangedListener(this); + fView = view; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) + */ + public void selectionChanged(SelectionChangedEvent event) { + if (event.getSelection().isEmpty()) { + setEnabled(false); + } else { + setEnabled(getDebugTarget().canPop()); + } + } + + public void run() { + TreeViewer viewer = (TreeViewer)fView.getViewer(); + IStructuredSelection selection = (IStructuredSelection)viewer.getSelection(); + Object popee = selection.getFirstElement(); + try { + PDADebugTarget target = getDebugTarget(); + IValue[] stack = target.getDataStack(); + List restore = new ArrayList(); + for (int i = 0; i < stack.length; i++) { + Object value = stack[i]; + if (popee.equals(value)) { + // pop & stop + target.pop(); + break; + } else { + // remember value to push back on + restore.add(target.pop()); + } + } + while (!restore.isEmpty()) { + IValue value = (IValue) restore.remove(restore.size() - 1); + target.push(value.getValueString()); + } + } catch (DebugException e) { + } + viewer.refresh(); + } + + /** + * Returns the debug target assocaited with the data view. + * + * @return the debug target assocaited with the data view + */ + protected PDADebugTarget getDebugTarget() { + TreeViewer viewer = (TreeViewer)fView.getViewer(); + return (PDADebugTarget) viewer.getInput(); + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushAction.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushAction.java new file mode 100644 index 000000000..8764cf3bc --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushAction.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Bjorn Freeman-Benson - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.views; + +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.examples.ui.pda.DebugUIPlugin; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.jface.window.Window; + + +/** + * Pushes a value onto the data stack. + */ +public class PushAction extends Action { + + private PDADebugTarget fTarget; + private DataStackView fView; + + /** + * Constructs an action to pop values off the stack + */ + protected PushAction(DataStackView view) { + super("Push"); + ImageRegistry imageRegistry = DebugUIPlugin.getDefault().getImageRegistry(); + setImageDescriptor(imageRegistry.getDescriptor(DebugUIPlugin.IMG_ELCL_PUSH)); + setDisabledImageDescriptor(imageRegistry.getDescriptor(DebugUIPlugin.IMG_DLCL_PUSH)); + setToolTipText("Push"); + setEnabled(false); + fView = view; + } + + public void run() { + InputDialog dialog = new InputDialog(fView.getSite().getShell(), "Specify Value", "Enter value to push", null, null); + if (dialog.open() == Window.OK) { + try { + fTarget.push(dialog.getValue()); + } catch (DebugException e) { + } + } + fView.getViewer().refresh(); + } + + protected void setDebugTarget(PDADebugTarget target) { + fTarget = target; + setEnabled(fTarget != null && fTarget.canPush()); + } + + +} |