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/src/org/eclipse/debug/examples/ui/pda/adapters | |
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/src/org/eclipse/debug/examples/ui/pda/adapters')
5 files changed, 335 insertions, 0 deletions
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; + } + +} |