From 2ba2d568d064ef4df39df29f763218eed768f7c6 Mon Sep 17 00:00:00 2001 From: Kevin Barnes Date: Mon, 7 Nov 2005 22:48:54 +0000 Subject: merging Asynchronous viewer branch --- org.eclipse.debug.ui/META-INF/MANIFEST.MF | 5 + org.eclipse.debug.ui/plugin.xml | 86 +- .../eclipse/debug/internal/ui/DebugUIPlugin.java | 7 + .../internal/ui/DelegatingModelPresentation.java | 10 +- .../internal/ui/IInternalDebugUIConstants.java | 48 +- .../debug/internal/ui/LazyModelPresentation.java | 4 + .../ui/actions/AbstractListenerActionDelegate.java | 120 --- .../ui/actions/AbstractRemoveActionDelegate.java | 42 - .../actions/AbstractRemoveAllActionDelegate.java | 63 -- .../internal/ui/actions/CollapseAllAction.java | 10 +- .../ui/actions/CopyToClipboardActionDelegate.java | 32 +- .../ui/actions/DisconnectActionDelegate.java | 66 -- .../ui/actions/DropToFrameActionDelegate.java | 89 -- .../internal/ui/actions/FindVariableAction.java | 88 -- .../internal/ui/actions/FindVariableDialog.java | 210 ----- .../ui/actions/RemoveAllBreakpointsAction.java | 120 --- .../ui/actions/RemoveAllExpressionsAction.java | 33 - .../ui/actions/RemoveAllTerminatedAction.java | 124 --- .../ui/actions/RemoveBreakpointAction.java | 122 --- .../ui/actions/RemoveExpressionAction.java | 58 -- .../internal/ui/actions/ResumeActionDelegate.java | 118 --- .../debug/internal/ui/actions/SelectAllAction.java | 76 -- .../ui/actions/SelectAllBreakpointsAction.java | 83 -- .../ui/actions/SelectAllExpressionsAction.java | 27 - .../ui/actions/SelectAllVariablesAction.java | 31 - .../internal/ui/actions/StepActionDelegate.java | 58 -- .../ui/actions/StepIntoActionDelegate.java | 54 -- .../ui/actions/StepOverActionDelegate.java | 53 -- .../ui/actions/StepReturnActionDelegate.java | 54 -- .../internal/ui/actions/SuspendActionDelegate.java | 56 -- .../ui/actions/TerminateActionDelegate.java | 111 --- .../internal/ui/actions/TerminateAllAction.java | 95 --- .../ui/actions/TerminateAndRelaunchAction.java | 55 -- .../actions/TerminateAndRemoveActionDelegate.java | 61 -- .../internal/ui/contexts/DebugContextManager.java | 135 ++++ .../ui/contexts/DebugWindowContextService.java | 261 ++++++ .../internal/ui/contexts/IDebugContextService.java | 69 ++ .../internal/ui/contexts/LaunchSuspendTrigger.java | 108 +++ .../ui/contexts/SuspendTriggerAdapterFactory.java | 43 + .../AbstractDebugContextActionDelegate.java | 462 +++++++++++ .../actions/AbstractRemoveActionDelegate.java | 42 + .../actions/AbstractRemoveAllActionDelegate.java | 63 ++ .../contexts/actions/DisconnectActionDelegate.java | 73 ++ .../actions/DropToFrameActionDelegate.java | 96 +++ .../ui/contexts/actions/FindVariableAction.java | 84 ++ .../ui/contexts/actions/FindVariableDialog.java | 211 +++++ .../actions/RemoveAllBreakpointsAction.java | 121 +++ .../actions/RemoveAllExpressionsAction.java | 33 + .../actions/RemoveAllTerminatedAction.java | 103 +++ .../contexts/actions/RemoveBreakpointAction.java | 123 +++ .../contexts/actions/RemoveExpressionAction.java | 75 ++ .../ui/contexts/actions/ResumeActionDelegate.java | 126 +++ .../ui/contexts/actions/SelectAllAction.java | 61 ++ .../actions/SelectAllBreakpointsAction.java | 83 ++ .../actions/SelectAllExpressionsAction.java | 25 + .../contexts/actions/SelectAllVariablesAction.java | 45 ++ .../ui/contexts/actions/StepActionDelegate.java | 73 ++ .../contexts/actions/StepIntoActionDelegate.java | 53 ++ .../contexts/actions/StepOverActionDelegate.java | 56 ++ .../contexts/actions/StepReturnActionDelegate.java | 54 ++ .../ui/contexts/actions/SuspendActionDelegate.java | 63 ++ .../contexts/actions/TerminateActionDelegate.java | 127 +++ .../ui/contexts/actions/TerminateAllAction.java | 95 +++ .../actions/TerminateAndRelaunchAction.java | 56 ++ .../actions/TerminateAndRemoveActionDelegate.java | 62 ++ .../adapters/AsynchronousDebugLabelAdapter.java | 109 +++ .../adapters/DebugTargetTreeContentAdapter.java | 43 + .../ui/elements/adapters/DeferredExpression.java | 65 -- .../DeferredExpressionLogicalStructure.java | 25 - .../adapters/DeferredExpressionManager.java | 82 -- .../ui/elements/adapters/DeferredLaunch.java | 33 - .../elements/adapters/DeferredLaunchManager.java | 32 - .../ui/elements/adapters/DeferredProcess.java | 38 - .../elements/adapters/DeferredRegisterGroup.java | 80 -- .../ui/elements/adapters/DeferredStackFrame.java | 96 --- .../ui/elements/adapters/DeferredTarget.java | 43 - .../ui/elements/adapters/DeferredThread.java | 44 - .../ui/elements/adapters/DeferredVariable.java | 237 ------ .../adapters/DeferredVariableLogicalStructure.java | 25 - .../ExpressionManagerTreeContentAdapter.java | 42 + .../adapters/ExpressionTreeContentAdapter.java | 45 ++ .../adapters/LauchManagerTreeContentAdapter.java | 42 + .../adapters/LaunchTreeContentAdapter.java | 42 + .../ui/elements/adapters/ProcessTreeAdapter.java | 40 + .../adapters/RegisterGroupTreeContentAdapter.java | 31 + .../adapters/StackFrameSourceDisplayAdapter.java | 164 ++++ .../adapters/StackFrameTreeContentAdapter.java | 57 ++ .../adapters/ThreadTreeContentAdapter.java | 42 + .../ui/elements/adapters/VariableLabelAdapter.java | 47 ++ .../adapters/VariableTreeContentAdapter.java | 209 +++++ .../launchConfigurations/PerspectiveManager.java | 57 +- .../ui/sourcelookup/SourceLookupManager.java | 86 ++ .../ui/sourcelookup/SourceLookupService.java | 70 ++ .../internal/ui/viewers/AbstractModelProxy.java | 48 ++ .../ui/viewers/AsynchronousLabelAdapter.java | 155 ++++ .../ui/viewers/AsynchronousRequestMonitor.java | 194 +++++ .../ui/viewers/AsynchronousTreeContentAdapter.java | 149 ++++ .../ui/viewers/AsynchronousTreeViewer.java | 892 ++++++++++++++++++++ .../internal/ui/viewers/AsynchronousViewer.java | 894 +++++++++++++++++++++ .../ui/viewers/ChildrenRequestMonitor.java | 74 ++ .../ui/viewers/ContainerRequestMonitor.java | 62 ++ .../ui/viewers/DefaultElementComparer.java | 38 + .../ui/viewers/IAsynchronousLabelAdapter.java | 35 + .../ui/viewers/IAsynchronousRequestMonitor.java | 45 ++ .../viewers/IAsynchronousTreeContentAdapter.java | 46 ++ .../ui/viewers/IChildrenRequestMonitor.java | 35 + .../ui/viewers/IContainerRequestMonitor.java | 30 + .../internal/ui/viewers/ILabelRequestMonitor.java | 62 ++ .../internal/ui/viewers/IModelChangedListener.java | 27 + .../debug/internal/ui/viewers/IModelDelta.java | 49 ++ .../debug/internal/ui/viewers/IModelDeltaNode.java | 30 + .../debug/internal/ui/viewers/IModelProxy.java | 28 + .../internal/ui/viewers/IModelProxyFactory.java | 20 + .../internal/ui/viewers/IModelSelectionPolicy.java | 65 ++ .../internal/ui/viewers/IPresentationContext.java | 34 + .../debug/internal/ui/viewers/IUpdatePolicy.java | 35 + .../internal/ui/viewers/IUpdatePolicyFactory.java | 32 + .../internal/ui/viewers/LabelRequestMonitor.java | 129 +++ .../internal/ui/viewers/PresentationContext.java | 42 + .../debug/internal/ui/viewers/TreePath.java | 179 +++++ .../debug/internal/ui/viewers/TreeSelection.java | 155 ++++ .../ui/viewers/update/AbstractUpdatePolicy.java | 52 ++ .../ui/viewers/update/DebugEventHandler.java | 154 ++++ .../ui/viewers/update/DebugTargetEventHandler.java | 70 ++ .../ui/viewers/update/DebugTargetProxy.java | 94 +++ .../viewers/update/DefaultModelProxyFactory.java | 39 + .../ui/viewers/update/DefaultSelectionPolicy.java | 114 +++ .../ui/viewers/update/DefaultUpdatePolicy.java | 126 +++ .../viewers/update/DefaultUpdatePolicyFactory.java | 32 + .../update/DefaultVariableViewModelProxy.java | 54 ++ .../ui/viewers/update/EventHandlerModelProxy.java | 251 ++++++ .../ui/viewers/update/LaunchManagerProxy.java | 66 ++ .../internal/ui/viewers/update/LaunchProxy.java | 80 ++ .../internal/ui/viewers/update/ModelDelta.java | 23 + .../internal/ui/viewers/update/ModelDeltaNode.java | 47 ++ .../internal/ui/viewers/update/ProcessProxy.java | 62 ++ .../ui/viewers/update/ThreadEventHandler.java | 92 +++ .../viewers/update/VariablesViewEventHandler.java | 58 ++ .../ui/views/AbstractDebugEventHandler.java | 61 +- .../ui/views/AbstractDebugEventHandlerView.java | 10 +- .../internal/ui/views/AbstractViewerState.java | 112 +-- .../ui/views/IRemoteTreeViewerUpdateListener.java | 15 - .../ui/views/RemoteTreeContentManager.java | 335 -------- .../debug/internal/ui/views/RemoteTreeViewer.java | 609 -------------- .../console/ConsoleRemoveAllTerminatedAction.java | 2 +- .../console/ConsoleTerminateActionDelegate.java | 2 +- .../expression/ExpressionPopupContentProvider.java | 44 - .../ui/views/expression/ExpressionView.java | 61 +- .../expression/ExpressionViewEventHandler.java | 39 +- .../expression/RemoteExpressionContentManager.java | 84 -- .../RemoteExpressionsContentProvider.java | 34 - .../views/launch/DebugElementAdapterFactory.java | 151 ++-- .../ui/views/launch/DebugElementHelper.java | 2 +- .../ui/views/launch/DebugViewContentProvider.java | 100 --- .../debug/internal/ui/views/launch/LaunchView.java | 264 +++--- .../ui/views/launch/LaunchViewEventHandler.java | 250 +++--- .../internal/ui/views/launch/LaunchViewer.java | 237 ++++-- .../registers/DeferredRegisterViewStackFrame.java | 42 - .../internal/ui/views/registers/RegistersView.java | 21 +- .../ui/views/registers/RegistersViewerState.java | 121 --- .../registers/RemoteRegisterContentManager.java | 35 - .../RemoteRegistersViewContentProvider.java | 56 -- .../AvailableLogicalStructuresAction.java | 2 +- .../variables/RemoteVariableContentManager.java | 114 --- .../variables/RemoteVariablesContentProvider.java | 224 ------ .../internal/ui/views/variables/VariablesView.java | 270 +++---- .../views/variables/VariablesViewEventHandler.java | 16 - .../ui/views/variables/VariablesViewer.java | 186 +---- .../internal/ui/views/variables/ViewerState.java | 117 ++- .../ui/org/eclipse/debug/ui/IDebugUIConstants.java | 8 + .../org/eclipse/debug/ui/InspectPopupDialog.java | 41 +- .../debug/ui/contexts/IDebugContextListener.java | 31 + .../debug/ui/contexts/IDebugContextManager.java | 99 +++ .../debug/ui/contexts/IDebugContextProvider.java | 35 + .../debug/ui/contexts/ISourceDisplayAdapter.java | 31 + .../eclipse/debug/ui/contexts/ISuspendTrigger.java | 26 + .../debug/ui/contexts/ISuspendTriggerListener.java | 29 + 177 files changed, 10405 insertions(+), 5785 deletions(-) delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractListenerActionDelegate.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractRemoveActionDelegate.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractRemoveAllActionDelegate.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/DisconnectActionDelegate.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/DropToFrameActionDelegate.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/FindVariableAction.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/FindVariableDialog.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveAllBreakpointsAction.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveAllExpressionsAction.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveAllTerminatedAction.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveBreakpointAction.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveExpressionAction.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ResumeActionDelegate.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllAction.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllBreakpointsAction.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllExpressionsAction.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllVariablesAction.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepActionDelegate.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepIntoActionDelegate.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepOverActionDelegate.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepReturnActionDelegate.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SuspendActionDelegate.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateActionDelegate.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateAllAction.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateAndRelaunchAction.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateAndRemoveActionDelegate.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/DebugContextManager.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/DebugWindowContextService.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/IDebugContextService.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/LaunchSuspendTrigger.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/SuspendTriggerAdapterFactory.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/AbstractDebugContextActionDelegate.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/AbstractRemoveActionDelegate.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/AbstractRemoveAllActionDelegate.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/DisconnectActionDelegate.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/DropToFrameActionDelegate.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/FindVariableAction.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/FindVariableDialog.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveAllBreakpointsAction.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveAllExpressionsAction.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveAllTerminatedAction.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveBreakpointAction.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveExpressionAction.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/ResumeActionDelegate.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllAction.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllBreakpointsAction.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllExpressionsAction.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllVariablesAction.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepActionDelegate.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepIntoActionDelegate.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepOverActionDelegate.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepReturnActionDelegate.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SuspendActionDelegate.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateActionDelegate.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateAllAction.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateAndRelaunchAction.java create mode 100755 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateAndRemoveActionDelegate.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/AsynchronousDebugLabelAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DebugTargetTreeContentAdapter.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredExpression.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredExpressionLogicalStructure.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredExpressionManager.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredLaunch.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredLaunchManager.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredProcess.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredRegisterGroup.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredStackFrame.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredTarget.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredThread.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredVariable.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredVariableLogicalStructure.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ExpressionManagerTreeContentAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ExpressionTreeContentAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/LauchManagerTreeContentAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/LaunchTreeContentAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ProcessTreeAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/RegisterGroupTreeContentAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/StackFrameSourceDisplayAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/StackFrameTreeContentAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ThreadTreeContentAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/VariableLabelAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/VariableTreeContentAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupManager.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupService.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AbstractModelProxy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousLabelAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousRequestMonitor.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousTreeContentAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousTreeViewer.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousViewer.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/ChildrenRequestMonitor.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/ContainerRequestMonitor.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/DefaultElementComparer.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IAsynchronousLabelAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IAsynchronousRequestMonitor.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IAsynchronousTreeContentAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IChildrenRequestMonitor.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IContainerRequestMonitor.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/ILabelRequestMonitor.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelChangedListener.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelDelta.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelDeltaNode.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelProxy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelProxyFactory.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelSelectionPolicy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IPresentationContext.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IUpdatePolicy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IUpdatePolicyFactory.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/LabelRequestMonitor.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/PresentationContext.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/TreePath.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/TreeSelection.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/AbstractUpdatePolicy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DebugEventHandler.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DebugTargetEventHandler.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DebugTargetProxy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultModelProxyFactory.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultSelectionPolicy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultUpdatePolicy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultUpdatePolicyFactory.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultVariableViewModelProxy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/EventHandlerModelProxy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/LaunchManagerProxy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/LaunchProxy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ModelDelta.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ModelDeltaNode.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ProcessProxy.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ThreadEventHandler.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/VariablesViewEventHandler.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/IRemoteTreeViewerUpdateListener.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeContentManager.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeViewer.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionPopupContentProvider.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/RemoteExpressionContentManager.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/RemoteExpressionsContentProvider.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugViewContentProvider.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/DeferredRegisterViewStackFrame.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RegistersViewerState.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RemoteRegisterContentManager.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RemoteRegistersViewContentProvider.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/RemoteVariableContentManager.java delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/RemoteVariablesContentProvider.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/IDebugContextListener.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/IDebugContextManager.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/IDebugContextProvider.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/ISourceDisplayAdapter.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/ISuspendTrigger.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/ISuspendTriggerListener.java diff --git a/org.eclipse.debug.ui/META-INF/MANIFEST.MF b/org.eclipse.debug.ui/META-INF/MANIFEST.MF index 8ae417f8c..33489edc5 100644 --- a/org.eclipse.debug.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.debug.ui/META-INF/MANIFEST.MF @@ -9,6 +9,8 @@ Bundle-Localization: plugin Export-Package: org.eclipse.debug.internal.ui;x-internal:=true, org.eclipse.debug.internal.ui.actions;x-internal:=true, org.eclipse.debug.internal.ui.actions.breakpointGroups;x-internal:=true, + org.eclipse.debug.internal.ui.contexts;x-internal:=true, + org.eclipse.debug.internal.ui.contexts.actions;x-internal:=true, org.eclipse.debug.internal.ui.elements.adapters;x-internal:=true, org.eclipse.debug.internal.ui.importexport.breakpoints;x-internal:=true, org.eclipse.debug.internal.ui.launchConfigurations;x-internal:=true, @@ -17,6 +19,8 @@ Export-Package: org.eclipse.debug.internal.ui;x-internal:=true, org.eclipse.debug.internal.ui.sourcelookup;x-internal:=true, org.eclipse.debug.internal.ui.sourcelookup.browsers;x-internal:=true, org.eclipse.debug.internal.ui.stringsubstitution;x-internal:=true, + org.eclipse.debug.internal.ui.viewers, + org.eclipse.debug.internal.ui.viewers.update;x-internal:=true, org.eclipse.debug.internal.ui.views;x-internal:=true, org.eclipse.debug.internal.ui.views.breakpoints;x-internal:=true, org.eclipse.debug.internal.ui.views.console;x-internal:=true, @@ -29,6 +33,7 @@ Export-Package: org.eclipse.debug.internal.ui;x-internal:=true, org.eclipse.debug.ui, org.eclipse.debug.ui.actions, org.eclipse.debug.ui.console, + org.eclipse.debug.ui.contexts, org.eclipse.debug.ui.memory, org.eclipse.debug.ui.sourcelookup Require-Bundle: org.eclipse.core.expressions, diff --git a/org.eclipse.debug.ui/plugin.xml b/org.eclipse.debug.ui/plugin.xml index 1cda9bdaa..23087b10f 100644 --- a/org.eclipse.debug.ui/plugin.xml +++ b/org.eclipse.debug.ui/plugin.xml @@ -187,7 +187,7 @@ - + @@ -1103,7 +1103,7 @@ label="%TerminateAndRemoveAction.label" icon="$nl$/icons/full/elcl16/terminate_rem_co.gif" helpContextId="terminate_and_remove_action_context" - class="org.eclipse.debug.internal.ui.actions.TerminateAndRemoveActionDelegate" + class="org.eclipse.debug.internal.ui.contexts.actions.TerminateAndRemoveActionDelegate" menubarPath="launchGroup" id="org.eclipse.debug.ui.debugview.popupMenu.terminateAndRemove"> @@ -1123,7 +1123,7 @@ label="%DisconnectAction.label" icon="$nl$/icons/full/elcl16/disconnect_co.gif" helpContextId="disconnect_action_context" - class="org.eclipse.debug.internal.ui.actions.DisconnectActionDelegate" + class="org.eclipse.debug.internal.ui.contexts.actions.DisconnectActionDelegate" menubarPath="threadGroup" id="org.eclipse.debug.ui.debugview.popupMenu.disconnect"> @@ -1169,7 +1169,7 @@ icon="$nl$/icons/full/elcl16/resume_co.gif" helpContextId="resume_action_context" definitionId="org.eclipse.debug.ui.commands.Resume" - class="org.eclipse.debug.internal.ui.actions.ResumeActionDelegate" + class="org.eclipse.debug.internal.ui.contexts.actions.ResumeActionDelegate" menubarPath="threadGroup" enablesFor="1" id="org.eclipse.debug.ui.debugview.popupMenu.resume"> @@ -1182,7 +1182,7 @@ label="%DropToFrameAction.label" icon="$nl$/icons/full/elcl16/drop_to_frame.gif" helpContextId="drop_to_frame_action_context" - class="org.eclipse.debug.internal.ui.actions.DropToFrameActionDelegate" + class="org.eclipse.debug.internal.ui.contexts.actions.DropToFrameActionDelegate" menubarPath="stepReturnGroup" enablesFor="1" id="org.eclipse.debug.ui.debugview.popupMenu.dropToFrame"> @@ -1195,7 +1195,7 @@ icon="$nl$/icons/full/elcl16/stepreturn_co.gif" helpContextId="step_return_action_context" definitionId="org.eclipse.debug.ui.commands.StepReturn" - class="org.eclipse.debug.internal.ui.actions.StepReturnActionDelegate" + class="org.eclipse.debug.internal.ui.contexts.actions.StepReturnActionDelegate" menubarPath="stepReturnGroup" enablesFor="1" id="org.eclipse.debug.ui.debugview.popupMenu.stepReturn"> @@ -1208,7 +1208,7 @@ icon="$nl$/icons/full/elcl16/stepover_co.gif" helpContextId="step_over_action_context" definitionId="org.eclipse.debug.ui.commands.StepOver" - class="org.eclipse.debug.internal.ui.actions.StepOverActionDelegate" + class="org.eclipse.debug.internal.ui.contexts.actions.StepOverActionDelegate" menubarPath="stepOverGroup" enablesFor="1" id="org.eclipse.debug.ui.debugview.popupMenu.stepOver"> @@ -1221,7 +1221,7 @@ icon="$nl$/icons/full/elcl16/stepinto_co.gif" helpContextId="step_into_action_context" definitionId="org.eclipse.debug.ui.commands.StepInto" - class="org.eclipse.debug.internal.ui.actions.StepIntoActionDelegate" + class="org.eclipse.debug.internal.ui.contexts.actions.StepIntoActionDelegate" menubarPath="stepIntoGroup" enablesFor="1" id="org.eclipse.debug.ui.debugview.popupMenu.stepInto"> @@ -1271,7 +1271,7 @@ label="%SelectAll.label" helpContextId="select_all_breakpoints_action_context" definitionId="org.eclipse.ui.edit.selectAll" - class="org.eclipse.debug.internal.ui.actions.SelectAllBreakpointsAction" + class="org.eclipse.debug.internal.ui.contexts.actions.SelectAllBreakpointsAction" menubarPath="breakpointGroup" id="org.eclipse.debug.ui.actions.SelectAllBreakpointsAction"> @@ -1279,7 +1279,7 @@ label="%RemoveAllAction.label" icon="$nl$/icons/full/elcl16/rem_all_co.gif" helpContextId="remove_all_breakpoints_action_context" - class="org.eclipse.debug.internal.ui.actions.RemoveAllBreakpointsAction" + class="org.eclipse.debug.internal.ui.contexts.actions.RemoveAllBreakpointsAction" menubarPath="breakpointGroup" id="org.eclipse.debug.ui.actions.RemoveAllBreakpoints"> @@ -1287,7 +1287,7 @@ label="%RemoveAction.label" icon="$nl$/icons/full/elcl16/rem_co.gif" helpContextId="remove_breakpoint_action_context" - class="org.eclipse.debug.internal.ui.actions.RemoveBreakpointAction" + class="org.eclipse.debug.internal.ui.contexts.actions.RemoveBreakpointAction" menubarPath="breakpointGroup" enablesFor="1+" id="org.eclipse.debug.ui.breakpointsView.toolbar.remove"> @@ -1346,7 +1346,7 @@ label="%SelectAll.label" helpContextId="select_all_variables_action_context" definitionId="org.eclipse.ui.edit.selectAll" - class="org.eclipse.debug.internal.ui.actions.SelectAllVariablesAction" + class="org.eclipse.debug.internal.ui.contexts.actions.SelectAllVariablesAction" menubarPath="variableGroup" id="org.eclipse.debug.ui.actions.SelectAllVariablesAction"> @@ -1360,7 +1360,7 @@ label="%RemoveAllAction.label" icon="$nl$/icons/full/elcl16/rem_all_co.gif" helpContextId="remove_all_expressions_action_context" - class="org.eclipse.debug.internal.ui.actions.RemoveAllExpressionsAction" + class="org.eclipse.debug.internal.ui.contexts.actions.RemoveAllExpressionsAction" menubarPath="expressionGroup" id="org.eclipse.debug.ui.debugview.popupMenu.removeAllExpressionsAction"> @@ -1368,7 +1368,7 @@ label="%RemoveAction.label" icon="$nl$/icons/full/elcl16/rem_co.gif" helpContextId="remove_expression_action_context" - class="org.eclipse.debug.internal.ui.actions.RemoveExpressionAction" + class="org.eclipse.debug.internal.ui.contexts.actions.RemoveExpressionAction" menubarPath="expressionGroup" id="org.eclipse.debug.ui.debugview.popupMenu.removeExpressionAction"> @@ -1416,7 +1416,7 @@ - + diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java index b4a0ec96f..3d270cb71 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java @@ -52,6 +52,7 @@ import org.eclipse.debug.core.ILaunchListener; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.IStatusHandler; import org.eclipse.debug.core.Launch; +import org.eclipse.debug.core.model.IDebugElement; import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IExpression; import org.eclipse.debug.core.model.IProcess; @@ -60,9 +61,11 @@ import org.eclipse.debug.core.model.IRegisterGroup; import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.core.model.IVariable; +import org.eclipse.debug.internal.ui.contexts.SuspendTriggerAdapterFactory; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; import org.eclipse.debug.internal.ui.launchConfigurations.PerspectiveManager; import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupFacility; +import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupManager; import org.eclipse.debug.internal.ui.stringsubstitution.SelectedResourceManager; import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointOrganizerManager; import org.eclipse.debug.internal.ui.views.breakpoints.OtherBreakpointCategory; @@ -417,9 +420,12 @@ public class DebugUIPlugin extends AbstractUIPlugin implements ILaunchListener { manager.registerAdapters(propertiesFactory, IExpression.class); manager.registerAdapters(propertiesFactory, IExpressionManager.class); manager.registerAdapters(propertiesFactory, OtherBreakpointCategory.class); + manager.registerAdapters(propertiesFactory, IDebugElement.class); DebugUIAdapterFactory uiFactory = new DebugUIAdapterFactory(); manager.registerAdapters(uiFactory, ILaunchConfiguration.class); manager.registerAdapters(uiFactory, ILaunchConfigurationType.class); + SuspendTriggerAdapterFactory factory = new SuspendTriggerAdapterFactory(); + manager.registerAdapters(factory, ILaunch.class); getStandardDisplay().asyncExec( new Runnable() { public void run() { @@ -665,6 +671,7 @@ public class DebugUIPlugin extends AbstractUIPlugin implements ILaunchListener { } getLaunchConfigurationManager().startup(); + SourceLookupManager.getDefault(); } /** diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DelegatingModelPresentation.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DelegatingModelPresentation.java index 1a968567e..23c462a3b 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DelegatingModelPresentation.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DelegatingModelPresentation.java @@ -293,7 +293,7 @@ public class DelegatingModelPresentation implements IDebugModelPresentation, IDe return show.booleanValue(); } - protected HashMap getAttributes() { + public HashMap getAttributes() { return fAttributes; } @@ -307,18 +307,10 @@ public class DelegatingModelPresentation implements IDebugModelPresentation, IDe return (Map) getAttributes().clone(); } - protected void setAttributes(HashMap attributes) { - fAttributes = attributes; - } - protected HashMap getLabelProviders() { return fLabelProviders; } - protected void setLabelProviders(HashMap labelProviders) { - fLabelProviders = labelProviders; - } - /* (non-Javadoc) * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object) */ diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java index 67db6b14c..afeade528 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java @@ -193,26 +193,34 @@ public interface IInternalDebugUIConstants { */ public static final String PREF_SWITCH_PERSPECTIVE_ON_SUSPEND= IDebugUIConstants.PLUGIN_ID + ".switch_perspective_on_suspend"; //$NON-NLS-1$ - /** - * String preference controlling whether the debugger waits for a currently - * pending (running or waiting) background build to complete before launching. - * Valid values are either "always", "never", or "prompt". - * If "always" or "never", launching will wait for builds to finish (or not) automatically. - * If "prompt", the user will be prompted each time. - * - * @since 3.0 - */ - public static final String PREF_WAIT_FOR_BUILD= IDebugUIConstants.PLUGIN_ID + ".wait_for_build"; //$NON-NLS-1$ - - /** - * Font for Memory View - * - * @since 3.0 - */ - public final static String FONT_NAME = IDebugUIConstants.PLUGIN_ID + ".MemoryViewTableFont"; //$NON-NLS-1$ - - public final static int ADD_UNIT_PER_LINE = 16; // number of addressable unit per line - public final static int CHAR_PER_BYTE = 2; // number of characters to represent one byte + /** + * String preference controlling whether the debugger waits for a currently + * pending (running or waiting) background build to complete before launching. + * Valid values are either "always", "never", or "prompt". + * If "always" or "never", launching will wait for builds to finish (or not) automatically. + * If "prompt", the user will be prompted each time. + * + * @since 3.0 + */ + public static final String PREF_WAIT_FOR_BUILD= IDebugUIConstants.PLUGIN_ID + ".wait_for_build"; //$NON-NLS-1$ + + /** + * Maximum number of characters to display in the details area of the variables + * view, or 0 if unlimited. + * + * @since 3.1 + */ + public static final String PREF_MAX_DETAIL_LENGTH = IDebugUIConstants.PLUGIN_ID + ".max_detail_length"; //$NON-NLS-1$ + + /** + * Font for Memory View + * + * @since 3.0 + */ + public final static String FONT_NAME = IDebugUIConstants.PLUGIN_ID + ".MemoryViewTableFont"; //$NON-NLS-1$ + + public final static int ADD_UNIT_PER_LINE = 16; // number of addressable unit per line + public final static int CHAR_PER_BYTE = 2; // number of characters to represent one byte /** * Memory view identifier (value "org.eclipse.debug.ui.MemoryView"). diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/LazyModelPresentation.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/LazyModelPresentation.java index 0a99ad7d1..140f0a556 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/LazyModelPresentation.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/LazyModelPresentation.java @@ -337,6 +337,10 @@ public class LazyModelPresentation implements IDebugModelPresentation, IDebugEdi public Map getAttributeMap() { return (Map) fAttributes.clone(); } + + public Map getAttributes() { + return fAttributes; + } /* (non-Javadoc) * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object) diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractListenerActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractListenerActionDelegate.java deleted file mode 100644 index a34217039..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractListenerActionDelegate.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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 - * Pawel Piech - Bug 75183 - *******************************************************************************/ -package org.eclipse.debug.internal.ui.actions; - - -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IDebugEventSetListener; -import org.eclipse.jface.action.IAction; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IActionDelegate2; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchWindow; - -public abstract class AbstractListenerActionDelegate extends AbstractDebugActionDelegate implements IDebugEventSetListener, IActionDelegate2 { - - private boolean fDisposed = false; - - /** - * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() - * @see org.eclipse.ui.IActionDelegate2#dispose() - */ - public synchronized void dispose() { - super.dispose(); - DebugPlugin.getDefault().removeDebugEventListener(this); - fDisposed = true; - } - - /** - * @see IDebugEventSetListener#handleDebugEvents(DebugEvent[]) - */ - public void handleDebugEvents(final DebugEvent[] events) { - if (getWindow() == null || getAction() == null) { - return; - } - Shell shell= getWindow().getShell(); - if (shell == null || shell.isDisposed()) { - return; - } - synchronized (this) { - if (fDisposed) { - return; - } - } - for (int i = 0; i < events.length; i++) { - if (events[i].getSource() != null) { - doHandleDebugEvent(events[i]); - } - } - } - - /** - * Default implementation to update on specific debug events. - * Subclasses should override to handle events differently. - */ - protected void doHandleDebugEvent(DebugEvent event) { - switch (event.getKind()) { - case DebugEvent.TERMINATE : - update(getAction(), getSelection()); - break; - case DebugEvent.RESUME : - if (!event.isEvaluation() || !((event.getDetail() & DebugEvent.EVALUATION_IMPLICIT) != 0)) { - update(getAction(), getSelection()); - } - break; - case DebugEvent.SUSPEND : - // Update on suspend events (even for evaluations), in case the user changed - // the selection during an implicit evaluation. - update(getAction(), getSelection()); - break; - case DebugEvent.CHANGE : - // Implementations can use this event for debugger state - // changes other than just suspend/resume. This may or - // may not affect the enable state of run/suspend/step - // actions. - update(getAction(), getSelection()); - break; - } - } - - /** - * @see IWorkbenchWindowActionDelegate#init(IWorkbenchWindow) - */ - public void init(IWorkbenchWindow window){ - super.init(window); - DebugPlugin.getDefault().addDebugEventListener(this); - } - - /** - * @see IViewActionDelegate#init(IViewPart) - */ - public void init(IViewPart view) { - super.init(view); - DebugPlugin.getDefault().addDebugEventListener(this); - setWindow(view.getViewSite().getWorkbenchWindow()); - } - - /** - * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) - */ - public void init(IAction action) { - } - - /** - * @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.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractRemoveActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractRemoveActionDelegate.java deleted file mode 100644 index 473bdd44d..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractRemoveActionDelegate.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.debug.ui.IDebugView; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IViewPart; - -public abstract class AbstractRemoveActionDelegate extends AbstractListenerActionDelegate { - - /** - * @see IViewActionDelegate#init(IViewPart) - */ - public void init(IViewPart view) { - setView(view); - setWindow(view.getViewSite().getWorkbenchWindow()); - } - - /** - * @see AbstractDebugActionDelegate#initialize(IAction, ISelection) - */ - protected boolean initialize(IAction action, ISelection selection) { - if (!isInitialized()) { - IDebugView debugView= (IDebugView)getView().getAdapter(IDebugView.class); - if (debugView != null) { - debugView.setAction(IDebugView.REMOVE_ACTION, action); - } - return super.initialize(action, selection); - } - return false; - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractRemoveAllActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractRemoveAllActionDelegate.java deleted file mode 100644 index 47d57a1c8..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractRemoveAllActionDelegate.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IViewPart; - -public abstract class AbstractRemoveAllActionDelegate extends AbstractListenerActionDelegate { - - /** - * @see AbstractDebugActionDelegate#doAction(Object) - */ - protected void doAction(Object element) { - doAction(); - update(); - } - - /** - * @see IActionDelegate#run(IAction) - */ - public void run(IAction action){ - doAction(null); - } - - protected abstract void doAction(); - - protected void update(IAction action, ISelection s) { - update(); - } - - protected abstract void update(); - - /** - * Remove all actions do care nothing about the current selection - * @see IActionDelegate#selectionChanged(IAction, ISelection) - */ - public void selectionChanged(IAction action, ISelection s) { - if (!isInitialized()) { - action.setEnabled(false); - setAction(action); - setInitialized(true); - } - update(); - } - - /** - * @see IViewActionDelegate#init(IViewPart) - */ - public void init(IViewPart view) { - setView(view); - setWindow(view.getViewSite().getWorkbenchWindow()); - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/CollapseAllAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/CollapseAllAction.java index 873e68ff2..fa0987b2e 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/CollapseAllAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/CollapseAllAction.java @@ -12,19 +12,19 @@ package org.eclipse.debug.internal.ui.actions; import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; import org.eclipse.jface.action.Action; -import org.eclipse.jface.viewers.AbstractTreeViewer; /** * CollapseAllAction */ public class CollapseAllAction extends Action { - private AbstractTreeViewer fViewer; + private AsynchronousTreeViewer fViewer; - public CollapseAllAction(AbstractTreeViewer viewer) { - super(ActionMessages.CollapseAllAction_0, DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_COLLAPSE_ALL)); - setToolTipText(ActionMessages.CollapseAllAction_0); + public CollapseAllAction(AsynchronousTreeViewer viewer) { + super(ActionMessages.CollapseAllAction_0, DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_COLLAPSE_ALL)); + setToolTipText(ActionMessages.CollapseAllAction_0); setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_COLLAPSE_ALL)); setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_LCL_COLLAPSE_ALL)); fViewer = viewer; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/CopyToClipboardActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/CopyToClipboardActionDelegate.java index 9d6037c11..88b97f922 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/CopyToClipboardActionDelegate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/CopyToClipboardActionDelegate.java @@ -23,19 +23,20 @@ import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ContentViewer; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWTError; import org.eclipse.swt.custom.BusyIndicator; import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; public class CopyToClipboardActionDelegate extends AbstractDebugActionDelegate { - private TreeViewer fViewer; + private ContentViewer fViewer; /** * @see AbstractDebugActionDelegate#initialize(IAction, ISelection) @@ -45,7 +46,7 @@ public class CopyToClipboardActionDelegate extends AbstractDebugActionDelegate { IDebugView adapter= (IDebugView)getView().getAdapter(IDebugView.class); if (adapter != null) { if (adapter.getViewer() instanceof ContentViewer) { - setViewer((TreeViewer) adapter.getViewer()); + setViewer((ContentViewer) adapter.getViewer()); } adapter.setAction(getActionId(), action); } @@ -134,15 +135,20 @@ public class CopyToClipboardActionDelegate extends AbstractDebugActionDelegate { * remove the child. */ protected Iterator pruneSelection() { - TreeItem[] selection= getViewer().getTree().getSelection(); - List items= new ArrayList(selection.length); - for (int i = 0; i < selection.length; i++) { - TreeItem item= selection[i]; - if (isEnabledFor(item.getData())) { - if(walkHierarchy(item, items)) { - items.add(item); + Control control = getViewer().getControl(); + List items = new ArrayList(); + if (control instanceof Tree) { + Tree tree = (Tree) control; + TreeItem[] selection = tree.getSelection(); + + for (int i = 0; i < selection.length; i++) { + TreeItem item = selection[i]; + if (isEnabledFor(item.getData())) { + if (walkHierarchy(item, items)) { + items.add(item); + } } - } + } } return items.iterator(); } @@ -167,11 +173,11 @@ public class CopyToClipboardActionDelegate extends AbstractDebugActionDelegate { return data instanceof IDebugTarget || data instanceof IThread; } - protected TreeViewer getViewer() { + protected ContentViewer getViewer() { return fViewer; } - protected void setViewer(TreeViewer viewer) { + protected void setViewer(ContentViewer viewer) { fViewer = viewer; } /** diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/DisconnectActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/DisconnectActionDelegate.java deleted file mode 100644 index bc2ee1866..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/DisconnectActionDelegate.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.IDisconnect; - -public class DisconnectActionDelegate extends AbstractListenerActionDelegate { - - /** - * @see AbstractDebugActionDelegate#doAction(Object) - */ - protected void doAction(Object element) throws DebugException { - if (element instanceof IDisconnect) { - ((IDisconnect) element).disconnect(); - } - } - - /** - * @see AbstractDebugActionDelegate#isRunInBackground() - */ - protected boolean isRunInBackground() { - return true; - } - - /** - * @see AbstractDebugActionDelegate#isEnabledFor(Object) - */ - protected boolean isEnabledFor(Object element) { - return element instanceof IDisconnect && ((IDisconnect) element).canDisconnect(); - } - - /** - * @see AbstractDebugActionDelegate#getStatusMessage() - */ - protected String getStatusMessage() { - return ActionMessages.DisconnectActionDelegate_Exceptions_occurred_attempting_to_disconnect__2; - } - - /** - * @see AbstractDebugActionDelegate#getErrorDialogMessage() - */ - protected String getErrorDialogMessage() { - return ActionMessages.DisconnectActionDelegate_Disconnect_failed_1; - } - - /** - * @see ListenerActionDelegate#doHandleDebugEvent(DebugEvent) - */ - protected void doHandleDebugEvent(DebugEvent event) { - if (event.getKind() == DebugEvent.TERMINATE && event.getSource() instanceof IDebugTarget) { - update(getAction(), getSelection()); - } - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/DropToFrameActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/DropToFrameActionDelegate.java deleted file mode 100644 index 5813bbfcd..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/DropToFrameActionDelegate.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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.internal.ui.actions; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IDropToFrame; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; - -/** - * Action delegate which performs a drop to frame. - */ -public class DropToFrameActionDelegate extends AbstractListenerActionDelegate { - - class UpdateJob extends Job { - IAction fAction; - ISelection fSelection; - - UpdateJob() { - super("Update Action Enablement"); //$NON-NLS-1$ System Job. Never intended to be seen by users. - } - - void setAction(IAction action) { - fAction = action; - } - void setSelection(ISelection selection) { - fSelection = selection; - } - - protected IStatus run(IProgressMonitor monitor) { - DropToFrameActionDelegate.super.update(fAction, fSelection); - return Status.OK_STATUS; - } - - } - - private UpdateJob fUpdateJob = new UpdateJob(); - - public DropToFrameActionDelegate() { - super(); - fUpdateJob.setSystem(true); - } - - /** - * Performs the drop to frame. - * @see AbstractDebugActionDelegate#doAction(Object) - */ - protected void doAction(Object element) throws DebugException { - if (element instanceof IDropToFrame) { - IDropToFrame dropToFrame= (IDropToFrame) element; - if (dropToFrame.canDropToFrame()) { - dropToFrame.dropToFrame(); - } - } - } - - /** - * @see AbstractDebugActionDelegate#isRunInBackground() - */ - protected boolean isRunInBackground() { - return true; - } - - /** - * Enable the action for implementers of IDropToFrame which are able to perform - * the drop to frame operation. - */ - protected boolean isEnabledFor(Object element) { - return element instanceof IDropToFrame && ((IDropToFrame) element).canDropToFrame(); - } - - protected void update(IAction action, ISelection selection) { - fUpdateJob.setAction(action); - fUpdateJob.setSelection(selection); - fUpdateJob.schedule(); - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/FindVariableAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/FindVariableAction.java deleted file mode 100644 index f951facf6..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/FindVariableAction.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 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 implementation - *******************************************************************************/ -package org.eclipse.debug.internal.ui.actions; - -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.debug.internal.ui.DebugUIPlugin; -import org.eclipse.debug.internal.ui.IDebugHelpContextIds; -import org.eclipse.debug.internal.ui.views.variables.VariablesView; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.texteditor.IUpdate; -import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; - -/** - * Action which prompts the user to help them find a variable in - * the variables view. - */ -public class FindVariableAction extends Action implements IUpdate { - - private class FindVariableDelegate extends AbstractListenerActionDelegate { - - protected void doAction(Object element) { - VariablesView view= (VariablesView) getView(); - Shell shell = view.getSite().getShell(); - FindVariableDialog dialog= new FindVariableDialog(shell, view); - dialog.open(); - } - - protected void update(IAction action, ISelection s) { - if (action != null) { - ((IUpdate) action).update(); - } - } - - protected void doHandleDebugEvent(DebugEvent event) { - update(getAction(), null); - } - - public void run(IAction action) { - doAction(null); - } - } - - private AbstractListenerActionDelegate fDelegate; - - public FindVariableAction(VariablesView view) { - setText(ActionMessages.FindVariableAction_0); - setId(DebugUIPlugin.getUniqueIdentifier() + ".FindVariableAction"); //$NON-NLS-1$ - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.FIND_VARIABLE_ACTION); - setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_REPLACE); - fDelegate= new FindVariableDelegate(); - fDelegate.init(view); - fDelegate.setAction(this); - } - - public void run() { - fDelegate.run(this); - } - - public void update() { - VariablesView view= (VariablesView) fDelegate.getView(); - if (view != null) { - Viewer viewer = view.getViewer(); - if (viewer != null) { - setEnabled(viewer.getInput() instanceof IStackFrame); - return; - } - } - setEnabled(false); - } - - public void dispose() { - fDelegate.dispose(); - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/FindVariableDialog.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/FindVariableDialog.java deleted file mode 100644 index d819ca1ec..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/FindVariableDialog.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 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 implementation - *******************************************************************************/ -package org.eclipse.debug.internal.ui.actions; - -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.core.model.IVariable; -import org.eclipse.debug.internal.ui.DebugUIPlugin; -import org.eclipse.debug.internal.ui.views.DebugViewDecoratingLabelProvider; -import org.eclipse.debug.internal.ui.views.DebugViewInterimLabelProvider; -import org.eclipse.debug.internal.ui.views.DebugViewLabelDecorator; -import org.eclipse.debug.internal.ui.views.variables.VariablesView; -import org.eclipse.debug.internal.ui.views.variables.VariablesViewer; -import org.eclipse.debug.ui.IDebugModelPresentation; -import org.eclipse.debug.ui.IValueDetailListener; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.internal.ide.StringMatcher; - -public class FindVariableDialog extends Dialog { - - private TableViewer fViewer; - private VariablesView fView; - private Text fText; - private StringMatcher fMatcher; - private int fTextLength; - - private class FindVariableContentProvider implements IStructuredContentProvider { - public void dispose() { - } - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - public Object[] getElements(Object inputElement) { - return getVariables(((VariablesViewer) fView.getViewer()).getTree().getItems()); - } - private IVariable[] getVariables(TreeItem[] items) { - List variables= new ArrayList(); - getVariables(items, variables); - return (IVariable[]) variables.toArray(new IVariable[variables.size()]); - } - private void getVariables(TreeItem[] items, List variables) { - for (int i = 0; i < items.length; i++) { - Object data = items[i].getData(); - if (data instanceof IVariable) { - variables.add(data); - } - getVariables(items[i].getItems(), variables); - } - } - } - - private class FindVariableFilter extends ViewerFilter { - public boolean select(Viewer viewer, Object parentElement, Object element) { - if (fMatcher == null) { - return true; - } - try { - String name= ((IVariable) element).getName(); - fMatcher.match(name, 0, fTextLength - 1); - return fMatcher.match(name); - } catch (DebugException e) { - } - return false; - } - } - - private class FindVariableModelPresentation implements IDebugModelPresentation { - public Image getImage(Object element) { - IVariable variable= (IVariable) element; - IDebugModelPresentation presentation= fView.getPresentation(variable.getModelIdentifier()); - return presentation.getImage(element); - } - public String getText(Object element) { - try { - return ((IVariable) element).getName(); - } catch (DebugException e) { - DebugUIPlugin.log(e.getStatus()); - } - return ActionMessages.FindVariableDialog_0; - } - public void setAttribute(String attribute, Object value) {} - public void computeDetail(IValue value, IValueDetailListener listener) {} - public void addListener(ILabelProviderListener listener) {} - public void dispose() {} - public boolean isLabelProperty(Object element, String property) { - return false; - } - public void removeListener(ILabelProviderListener listener) {} - public IEditorInput getEditorInput(Object element) { - return null; - } - public String getEditorId(IEditorInput input, Object element) { - return null; - } - } - - protected FindVariableDialog(Shell parentShell, VariablesView view) { - super(parentShell); - fView= view; - } - - protected Control createDialogArea(Composite parent) { - Composite composite= (Composite) super.createDialogArea(parent); - - Label label= new Label(composite, SWT.NONE); - label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - label.setFont(parent.getFont()); - label.setText(ActionMessages.FindVariableDialog_1); - - fText= new Text(composite, SWT.SINGLE | SWT.BORDER); - fText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fText.setFont(parent.getFont()); - fText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - textModified(); - } - }); - - label= new Label(composite, SWT.NONE); - label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - label.setFont(parent.getFont()); - label.setText(ActionMessages.FindVariableDialog_2); - - fViewer= new TableViewer(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); - Table table = fViewer.getTable(); - GridData gridData = new GridData(GridData.FILL_BOTH); - gridData.heightHint= 200; - table.setLayoutData(gridData); - table.setFont(parent.getFont()); - fViewer.setContentProvider(new FindVariableContentProvider()); - fViewer.addFilter(new FindVariableFilter()); - fViewer.setInput(new Object()); - FindVariableModelPresentation presentation = new FindVariableModelPresentation(); - ILabelProvider provider= new DebugViewDecoratingLabelProvider(fViewer, new DebugViewInterimLabelProvider(presentation), new DebugViewLabelDecorator(presentation)); - fViewer.setLabelProvider(provider); - fViewer.addPostSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - FindVariableDialog.this.selectionChanged(); - } - }); - - return composite; - } - - private void textModified() { - StringBuffer text = new StringBuffer(fText.getText()); - if (text.length() == 0 || text.charAt(text.length() - 1) != '*') { - text.append("*"); //$NON-NLS-1$ - } - fMatcher= new StringMatcher(text.toString(), true, false); - fTextLength= text.length(); - fViewer.refresh(false); - if (((IStructuredSelection) fViewer.getSelection()).isEmpty()) { - Table table= fViewer.getTable(); - if (table.getItemCount() > 0) { - fViewer.setSelection(new StructuredSelection(table.getItem(0).getData())); - selectionChanged(); - } - } - } - - private void selectionChanged() { - fView.getViewer().setSelection(fViewer.getSelection(), true); - } - - protected void createButtonsForButtonBar(Composite parent) { - createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, - true); - } - - protected void configureShell(Shell newShell) { - newShell.setText(ActionMessages.FindVariableDialog_3); - super.configureShell(newShell); - } - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveAllBreakpointsAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveAllBreakpointsAction.java deleted file mode 100644 index 29213a6c6..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveAllBreakpointsAction.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.core.resources.IMarkerDelta; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IBreakpointManager; -import org.eclipse.debug.core.IBreakpointsListener; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.internal.ui.DebugUIPlugin; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchWindow; - -/** - * Removes all breakpoints from the source (markers) and remove all - * breakpoints from processes - */ -public class RemoveAllBreakpointsAction extends AbstractRemoveAllActionDelegate implements IBreakpointsListener { - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.actions.AbstractRemoveAllActionDelegate#doAction() - */ - protected void doAction() { - final IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager(); - final IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(); - if (breakpoints.length < 1) { - return; - } - IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow(); - if (window == null) { - return; - } - boolean proceed = MessageDialog.openQuestion(window.getShell(), ActionMessages.RemoveAllBreakpointsAction_0, ActionMessages.RemoveAllBreakpointsAction_1); // - if (proceed) { - new Job(ActionMessages.RemoveAllBreakpointsAction_2) { - protected IStatus run(IProgressMonitor monitor) { - try { - breakpointManager.removeBreakpoints(breakpoints, true); - } catch (CoreException e) { - DebugUIPlugin.log(e); - return Status.CANCEL_STATUS; - } - return Status.OK_STATUS; - } - }.schedule(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.actions.AbstractRemoveAllActionDelegate#update() - */ - protected void update() { - getAction().setEnabled( - DebugPlugin.getDefault().getBreakpointManager().hasBreakpoints()); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsAdded(org.eclipse.debug.core.model.IBreakpoint[]) - */ - public void breakpointsAdded(IBreakpoint[] breakpoints) { - if (getAction() != null && !getAction().isEnabled()){ - update(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsChanged(org.eclipse.debug.core.model.IBreakpoint[], org.eclipse.core.resources.IMarkerDelta[]) - */ - public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { - } - - /* (non-Javadoc) - * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsRemoved(org.eclipse.debug.core.model.IBreakpoint[], org.eclipse.core.resources.IMarkerDelta[]) - */ - public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { - if (getAction() != null) { - update(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) - */ - public void init(IViewPart view) { - super.init(view); - DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() - */ - public void dispose() { - DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this); - super.dispose(); - } - - - /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) - */ - public void init(IWorkbenchWindow window) { - super.init(window); - DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveAllExpressionsAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveAllExpressionsAction.java deleted file mode 100644 index 127c8829d..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveAllExpressionsAction.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IExpressionManager; -import org.eclipse.debug.core.model.IExpression; - -/** - * Removes all expressions from the expressions view. - */ -public class RemoveAllExpressionsAction extends AbstractRemoveAllActionDelegate { - - protected void doAction() { - IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager(); - IExpression[] expressions= manager.getExpressions(); - manager.removeExpressions(expressions); - } - - protected void update() { - getAction().setEnabled( - DebugPlugin.getDefault().getExpressionManager().hasExpressions()); - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveAllTerminatedAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveAllTerminatedAction.java deleted file mode 100644 index 17b80999a..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveAllTerminatedAction.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.debug.core.DebugEvent; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.core.ILaunchManager; -import org.eclipse.debug.core.ILaunchesListener; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.IProcess; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.ui.IViewPart; - -/** - * Removes all terminated/detached launches from the - * active debug view. - */ -public class RemoveAllTerminatedAction extends AbstractRemoveAllActionDelegate implements ILaunchesListener { - - /** - * @see ListenerActionDelegate#doHandleDebugEvent(DebugEvent) - */ - protected void doHandleDebugEvent(DebugEvent event) { - if (event.getKind() == DebugEvent.TERMINATE) { - Object source = event.getSource(); - if (event.getKind() == DebugEvent.TERMINATE && (source instanceof IDebugTarget || source instanceof IProcess)) { - update(); - } - } - } - - /** - * Updates the enabled state of this action to enabled if at - * least one launch is terminated and relative to the current perspective. - */ - protected void update() { - ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches(); - if (launches != null) { - for (int i= 0; i < launches.length; i++) { - if (launches[i].isTerminated()) { - getAction().setEnabled(true); - return; - } - } - } - getAction().setEnabled(false); - } - - protected void doAction() { - ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches(); - removeTerminatedLaunches(launches); - } - - public static void removeTerminatedLaunches(ILaunch[] elements) { - List removed = new ArrayList(); - for (int i = 0; i < elements.length; i++) { - ILaunch launch = elements[i]; - if (launch.isTerminated()) { - removed.add(launch); - } - } - if (!removed.isEmpty()) { - ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); - manager.removeLaunches((ILaunch[])removed.toArray(new ILaunch[removed.size()])); - } - } - - /** - * @see IViewActionDelegate#init(IViewPart) - */ - public void init(IViewPart view) { - super.init(view); - DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); - DebugPlugin.getDefault().addDebugEventListener(this); - } - - /** - * @see IWorkbenchWindowActionDelegate#dispose() - */ - public void dispose() { - //removes as a debug event listener - super.dispose(); - DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this); - IViewPart view = getView(); - if (view != null) { - view.getSite().getSelectionProvider().removeSelectionChangedListener((ISelectionChangedListener) getAction()); - } - } - - /** - * @see ILaunchesListener#launchesAdded(ILaunch[]) - */ - public void launchesAdded(ILaunch[] launches) { - } - - /** - * @see ILaunchesListener#launchesChanged(ILaunch[]) - */ - public void launchesChanged(ILaunch[] launches) { - } - - /** - * @see ILaunchesListener#launchesRemoved(ILaunch[]) - */ - public void launchesRemoved(ILaunch[] launches) { - if (getAction().isEnabled()) { - update(); - } - } -} - diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveBreakpointAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveBreakpointAction.java deleted file mode 100644 index 3fb9528de..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveBreakpointAction.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.internal.ui.DebugUIPlugin; -import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointContainer; -import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchWindow; - -public class RemoveBreakpointAction extends AbstractRemoveActionDelegate { - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run(IAction action) { - IStructuredSelection selection= getSelection(); - if (selection.isEmpty()) { - return; - } - final List state = ((BreakpointsView)getView()).getSelectionState(); - final Iterator itr= selection.iterator(); - final CoreException[] exception= new CoreException[1]; - IWorkspaceRunnable runnable= new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) { - List breakpointsToDelete= new ArrayList(); - boolean deleteContainers= false; - while (itr.hasNext()) { - Object next= itr.next(); - if (next instanceof IBreakpoint) { - breakpointsToDelete.add(next); - } else if (next instanceof BreakpointContainer) { - if (!deleteContainers) { - // Prompt the user to delete containers only once. - deleteContainers = MessageDialog.openConfirm(getView().getSite().getShell(), ActionMessages.RemoveBreakpointAction_0, ActionMessages.RemoveBreakpointAction_1); // - if (!deleteContainers) { - // User cancelled. Do nothing - return; - } - } - // To get here, deletion has to have been confirmed. - IBreakpoint[] breakpoints = ((BreakpointContainer) next).getBreakpoints(); - for (int i = 0; i < breakpoints.length; i++) { - breakpointsToDelete.add(breakpoints[i]); - } - } - } - final IBreakpoint[] breakpoints= (IBreakpoint[]) breakpointsToDelete.toArray(new IBreakpoint[0]); - new Job(ActionMessages.RemoveBreakpointAction_2) { - protected IStatus run(IProgressMonitor pmonitor) { - try { - DebugPlugin.getDefault().getBreakpointManager().removeBreakpoints(breakpoints, true); - if (state != null) { - Runnable r = new Runnable() { - - public void run() { - ((BreakpointsView) getView()).preserveSelectionState(state); - } - }; - DebugUIPlugin.getStandardDisplay().asyncExec(r); - } - return Status.OK_STATUS; - } catch (CoreException e) { - DebugUIPlugin.log(e); - } - return Status.CANCEL_STATUS; - } - }.schedule(); - } - }; - try { - ResourcesPlugin.getWorkspace().run(runnable, null, 0, null); - } catch (CoreException ce) { - exception[0]= ce; - } - if (exception[0] != null) { - IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow(); - if (window != null) { - DebugUIPlugin.errorDialog(window.getShell(), ActionMessages.RemoveBreakpointAction_Removing_a_breakpoint_4,ActionMessages.RemoveBreakpointAction_Exceptions_occurred_attempting_to_remove_a_breakpoint__5 , exception[0]); // - } else { - DebugUIPlugin.log(exception[0]); - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#doAction(java.lang.Object) - */ - protected void doAction(Object element) { - //not used - } - - protected boolean isEnabledFor(Object element) { - if (element instanceof BreakpointContainer) - return ((BreakpointContainer)element).getChildren().length > 0; - return super.isEnabledFor(element); - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveExpressionAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveExpressionAction.java deleted file mode 100644 index a699857c1..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RemoveExpressionAction.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IExpressionManager; -import org.eclipse.debug.core.model.IExpression; -import org.eclipse.debug.ui.IDebugView; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.Viewer; - -public class RemoveExpressionAction extends AbstractRemoveActionDelegate { - - protected void doAction(Object element) { - IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager(); - IExpression exp = getExpression(element); - if (exp != null) { - manager.removeExpression(exp); - } - } - - /** - * Returns the expression associated with the given - * element. - * - * @param element an expression of child of an expression in - * the expression view. - * @return associated expression - */ - protected IExpression getExpression(Object obj) { - if (getView() == null) { - return null; - } - IDebugView adapter= (IDebugView)getView().getAdapter(IDebugView.class); - if (adapter != null) { - Viewer v= adapter.getViewer(); - if (v instanceof TreeViewer) { - ITreeContentProvider cp = (ITreeContentProvider)((TreeViewer)v).getContentProvider(); - while (!(obj instanceof IExpression) && obj != null) { - obj = cp.getParent(obj); - } - return (IExpression)obj; - } - } - return null; - } -} - diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ResumeActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ResumeActionDelegate.java deleted file mode 100644 index 3901fe488..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ResumeActionDelegate.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import java.util.Iterator; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.ISuspendResume; -import org.eclipse.debug.core.model.IThread; -import org.eclipse.jface.viewers.IStructuredSelection; - -public class ResumeActionDelegate extends AbstractListenerActionDelegate { - - /** - * @see AbstractDebugActionDelegate#doAction(Object) - */ - protected void doAction(Object object) throws DebugException { - if (isEnabledFor(object)) { - ISuspendResume resume = (ISuspendResume)object; - resume.resume(); - } else { - doActionForAllThreads(object); - } - } - - /** - * Resumes all threads in the target associated with the given element - * - * @param object debug element - * @throws DebugException on failure - */ - protected void doActionForAllThreads(Object object) throws DebugException { - if (isEnabledForAllThreads(object)) { - IDebugElement debugElement = (IDebugElement) object; - IThread[] threads = debugElement.getDebugTarget().getThreads(); - for (int i = 0; i < threads.length; i++) { - IThread thread = threads[i]; - if (thread.canResume()) { - thread.resume(); - } - } - } - } - - /** - * @see AbstractDebugActionDelegate#isRunInBackground() - */ - protected boolean isRunInBackground() { - return true; - } - - /** - * @see AbstractDebugActionDelegate#isEnabledFor(Object) - */ - protected boolean isEnabledFor(Object element) { - return element instanceof ISuspendResume && ((ISuspendResume) element).canResume(); - } - - /** - * @see AbstractDebugActionDelegate#getEnableStateForSelection(IStructuredSelection) - */ - protected boolean getEnableStateForSelection(IStructuredSelection selection) { - if (selection.isEmpty()) { - return false; - } - for (Iterator i = selection.iterator(); i.hasNext(); ) { - Object element = i.next(); - if (!(isEnabledFor(element) || isEnabledForAllThreads(element))) { - return false; - } - } - return true; - } - - /** - * Returns whether 'resume all threads' should be enabled for the given element. - */ - protected boolean isEnabledForAllThreads(Object element) { - if (element instanceof IDebugElement) { - IDebugElement debugElement = (IDebugElement) element; - try { - IThread[] threads = debugElement.getDebugTarget().getThreads(); - for (int i = 0; i < threads.length; i++) { - if (threads[i].canResume()) { - return true; - } - } - } catch (DebugException e) { - } - } - return false; - } - - /** - * @see AbstractDebugActionDelegate#getStatusMessage() - */ - protected String getStatusMessage() { - return ActionMessages.ResumeActionDelegate_Exceptions_occurred_attempting_to_resume__2; - } - - /** - * @see AbstractDebugActionDelegate#getErrorDialogMessage() - */ - protected String getErrorDialogMessage() { - return ActionMessages.ResumeActionDelegate_Resume_failed__1; - } - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllAction.java deleted file mode 100644 index 0b0155de8..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllAction.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.debug.ui.IDebugView; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.ui.IViewPart; - -public abstract class SelectAllAction extends AbstractListenerActionDelegate { - - /** - * @see IViewActionDelegate#init(IViewPart) - */ - public void init(IViewPart view) { - setView(view); - setWindow(view.getViewSite().getWorkbenchWindow()); - } - - /** - * @see AbstractDebugActionDelegate#initialize(IAction, ISelection) - */ - protected boolean initialize(IAction action, ISelection selection) { - if (!isInitialized()) { - IDebugView debugView = - (IDebugView) getView().getAdapter(IDebugView.class); - if (debugView != null) { - debugView.setAction(getActionId(), action); - } - return super.initialize(action, selection); - } - return false; - } - - protected abstract String getActionId(); - - /** - * @see IActionDelegate#run(IAction) - */ - public void run(IAction action){ - doAction(null); - } - - /** - * @see AbstractDebugActionDelegate#doAction(Object) - */ - protected void doAction(Object element) { - if (!(getView() instanceof IDebugView)) { - return; - } - Viewer viewer = ((IDebugView) getView()).getViewer(); - if (!(viewer instanceof TreeViewer)) { - return; - } - ((TreeViewer) viewer).getTree().selectAll(); - //ensure that the selection change callback is fired - viewer.setSelection(viewer.getSelection()); - } - - protected abstract void update(); - - protected void update(IAction action, ISelection selection) { - update(); - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllBreakpointsAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllBreakpointsAction.java deleted file mode 100644 index fb1b285bd..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllBreakpointsAction.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.core.resources.IMarkerDelta; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IBreakpointsListener; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView; -import org.eclipse.debug.ui.IDebugView; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.ui.IViewPart; - -public class SelectAllBreakpointsAction extends SelectAllAction implements IBreakpointsListener { - - protected void update() { - getAction().setEnabled( - DebugPlugin.getDefault().getBreakpointManager().hasBreakpoints()); - } - - /** - * @see AbstractDebugActionDelegate#doAction(Object) - */ - protected void doAction(Object element) { - if (!(getView() instanceof BreakpointsView)) { - return; - } - CheckboxTreeViewer viewer = ((BreakpointsView) getView()).getCheckboxViewer(); - viewer.getTree().selectAll(); - //ensure that the selection change callback is fired - viewer.setSelection(viewer.getSelection()); - } - - /** - * @see IBreakpointsListener#breakpointsAdded(IBreakpoint[])breakpointAdded(IBreakpoint) - */ - public void breakpointsAdded(IBreakpoint[] breakpoints) { - if (getAction() != null && !getAction().isEnabled()) { - update(); - } - } - - /** - * @see IBreakpointsListener#breakpointsChanged(IBreakpoint[], IMarkerDelta[])breakpointChanged(IBreakpoint, IMarkerDelta) - */ - public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { - } - - /** - * @see IBreakpointsListener#breakpointsRemoved(IBreakpoint[], IMarkerDelta[]) - */ - public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { - if (getAction() != null) { - update(); - } - } - - /** - * @see IViewActionDelegate#init(IViewPart) - */ - public void init(IViewPart view) { - super.init(view); - DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); - } - - public void dispose() { - DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this); - super.dispose(); - } - - protected String getActionId() { - return IDebugView.SELECT_ALL_ACTION; - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllExpressionsAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllExpressionsAction.java deleted file mode 100644 index 58e0bcd69..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllExpressionsAction.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.ui.IDebugView; - -public class SelectAllExpressionsAction extends SelectAllAction { - - protected void update() { - getAction().setEnabled( - DebugPlugin.getDefault().getExpressionManager().hasExpressions()); - } - - protected String getActionId() { - return IDebugView.SELECT_ALL_ACTION + ".Variables"; //$NON-NLS-1$ - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllVariablesAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllVariablesAction.java deleted file mode 100644 index 88af02d21..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SelectAllVariablesAction.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.debug.ui.IDebugView; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.Viewer; - -public class SelectAllVariablesAction extends SelectAllAction { - - protected void update() { - if (!(getView() instanceof IDebugView)) { - return; - } - Viewer viewer= ((IDebugView)getView()).getViewer(); - getAction().setEnabled(((TreeViewer)viewer).getTree().getItemCount() != 0); - } - - protected String getActionId() { - return IDebugView.SELECT_ALL_ACTION + ".Variables"; //$NON-NLS-1$ - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepActionDelegate.java deleted file mode 100644 index 1a5fcdf3f..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepActionDelegate.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IStep; - -public abstract class StepActionDelegate extends AbstractListenerActionDelegate { - - /** - * @see AbstractDebugActionDelegate#doAction(Object) - */ - protected void doAction(Object object) throws DebugException { - if (object instanceof IStep) { - stepAction((IStep)object); - } - } - - /** - * @see AbstractDebugActionDelegate#isRunInBackground() - */ - protected boolean isRunInBackground() { - return true; - } - - /** - * @see AbstractDebugActionDelegate#isEnabledFor(Object) - */ - protected boolean isEnabledFor(Object element) { - if (element instanceof IStep) { - return checkCapability((IStep)element); - } - return false; - } - - /** - * Returns whether the IStep has the capability to perform the - * requested step action. - */ - protected abstract boolean checkCapability(IStep element); - - /** - * Performs the specific step action. - * - * @exception DebugException if the action fails - */ - protected abstract void stepAction(IStep element) throws DebugException; -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepIntoActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepIntoActionDelegate.java deleted file mode 100644 index 5c981a48e..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepIntoActionDelegate.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IStep; - -public class StepIntoActionDelegate extends StepActionDelegate { - - /** - * @see StepActionDelegate#checkCapability(IStep) - */ - protected boolean checkCapability(IStep element) { - return element.canStepInto(); - } - - /** - * @see StepActionDelegate#stepAction(IStep) - */ - protected void stepAction(IStep element) throws DebugException { - element.stepInto(); - } - - /** - * @see AbstractDebugActionDelegate#getStatusMessage() - */ - protected String getStatusMessage() { - return ActionMessages.StepIntoActionDelegate_Exceptions_occurred_attempting_to_step_into_the_frame_2; - } - - /** - * @see AbstractDebugActionDelegate#getErrorDialogMessage() - */ - protected String getErrorDialogMessage() { - return ActionMessages.StepIntoActionDelegate_Step_into_failed_1; - } - - /** - * @see org.eclipse.debug.internal.ui.actions.StepActionDelegate#getActionDefinitionId() - */ - protected String getActionDefinitionId() { - return "org.eclipse.debug.internal.ui.actions.StepIntoActionDelegate"; //$NON-NLS-1$ - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepOverActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepOverActionDelegate.java deleted file mode 100644 index d785453dc..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepOverActionDelegate.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IStep; - -public class StepOverActionDelegate extends StepActionDelegate { - - /** - * @see StepActionDelegate#checkCapability(IStep) - */ - protected boolean checkCapability(IStep element) { - return element.canStepOver(); - } - - /** - * @see StepActionDelegate#stepAction(IStep) - */ - protected void stepAction(IStep element) throws DebugException { - element.stepOver(); - } - - /** - * @see AbstractDebugActionDelegate#getStatusMessage() - */ - protected String getStatusMessage() { - return ActionMessages.StepOverActionDelegate_Exceptions_occurred_attempting_to_step_over_the_frame_2; - } - - /** - * @see AbstractDebugActionDelegate#getErrorDialogMessage() - */ - protected String getErrorDialogMessage() { - return ActionMessages.StepOverActionDelegate_Step_over_failed_1; - } - - /** - * @see org.eclipse.debug.internal.ui.actions.StepActionDelegate#getActionDefinitionId() - */ - protected String getActionDefinitionId() { - return "org.eclipse.debug.internal.ui.actions.StepOverActionDelegate"; //$NON-NLS-1$ - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepReturnActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepReturnActionDelegate.java deleted file mode 100644 index edbd7bfa7..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/StepReturnActionDelegate.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IStep; - -public class StepReturnActionDelegate extends StepActionDelegate { - - /** - * @see StepActionDelegate#checkCapability(IStep) - */ - protected boolean checkCapability(IStep element) { - return element.canStepReturn(); - } - - /** - * @see StepActionDelegate#stepAction(IStep) - */ - protected void stepAction(IStep element) throws DebugException { - element.stepReturn(); - } - - /** - * @see AbstractDebugActionDelegate#getStatusMessage() - */ - protected String getStatusMessage() { - return ActionMessages.StepReturnActionDelegate_Exceptions_occurred_attempting_to_run_to_return_of_the_frame__2; - } - - /** - * @see AbstractDebugActionDelegate#getErrorDialogMessage() - */ - protected String getErrorDialogMessage() { - return ActionMessages.StepReturnActionDelegate_Run_to_return_failed__1; - } - - /** - * @see org.eclipse.debug.internal.ui.actions. - * StepActionDelegate#getActionDefinitionId() - */ - protected String getActionDefinitionId() { - return "org.eclipse.debug.internal.ui.actions.StepReturnActionDelegate"; //$NON-NLS-1$ - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SuspendActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SuspendActionDelegate.java deleted file mode 100644 index e813a3e99..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SuspendActionDelegate.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.ISuspendResume; - -public class SuspendActionDelegate extends AbstractListenerActionDelegate { - - /** - * @see AbstractDebugActionDelegate#doAction(Object) - */ - protected void doAction(Object element) throws DebugException { - if (element instanceof ISuspendResume) { - ((ISuspendResume) element).suspend(); - } - } - - /** - * @see AbstractDebugActionDelegate#isRunInBackground() - */ - protected boolean isRunInBackground() { - return true; - } - - /** - * @see AbstractDebugActionDelegate#isEnabledFor(Object) - */ - protected boolean isEnabledFor(Object element) { - return element instanceof ISuspendResume && ((ISuspendResume)element).canSuspend(); - } - - /** - * @see AbstractDebugActionDelegate#getStatusMessage() - */ - protected String getStatusMessage() { - return ActionMessages.SuspendActionDelegate_Exceptions_occurred_attempting_to_suspend__2; - } - - /** - * @see AbstractDebugActionDelegate#getErrorDialogMessage() - */ - protected String getErrorDialogMessage() { - return ActionMessages.SuspendActionDelegate_Suspend_failed_1; - } - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateActionDelegate.java deleted file mode 100644 index 06d9894ef..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateActionDelegate.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -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.IProcess; -import org.eclipse.debug.core.model.ITerminate; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; - -public class TerminateActionDelegate extends AbstractListenerActionDelegate { - - /** - * @see AbstractDebugActionDelegate#doAction(Object) - */ - protected void doAction(Object element) throws DebugException { - if (element instanceof ITerminate) { - if (element instanceof IProcess) { - killTargets((IProcess) element); - } - ((ITerminate)element).terminate(); - } - } - - private void killTargets(IProcess process) throws DebugException { - ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); - ILaunch[] launches = launchManager.getLaunches(); - - for (int i = 0; i < launches.length; i++) { - ILaunch launch = launches[i]; - IProcess[] processes = launch.getProcesses(); - for (int j = 0; j < processes.length; j++) { - IProcess process2 = processes[j]; - if (process2.equals(process)) { - IDebugTarget[] debugTargets = launch.getDebugTargets(); - for (int k = 0; k < debugTargets.length; k++) { - IDebugTarget target = debugTargets[k]; - if (target.canTerminate()) { - target.terminate(); - } - } - return; // all possible targets have been terminated for the launch. - } - } - } - } - - /** - * @see AbstractDebugActionDelegate#isRunInBackground() - */ - protected boolean isRunInBackground() { - return true; - } - - /** - * @see AbstractDebugActionDelegate#isEnabledFor(Object) - */ - protected boolean isEnabledFor(Object element) { - return element instanceof ITerminate && ((ITerminate)element).canTerminate(); - } - - /** - * @see AbstractDebugActionDelegate#getStatusMessage() - */ - protected String getStatusMessage() { - return ActionMessages.TerminateActionDelegate_Exceptions_occurred_attempting_to_terminate__2; - } - - /** - * @see AbstractDebugActionDelegate#getErrorDialogMessage() - */ - protected String getErrorDialogMessage() { - return ActionMessages.TerminateActionDelegate_Terminate_failed__1; - } - - /** - * @see ListenerActionDelegate#doHandleDebugEvent(DebugEvent) - */ - protected void doHandleDebugEvent(DebugEvent event) { - if (event.getKind() == DebugEvent.TERMINATE || event.getKind() == DebugEvent.CREATE) { - update(getAction(), getSelection()); - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#update(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) - */ - protected void update(IAction action, ISelection s) { - // ignore non-structured selections (for example, text selection in console) - if (s instanceof IStructuredSelection) { - super.update(action, s); - } - } - - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateAllAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateAllAction.java deleted file mode 100644 index f24fceb94..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateAllAction.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -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.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; - -/** - * Terminates all launches. - */ -public class TerminateAllAction extends AbstractListenerActionDelegate { - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#doAction(java.lang.Object) - */ - protected void doAction(Object element) throws DebugException { - if (element instanceof ILaunch) { - ILaunch launch = (ILaunch) element; - if (!launch.isTerminated() && DebugPlugin.getDefault().getLaunchManager().isRegistered(launch)) { - launch.terminate(); - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#isRunInBackground() - */ - protected boolean isRunInBackground() { - return true; - } - - /** - * Update the action enablement based on the launches present in - * the launch manager. selection is unused and can be null. - * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#update(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) - */ - protected void update(IAction action, ISelection selection) { - ILaunchManager lManager= DebugPlugin.getDefault().getLaunchManager(); - ILaunch[] launches= lManager.getLaunches(); - for (int i= 0; i< launches.length; i++) { - ILaunch launch= launches[i]; - if (!launch.isTerminated()) { - action.setEnabled(true); - return; - } - } - action.setEnabled(false); - } - - /* (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) { - setAction(action); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.actions.AbstractListenerActionDelegate#doHandleDebugEvent(org.eclipse.debug.core.DebugEvent) - */ - protected void doHandleDebugEvent(DebugEvent event) { - switch (event.getKind()) { - case DebugEvent.TERMINATE : - update(getAction(), null); - break; - case DebugEvent.CREATE : - update(getAction(), null); - break; - } - } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#getSelection() - */ - protected IStructuredSelection getSelection() { - return new StructuredSelection(DebugPlugin.getDefault().getLaunchManager().getLaunches()); - } - - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateAndRelaunchAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateAndRelaunchAction.java deleted file mode 100644 index 0762f3b00..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateAndRelaunchAction.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 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 implementation - *******************************************************************************/ -package org.eclipse.debug.internal.ui.actions; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.core.model.ITerminate; -import org.eclipse.debug.internal.ui.DebugUIPlugin; - -/** - * Action which terminates a launch and then relaunches it. - * This is equivalent to the Terminate action followed by - * Relaunch, but is provided to the user as a convenience. - */ -public class TerminateAndRelaunchAction extends AbstractListenerActionDelegate { - - protected void doAction(Object element) throws DebugException { - final ILaunch launch= RelaunchActionDelegate.getLaunch(element); - if (launch == null || !(element instanceof ITerminate)) { - // Shouldn't happen because of enablement check. - return; - } - - ((ITerminate)element).terminate(); - DebugUIPlugin.getStandardDisplay().asyncExec(new Runnable() { - public void run() { - // Must be run in the UI thread since the launch can require prompting to proceed - RelaunchActionDelegate.relaunch(launch.getLaunchConfiguration(), launch.getLaunchMode()); - } - }); - } - - /** - * @see AbstractDebugActionDelegate#isRunInBackground() - */ - protected boolean isRunInBackground() { - return true; - } - - /** - * @see AbstractDebugActionDelegate#isEnabledFor(Object) - */ - protected boolean isEnabledFor(Object element) { - return element instanceof ITerminate && ((ITerminate)element).canTerminate() && - RelaunchActionDelegate.getLaunch(element) != null; - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateAndRemoveActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateAndRemoveActionDelegate.java deleted file mode 100644 index 65dcc6ecd..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/TerminateAndRemoveActionDelegate.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.actions; - - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.ITerminate; -import org.eclipse.debug.internal.ui.views.launch.LaunchView; - -public class TerminateAndRemoveActionDelegate extends AbstractDebugActionDelegate { - - /** - * @see AbstractDebugActionDelegate#doAction(Object) - */ - protected void doAction(Object element) throws DebugException { - LaunchView.terminateAndRemove(element); - } - - /** - * @see AbstractDebugActionDelegate#isRunInBackground() - */ - protected boolean isRunInBackground() { - return true; - } - - /** - * @see AbstractDebugActionDelegate#isEnabledFor(Object) - */ - protected boolean isEnabledFor(Object element) { - if (element instanceof ITerminate) { - ITerminate terminate= (ITerminate)element; - //do not want to terminate an attach launch that does not - //have termination enabled - return terminate.canTerminate() || terminate.isTerminated(); - } - return false; - } - - /** - * @see AbstractDebugActionDelegate#getStatusMessage() - */ - protected String getStatusMessage() { - return ActionMessages.TerminateAndRemoveActionDelegate_Exceptions_occurred_attempting_to_terminate_and_remove_2; - } - - /** - * @see AbstractDebugActionDelegate#getErrorDialogMessage() - */ - protected String getErrorDialogMessage() { - return ActionMessages.TerminateAndRemoveActionDelegate_Terminate_and_remove_failed_1; - } - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/DebugContextManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/DebugContextManager.java new file mode 100644 index 000000000..f3ac0b4f9 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/DebugContextManager.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.contexts; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.debug.ui.contexts.IDebugContextListener; +import org.eclipse.debug.ui.contexts.IDebugContextManager; +import org.eclipse.debug.ui.contexts.IDebugContextProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; + +/** + * @since 3.2 + */ +public class DebugContextManager implements IDebugContextManager { + + private static DebugContextManager fgDefault; + private Map fServices = new HashMap(); + + private DebugContextManager() { + } + + public static IDebugContextManager getDefault() { + if (fgDefault == null) { + fgDefault = new DebugContextManager(); + } + return fgDefault; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextManager#addDebugContextProvider(org.eclipse.debug.ui.contexts.IDebugContextProvider) + */ + public void addDebugContextProvider(IDebugContextProvider provider) { + IWorkbenchPart part = provider.getPart(); + IWorkbenchWindow window = part.getSite().getWorkbenchWindow(); + DebugWindowContextService service = createService(window); + service.addProvider(provider); + } + + protected DebugWindowContextService createService(IWorkbenchWindow window) { + DebugWindowContextService service = (DebugWindowContextService) fServices.get(window); + if (service == null) { + service = new DebugWindowContextService(window); + fServices.put(window, service); + // TODO: register 'null' provider (global) + } + return service; + } + + protected IDebugContextService getService(IWorkbenchWindow window) { + return (DebugWindowContextService) fServices.get(window); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextManager#removeDebugContextProvider(org.eclipse.debug.ui.contexts.IDebugContextProvider) + */ + public void removeDebugContextProvider(IDebugContextProvider provider) { + IWorkbenchPart part = provider.getPart(); + IWorkbenchWindow window = part.getSite().getWorkbenchWindow(); + DebugWindowContextService service = (DebugWindowContextService) fServices.get(window); + if (service != null) { + service.removeProvider(provider); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextManager#addDebugContextListener(org.eclipse.debug.ui.contexts.IDebugContextListener, org.eclipse.ui.IWorkbenchWindow) + */ + public void addDebugContextListener(IDebugContextListener listener, IWorkbenchWindow window) { + IDebugContextService service = createService(window); + service.addDebugContextListener(listener); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextManager#removeDebugContextListener(org.eclipse.debug.ui.contexts.IDebugContextListener, org.eclipse.ui.IWorkbenchWindow) + */ + public void removeDebugContextListener(IDebugContextListener listener, IWorkbenchWindow window) { + IDebugContextService service = getService(window); + if (service != null) { + service.removeDebugContextListener(listener); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextManager#addDebugContextListener(org.eclipse.debug.ui.contexts.IDebugContextListener, org.eclipse.ui.IWorkbenchWindow, java.lang.String) + */ + public void addDebugContextListener(IDebugContextListener listener, IWorkbenchWindow window, String partId) { + DebugWindowContextService service = createService(window); + service.addDebugContextListener(listener, partId); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextManager#removeDebugContextListener(org.eclipse.debug.ui.contexts.IDebugContextListener, org.eclipse.ui.IWorkbenchWindow, java.lang.String) + */ + public void removeDebugContextListener(IDebugContextListener listener, IWorkbenchWindow window, String partId) { + IDebugContextService service = getService(window); + if (service != null) { + service.removeDebugContextListener(listener, partId); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextManager#getActiveContext(org.eclipse.ui.IWorkbenchWindow) + */ + public ISelection getActiveContext(IWorkbenchWindow window) { + IDebugContextService service = getService(window); + if (service != null) { + return service.getActiveContext(); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextManager#getActiveContext(org.eclipse.ui.IWorkbenchWindow, java.lang.String) + */ + public ISelection getActiveContext(IWorkbenchWindow window, String partId) { + IDebugContextService service = getService(window); + if (service != null) { + return service.getActiveContext(partId); + } + return null; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/DebugWindowContextService.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/DebugWindowContextService.java new file mode 100644 index 000000000..8397fb433 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/DebugWindowContextService.java @@ -0,0 +1,261 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.contexts; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.ISafeRunnable; +import org.eclipse.core.runtime.Platform; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.ui.contexts.IDebugContextListener; +import org.eclipse.debug.ui.contexts.IDebugContextProvider; +import org.eclipse.jface.util.ListenerList; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IPartListener2; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartReference; +import org.eclipse.ui.IWorkbenchWindow; + +/** + * Context service for a specific window. + * + * @since 3.2 + */ +public class DebugWindowContextService implements IDebugContextService, IPartListener2, IDebugContextListener { + + private Map fListenersByPartId = new HashMap(); + private Map fProvidersByPartId = new HashMap(); + + private IWorkbenchWindow fWindow; + private List fProviders = new ArrayList(); + + public DebugWindowContextService(IWorkbenchWindow window) { + fWindow = window; + fWindow.getPartService().addPartListener(this); + } + + public void dispose() { + fWindow.getPartService().removePartListener(this); + fWindow = null; + } + + protected synchronized void addProvider(IDebugContextProvider provider) { + IWorkbenchPart part = provider.getPart(); + String id = null; + if (part != null) { + id = part.getSite().getId(); + } + fProvidersByPartId.put(part, id); + fProviders.add(provider); + IWorkbenchPart active = null; + IWorkbenchPage activePage = fWindow.getActivePage(); + if (activePage != null) { + active = activePage.getActivePart(); + } + if (fProviders.size() == 1 && (part == null || part.equals(active))) { + notifyActivated(); + } + provider.addDebugContextListener(this); + } + + protected synchronized void removeProvider(IDebugContextProvider provider) { + int index = fProviders.indexOf(provider); + if (index >= 0) { + IWorkbenchPart part = provider.getPart(); + String id = null; + if (part != null) { + id = part.getSite().getId(); + } + fProvidersByPartId.remove(id); + fProviders.remove(index); + if (index == 0) { + notifyActivated(); + } + } + provider.removeDebugContextListener(this); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextService#addDebugContextListener(org.eclipse.debug.ui.contexts.IDebugContextListener) + */ + public void addDebugContextListener(IDebugContextListener listener) { + addDebugContextListener(listener, null); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextService#removeDebugContextListener(org.eclipse.debug.ui.contexts.IDebugContextListener) + */ + public void removeDebugContextListener(IDebugContextListener listener) { + removeDebugContextListener(listener, null); + } + + protected void notifyActivated() { + if (fProviders.isEmpty()) { + notifyActivated(null, null); + } else { + IDebugContextProvider provider = (IDebugContextProvider) fProviders.get(0); + notifyActivated(provider.getActiveContext(), provider.getPart()); + } + } + + protected void notifyActivated(ISelection context, IWorkbenchPart part) { + notifyActivated(getListeners(null), context, part); + if (part != null) { + notifyActivated(getListeners(part), context, part); + } + } + protected void notifyActivated(ListenerList list, final ISelection context, final IWorkbenchPart part) { + if (list != null) { + Object[] listeners = list.getListeners(); + for (int i = 0; i < listeners.length; i++) { + final IDebugContextListener listener = (IDebugContextListener) listeners[i]; + Platform.run(new ISafeRunnable() { + public void run() throws Exception { + listener.contextActivated(context, part); + } + public void handleException(Throwable exception) { + DebugUIPlugin.log(exception); + } + }); + } + } + } + + protected ListenerList getListeners(IWorkbenchPart part) { + String id = null; + if (part != null) { + id = part.getSite().getId(); + } + return (ListenerList) fListenersByPartId.get(id); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextService#addDebugContextListener(org.eclipse.debug.ui.contexts.IDebugContextListener, java.lang.String) + */ + public synchronized void addDebugContextListener(IDebugContextListener listener, String partId) { + ListenerList list = (ListenerList) fListenersByPartId.get(partId); + if (list == null) { + list = new ListenerList(); + fListenersByPartId.put(partId, list); + } + list.add(listener); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextService#removeDebugContextListener(org.eclipse.debug.ui.contexts.IDebugContextListener, java.lang.String) + */ + public void removeDebugContextListener(IDebugContextListener listener, String partId) { + ListenerList list = (ListenerList) fListenersByPartId.get(partId); + if (list != null) { + list.remove(listener); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextService#getActiveContext(java.lang.String) + */ + public ISelection getActiveContext(String partId) { + IDebugContextProvider provider = (IDebugContextProvider) fProvidersByPartId.get(partId); + if (provider != null) { + return provider.getActiveContext(); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextService#getActiveContext() + */ + public ISelection getActiveContext() { + if (!fProviders.isEmpty()) { + ((IDebugContextProvider)fProviders.get(0)).getActiveContext(); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener2#partActivated(org.eclipse.ui.IWorkbenchPartReference) + */ + public void partActivated(IWorkbenchPartReference partRef) { + Object provider = fProvidersByPartId.get(partRef.getId()); + if (provider != null) { + int index = fProviders.indexOf(provider); + if (index > 0) { + fProviders.remove(index); + fProviders.add(0, provider); + notifyActivated(); + } + } + + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener2#partBroughtToTop(org.eclipse.ui.IWorkbenchPartReference) + */ + public void partBroughtToTop(IWorkbenchPartReference partRef) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference) + */ + public synchronized void partClosed(IWorkbenchPartReference partRef) { + IDebugContextProvider provider = (IDebugContextProvider) fProvidersByPartId.get(partRef.getId()); + if (provider != null) { + removeProvider(provider); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener2#partDeactivated(org.eclipse.ui.IWorkbenchPartReference) + */ + public void partDeactivated(IWorkbenchPartReference partRef) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference) + */ + public void partOpened(IWorkbenchPartReference partRef) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener2#partHidden(org.eclipse.ui.IWorkbenchPartReference) + */ + public void partHidden(IWorkbenchPartReference partRef) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener2#partVisible(org.eclipse.ui.IWorkbenchPartReference) + */ + public void partVisible(IWorkbenchPartReference partRef) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener2#partInputChanged(org.eclipse.ui.IWorkbenchPartReference) + */ + public void partInputChanged(IWorkbenchPartReference partRef) { + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextListener#contextActivated(java.lang.Object, org.eclipse.ui.IWorkbenchPart) + */ + public synchronized void contextActivated(ISelection context, IWorkbenchPart part) { + if (!fProviders.isEmpty()) { + IDebugContextProvider provider = (IDebugContextProvider) fProviders.get(0); + if (provider.getPart() == part) { + notifyActivated(); + } + } + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/IDebugContextService.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/IDebugContextService.java new file mode 100644 index 000000000..146f262e3 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/IDebugContextService.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.contexts; + +import org.eclipse.debug.ui.contexts.IDebugContextListener; +import org.eclipse.jface.viewers.ISelection; + + +/** + * Debug context service for a window. + * + * @since 3.2 + */ +public interface IDebugContextService { + + /** + * Registers for context activation notification in this service. + * + * @param listener + */ + public void addDebugContextListener(IDebugContextListener listener); + /** + * Deregisters for context activation notification in this service. + * + * @param listener + */ + public void removeDebugContextListener(IDebugContextListener listener); + + /** + * Registers for context activation notification in the specified part. + * + * @param listener + * @param partId + */ + public void addDebugContextListener(IDebugContextListener listener, String partId); + + /** + * Deregisters for context activation notification in the specified part. + * + * @param listener + * @param partId + */ + public void removeDebugContextListener(IDebugContextListener listener, String partId); + + /** + * Returns the active context in this service's window + * or null. + * + * @return + */ + public ISelection getActiveContext(); + + /** + * Returns the active context in the specified part or null. + * + * @param partId + * @return + */ + public ISelection getActiveContext(String partId); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/LaunchSuspendTrigger.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/LaunchSuspendTrigger.java new file mode 100644 index 000000000..5c9e57cff --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/LaunchSuspendTrigger.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.contexts; + +import org.eclipse.core.runtime.ISafeRunnable; +import org.eclipse.core.runtime.Platform; +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IDebugEventSetListener; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.model.IDebugElement; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.core.model.IThread; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.ui.contexts.ISuspendTrigger; +import org.eclipse.debug.ui.contexts.ISuspendTriggerListener; +import org.eclipse.jface.util.ListenerList; + +/** + * @since 3.2 + */ +public class LaunchSuspendTrigger implements ISuspendTrigger, IDebugEventSetListener { + + private ListenerList fListeners = new ListenerList(); + + public LaunchSuspendTrigger() { + DebugPlugin.getDefault().addDebugEventListener(this); + } + + protected void dispose() { + fListeners.clear(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.ISuspendTrigger#addSuspendTriggerListener(org.eclipse.debug.ui.contexts.ISuspendTriggerListener) + */ + public void addSuspendTriggerListener(ISuspendTriggerListener listener) { + fListeners.add(listener); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.ISuspendTrigger#removeSuspendTriggerListener(org.eclipse.debug.ui.contexts.ISuspendTriggerListener) + */ + public void removeSuspendTriggerListener(ISuspendTriggerListener listener) { + fListeners.remove(listener); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[]) + */ + public void handleDebugEvents(DebugEvent[] events) { + // open the debugger if this is a suspend event and the debug view is not yet open + // and the preferences are set to switch + for (int i = 0; i < events.length; i++) { + DebugEvent event = events[i]; + if (event.getKind() == DebugEvent.SUSPEND && !event.isEvaluation() && event.getDetail() != DebugEvent.STEP_END) { + // Don't switch perspective for evaluations or stepping + notifySuspend(event); + } + } + } + + /** + * @param event + */ + private void notifySuspend(DebugEvent event) { + Object source = event.getSource(); + if (source instanceof IDebugElement) { + final ILaunch launch = ((IDebugElement)source).getLaunch(); + Object context = null; + if (source instanceof IThread) { + try { + context = ((IThread)source).getTopStackFrame(); + } catch (DebugException e) { + } + } else if (source instanceof IDebugTarget) { + context = source; + } + final Object temp = context; + Object[] listeners = fListeners.getListeners(); + for (int i = 0; i < listeners.length; i++) { + final ISuspendTriggerListener listener = (ISuspendTriggerListener) listeners[i]; + Platform.run(new ISafeRunnable() { + public void run() throws Exception { + listener.suspended(launch, temp); + } + + public void handleException(Throwable exception) { + DebugUIPlugin.log(exception); + } + + }); + } + + } + + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/SuspendTriggerAdapterFactory.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/SuspendTriggerAdapterFactory.java new file mode 100644 index 000000000..056b7c418 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/SuspendTriggerAdapterFactory.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.contexts; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.ui.contexts.ISuspendTrigger; + +/** + * @since 3.2 + */ +public class SuspendTriggerAdapterFactory implements IAdapterFactory { + + private static ISuspendTrigger fgTrigger = new LaunchSuspendTrigger(); + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) + */ + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adapterType.equals(ISuspendTrigger.class)) { + if (adaptableObject instanceof ILaunch) { + return fgTrigger; + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() + */ + public Class[] getAdapterList() { + return new Class[]{ISuspendTrigger.class}; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/AbstractDebugContextActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/AbstractDebugContextActionDelegate.java new file mode 100644 index 000000000..5fe1dea6f --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/AbstractDebugContextActionDelegate.java @@ -0,0 +1,462 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + +import java.util.Iterator; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.internal.ui.contexts.DebugContextManager; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.debug.ui.contexts.IDebugContextListener; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IActionDelegate2; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; +import org.eclipse.ui.progress.IWorkbenchSiteProgressService; + +public abstract class AbstractDebugContextActionDelegate implements IWorkbenchWindowActionDelegate, IViewActionDelegate, IActionDelegate2, IDebugContextListener { + + /** + * The underlying action for this delegate + */ + private IAction fAction; + /** + * This action's view part, or null if not installed in a + * view. + */ + private IViewPart fViewPart; + + /** + * Cache of the most recent seletion + */ + private IStructuredSelection fSelection = StructuredSelection.EMPTY; + + /** + * Whether this delegate has been initialized + */ + private boolean fInitialized = false; + + /** + * The window associated with this action delegate May be null + */ + protected IWorkbenchWindow fWindow; + + /** + * Background job for this action, or null if none. + */ + private DebugRequestJob fBackgroundJob = null; + + /** + * Background job to update enablement. + */ + private UpdateEnablementJob fUpdateEnablementJob = new UpdateEnablementJob(); + + /** + * Used to schedule jobs, or null if none + */ + private IWorkbenchSiteProgressService fProgressService = null; + + class UpdateEnablementJob extends Job { + + IAction targetAction = null; + ISelection targetSelection = null; + + public UpdateEnablementJob() { + super(ActionMessages.AbstractDebugActionDelegate_1); + setPriority(Job.INTERACTIVE); + setSystem(true); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + protected IStatus run(IProgressMonitor monitor) { + IAction action = null; + ISelection selection = null; + synchronized (this) { + action = targetAction; + selection = targetSelection; + } + update(action, selection); + return Status.OK_STATUS; + } + + public synchronized void setTargets(IAction action, ISelection selection) { + targetAction = action; + targetSelection = selection; + } + } + + class DebugRequestJob extends Job { + + private Object[] fElements = null; + + /** + * Constructs a new job to perform a debug request (for example, step) + * in the background. + * + * @param name job name + */ + public DebugRequestJob(String name) { + super(name); + setPriority(Job.INTERACTIVE); + setSystem(true); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + protected IStatus run(IProgressMonitor monitor) { + MultiStatus status = new MultiStatus(DebugUIPlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, getStatusMessage(), null); + Object[] targets = null; + synchronized (this) { + targets = fElements; + fElements = null; + } + for (int i = 0; i < targets.length; i++) { + Object element = targets[i]; + Object target = getTarget(element); + try { + // Action's enablement could have been changed since + // it was last enabled. Check that the action is still + // enabled before running the action. + if (target != null && isEnabledFor(target)) + doAction(target); + } catch (DebugException e) { + status.merge(e.getStatus()); + } + } + return status; + } + + /** + * Sets the selection to operate on. + * + * @param elements + */ + public synchronized void setTargets(Object[] elements) { + fElements = elements; + } + + } + + /** + * It's crucial that delegate actions have a zero-arg constructor so that + * they can be reflected into existence when referenced in an action set in + * the plugin's plugin.xml file. + */ + public AbstractDebugContextActionDelegate() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() + */ + public void dispose() { + IWorkbenchWindow window = getWindow(); + if (getWindow() != null) { + IViewPart view = getView(); + if (view != null) { + String partId = view.getSite().getId(); + DebugContextManager.getDefault().removeDebugContextListener(this, window, partId); + } else { + DebugContextManager.getDefault().removeDebugContextListener(this, window); + } + } + fBackgroundJob = null; + fSelection = null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) + */ + public void init(IWorkbenchWindow window) { + setWindow(window); + DebugContextManager.getDefault().addDebugContextListener(this, window); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run(IAction action) { + if (action.isEnabled()) { + IStructuredSelection selection = getContext(); + // disable the action so it cannot be run again until an event or + // selection change updates the enablement + action.setEnabled(false); + runInBackground(action, selection); + } + } + + /** + * Runs this action in a background job. + */ + private void runInBackground(IAction action, IStructuredSelection selection) { + if (fBackgroundJob == null) { + fBackgroundJob = new DebugRequestJob(DebugUIPlugin.removeAccelerators(action.getText())); + } + fBackgroundJob.setTargets(selection.toArray()); + schedule(fBackgroundJob); + } + + /** + * AbstractDebugActionDelegates come in 2 flavors: IViewActionDelegate, + * IWorkbenchWindowActionDelegate delegates. + *

+ *
    + *
  • IViewActionDelegate delegate: getView() != null
  • + *
  • IWorkbenchWindowActionDelegate: getView == null
  • + *
+ *

+ * Only want to call update(action, selection) for IViewActionDelegates. An + * initialize call to update(action, selection) is made for all flavors to + * set the initial enabled state of the underlying action. + * IWorkbenchWindowActionDelegate's listen to selection changes in the debug + * view only. + *

+ * + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, + * org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IAction action, ISelection s) { + boolean wasInitialized = initialize(action, s); + if (!wasInitialized) { + if (getView() != null) { + fUpdateEnablementJob.setTargets(action, s); + schedule(fUpdateEnablementJob); + + } + } + } + + protected void update(IAction action, ISelection s) { + if (s instanceof IStructuredSelection) { + IStructuredSelection ss = (IStructuredSelection) s; + action.setEnabled(getEnableStateForContext(ss)); + setContext(ss); + } else { + action.setEnabled(false); + setContext(StructuredSelection.EMPTY); + } + } + + /** + * Performs the specific action on this element. + */ + protected abstract void doAction(Object element) throws DebugException; + + /** + * Returns the String to use as an error dialog message for a failed action. + * This message appears as the "Message:" in the error dialog for this + * action. Default is to return null. + */ + protected String getErrorDialogMessage() { + return null; + } + + /** + * Returns the String to use as a status message for a failed action. This + * message appears as the "Reason:" in the error dialog for this action. + * Default is to return the empty String. + */ + protected String getStatusMessage() { + return ""; //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) + */ + public void init(IViewPart view) { + fViewPart = view; + fProgressService = (IWorkbenchSiteProgressService) view.getAdapter(IWorkbenchSiteProgressService.class); + } + + /** + * Returns this action's view part, or null if not installed + * in a view. + * + * @return view part or null + */ + protected IViewPart getView() { + return fViewPart; + } + + /** + * Initialize this delegate, updating this delegate's presentation. As well, + * all of the flavors of AbstractDebugActionDelegates need to have the + * initial enabled state set with a call to update(IAction, ISelection). + * + * @param action the presentation for this action + * @return whether the action was initialized + */ + protected boolean initialize(IAction action, ISelection selection) { + if (!isInitialized()) { + setAction(action); + if (getView() == null) { + // update on the selection in the debug view + IWorkbenchWindow window = getWindow(); + if (window != null && window.getShell() != null && !window.getShell().isDisposed()) { + IWorkbenchPage page = window.getActivePage(); + if (page != null) { + selection = page.getSelection(IDebugUIConstants.ID_DEBUG_VIEW); + } + } + } + update(action, selection); + setInitialized(true); + return true; + } + return false; + } + + /** + * Returns the most recent selection + * + * @return structured selection + */ + protected IStructuredSelection getContext() { + return fSelection; + } + + /** + * Sets the most recent selection + * + * @parm selection structured selection + */ + private void setContext(IStructuredSelection context) { + fSelection = context; + } + + public void contextActivated(ISelection context, IWorkbenchPart part) { + fUpdateEnablementJob.setTargets(getAction(), context); + schedule(fUpdateEnablementJob); + } + + protected void setAction(IAction action) { + fAction = action; + } + + protected IAction getAction() { + return fAction; + } + + protected void setView(IViewPart viewPart) { + fViewPart = viewPart; + } + + protected boolean isInitialized() { + return fInitialized; + } + + protected void setInitialized(boolean initialized) { + fInitialized = initialized; + } + + protected IWorkbenchWindow getWindow() { + return fWindow; + } + + protected void setWindow(IWorkbenchWindow window) { + fWindow = window; + } + + /** + * Return whether the action should be enabled or not based on the given + * selection. + */ + protected boolean getEnableStateForContext(IStructuredSelection selection) { + if (selection.size() == 0) { + return false; + } + Iterator itr = selection.iterator(); + while (itr.hasNext()) { + Object element = itr.next(); + Object target = getTarget(element); + if (target == null || !isEnabledFor(target)) { + return false; + } + } + return true; + } + + /** + * Translates the selected object to the target to operate + * on as required. For example, an adpater on the selection. + * + * @param selectee + * @return target to operate/enable action on + */ + protected Object getTarget(Object selectee) { + return selectee; + } + + protected boolean isEnabledFor(Object element) { + return true; + } + + /* + * (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); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) + */ + public void init(IAction action) { + } + + /** + * Schedules the given job with this action's progress service + * + * @param job + */ + private void schedule(Job job) { + if (fProgressService == null) { + job.schedule(); + } else { + fProgressService.schedule(job); + } + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/AbstractRemoveActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/AbstractRemoveActionDelegate.java new file mode 100755 index 000000000..0bf3a1a4b --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/AbstractRemoveActionDelegate.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +import org.eclipse.debug.ui.IDebugView; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IViewPart; + +public abstract class AbstractRemoveActionDelegate extends AbstractDebugContextActionDelegate { + + /** + * @see IViewActionDelegate#init(IViewPart) + */ + public void init(IViewPart view) { + setView(view); + setWindow(view.getViewSite().getWorkbenchWindow()); + } + + /** + * @see AbstractDebugActionDelegate#initialize(IAction, ISelection) + */ + protected boolean initialize(IAction action, ISelection selection) { + if (!isInitialized()) { + IDebugView debugView= (IDebugView)getView().getAdapter(IDebugView.class); + if (debugView != null) { + debugView.setAction(IDebugView.REMOVE_ACTION, action); + } + return super.initialize(action, selection); + } + return false; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/AbstractRemoveAllActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/AbstractRemoveAllActionDelegate.java new file mode 100755 index 000000000..bc89eebb8 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/AbstractRemoveAllActionDelegate.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IViewPart; + +public abstract class AbstractRemoveAllActionDelegate extends AbstractDebugContextActionDelegate { + + /** + * @see AbstractDebugActionDelegate#doAction(Object) + */ + protected void doAction(Object element) { + doAction(); + update(); + } + + /** + * @see IActionDelegate#run(IAction) + */ + public void run(IAction action){ + doAction(null); + } + + protected abstract void doAction(); + + protected void update(IAction action, ISelection s) { + update(); + } + + protected abstract void update(); + + /** + * Remove all actions do care nothing about the current selection + * @see IActionDelegate#selectionChanged(IAction, ISelection) + */ + public void selectionChanged(IAction action, ISelection s) { + if (!isInitialized()) { + action.setEnabled(false); + setAction(action); + setInitialized(true); + } + update(); + } + + /** + * @see IViewActionDelegate#init(IViewPart) + */ + public void init(IViewPart view) { + setView(view); + setWindow(view.getViewSite().getWorkbenchWindow()); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/DisconnectActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/DisconnectActionDelegate.java new file mode 100755 index 000000000..d995da663 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/DisconnectActionDelegate.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.core.model.IDisconnect; +import org.eclipse.debug.internal.ui.actions.ActionMessages; + +public class DisconnectActionDelegate extends AbstractDebugContextActionDelegate { + + /** + * @see AbstractDebugActionDelegate#doAction(Object) + */ + protected void doAction(Object element) throws DebugException { + if (element instanceof IDisconnect) { + ((IDisconnect) element).disconnect(); + } + } + + /** + * @see AbstractDebugActionDelegate#isEnabledFor(Object) + */ + protected boolean isEnabledFor(Object element) { + return element instanceof IDisconnect && ((IDisconnect) element).canDisconnect(); + } + + /** + * @see AbstractDebugActionDelegate#getStatusMessage() + */ + protected String getStatusMessage() { + return ActionMessages.DisconnectActionDelegate_Exceptions_occurred_attempting_to_disconnect__2; + } + + /** + * @see AbstractDebugActionDelegate#getErrorDialogMessage() + */ + protected String getErrorDialogMessage() { + return ActionMessages.DisconnectActionDelegate_Disconnect_failed_1; + } + + /** + * @see ListenerActionDelegate#doHandleDebugEvent(DebugEvent) + */ + protected void doHandleDebugEvent(DebugEvent event) { + if (event.getKind() == DebugEvent.TERMINATE && event.getSource() instanceof IDebugTarget) { + update(getAction(), getContext()); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.contexts.actions.AbstractDebugContextActionDelegate#getTarget(java.lang.Object) + */ + protected Object getTarget(Object selectee) { + if (selectee instanceof IDisconnect) { + return selectee; + } + if (selectee instanceof IAdaptable) { + return ((IAdaptable)selectee).getAdapter(IDisconnect.class); + } + return null; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/DropToFrameActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/DropToFrameActionDelegate.java new file mode 100755 index 000000000..70d628202 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/DropToFrameActionDelegate.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.contexts.actions; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IDropToFrame; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; + +/** + * Action delegate which performs a drop to frame. + */ +public class DropToFrameActionDelegate extends AbstractDebugContextActionDelegate { + + class UpdateJob extends Job { + IAction fAction; + ISelection fSelection; + + UpdateJob() { + super("Update Action Enablement"); //$NON-NLS-1$ System Job. Never intended to be seen by users. + } + + void setAction(IAction action) { + fAction = action; + } + void setSelection(ISelection selection) { + fSelection = selection; + } + + protected IStatus run(IProgressMonitor monitor) { + DropToFrameActionDelegate.super.update(fAction, fSelection); + return Status.OK_STATUS; + } + + } + + private UpdateJob fUpdateJob = new UpdateJob(); + + public DropToFrameActionDelegate() { + super(); + fUpdateJob.setSystem(true); + } + + /** + * Performs the drop to frame. + * @see AbstractDebugActionDelegate#doAction(Object) + */ + protected void doAction(Object element) throws DebugException { + if (element instanceof IDropToFrame) { + IDropToFrame dropToFrame= (IDropToFrame) element; + if (dropToFrame.canDropToFrame()) { + dropToFrame.dropToFrame(); + } + } + } + + /** + * Enable the action for implementers of IDropToFrame which are able to perform + * the drop to frame operation. + */ + protected boolean isEnabledFor(Object element) { + return element instanceof IDropToFrame && ((IDropToFrame) element).canDropToFrame(); + } + + protected void update(IAction action, ISelection selection) { + fUpdateJob.setAction(action); + fUpdateJob.setSelection(selection); + fUpdateJob.schedule(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.contexts.actions.AbstractDebugContextActionDelegate#getTarget(java.lang.Object) + */ + protected Object getTarget(Object selectee) { + if (selectee instanceof IDropToFrame) { + return selectee; + } + if (selectee instanceof IAdaptable) { + return ((IAdaptable)selectee).getAdapter(IDropToFrame.class); + } + return null; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/FindVariableAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/FindVariableAction.java new file mode 100755 index 000000000..99ff587f3 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/FindVariableAction.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2004, 2005 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 implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.contexts.actions; + +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.IDebugHelpContextIds; +import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.internal.ui.views.variables.VariablesView; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.texteditor.IUpdate; +import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; + +/** + * Action which prompts the user to help them find a variable in the variables + * view. + */ +public class FindVariableAction extends Action implements IUpdate { + + private class FindVariableDelegate extends AbstractDebugContextActionDelegate { + + protected void doAction(Object element) { + VariablesView view = (VariablesView) getView(); + Shell shell = view.getSite().getShell(); + FindVariableDialog dialog = new FindVariableDialog(shell, view); + dialog.open(); + } + + protected void update(IAction action, ISelection s) { + if (action != null) { + ((IUpdate) action).update(); + } + } + + public void run(IAction action) { + doAction(null); + } + } + + private AbstractDebugContextActionDelegate fDelegate; + + public FindVariableAction(VariablesView view) { + setText(ActionMessages.FindVariableAction_0); + setId(DebugUIPlugin.getUniqueIdentifier() + ".FindVariableAction"); //$NON-NLS-1$ + PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.FIND_VARIABLE_ACTION); + setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_REPLACE); + fDelegate = new FindVariableDelegate(); + fDelegate.init(view); + fDelegate.setAction(this); + } + + public void run() { + fDelegate.run(this); + } + + public void update() { + VariablesView view = (VariablesView) fDelegate.getView(); + if (view != null) { + Viewer viewer = view.getViewer(); + if (viewer != null) { + setEnabled(viewer.getInput() instanceof IStackFrame); + return; + } + } + setEnabled(false); + } + + public void dispose() { + fDelegate.dispose(); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/FindVariableDialog.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/FindVariableDialog.java new file mode 100755 index 000000000..3b8e86c53 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/FindVariableDialog.java @@ -0,0 +1,211 @@ +/******************************************************************************* + * Copyright (c) 2004, 2005 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 implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.contexts.actions; + +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.core.model.IVariable; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; +import org.eclipse.debug.internal.ui.views.DebugViewDecoratingLabelProvider; +import org.eclipse.debug.internal.ui.views.DebugViewInterimLabelProvider; +import org.eclipse.debug.internal.ui.views.DebugViewLabelDecorator; +import org.eclipse.debug.internal.ui.views.variables.VariablesView; +import org.eclipse.debug.ui.IDebugModelPresentation; +import org.eclipse.debug.ui.IValueDetailListener; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.internal.ide.StringMatcher; + +public class FindVariableDialog extends Dialog { + + private TableViewer fViewer; + private VariablesView fView; + private Text fText; + private StringMatcher fMatcher; + private int fTextLength; + + private class FindVariableContentProvider implements IStructuredContentProvider { + public void dispose() { + } + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + public Object[] getElements(Object inputElement) { + return getVariables(((AsynchronousTreeViewer) fView.getViewer()).getTree().getItems()); + } + private IVariable[] getVariables(TreeItem[] items) { + List variables= new ArrayList(); + getVariables(items, variables); + return (IVariable[]) variables.toArray(new IVariable[variables.size()]); + } + private void getVariables(TreeItem[] items, List variables) { + for (int i = 0; i < items.length; i++) { + Object data = items[i].getData(); + if (data instanceof IVariable) { + variables.add(data); + } + getVariables(items[i].getItems(), variables); + } + } + } + + private class FindVariableFilter extends ViewerFilter { + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (fMatcher == null) { + return true; + } + try { + String name= ((IVariable) element).getName(); + fMatcher.match(name, 0, fTextLength - 1); + return fMatcher.match(name); + } catch (DebugException e) { + } + return false; + } + } + + private class FindVariableModelPresentation implements IDebugModelPresentation { + public Image getImage(Object element) { + IVariable variable= (IVariable) element; + IDebugModelPresentation presentation= fView.getPresentation(variable.getModelIdentifier()); + return presentation.getImage(element); + } + public String getText(Object element) { + try { + return ((IVariable) element).getName(); + } catch (DebugException e) { + DebugUIPlugin.log(e.getStatus()); + } + return ActionMessages.FindVariableDialog_0; + } + public void setAttribute(String attribute, Object value) {} + public void computeDetail(IValue value, IValueDetailListener listener) {} + public void addListener(ILabelProviderListener listener) {} + public void dispose() {} + public boolean isLabelProperty(Object element, String property) { + return false; + } + public void removeListener(ILabelProviderListener listener) {} + public IEditorInput getEditorInput(Object element) { + return null; + } + public String getEditorId(IEditorInput input, Object element) { + return null; + } + } + + protected FindVariableDialog(Shell parentShell, VariablesView view) { + super(parentShell); + fView= view; + } + + protected Control createDialogArea(Composite parent) { + Composite composite= (Composite) super.createDialogArea(parent); + + Label label= new Label(composite, SWT.NONE); + label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + label.setFont(parent.getFont()); + label.setText(ActionMessages.FindVariableDialog_1); + + fText= new Text(composite, SWT.SINGLE | SWT.BORDER); + fText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + fText.setFont(parent.getFont()); + fText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + textModified(); + } + }); + + label= new Label(composite, SWT.NONE); + label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + label.setFont(parent.getFont()); + label.setText(ActionMessages.FindVariableDialog_2); + + fViewer= new TableViewer(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + Table table = fViewer.getTable(); + GridData gridData = new GridData(GridData.FILL_BOTH); + gridData.heightHint= 200; + table.setLayoutData(gridData); + table.setFont(parent.getFont()); + fViewer.setContentProvider(new FindVariableContentProvider()); + fViewer.addFilter(new FindVariableFilter()); + fViewer.setInput(new Object()); + FindVariableModelPresentation presentation = new FindVariableModelPresentation(); + ILabelProvider provider= new DebugViewDecoratingLabelProvider(fViewer, new DebugViewInterimLabelProvider(presentation), new DebugViewLabelDecorator(presentation)); + fViewer.setLabelProvider(provider); + fViewer.addPostSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + FindVariableDialog.this.selectionChanged(); + } + }); + + return composite; + } + + private void textModified() { + StringBuffer text = new StringBuffer(fText.getText()); + if (text.length() == 0 || text.charAt(text.length() - 1) != '*') { + text.append("*"); //$NON-NLS-1$ + } + fMatcher= new StringMatcher(text.toString(), true, false); + fTextLength= text.length(); + fViewer.refresh(false); + if (((IStructuredSelection) fViewer.getSelection()).isEmpty()) { + Table table= fViewer.getTable(); + if (table.getItemCount() > 0) { + fViewer.setSelection(new StructuredSelection(table.getItem(0).getData())); + selectionChanged(); + } + } + } + + private void selectionChanged() { + fView.getViewer().setSelection(fViewer.getSelection(), true); + } + + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, + true); + } + + protected void configureShell(Shell newShell) { + newShell.setText(ActionMessages.FindVariableDialog_3); + super.configureShell(newShell); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveAllBreakpointsAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveAllBreakpointsAction.java new file mode 100755 index 000000000..cc6d99128 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveAllBreakpointsAction.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +import org.eclipse.core.resources.IMarkerDelta; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IBreakpointManager; +import org.eclipse.debug.core.IBreakpointsListener; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchWindow; + +/** + * Removes all breakpoints from the source (markers) and remove all + * breakpoints from processes + */ +public class RemoveAllBreakpointsAction extends AbstractRemoveAllActionDelegate implements IBreakpointsListener { + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.actions.AbstractRemoveAllActionDelegate#doAction() + */ + protected void doAction() { + final IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager(); + final IBreakpoint[] breakpoints= breakpointManager.getBreakpoints(); + if (breakpoints.length < 1) { + return; + } + IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow(); + if (window == null) { + return; + } + boolean proceed = MessageDialog.openQuestion(window.getShell(), ActionMessages.RemoveAllBreakpointsAction_0, ActionMessages.RemoveAllBreakpointsAction_1); + if (proceed) { + new Job(ActionMessages.RemoveAllBreakpointsAction_2) { + protected IStatus run(IProgressMonitor monitor) { + try { + breakpointManager.removeBreakpoints(breakpoints, true); + } catch (CoreException e) { + DebugUIPlugin.log(e); + return Status.CANCEL_STATUS; + } + return Status.OK_STATUS; + } + }.schedule(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.actions.AbstractRemoveAllActionDelegate#update() + */ + protected void update() { + getAction().setEnabled( + DebugPlugin.getDefault().getBreakpointManager().hasBreakpoints()); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsAdded(org.eclipse.debug.core.model.IBreakpoint[]) + */ + public void breakpointsAdded(IBreakpoint[] breakpoints) { + if (getAction() != null && !getAction().isEnabled()){ + update(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsChanged(org.eclipse.debug.core.model.IBreakpoint[], org.eclipse.core.resources.IMarkerDelta[]) + */ + public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsRemoved(org.eclipse.debug.core.model.IBreakpoint[], org.eclipse.core.resources.IMarkerDelta[]) + */ + public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { + if (getAction() != null) { + update(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) + */ + public void init(IViewPart view) { + super.init(view); + DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() + */ + public void dispose() { + DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this); + super.dispose(); + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) + */ + public void init(IWorkbenchWindow window) { + super.init(window); + DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveAllExpressionsAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveAllExpressionsAction.java new file mode 100755 index 000000000..77c98d050 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveAllExpressionsAction.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IExpressionManager; +import org.eclipse.debug.core.model.IExpression; + +/** + * Removes all expressions from the expressions view. + */ +public class RemoveAllExpressionsAction extends AbstractRemoveAllActionDelegate { + + protected void doAction() { + IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager(); + IExpression[] expressions= manager.getExpressions(); + manager.removeExpressions(expressions); + } + + protected void update() { + getAction().setEnabled( + DebugPlugin.getDefault().getExpressionManager().hasExpressions()); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveAllTerminatedAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveAllTerminatedAction.java new file mode 100755 index 000000000..918714d12 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveAllTerminatedAction.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.ILaunchesListener2; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.ui.IViewPart; + +/** + * Removes all terminated/detached launches from the + * active debug view. + */ +public class RemoveAllTerminatedAction extends AbstractRemoveAllActionDelegate implements ILaunchesListener2 { + + /** + * Updates the enabled state of this action to enabled if at + * least one launch is terminated and relative to the current perspective. + */ + protected void update() { + ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches(); + if (launches != null) { + for (int i= 0; i < launches.length; i++) { + if (launches[i].isTerminated()) { + getAction().setEnabled(true); + return; + } + } + } + getAction().setEnabled(false); + } + + protected void doAction() { + ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches(); + removeTerminatedLaunches(launches); + } + + public static void removeTerminatedLaunches(ILaunch[] elements) { + List removed = new ArrayList(); + for (int i = 0; i < elements.length; i++) { + ILaunch launch = elements[i]; + if (launch.isTerminated()) { + removed.add(launch); + } + } + if (!removed.isEmpty()) { + ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); + manager.removeLaunches((ILaunch[])removed.toArray(new ILaunch[removed.size()])); + } + } + + /** + * @see IViewActionDelegate#init(IViewPart) + */ + public void init(IViewPart view) { + super.init(view); + DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); + } + + /** + * @see IWorkbenchWindowActionDelegate#dispose() + */ + public void dispose() { + //removes as a debug event listener + super.dispose(); + DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this); + IViewPart view = getView(); + if (view != null) { + view.getSite().getSelectionProvider().removeSelectionChangedListener((ISelectionChangedListener) getAction()); + } + } + + public void launchesAdded(ILaunch[] launches) { + } + + public void launchesChanged(ILaunch[] launches) { + } + + public void launchesRemoved(ILaunch[] launches) { + if (getAction().isEnabled()) { + update(); + } + } + + public void launchesTerminated(ILaunch[] launches) { + update(); + } +} + diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveBreakpointAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveBreakpointAction.java new file mode 100755 index 000000000..42b8b8a84 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveBreakpointAction.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointContainer; +import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbenchWindow; + +public class RemoveBreakpointAction extends AbstractRemoveActionDelegate { + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run(IAction action) { + IStructuredSelection selection= getContext(); + if (selection.isEmpty()) { + return; + } + final List state = ((BreakpointsView)getView()).getSelectionState(); + final Iterator itr= selection.iterator(); + final CoreException[] exception= new CoreException[1]; + IWorkspaceRunnable runnable= new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) { + List breakpointsToDelete= new ArrayList(); + boolean deleteContainers= false; + while (itr.hasNext()) { + Object next= itr.next(); + if (next instanceof IBreakpoint) { + breakpointsToDelete.add(next); + } else if (next instanceof BreakpointContainer) { + if (!deleteContainers) { + // Prompt the user to delete containers only once. + deleteContainers = MessageDialog.openConfirm(getView().getSite().getShell(), ActionMessages.RemoveBreakpointAction_0, ActionMessages.RemoveBreakpointAction_1); + if (!deleteContainers) { + // User cancelled. Do nothing + return; + } + } + // To get here, deletion has to have been confirmed. + IBreakpoint[] breakpoints = ((BreakpointContainer) next).getBreakpoints(); + for (int i = 0; i < breakpoints.length; i++) { + breakpointsToDelete.add(breakpoints[i]); + } + } + } + final IBreakpoint[] breakpoints= (IBreakpoint[]) breakpointsToDelete.toArray(new IBreakpoint[0]); + new Job(ActionMessages.RemoveBreakpointAction_2) { + protected IStatus run(IProgressMonitor pmonitor) { + try { + DebugPlugin.getDefault().getBreakpointManager().removeBreakpoints(breakpoints, true); + if (state != null) { + Runnable r = new Runnable() { + + public void run() { + ((BreakpointsView) getView()).preserveSelectionState(state); + } + }; + DebugUIPlugin.getStandardDisplay().asyncExec(r); + } + return Status.OK_STATUS; + } catch (CoreException e) { + DebugUIPlugin.log(e); + } + return Status.CANCEL_STATUS; + } + }.schedule(); + } + }; + try { + ResourcesPlugin.getWorkspace().run(runnable, null, 0, null); + } catch (CoreException ce) { + exception[0]= ce; + } + if (exception[0] != null) { + IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow(); + if (window != null) { + DebugUIPlugin.errorDialog(window.getShell(), ActionMessages.RemoveBreakpointAction_Removing_a_breakpoint_4,ActionMessages.RemoveBreakpointAction_Exceptions_occurred_attempting_to_remove_a_breakpoint__5 , exception[0]); + } else { + DebugUIPlugin.log(exception[0]); + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#doAction(java.lang.Object) + */ + protected void doAction(Object element) { + //not used + } + + protected boolean isEnabledFor(Object element) { + if (element instanceof BreakpointContainer) + return ((BreakpointContainer)element).getChildren().length > 0; + return super.isEnabledFor(element); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveExpressionAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveExpressionAction.java new file mode 100755 index 000000000..e143f3be4 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/RemoveExpressionAction.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IExpressionManager; +import org.eclipse.debug.core.model.IExpression; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; +import org.eclipse.debug.internal.ui.viewers.TreePath; +import org.eclipse.debug.internal.ui.viewers.TreeSelection; +import org.eclipse.debug.ui.IDebugView; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.ui.progress.WorkbenchJob; + +public class RemoveExpressionAction extends AbstractRemoveActionDelegate { + + protected void doAction(Object element) { + WorkbenchJob job = new WorkbenchJob("remove expression") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager(); + IExpression exp = getExpression(); + if (exp != null) { + manager.removeExpression(exp); + } + return Status.OK_STATUS; + } + }; + job.setSystem(true); + job.schedule(); + } + + /** + * Returns the expression associated with the given + * element. + * + * @param element an expression of child of an expression in + * the expression view. + * @return associated expression + */ + protected IExpression getExpression() { + if (getView() == null) { + return null; + } + IDebugView adapter= (IDebugView)getView().getAdapter(IDebugView.class); + if (adapter != null) { + Viewer v= adapter.getViewer(); + if (v instanceof AsynchronousTreeViewer) { + AsynchronousTreeViewer viewer = (AsynchronousTreeViewer) v; + TreeSelection selection = (TreeSelection) viewer.getSelection(); + TreePath[] paths = selection.getPaths(); + for (int i = paths.length-1; i >=0; i--) { + TreePath path = paths[i]; + Object segment = path.getLastSegment(); + if (segment instanceof IExpression) { + return (IExpression) segment; + } + } + } + } + return null; + } +} + diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/ResumeActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/ResumeActionDelegate.java new file mode 100755 index 000000000..14fd8358c --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/ResumeActionDelegate.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +import java.util.Iterator; + +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.ISuspendResume; +import org.eclipse.debug.core.model.IThread; +import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.jface.viewers.IStructuredSelection; + +public class ResumeActionDelegate extends AbstractDebugContextActionDelegate { + + /** + * @see AbstractDebugActionDelegate#doAction(Object) + */ + protected void doAction(Object object) throws DebugException { + if (isEnabledFor(object)) { + ISuspendResume resume = (ISuspendResume)object; + resume.resume(); + } else { + doActionForAllThreads(object); + } + } + + /** + * Resumes all threads in the target associated with the given element + * + * @param object debug element + * @throws DebugException on failure + */ + protected void doActionForAllThreads(Object object) throws DebugException { + if (isEnabledForAllThreads(object)) { + IDebugElement debugElement = (IDebugElement) object; + IThread[] threads = debugElement.getDebugTarget().getThreads(); + for (int i = 0; i < threads.length; i++) { + IThread thread = threads[i]; + if (thread.canResume()) { + thread.resume(); + } + } + } + } + + + /** + * @see AbstractDebugActionDelegate#isEnabledFor(Object) + */ + protected boolean isEnabledFor(Object element) { + return element instanceof ISuspendResume && ((ISuspendResume) element).canResume(); + } + + /** + * @see AbstractDebugActionDelegate#getEnableStateForSelection(IStructuredSelection) + */ + protected boolean getEnableStateForSelection(IStructuredSelection selection) { + if (selection.isEmpty()) { + return false; + } + for (Iterator i = selection.iterator(); i.hasNext(); ) { + Object element = i.next(); + if (!(isEnabledFor(element) || isEnabledForAllThreads(element))) { + return false; + } + } + return true; + } + + /** + * Returns whether 'resume all threads' should be enabled for the given element. + */ + protected boolean isEnabledForAllThreads(Object element) { + if (element instanceof IDebugElement) { + IDebugElement debugElement = (IDebugElement) element; + try { + IThread[] threads = debugElement.getDebugTarget().getThreads(); + for (int i = 0; i < threads.length; i++) { + if (threads[i].canResume()) { + return true; + } + } + } catch (DebugException e) { + } + } + return false; + } + + /** + * @see AbstractDebugActionDelegate#getStatusMessage() + */ + protected String getStatusMessage() { + return ActionMessages.ResumeActionDelegate_Exceptions_occurred_attempting_to_resume__2; + } + + /** + * @see AbstractDebugActionDelegate#getErrorDialogMessage() + */ + protected String getErrorDialogMessage() { + return ActionMessages.ResumeActionDelegate_Resume_failed__1; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.contexts.actions.AbstractDebugContextActionDelegate#getTarget(java.lang.Object) + */ + protected Object getTarget(Object selectee) { + if (selectee instanceof ISuspendResume) { + return selectee; + } + if (selectee instanceof IAdaptable) { + return ((IAdaptable)selectee).getAdapter(ISuspendResume.class); + } + return null; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllAction.java new file mode 100755 index 000000000..32bf33753 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllAction.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + +import org.eclipse.debug.ui.IDebugView; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; + +public abstract class SelectAllAction extends AbstractDebugContextActionDelegate { + + + protected boolean initialize(IAction action, ISelection selection) { + if (!isInitialized()) { + IDebugView debugView = + (IDebugView) getView().getAdapter(IDebugView.class); + if (debugView != null) { + debugView.setAction(getActionId(), action); + } + return super.initialize(action, selection); + } + return false; + } + + protected abstract String getActionId(); + + /** + * @see IActionDelegate#run(IAction) + */ + public void run(IAction action){ + doAction(null); + } + + protected void doAction(Object element) { + if (!(getView() instanceof IDebugView)) { + return; + } + Viewer viewer = ((IDebugView) getView()).getViewer(); + if (!(viewer instanceof TreeViewer)) { + return; + } + ((TreeViewer) viewer).getTree().selectAll(); + //ensure that the selection change callback is fired + viewer.setSelection(viewer.getSelection()); + } + + protected abstract void update(); + + protected void update(IAction action, ISelection selection) { + update(); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllBreakpointsAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllBreakpointsAction.java new file mode 100755 index 000000000..9d9f258be --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllBreakpointsAction.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + +import org.eclipse.core.resources.IMarkerDelta; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IBreakpointsListener; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView; +import org.eclipse.debug.ui.IDebugView; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.ui.IViewPart; + +public class SelectAllBreakpointsAction extends SelectAllAction implements IBreakpointsListener { + + protected void update() { + getAction().setEnabled(DebugPlugin.getDefault().getBreakpointManager().hasBreakpoints()); + } + + /** + * @see AbstractDebugActionDelegate#doAction(Object) + */ + protected void doAction(Object element) { + if (!(getView() instanceof BreakpointsView)) { + return; + } + CheckboxTreeViewer viewer = ((BreakpointsView) getView()).getCheckboxViewer(); + viewer.getTree().selectAll(); + // ensure that the selection change callback is fired + viewer.setSelection(viewer.getSelection()); + } + + /** + * @see IBreakpointsListener#breakpointsAdded(IBreakpoint[])breakpointAdded(IBreakpoint) + */ + public void breakpointsAdded(IBreakpoint[] breakpoints) { + if (getAction() != null && !getAction().isEnabled()) { + update(); + } + } + + /** + * @see IBreakpointsListener#breakpointsChanged(IBreakpoint[], + * IMarkerDelta[])breakpointChanged(IBreakpoint, IMarkerDelta) + */ + public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { + } + + /** + * @see IBreakpointsListener#breakpointsRemoved(IBreakpoint[], + * IMarkerDelta[]) + */ + public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { + if (getAction() != null) { + update(); + } + } + + /** + * @see IViewActionDelegate#init(IViewPart) + */ + public void init(IViewPart view) { + super.init(view); + DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); + } + + public void dispose() { + DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this); + super.dispose(); + } + + protected String getActionId() { + return IDebugView.SELECT_ALL_ACTION; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllExpressionsAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllExpressionsAction.java new file mode 100755 index 000000000..b77033043 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllExpressionsAction.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.ui.IDebugView; + +public class SelectAllExpressionsAction extends SelectAllAction { + + protected void update() { + getAction().setEnabled(DebugPlugin.getDefault().getExpressionManager().hasExpressions()); + } + + protected String getActionId() { + return IDebugView.SELECT_ALL_ACTION + ".Variables"; //$NON-NLS-1$ + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllVariablesAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllVariablesAction.java new file mode 100755 index 000000000..7e653c673 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SelectAllVariablesAction.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.ui.IDebugView; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.progress.WorkbenchJob; + +public class SelectAllVariablesAction extends SelectAllAction { + + protected void update() { + WorkbenchJob job = new WorkbenchJob("update select all variables action") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + if (!(getView() instanceof IDebugView)) { + return Status.OK_STATUS; + } + Viewer viewer = ((IDebugView) getView()).getViewer(); + if (viewer != null) { + Tree tree = (Tree) viewer.getControl(); + getAction().setEnabled(tree.getItemCount() != 0); + } + return Status.OK_STATUS; + } + }; + + job.setSystem(true); + job.schedule(); + } + + protected String getActionId() { + return IDebugView.SELECT_ALL_ACTION + ".Variables"; //$NON-NLS-1$ + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepActionDelegate.java new file mode 100644 index 000000000..a2ea2426f --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepActionDelegate.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IStep; + +public abstract class StepActionDelegate extends AbstractDebugContextActionDelegate { + + /** + * @see AbstractDebugActionDelegate#doAction(Object) + */ + protected void doAction(Object object) throws DebugException { + if (object instanceof IStep) { + stepAction((IStep)object); + } + } + + /** + * @see AbstractDebugActionDelegate#isRunInBackground() + */ + protected boolean isRunInBackground() { + return true; + } + + /** + * @see AbstractDebugActionDelegate#isEnabledFor(Object) + */ + protected boolean isEnabledFor(Object element) { + if (element instanceof IStep) { + return checkCapability((IStep)element); + } + return false; + } + + /** + * Returns whether the IStep has the capability to perform the + * requested step action. + */ + protected abstract boolean checkCapability(IStep element); + + /** + * Performs the specific step action. + * + * @exception DebugException if the action fails + */ + protected abstract void stepAction(IStep element) throws DebugException; + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.contexts.actions.AbstractDebugContextActionDelegate#getTarget(java.lang.Object) + */ + protected Object getTarget(Object selectee) { + if (selectee instanceof IStep) { + return selectee; + } + if (selectee instanceof IAdaptable) { + return ((IAdaptable)selectee).getAdapter(IStep.class); + } + return null; + } + + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepIntoActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepIntoActionDelegate.java new file mode 100644 index 000000000..daee5b0b6 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepIntoActionDelegate.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IStep; +import org.eclipse.debug.internal.ui.actions.ActionMessages; + +public class StepIntoActionDelegate extends StepActionDelegate { + + /** + * @see StepActionDelegate#checkCapability(IStep) + */ + protected boolean checkCapability(IStep element) { + return element.canStepInto(); + } + + /** + * @see StepActionDelegate#stepAction(IStep) + */ + protected void stepAction(IStep element) throws DebugException { + element.stepInto(); + } + + /** + * @see AbstractDebugActionDelegate#getStatusMessage() + */ + protected String getStatusMessage() { + return ActionMessages.StepIntoActionDelegate_Exceptions_occurred_attempting_to_step_into_the_frame_2; + } + + /** + * @see AbstractDebugActionDelegate#getErrorDialogMessage() + */ + protected String getErrorDialogMessage() { + return ActionMessages.StepIntoActionDelegate_Step_into_failed_1; + } + + /** + * @see org.eclipse.debug.internal.ui.actions.StepActionDelegate#getActionDefinitionId() + */ + protected String getActionDefinitionId() { + return "org.eclipse.debug.internal.ui.actions.StepIntoActionDelegate"; //$NON-NLS-1$ + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepOverActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepOverActionDelegate.java new file mode 100644 index 000000000..5b51652cc --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepOverActionDelegate.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IStep; +import org.eclipse.debug.internal.ui.actions.ActionMessages; + +public class StepOverActionDelegate extends StepActionDelegate { + + /** + * @see StepActionDelegate#checkCapability(IStep) + */ + protected boolean checkCapability(IStep element) { + return element.canStepOver(); + } + + /** + * @see StepActionDelegate#stepAction(IStep) + */ + protected void stepAction(IStep element) throws DebugException { + element.stepOver(); + } + + /** + * @see AbstractDebugActionDelegate#getStatusMessage() + */ + protected String getStatusMessage() { + return ActionMessages.StepOverActionDelegate_Exceptions_occurred_attempting_to_step_over_the_frame_2; + } + + /** + * @see AbstractDebugActionDelegate#getErrorDialogMessage() + */ + protected String getErrorDialogMessage() { + return ActionMessages.StepOverActionDelegate_Step_over_failed_1; + } + + /** + * @see org.eclipse.debug.internal.ui.actions.StepActionDelegate#getActionDefinitionId() + */ + protected String getActionDefinitionId() { + return "org.eclipse.debug.internal.ui.actions.StepOverActionDelegate"; //$NON-NLS-1$ + } +} + diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepReturnActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepReturnActionDelegate.java new file mode 100644 index 000000000..f3bdbb77d --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/StepReturnActionDelegate.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IStep; +import org.eclipse.debug.internal.ui.actions.ActionMessages; + +public class StepReturnActionDelegate extends StepActionDelegate { + + /** + * @see StepActionDelegate#checkCapability(IStep) + */ + protected boolean checkCapability(IStep element) { + return element.canStepReturn(); + } + + /** + * @see StepActionDelegate#stepAction(IStep) + */ + protected void stepAction(IStep element) throws DebugException { + element.stepReturn(); + } + + /** + * @see AbstractDebugActionDelegate#getStatusMessage() + */ + protected String getStatusMessage() { + return ActionMessages.StepReturnActionDelegate_Exceptions_occurred_attempting_to_run_to_return_of_the_frame__2; + } + + /** + * @see AbstractDebugActionDelegate#getErrorDialogMessage() + */ + protected String getErrorDialogMessage() { + return ActionMessages.StepReturnActionDelegate_Run_to_return_failed__1; + } + + /** + * @see org.eclipse.debug.internal.ui.actions. + * StepActionDelegate#getActionDefinitionId() + */ + protected String getActionDefinitionId() { + return "org.eclipse.debug.internal.ui.actions.StepReturnActionDelegate"; //$NON-NLS-1$ + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SuspendActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SuspendActionDelegate.java new file mode 100755 index 000000000..aa9f4fa6d --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/SuspendActionDelegate.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.ISuspendResume; +import org.eclipse.debug.internal.ui.actions.ActionMessages; + +public class SuspendActionDelegate extends AbstractDebugContextActionDelegate { + + /** + * @see AbstractDebugActionDelegate#doAction(Object) + */ + protected void doAction(Object element) throws DebugException { + if (element instanceof ISuspendResume) { + ((ISuspendResume) element).suspend(); + } + } + + /** + * @see AbstractDebugActionDelegate#isEnabledFor(Object) + */ + protected boolean isEnabledFor(Object element) { + return element instanceof ISuspendResume && ((ISuspendResume)element).canSuspend(); + } + + /** + * @see AbstractDebugActionDelegate#getStatusMessage() + */ + protected String getStatusMessage() { + return ActionMessages.SuspendActionDelegate_Exceptions_occurred_attempting_to_suspend__2; + } + + /** + * @see AbstractDebugActionDelegate#getErrorDialogMessage() + */ + protected String getErrorDialogMessage() { + return ActionMessages.SuspendActionDelegate_Suspend_failed_1; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.contexts.actions.AbstractDebugContextActionDelegate#getTarget(java.lang.Object) + */ + protected Object getTarget(Object selectee) { + if (selectee instanceof ISuspendResume) { + return selectee; + } + if (selectee instanceof IAdaptable) { + return ((IAdaptable)selectee).getAdapter(ISuspendResume.class); + } + return null; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateActionDelegate.java new file mode 100755 index 000000000..2bc940223 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateActionDelegate.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +import org.eclipse.core.runtime.IAdaptable; +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.IProcess; +import org.eclipse.debug.core.model.ITerminate; +import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; + +public class TerminateActionDelegate extends AbstractDebugContextActionDelegate { + + /** + * @see AbstractDebugActionDelegate#doAction(Object) + */ + protected void doAction(Object element) throws DebugException { + if (element instanceof ITerminate) { + if (element instanceof IProcess) { + killTargets((IProcess) element); + } + ((ITerminate)element).terminate(); + } + } + + private void killTargets(IProcess process) throws DebugException { + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); + ILaunch[] launches = launchManager.getLaunches(); + + for (int i = 0; i < launches.length; i++) { + ILaunch launch = launches[i]; + IProcess[] processes = launch.getProcesses(); + for (int j = 0; j < processes.length; j++) { + IProcess process2 = processes[j]; + if (process2.equals(process)) { + IDebugTarget[] debugTargets = launch.getDebugTargets(); + for (int k = 0; k < debugTargets.length; k++) { + IDebugTarget target = debugTargets[k]; + if (target.canTerminate()) { + target.terminate(); + } + } + return; // all possible targets have been terminated for the launch. + } + } + } + } + + /** + * @see AbstractDebugActionDelegate#isRunInBackground() + */ + protected boolean isRunInBackground() { + return true; + } + + /** + * @see AbstractDebugActionDelegate#isEnabledFor(Object) + */ + protected boolean isEnabledFor(Object element) { + return element instanceof ITerminate && ((ITerminate)element).canTerminate(); + } + + /** + * @see AbstractDebugActionDelegate#getStatusMessage() + */ + protected String getStatusMessage() { + return ActionMessages.TerminateActionDelegate_Exceptions_occurred_attempting_to_terminate__2; + } + + /** + * @see AbstractDebugActionDelegate#getErrorDialogMessage() + */ + protected String getErrorDialogMessage() { + return ActionMessages.TerminateActionDelegate_Terminate_failed__1; + } + + /** + * @see ListenerActionDelegate#doHandleDebugEvent(DebugEvent) + */ + protected void doHandleDebugEvent(DebugEvent event) { + if (event.getKind() == DebugEvent.TERMINATE || event.getKind() == DebugEvent.CREATE) { + update(getAction(), getContext()); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#update(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + */ + protected void update(IAction action, ISelection s) { + // ignore non-structured selections (for example, text selection in console) + if (s instanceof IStructuredSelection) { + super.update(action, s); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.contexts.actions.AbstractDebugContextActionDelegate#getTarget(java.lang.Object) + */ + protected Object getTarget(Object selectee) { + if (selectee instanceof ITerminate) { + return selectee; + } + if (selectee instanceof IAdaptable) { + return ((IAdaptable)selectee).getAdapter(ITerminate.class); + } + return null; + } + + + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateAllAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateAllAction.java new file mode 100755 index 000000000..7f50937f7 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateAllAction.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +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.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; + +/** + * Terminates all launches. + */ +public class TerminateAllAction extends AbstractDebugContextActionDelegate { + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#doAction(java.lang.Object) + */ + protected void doAction(Object element) throws DebugException { + if (element instanceof ILaunch) { + ILaunch launch = (ILaunch) element; + if (!launch.isTerminated() && DebugPlugin.getDefault().getLaunchManager().isRegistered(launch)) { + launch.terminate(); + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#isRunInBackground() + */ + protected boolean isRunInBackground() { + return true; + } + + /** + * Update the action enablement based on the launches present in + * the launch manager. selection is unused and can be null. + * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#update(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + */ + protected void update(IAction action, ISelection selection) { + ILaunchManager lManager= DebugPlugin.getDefault().getLaunchManager(); + ILaunch[] launches= lManager.getLaunches(); + for (int i= 0; i< launches.length; i++) { + ILaunch launch= launches[i]; + if (!launch.isTerminated()) { + action.setEnabled(true); + return; + } + } + action.setEnabled(false); + } + + /* (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) { + setAction(action); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.actions.AbstractListenerActionDelegate#doHandleDebugEvent(org.eclipse.debug.core.DebugEvent) + */ + protected void doHandleDebugEvent(DebugEvent event) { + switch (event.getKind()) { + case DebugEvent.TERMINATE : + update(getAction(), null); + break; + case DebugEvent.CREATE : + update(getAction(), null); + break; + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#getSelection() + */ + protected IStructuredSelection getSelection() { + return new StructuredSelection(DebugPlugin.getDefault().getLaunchManager().getLaunches()); + } + + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateAndRelaunchAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateAndRelaunchAction.java new file mode 100755 index 000000000..f17802b04 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateAndRelaunchAction.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2004, 2005 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 implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.contexts.actions; + +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.model.ITerminate; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.actions.RelaunchActionDelegate; + +/** + * Action which terminates a launch and then relaunches it. + * This is equivalent to the Terminate action followed by + * Relaunch, but is provided to the user as a convenience. + */ +public class TerminateAndRelaunchAction extends AbstractDebugContextActionDelegate { + + protected void doAction(Object element) throws DebugException { + final ILaunch launch= RelaunchActionDelegate.getLaunch(element); + if (launch == null || !(element instanceof ITerminate)) { + // Shouldn't happen because of enablement check. + return; + } + + ((ITerminate)element).terminate(); + DebugUIPlugin.getStandardDisplay().asyncExec(new Runnable() { + public void run() { + // Must be run in the UI thread since the launch can require prompting to proceed + RelaunchActionDelegate.relaunch(launch.getLaunchConfiguration(), launch.getLaunchMode()); + } + }); + } + + /** + * @see AbstractDebugActionDelegate#isRunInBackground() + */ + protected boolean isRunInBackground() { + return true; + } + + /** + * @see AbstractDebugActionDelegate#isEnabledFor(Object) + */ + protected boolean isEnabledFor(Object element) { + return element instanceof ITerminate && ((ITerminate)element).canTerminate() && + RelaunchActionDelegate.getLaunch(element) != null; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateAndRemoveActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateAndRemoveActionDelegate.java new file mode 100755 index 000000000..7d0aa6d62 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contexts/actions/TerminateAndRemoveActionDelegate.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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.internal.ui.contexts.actions; + + +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.ITerminate; +import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.internal.ui.views.launch.LaunchView; + +public class TerminateAndRemoveActionDelegate extends AbstractDebugContextActionDelegate { + + /** + * @see AbstractDebugActionDelegate#doAction(Object) + */ + protected void doAction(Object element) throws DebugException { + LaunchView.terminateAndRemove(element); + } + + /** + * @see AbstractDebugActionDelegate#isRunInBackground() + */ + protected boolean isRunInBackground() { + return true; + } + + /** + * @see AbstractDebugActionDelegate#isEnabledFor(Object) + */ + protected boolean isEnabledFor(Object element) { + if (element instanceof ITerminate) { + ITerminate terminate= (ITerminate)element; + //do not want to terminate an attach launch that does not + //have termination enabled + return terminate.canTerminate() || terminate.isTerminated(); + } + return false; + } + + /** + * @see AbstractDebugActionDelegate#getStatusMessage() + */ + protected String getStatusMessage() { + return ActionMessages.TerminateAndRemoveActionDelegate_Exceptions_occurred_attempting_to_terminate_and_remove_2; + } + + /** + * @see AbstractDebugActionDelegate#getErrorDialogMessage() + */ + protected String getErrorDialogMessage() { + return ActionMessages.TerminateAndRemoveActionDelegate_Terminate_and_remove_failed_1; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/AsynchronousDebugLabelAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/AsynchronousDebugLabelAdapter.java new file mode 100644 index 000000000..2867af51e --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/AsynchronousDebugLabelAdapter.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.elements.adapters; + +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.model.IDebugElement; +import org.eclipse.debug.internal.ui.DelegatingModelPresentation; +import org.eclipse.debug.internal.ui.LazyModelPresentation; +import org.eclipse.debug.internal.ui.viewers.AsynchronousLabelAdapter; +import org.eclipse.debug.internal.ui.viewers.ILabelRequestMonitor; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.internal.ui.views.launch.DebugElementHelper; +import org.eclipse.debug.ui.IDebugModelPresentation; +import org.eclipse.debug.ui.IDebugView; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.ui.IWorkbenchPart; + +/** + * Asynchronous label adapter for debug elements. + * + * @since 3.2 + */ +public class AsynchronousDebugLabelAdapter extends AsynchronousLabelAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#computeLabels(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext, org.eclipse.debug.ui.viewers.ILabelRequestMonitor) + */ + protected void computeLabels(Object element, IPresentationContext context, ILabelRequestMonitor monitor) { + DelegatingModelPresentation presentation = DebugElementHelper.getPresentation(); + // Honor view specific settings in a debug view by copying model presentation settings + // into the debug element helper's presentation before we get the label. This allows + // for qualified name and type name settings to remain in tact. + if (element instanceof IDebugElement && context.getPart() instanceof IDebugView) { + IWorkbenchPart part = context.getPart(); + if (part instanceof IDebugView) { + IDebugModelPresentation pres = ((IDebugView)part).getPresentation(((IDebugElement)element).getModelIdentifier()); + Map settings = null; + synchronized (presentation) { + if (pres instanceof DelegatingModelPresentation) { + settings = ((DelegatingModelPresentation)pres).getAttributes(); + } else if (pres instanceof LazyModelPresentation) { + settings = ((LazyModelPresentation)pres).getAttributes(); + } + if (settings != null) { + Iterator iterator = settings.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry entry = (Entry) iterator.next(); + presentation.setAttribute((String) entry.getKey(), entry.getValue()); + } + super.computeLabels(element, context, monitor); + return; + } + } + } + } + super.computeLabels(element, context, monitor); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#getLabels(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected String[] getLabels(Object element, IPresentationContext context) throws CoreException { + return new String[] {DebugElementHelper.getLabel(element)}; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#getImageDescriptors(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected ImageDescriptor[] getImageDescriptors(Object element, IPresentationContext context) throws CoreException { + return new ImageDescriptor[] {DebugElementHelper.getImageDescriptor(element)}; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#getFontDatas(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected FontData[] getFontDatas(Object element, IPresentationContext context) throws CoreException { + return new FontData[] {DebugElementHelper.getFont(element)}; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#getForegrounds(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected RGB[] getForegrounds(Object element, IPresentationContext context) throws CoreException { + return new RGB[] {DebugElementHelper.getForeground(element)}; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#getBackgrounds(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected RGB[] getBackgrounds(Object element, IPresentationContext context) throws CoreException { + return new RGB[] {DebugElementHelper.getBackground(element)}; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DebugTargetTreeContentAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DebugTargetTreeContentAdapter.java new file mode 100644 index 000000000..eeeb01d3f --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DebugTargetTreeContentAdapter.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.elements.adapters; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; + +public class DebugTargetTreeContentAdapter extends AsynchronousTreeContentAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#getChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + return ((IDebugTarget) parent).getThreads(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#hasChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + return ((IDebugTarget)element).hasThreads(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#supportsPartId(java.lang.String) + */ + protected boolean supportsPartId(String id) { + return IDebugUIConstants.ID_DEBUG_VIEW.equals(id); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredExpression.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredExpression.java deleted file mode 100644 index a0a6d3bab..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredExpression.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.elements.adapters; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IErrorReportingExpression; -import org.eclipse.debug.core.model.IExpression; -import org.eclipse.debug.core.model.IValue; - -public class DeferredExpression extends DeferredVariable { - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parent) { - if (parent instanceof IErrorReportingExpression) { - IErrorReportingExpression expression= (IErrorReportingExpression) parent; - if (expression.hasErrors()) { - return expression.getErrorMessages(); - } - } - if (parent instanceof IExpression) { - IExpression expression = (IExpression)parent; - IValue value = expression.getValue(); - try { - return getValueChildren(expression, value); - } catch (DebugException e) { - } - } - return super.getChildren(parent); - } - - protected boolean hasChildren(Object child) { - if (child instanceof IErrorReportingExpression) { - IErrorReportingExpression expression = (IErrorReportingExpression) child; - if (expression.hasErrors()) { - return true; - } - } - - if (child instanceof IExpression) { - IExpression expression = (IExpression) child; - IValue value = expression.getValue(); - if (value != null) { - try { - return value.hasVariables(); - } catch (DebugException e) { - } - } - } - - return super.hasChildren(child); - } - - - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredExpressionLogicalStructure.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredExpressionLogicalStructure.java deleted file mode 100644 index d438af7dc..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredExpressionLogicalStructure.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.elements.adapters; - - -/** - * Workbench adapter for an expression when showing logical structures. - */ -public class DeferredExpressionLogicalStructure extends DeferredExpression { - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.views.variables.DeferredVariable#isShowLogicalStructure() - */ - protected boolean isShowLogicalStructure() { - return true; - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredExpressionManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredExpressionManager.java deleted file mode 100644 index 4b3d615f7..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredExpressionManager.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.elements.adapters; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IExpressionManager; -import org.eclipse.debug.core.model.IExpression; -import org.eclipse.debug.core.model.IValue; -import org.eclipse.debug.internal.ui.views.variables.RemoteVariableContentManager; -import org.eclipse.debug.ui.DeferredDebugElementWorkbenchAdapter; -import org.eclipse.ui.progress.IElementCollector; - -public class DeferredExpressionManager extends DeferredDebugElementWorkbenchAdapter { - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parent) { - return ((IExpressionManager)parent).getExpressions(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object) - */ - public Object getParent(Object element) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#fetchDeferredChildren(java.lang.Object, org.eclipse.ui.progress.IElementCollector, org.eclipse.core.runtime.IProgressMonitor) - */ - public void fetchDeferredChildren(Object object, IElementCollector collector, IProgressMonitor monitor) { - if (monitor.isCanceled()) { - return; - } - Object[] children = getChildren(object); - if (monitor.isCanceled()) { - return; - } - if (children.length > 0) { - if (collector instanceof RemoteVariableContentManager.VariableCollector) { - RemoteVariableContentManager.VariableCollector remoteCollector = (RemoteVariableContentManager.VariableCollector) collector; - for (int i = 0; i < children.length; i++) { - if (monitor.isCanceled()) { - return; - } - IExpression child = (IExpression) children[i]; - try { - IValue value = child.getValue(); - if (value == null) { - remoteCollector.setHasChildren(child, false); - } else { - remoteCollector.setHasChildren(child, value.hasVariables()); - } - } catch (DebugException e) { - } - } - } - collector.add(children, monitor); - } - collector.done(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#isContainer() - */ - public boolean isContainer() { - return DebugPlugin.getDefault().getExpressionManager().hasExpressions(); - } - - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredLaunch.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredLaunch.java deleted file mode 100644 index 0cd8a6bda..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredLaunch.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.elements.adapters; - -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.ui.DeferredDebugElementWorkbenchAdapter; - -public class DeferredLaunch extends DeferredDebugElementWorkbenchAdapter { - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parent) { - return ((ILaunch)parent).getChildren(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object) - */ - public Object getParent(Object element) { - return DebugPlugin.getDefault().getLaunchManager(); - } - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredLaunchManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredLaunchManager.java deleted file mode 100644 index bd56dfae1..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredLaunchManager.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.elements.adapters; - -import org.eclipse.debug.core.ILaunchManager; -import org.eclipse.debug.ui.DeferredDebugElementWorkbenchAdapter; - -public class DeferredLaunchManager extends DeferredDebugElementWorkbenchAdapter { - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parent) { - return ((ILaunchManager) parent).getLaunches(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object) - */ - public Object getParent(Object element) { - return null; - } - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredProcess.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredProcess.java deleted file mode 100644 index 341f5c438..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredProcess.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.elements.adapters; - -import org.eclipse.debug.core.model.IProcess; -import org.eclipse.debug.ui.DeferredDebugElementWorkbenchAdapter; -import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; - - -/** - * Default deferred content provider for a process. - */ -public class DeferredProcess extends DeferredDebugElementWorkbenchAdapter implements IDeferredWorkbenchAdapter { - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parent) { - return EMPTY; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object) - */ - public Object getParent(Object element) { - return ((IProcess)element).getLaunch(); - } - - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredRegisterGroup.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredRegisterGroup.java deleted file mode 100644 index 5c1fd35d6..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredRegisterGroup.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.elements.adapters; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IRegisterGroup; -import org.eclipse.debug.core.model.IValue; -import org.eclipse.debug.core.model.IVariable; -import org.eclipse.debug.internal.ui.views.variables.RemoteVariableContentManager; -import org.eclipse.debug.ui.DeferredDebugElementWorkbenchAdapter; -import org.eclipse.ui.progress.IElementCollector; - -public class DeferredRegisterGroup extends DeferredDebugElementWorkbenchAdapter { - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parent) { - try { - return ((IRegisterGroup)parent).getRegisters(); - } catch (DebugException e) { - } - return EMPTY; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object) - */ - public Object getParent(Object element) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#fetchDeferredChildren(java.lang.Object, org.eclipse.ui.progress.IElementCollector, org.eclipse.core.runtime.IProgressMonitor) - */ - public void fetchDeferredChildren(Object object, IElementCollector collector, IProgressMonitor monitor) { - if (monitor.isCanceled()) { - return; - } - Object[] children = getChildren(object); - if (monitor.isCanceled()) { - return; - } - if (children.length > 0) { - if (collector instanceof RemoteVariableContentManager.VariableCollector) { - RemoteVariableContentManager.VariableCollector remoteCollector = (RemoteVariableContentManager.VariableCollector) collector; - for (int i = 0; i < children.length; i++) { - if (monitor.isCanceled()) { - return; - } - Object child = children[i]; - remoteCollector.setHasChildren(child, hasChildren(child)); - } - } - collector.add(children, monitor); - } - collector.done(); - } - - protected boolean hasChildren(Object child) { - if (child instanceof IVariable) { - IVariable var = (IVariable) child; - try { - IValue value = var.getValue(); - return value.hasVariables(); - } catch (DebugException e) { - } - } - return false; - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredStackFrame.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredStackFrame.java deleted file mode 100644 index eec8af2f0..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredStackFrame.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.elements.adapters; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.debug.core.model.IValue; -import org.eclipse.debug.core.model.IVariable; -import org.eclipse.debug.internal.ui.views.variables.RemoteVariableContentManager; -import org.eclipse.debug.ui.DeferredDebugElementWorkbenchAdapter; -import org.eclipse.ui.progress.IElementCollector; - - -/** - * Default deferred workbench adapter for a stack frame - */ -public class DeferredStackFrame extends DeferredDebugElementWorkbenchAdapter { - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parent) { - if (parent instanceof IStackFrame) { - IStackFrame frame = (IStackFrame) parent; - try { - return frame.getVariables(); - } catch (DebugException e) { - return new Object[]{e}; - } - } - return EMPTY; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object) - */ - public Object getParent(Object element) { - return ((IStackFrame)element).getThread(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#fetchDeferredChildren(java.lang.Object, org.eclipse.ui.progress.IElementCollector, org.eclipse.core.runtime.IProgressMonitor) - */ - public void fetchDeferredChildren(Object object, IElementCollector collector, IProgressMonitor monitor) { - if (monitor.isCanceled()) { - return; - } - Object[] children = getChildren(object); - if (monitor.isCanceled()) { - return; - } - if (children.length > 0) { - if (collector instanceof RemoteVariableContentManager.VariableCollector) { - RemoteVariableContentManager.VariableCollector remoteCollector = (RemoteVariableContentManager.VariableCollector) collector; - for (int i = 0; i < children.length; i++) { - if (monitor.isCanceled()) { - return; - } - Object child = children[i]; - remoteCollector.setHasChildren(child, hasChildren(child)); - } - } - collector.add(children, monitor); - } - collector.done(); - } - - /** - * Returns whether the given child has children. - * Subclasses should override for different type of children. - * - * @param child child fetched from getChildren() - * @return whether the given child has children - */ - protected boolean hasChildren(Object child) { - if (child instanceof IVariable) { - IVariable variable = (IVariable) child; - try { - IValue value = variable.getValue(); - return value.hasVariables(); - } catch (DebugException e) { - } - } - return false; - } - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredTarget.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredTarget.java deleted file mode 100644 index f28d0c8d7..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredTarget.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.elements.adapters; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.ui.DeferredDebugElementWorkbenchAdapter; -import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; - - -/** - * Default deferred content provider for a debug target - */ -public class DeferredTarget extends DeferredDebugElementWorkbenchAdapter implements IDeferredWorkbenchAdapter { - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parent) { - try { - return ((IDebugTarget)parent).getThreads(); - } catch (DebugException e) { - } - return EMPTY; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object) - */ - public Object getParent(Object element) { - return ((IDebugTarget)element).getLaunch(); - } - - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredThread.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredThread.java deleted file mode 100644 index 5a588fabc..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredThread.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.elements.adapters; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IThread; -import org.eclipse.debug.ui.DeferredDebugElementWorkbenchAdapter; -import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; - - -/** - * Default deferred content provider for a debug target - */ -public class DeferredThread extends DeferredDebugElementWorkbenchAdapter implements IDeferredWorkbenchAdapter { - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parent) { - try { - return ((IThread)parent).getStackFrames(); - } catch (DebugException e) { - } - return EMPTY; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object) - */ - public Object getParent(Object element) { - return ((IThread)element).getDebugTarget(); - } - - - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredVariable.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredVariable.java deleted file mode 100644 index d75f2bb08..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredVariable.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.elements.adapters; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILogicalStructureType; -import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IIndexedValue; -import org.eclipse.debug.core.model.IValue; -import org.eclipse.debug.core.model.IVariable; -import org.eclipse.debug.internal.ui.views.variables.IndexedVariablePartition; -import org.eclipse.debug.internal.ui.views.variables.RemoteVariableContentManager; -import org.eclipse.debug.ui.DeferredDebugElementWorkbenchAdapter; -import org.eclipse.ui.progress.IElementCollector; - - -/** - * Default deferred content provider for a variable - */ -public class DeferredVariable extends DeferredDebugElementWorkbenchAdapter { - - private static final IVariable[] EMPTY_VARS = new IVariable[0]; - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parent) { - if (parent instanceof IVariable) { - try { - IVariable variable = (IVariable) parent; - IValue value = variable.getValue(); - if (value != null) { - return getValueChildren(variable, value); - } - } catch (DebugException e) { - } - } - return EMPTY; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#fetchDeferredChildren(java.lang.Object, org.eclipse.ui.progress.IElementCollector, org.eclipse.core.runtime.IProgressMonitor) - */ - public void fetchDeferredChildren(Object object, IElementCollector collector, IProgressMonitor monitor) { - if (monitor.isCanceled()) { - return; - } - Object[] children = getChildren(object); - if (monitor.isCanceled()) { - return; - } - if (children.length > 0) { - if (collector instanceof RemoteVariableContentManager.VariableCollector) { - RemoteVariableContentManager.VariableCollector remoteCollector = (RemoteVariableContentManager.VariableCollector) collector; - for (int i = 0; i < children.length; i++) { - if (monitor.isCanceled()) { - return; - } - Object child = children[i]; - remoteCollector.setHasChildren(child, hasChildren(child)); - } - } - collector.add(children, monitor); - } - collector.done(); - } - - protected boolean hasChildren(Object child) { - if (child instanceof IVariable) { - IVariable var = (IVariable) child; - try { - IValue value = var.getValue(); - return value.hasVariables(); - } catch (DebugException e) { - } - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object) - */ - public Object getParent(Object element) { - return null; - } - - /** - * Returns children for the given value, creating array paritions if required - * - * @param parent expression or variable containing the given value - * @param value the value to retrieve children for - * @return children for the given value, creating array paritions if required - * @throws DebugException - */ - protected IVariable[] getValueChildren(IDebugElement parent, IValue value) throws DebugException { - if (value == null) { - return EMPTY_VARS; - } - IValue logicalValue = getLogicalValue(value); - if (logicalValue instanceof IIndexedValue) { - IIndexedValue indexedValue = (IIndexedValue)logicalValue; - int partitionSize = computeParitionSize(indexedValue); - if (partitionSize > 1) { - int offset = indexedValue.getInitialOffset(); - int length = indexedValue.getSize(); - int numPartitions = length / partitionSize; - int remainder = length % partitionSize; - if (remainder > 0) { - numPartitions++; - } - IVariable[] partitions = new IVariable[numPartitions]; - for (int i = 0; i < (numPartitions - 1); i++) { - partitions[i] = new IndexedVariablePartition(parent, indexedValue, offset, partitionSize); - offset = offset + partitionSize; - } - if (remainder == 0) { - remainder = partitionSize; - } - partitions[numPartitions - 1] = new IndexedVariablePartition(parent, indexedValue, offset, remainder); - return partitions; - } - } - if (logicalValue == null) { - // safeguard against an structure type returning null - logicalValue = value; - } - return logicalValue.getVariables(); - } - - /** - * Returns any logical value for the raw value. - * - * @param value - * @return - */ - protected IValue getLogicalValue(IValue value) { - return getLogicalValue(value, new ArrayList()); - } - - /** - * Returns any logical value for the raw value. This method will recurse - * over the returned value until the same structure is encountered again - * (to avoid infinite recursion). - * - * @param value - * @param previousStructureIds the list of logical structures that have already - * been applied to the returned value during the recursion of this method. Callers - * should always pass in a new, empty list. - * @return - */ - private IValue getLogicalValue(IValue value, List previousStructureIds) { - if (isShowLogicalStructure()) { - ILogicalStructureType[] types = DebugPlugin.getLogicalStructureTypes(value); - if (types.length > 0) { - ILogicalStructureType type = DebugPlugin.getDefaultStructureType(types); - if (type != null && !previousStructureIds.contains(type.getId())) { - try { - value= type.getLogicalStructure(value); - previousStructureIds.add(type.getId()); - return getLogicalValue(value, previousStructureIds); - } catch (CoreException e) { - // unable to display logical structure - } - } - } - } - return value; - } - - /** - * Return wether to show compute a logical structure or a raw structure. - * - * @return wether to show compute a logical structure or a raw structure - */ - protected boolean isShowLogicalStructure() { - return false; - } - - /** - * Returns the partition size to use for the given indexed value. - * The partition size is computed by determining the number of levels - * that an indexed collection must be nested in order to partition - * the collection sub-collections of the preferred partition size. - * - * @param value indexed value - * @return size of paritions the value should be subdivided into - */ - protected int computeParitionSize(IIndexedValue value) { - int partitionSize = 1; - try { - int length = value.getSize(); - int partitionDepth = 0; - int preferredSize = getArrayPartitionSize(); - int remainder = length % preferredSize; - length = length / preferredSize; - while (length > 0) { - if (remainder == 0 && length == 1) { - break; - } - partitionDepth++; - remainder = length % preferredSize; - length = length / preferredSize; - } - for (int i = 0; i < partitionDepth; i++) { - partitionSize = partitionSize * preferredSize; - } - } catch (DebugException e) { - } - return partitionSize; - } - - /** - * Returns the number of entries that should be displayed in each - * partition of an indexed collection. - * - * @return the number of entries that should be displayed in each - * partition of an indexed collection - */ - protected int getArrayPartitionSize() { - // TODO: should fix this with a user pref - return 100; - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredVariableLogicalStructure.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredVariableLogicalStructure.java deleted file mode 100644 index 686def947..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/DeferredVariableLogicalStructure.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.elements.adapters; - - -/** - * Workbench adapter for a variable when showing logical structures. - */ -public class DeferredVariableLogicalStructure extends DeferredVariable { - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.views.variables.DeferredVariable#isShowLogicalStructure() - */ - protected boolean isShowLogicalStructure() { - return true; - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ExpressionManagerTreeContentAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ExpressionManagerTreeContentAdapter.java new file mode 100644 index 000000000..865cfa899 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ExpressionManagerTreeContentAdapter.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.elements.adapters; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.IExpressionManager; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; + +public class ExpressionManagerTreeContentAdapter extends AsynchronousTreeContentAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.elements.adapters.AsynchronousDebugTreeContentAdapter#getChildren(java.lang.Object, org.eclipse.debug.internal.ui.treeviewer.IPresentationContext) + */ + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + return ((IExpressionManager) parent).getExpressions(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.elements.adapters.AsynchronousDebugTreeContentAdapter#hasChildren(java.lang.Object, org.eclipse.debug.internal.ui.treeviewer.IPresentationContext) + */ + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + return ((IExpressionManager)element).hasExpressions(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#supportsPartId(java.lang.String) + */ + protected boolean supportsPartId(String id) { + return id.equals(IDebugUIConstants.ID_EXPRESSION_VIEW); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ExpressionTreeContentAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ExpressionTreeContentAdapter.java new file mode 100644 index 000000000..d35c00084 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ExpressionTreeContentAdapter.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.elements.adapters; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.model.IExpression; +import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; + +/** + * + */ +public class ExpressionTreeContentAdapter extends VariableTreeContentAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#getChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + IExpression expression = (IExpression) parent; + IValue value = expression.getValue(); + if (value != null) { + return getValueChildren(expression, value, context); + } + return EMPTY; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#hasChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + IValue value = ((IExpression)element).getValue(); + if (value == null) { + return false; + } + return value.hasVariables(); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/LauchManagerTreeContentAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/LauchManagerTreeContentAdapter.java new file mode 100644 index 000000000..aa8a536a5 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/LauchManagerTreeContentAdapter.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.elements.adapters; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; + +public class LauchManagerTreeContentAdapter extends AsynchronousTreeContentAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#getChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + return ((ILaunchManager) parent).getLaunches(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#hasChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + return ((ILaunchManager)element).getLaunches().length > 0; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#supportsPartId(java.lang.String) + */ + protected boolean supportsPartId(String id) { + return IDebugUIConstants.ID_DEBUG_VIEW.equals(id); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/LaunchTreeContentAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/LaunchTreeContentAdapter.java new file mode 100644 index 000000000..7cebf9a8d --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/LaunchTreeContentAdapter.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.elements.adapters; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; + +public class LaunchTreeContentAdapter extends AsynchronousTreeContentAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#getChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + return ((ILaunch) parent).getChildren(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#hasChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + return ((ILaunch)element).hasChildren(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#supportsPartId(java.lang.String) + */ + protected boolean supportsPartId(String id) { + return IDebugUIConstants.ID_DEBUG_VIEW.equals(id); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ProcessTreeAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ProcessTreeAdapter.java new file mode 100644 index 000000000..2c4fc02c2 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ProcessTreeAdapter.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.elements.adapters; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; + +public class ProcessTreeAdapter extends AsynchronousTreeContentAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#getChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + return EMPTY; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#hasChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#supportsPartId(java.lang.String) + */ + protected boolean supportsPartId(String id) { + return IDebugUIConstants.ID_DEBUG_VIEW.equals(id); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/RegisterGroupTreeContentAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/RegisterGroupTreeContentAdapter.java new file mode 100644 index 000000000..477fbcf42 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/RegisterGroupTreeContentAdapter.java @@ -0,0 +1,31 @@ +package org.eclipse.debug.internal.ui.elements.adapters; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.model.IRegisterGroup; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; + +public class RegisterGroupTreeContentAdapter extends AsynchronousTreeContentAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#getChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + return ((IRegisterGroup)parent).getRegisters(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#hasChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + return ((IRegisterGroup)element).hasRegisters(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#supportsPartId(java.lang.String) + */ + protected boolean supportsPartId(String id) { + return id.equals(IDebugUIConstants.ID_REGISTER_VIEW); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/StackFrameSourceDisplayAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/StackFrameSourceDisplayAdapter.java new file mode 100644 index 000000000..08024e5ab --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/StackFrameSourceDisplayAdapter.java @@ -0,0 +1,164 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.elements.adapters; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IDebugEventSetListener; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.core.model.ISourceLocator; +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.core.model.IThread; +import org.eclipse.debug.internal.ui.InstructionPointerManager; +import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupResult; +import org.eclipse.debug.internal.ui.views.launch.DecorationManager; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.contexts.ISourceDisplayAdapter; +import org.eclipse.debug.ui.sourcelookup.ISourceLookupResult; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.progress.UIJob; + +/** + * @since 3.2 + */ +public class StackFrameSourceDisplayAdapter implements ISourceDisplayAdapter { + + private IStackFrame fPrevFrame; + private SourceLookupResult fPrevResult; + + /** + * Constructs singleton source display adapter for stack frames. + */ + public StackFrameSourceDisplayAdapter() { + DebugPlugin.getDefault().addDebugEventListener(new IDebugEventSetListener() { + public void handleDebugEvents(DebugEvent[] events) { + for (int i = 0; i < events.length; i++) { + DebugEvent event = events[i]; + switch (event.getKind()) { + case DebugEvent.TERMINATE: + case DebugEvent.RESUME: + if (!event.isEvaluation()) { + clearSourceSelection(event.getSource()); + } + break; + } + } + } + }); + } + + /** + * A job to perform source lookup on the currently selected stack frame. + */ + class SourceLookupJob extends Job { + + private IStackFrame fTarget; + private ISourceLocator fLocator; + private IWorkbenchPage fPage; + + /** + * Constructs a new source lookup job. + */ + public SourceLookupJob(IStackFrame frame, ISourceLocator locator, IWorkbenchPage page) { + super("Debug Source Lookup"); + setPriority(Job.INTERACTIVE); + setSystem(true); + fTarget = frame; + fLocator = locator; + fPage = page; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + protected IStatus run(IProgressMonitor monitor) { + if (!monitor.isCanceled()) { + ISourceLookupResult result = null; + result = DebugUITools.lookupSource(fTarget, fLocator); + synchronized (StackFrameSourceDisplayAdapter.this) { + fPrevResult = (SourceLookupResult)result; + fPrevFrame = fTarget; + } + if (!monitor.isCanceled()) { + SourceDisplayJob job = new SourceDisplayJob(result, fPage); + job.schedule(); + } + } + return Status.OK_STATUS; + } + + } + + class SourceDisplayJob extends UIJob { + + private ISourceLookupResult fResult; + private IWorkbenchPage fPage; + + /** + * Constructs a new source display job + */ + public SourceDisplayJob(ISourceLookupResult result, IWorkbenchPage page) { + super("Debug Source Display"); + setSystem(true); + setPriority(Job.INTERACTIVE); + fResult = result; + fPage = page; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) + */ + public IStatus runInUIThread(IProgressMonitor monitor) { + if (!monitor.isCanceled()) { + DebugUITools.displaySource(fResult, fPage); + } + return Status.OK_STATUS; + } + + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.ISourceDisplayAdapter#displaySource(java.lang.Object, org.eclipse.ui.IWorkbenchPage) + */ + public synchronized void displaySource(Object context, IWorkbenchPage page) { + IStackFrame frame = (IStackFrame)context; + if (frame.equals(fPrevFrame)) { + fPrevResult.updateArtifact(context); + (new SourceDisplayJob(fPrevResult, page)).schedule(); + } else { + (new SourceLookupJob(frame, frame.getLaunch().getSourceLocator(), page)).schedule(); + } + + } + + /** + * Deselects any source decorations associated with the given thread or + * debug target. + * + * @param source thread or debug target + */ + private void clearSourceSelection(Object source) { + if (source instanceof IThread) { + IThread thread = (IThread)source; + DecorationManager.removeDecorations(thread); + InstructionPointerManager.getDefault().removeAnnotations(thread); + } else if (source instanceof IDebugTarget) { + IDebugTarget target = (IDebugTarget)source; + DecorationManager.removeDecorations(target); + InstructionPointerManager.getDefault().removeAnnotations(target); + } + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/StackFrameTreeContentAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/StackFrameTreeContentAdapter.java new file mode 100644 index 000000000..79790ee35 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/StackFrameTreeContentAdapter.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.elements.adapters; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; + +public class StackFrameTreeContentAdapter extends AsynchronousTreeContentAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#getChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + String id = context.getPart().getSite().getId(); + IStackFrame frame = (IStackFrame) parent; + if (id.equals(IDebugUIConstants.ID_VARIABLE_VIEW)) { + return frame.getVariables(); + } else if (id.equals(IDebugUIConstants.ID_REGISTER_VIEW)) { + return frame.getRegisterGroups(); + } + return EMPTY; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#hasChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + String id = context.getPart().getSite().getId(); + IStackFrame frame = (IStackFrame) element; + if (id.equals(IDebugUIConstants.ID_VARIABLE_VIEW)) { + return frame.hasVariables(); + } else if (id.equals(IDebugUIConstants.ID_REGISTER_VIEW)) { + return frame.hasRegisterGroups(); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#supportsPartId(java.lang.String) + */ + protected boolean supportsPartId(String id) { + return id.equals(IDebugUIConstants.ID_VARIABLE_VIEW) || id.equals(IDebugUIConstants.ID_REGISTER_VIEW); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ThreadTreeContentAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ThreadTreeContentAdapter.java new file mode 100644 index 000000000..4f25a4de7 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/ThreadTreeContentAdapter.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.elements.adapters; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.model.IThread; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; + +public class ThreadTreeContentAdapter extends AsynchronousTreeContentAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#getChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + return ((IThread) parent).getStackFrames(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#hasChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + return ((IThread)element).hasStackFrames(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#supportsPartId(java.lang.String) + */ + protected boolean supportsPartId(String id) { + return IDebugUIConstants.ID_DEBUG_VIEW.equals(id); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/VariableLabelAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/VariableLabelAdapter.java new file mode 100644 index 000000000..917b94cde --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/VariableLabelAdapter.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.elements.adapters; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IVariable; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.internal.ui.views.launch.DebugElementHelper; +import org.eclipse.swt.graphics.RGB; + +/** + * Label adapter for variables. + * + * @since 3.2 + */ +public class VariableLabelAdapter extends AsynchronousDebugLabelAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousLabelAdapter#getForeground(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected RGB[] getForegrounds(Object element, IPresentationContext context) throws CoreException { + if (element instanceof IVariable) { + IVariable variable = (IVariable) element; + try { + if (variable.hasValueChanged()) { + return new RGB[] {DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CHANGED_VARIABLE_COLOR).getRGB()}; + } + } catch (DebugException e) { + } + return new RGB[] {DebugElementHelper.getForeground(element)}; + } + return super.getForegrounds(element, context); + } + + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/VariableTreeContentAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/VariableTreeContentAdapter.java new file mode 100644 index 000000000..1e37a1528 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/VariableTreeContentAdapter.java @@ -0,0 +1,209 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.elements.adapters; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILogicalStructureType; +import org.eclipse.debug.core.model.IDebugElement; +import org.eclipse.debug.core.model.IIndexedValue; +import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.core.model.IVariable; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.internal.ui.views.variables.IndexedVariablePartition; +import org.eclipse.debug.internal.ui.views.variables.VariablesView; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.ui.IWorkbenchPart; + +public class VariableTreeContentAdapter extends AsynchronousTreeContentAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#getChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + IVariable variable = (IVariable) parent; + IValue value = variable.getValue(); + if (value != null) { + return getValueChildren(variable, value, context); + } + return EMPTY; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#hasChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + IValue value = ((IVariable)element).getValue(); + return value.hasVariables(); + } + + /** + * Returns children for the given value, creating array paritions if + * required + * + * @param parent expression or variable containing the given value + * @param value the value to retrieve children for + * @param context the context in which children have been requested + * @return children for the given value, creating array paritions if + * required + * @throws CoreException + */ + protected Object[] getValueChildren(IDebugElement parent, IValue value, IPresentationContext context) throws CoreException { + if (value == null) { + return EMPTY; + } + IValue logicalValue = getLogicalValue(value, context); + if (logicalValue instanceof IIndexedValue) { + IIndexedValue indexedValue = (IIndexedValue) logicalValue; + int partitionSize = computeParitionSize(indexedValue); + if (partitionSize > 1) { + int offset = indexedValue.getInitialOffset(); + int length = indexedValue.getSize(); + int numPartitions = length / partitionSize; + int remainder = length % partitionSize; + if (remainder > 0) { + numPartitions++; + } + IVariable[] partitions = new IVariable[numPartitions]; + for (int i = 0; i < (numPartitions - 1); i++) { + partitions[i] = new IndexedVariablePartition(parent, indexedValue, offset, partitionSize); + offset = offset + partitionSize; + } + if (remainder == 0) { + remainder = partitionSize; + } + partitions[numPartitions - 1] = new IndexedVariablePartition(parent, indexedValue, offset, remainder); + return partitions; + } + } + if (logicalValue == null) { + // safeguard against an structure type returning null + logicalValue = value; + } + return logicalValue.getVariables(); + } + + /** + * Returns the partition size to use for the given indexed value. The + * partition size is computed by determining the number of levels that an + * indexed collection must be nested in order to partition the collection + * sub-collections of the preferred partition size. + * + * @param value + * indexed value + * @return size of paritions the value should be subdivided into + */ + protected int computeParitionSize(IIndexedValue value) { + int partitionSize = 1; + try { + int length = value.getSize(); + int partitionDepth = 0; + int preferredSize = getArrayPartitionSize(); + int remainder = length % preferredSize; + length = length / preferredSize; + while (length > 0) { + if (remainder == 0 && length == 1) { + break; + } + partitionDepth++; + remainder = length % preferredSize; + length = length / preferredSize; + } + for (int i = 0; i < partitionDepth; i++) { + partitionSize = partitionSize * preferredSize; + } + } catch (DebugException e) { + } + return partitionSize; + } + + /** + * Returns any logical value for the raw value in the specified context + * + * @param value + * @param context + * @return + */ + protected IValue getLogicalValue(IValue value, IPresentationContext context) { + return getLogicalValue(value, new ArrayList(), context); + } + + /** + * Returns any logical value for the raw value. This method will recurse + * over the returned value until the same structure is encountered again (to + * avoid infinite recursion). + * + * @param value + * @param previousStructureIds + * the list of logical structures that have already been applied + * to the returned value during the recursion of this method. + * Callers should always pass in a new, empty list. + * @return + */ + protected IValue getLogicalValue(IValue value, List previousStructureIds, IPresentationContext context) { + if (isShowLogicalStructure(context)) { + ILogicalStructureType[] types = DebugPlugin.getLogicalStructureTypes(value); + if (types.length > 0) { + ILogicalStructureType type = DebugPlugin.getDefaultStructureType(types); + if (type != null && !previousStructureIds.contains(type.getId())) { + try { + value = type.getLogicalStructure(value); + previousStructureIds.add(type.getId()); + return getLogicalValue(value, previousStructureIds, context); + } catch (CoreException e) { + // unable to display logical structure + } + } + } + } + return value; + } + + /** + * Return wether to show compute a logical structure or a raw structure + * in the specified context + * + * @return wether to show compute a logical structure or a raw structure + * in the specified context + */ + protected boolean isShowLogicalStructure(IPresentationContext context) { + IWorkbenchPart part = context.getPart(); + if (part instanceof VariablesView) { + return ((VariablesView) part).isShowLogicalStructure(); + } + return false; + } + + /** + * Returns the number of entries that should be displayed in each partition + * of an indexed collection. + * + * @return the number of entries that should be displayed in each partition + * of an indexed collection + */ + protected int getArrayPartitionSize() { + // TODO: should fix this with a user pref + return 100; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#supportsPartId(java.lang.String) + */ + protected boolean supportsPartId(String id) { + return id.equals(IDebugUIConstants.ID_VARIABLE_VIEW) || id.equals(IDebugUIConstants.ID_REGISTER_VIEW); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/PerspectiveManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/PerspectiveManager.java index 8fbeed8cb..be07fe5cd 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/PerspectiveManager.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/PerspectiveManager.java @@ -19,26 +19,26 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; + import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IDebugEventSetListener; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchListener; import org.eclipse.debug.core.ILaunchManager; -import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.debug.ui.contexts.ISuspendTrigger; +import org.eclipse.debug.ui.contexts.ISuspendTriggerListener; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.swt.widgets.Display; @@ -67,7 +67,7 @@ import org.xml.sax.helpers.DefaultHandler; * @see IDebugUIContants.ATTR_RUN_PERSPECTIVE * @see IDebugUIContants.ATTR_DEBUG_PERSPECTIVE */ -public class PerspectiveManager implements ILaunchListener, IDebugEventSetListener { +public class PerspectiveManager implements ILaunchListener, ISuspendTriggerListener { /** * Table of config types to tables of user specified perspective settings (mode ids @@ -134,7 +134,6 @@ public class PerspectiveManager implements ILaunchListener, IDebugEventSetListen public void startup() { DebugPlugin plugin = DebugPlugin.getDefault(); plugin.getLaunchManager().addLaunchListener(this); - plugin.addDebugEventListener(this); } /** @@ -145,7 +144,6 @@ public class PerspectiveManager implements ILaunchListener, IDebugEventSetListen public void shutdown() { DebugPlugin plugin = DebugPlugin.getDefault(); plugin.getLaunchManager().removeLaunchListener(this); - plugin.removeDebugEventListener(this); } /** @@ -154,6 +152,10 @@ public class PerspectiveManager implements ILaunchListener, IDebugEventSetListen * @see ILaunchListener#launchRemoved(ILaunch) */ public void launchRemoved(ILaunch launch) { + ISuspendTrigger trigger = (ISuspendTrigger) launch.getAdapter(ISuspendTrigger.class); + if (trigger != null) { + trigger.removeSuspendTriggerListener(this); + } } /** @@ -172,6 +174,11 @@ public class PerspectiveManager implements ILaunchListener, IDebugEventSetListen */ public void launchAdded(ILaunch launch) { + ISuspendTrigger trigger = (ISuspendTrigger) launch.getAdapter(ISuspendTrigger.class); + if (trigger != null) { + trigger.addSuspendTriggerListener(this); + } + fPerspectiveSwitchLock.startSwitch(); String perspectiveId = null; @@ -263,25 +270,6 @@ public class PerspectiveManager implements ILaunchListener, IDebugEventSetListen }}); } - /** - * On a SUSPEND event, show the debug view. If no debug view is open, - * switch to the perspective specified by the launcher. - * - * @see IDebugEventSetListener#handleDebugEvents(DebugEvent[]) - */ - public void handleDebugEvents(DebugEvent[] events) { - // open the debugger if this is a suspend event and the debug view is not yet open - // and the preferences are set to switch - for (int i = 0; i < events.length; i++) { - DebugEvent event = events[i]; - if (event.getKind() == DebugEvent.SUSPEND && !event.isEvaluation() && - event.getDetail() != DebugEvent.STEP_END) { - // Don't switch perspective for evaluations or stepping - handleBreakpointHit(event); - } - } - } - /** * Makes the debug view visible. */ @@ -332,7 +320,7 @@ public class PerspectiveManager implements ILaunchListener, IDebugEventSetListen * * @param event the suspend event */ - private void handleBreakpointHit(DebugEvent event) { + private void handleBreakpointHit(ILaunch launch) { // Must be called here to indicate that the perspective // may be switching. @@ -342,14 +330,6 @@ public class PerspectiveManager implements ILaunchListener, IDebugEventSetListen // the perspective switch. fPerspectiveSwitchLock.startSwitch(); - // apply event filters - ILaunch launch= null; - Object source = event.getSource(); - if (source instanceof IDebugElement) { - launch = ((IDebugElement)source).getLaunch(); - } else if (source instanceof IProcess) { - launch = ((IProcess)source).getLaunch(); - } String perspectiveId = null; try { perspectiveId = getPerspectiveId(launch); @@ -815,4 +795,11 @@ public class PerspectiveManager implements ILaunchListener, IDebugEventSetListen public void schedulePostSwitch(Job job) { fPerspectiveSwitchLock.schedulePostSwitch(job); } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.ISuspendTriggerListener#suspended(org.eclipse.debug.core.ILaunch, java.lang.Object) + */ + public void suspended(ILaunch launch, Object context) { + handleBreakpointHit(launch); + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupManager.java new file mode 100644 index 000000000..952350436 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupManager.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.sourcelookup; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.ui.IWindowListener; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +/** + * Starts a source lookup service in each workbench window. + * + * @since 3.2 + */ +public class SourceLookupManager implements IWindowListener { + + private static SourceLookupManager fgDefault; + + /** + * Services per window + */ + private Map fServices = new HashMap(); + + private SourceLookupManager() { + IWorkbench workbench = PlatformUI.getWorkbench(); + IWorkbenchWindow[] workbenchWindows = workbench.getWorkbenchWindows(); + for (int i = 0; i < workbenchWindows.length; i++) { + IWorkbenchWindow window = workbenchWindows[i]; + windowOpened(window); + } + workbench.addWindowListener(this); + } + + /** + * Returns the default source lookup manager. + * + * @return + */ + public static SourceLookupManager getDefault() { + if (fgDefault == null) { + fgDefault = new SourceLookupManager(); + } + return fgDefault; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow) + */ + public void windowActivated(IWorkbenchWindow window) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow) + */ + public void windowDeactivated(IWorkbenchWindow window) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow) + */ + public void windowClosed(IWorkbenchWindow window) { + SourceLookupService service = (SourceLookupService) fServices.get(window); + if (service != null) { + service.dispose(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow) + */ + public void windowOpened(IWorkbenchWindow window) { + SourceLookupService service = new SourceLookupService(window); + fServices.put(window, service); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupService.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupService.java new file mode 100644 index 000000000..39cc2da9a --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupService.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.sourcelookup; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.internal.ui.contexts.DebugContextManager; +import org.eclipse.debug.ui.contexts.IDebugContextListener; +import org.eclipse.debug.ui.contexts.ISourceDisplayAdapter; +import org.eclipse.debug.ui.sourcelookup.ISourceLookupResult; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; + +/** + * Performs source lookup in a window. + * + * @since 3.2 + */ +public class SourceLookupService implements IDebugContextListener { + + private IWorkbenchWindow fWindow; + + private Object fPrevTarget; + private ISourceLookupResult fPrevResult; + + public SourceLookupService(IWorkbenchWindow window) { + fWindow = window; + DebugContextManager.getDefault().addDebugContextListener(this, window); + } + + public void dispose() { + DebugContextManager.getDefault().removeDebugContextListener(this, fWindow); + } + + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextListener#contextActivated(java.lang.Object, org.eclipse.ui.IWorkbenchPart) + */ + public synchronized void contextActivated(ISelection selection, IWorkbenchPart part) { + if (selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection)selection; + if (structuredSelection.size() == 1) { + Object context = (structuredSelection).getFirstElement(); + if (context instanceof IAdaptable) { + IAdaptable adaptable = (IAdaptable) context; + ISourceDisplayAdapter adapter = (ISourceDisplayAdapter) adaptable.getAdapter(ISourceDisplayAdapter.class); + if (adapter != null) { + IWorkbenchPage page = null; + if (part == null) { + page = fWindow.getActivePage(); + } else { + page = part.getSite().getPage(); + } + adapter.displaySource(context, page); + } + } + } + } + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AbstractModelProxy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AbstractModelProxy.java new file mode 100644 index 000000000..eec03e25e --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AbstractModelProxy.java @@ -0,0 +1,48 @@ +package org.eclipse.debug.internal.ui.viewers; + +import org.eclipse.core.runtime.ISafeRunnable; +import org.eclipse.core.runtime.Platform; +import org.eclipse.debug.internal.core.ListenerList; +import org.eclipse.debug.internal.ui.DebugUIPlugin; + +public abstract class AbstractModelProxy implements IModelProxy { + + protected ListenerList fListeners = new ListenerList(1); + + protected Object[] getListeners() { + synchronized (fListeners) { + return fListeners.getListeners(); + } + } + + public void addModelChangedListener(IModelChangedListener listener) { + synchronized (fListeners) { + fListeners.add(listener); + } + } + + public void removeModelChangedListener(IModelChangedListener listener) { + synchronized (fListeners) { + fListeners.remove(listener); + } + } + + public void fireModelChanged(final IModelDelta delta) { + Object[] listeners = getListeners(); + for (int i = 0; i < listeners.length; i++) { + final IModelChangedListener listener = (IModelChangedListener) listeners[i]; + ISafeRunnable safeRunnable = new ISafeRunnable() { + public void handleException(Throwable exception) { + DebugUIPlugin.log(exception); + } + + public void run() throws Exception { + listener.modelChanged(delta); + } + + }; + Platform.run(safeRunnable); + } + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousLabelAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousLabelAdapter.java new file mode 100644 index 000000000..0059c1926 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousLabelAdapter.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.ui.progress.UIJob; + +/** + * Abstract implementation of an asynchronous label adapter + *

+ * Clients may subclass this class. + *

+ * @since 3.2 + */ +public abstract class AsynchronousLabelAdapter implements IAsynchronousLabelAdapter { + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IAsynchronousLabelAdapter#retrieveLabel(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext, org.eclipse.debug.ui.viewers.ILabelRequestMonitor) + */ + public void retrieveLabel(final Object element, final IPresentationContext context, final ILabelRequestMonitor result) { + Job job = null; + if (requiresUIJob()) { + job = new UIJob("Retrieving labels") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + computeLabels(element, context, result); + return Status.OK_STATUS; + } + }; + } else { + job = new Job("Retrieving labels") { //$NON-NLS-1$ + protected IStatus run(IProgressMonitor monitor) { + computeLabels(element, context, result); + return Status.OK_STATUS; + } + }; + } + job.setSystem(true); + job.schedule(); + } + + /** + * Returns whether this label adapter requires to be run in the UI thread. + * By default, label jobs are not run in the UI thread. Subclasses should + * override if required. + * + * @return whether this label adapter requires to be run in the UI thread. + */ + protected boolean requiresUIJob() { + return false; + } + + /** + * Computes label attributes for the given element in the specified context. + * + * @param element element to compute label for + * @param context presentation context + * @param result monitor to report results to + */ + protected void computeLabels(Object element, IPresentationContext context, ILabelRequestMonitor monitor) { + if (!monitor.isCanceled()) { + IStatus status = Status.OK_STATUS; + try { + monitor.setLabels(getLabels(element, context)); + if (!monitor.isCanceled()) { + monitor.setImageDescriptors(getImageDescriptors(element, context)); + } + if (!monitor.isCanceled()) { + monitor.setFontDatas(getFontDatas(element, context)); + } + if (!monitor.isCanceled()) { + monitor.setBackgrounds(getBackgrounds(element, context)); + } + if (!monitor.isCanceled()) { + monitor.setForegrounds(getForegrounds(element, context)); + } + } catch (CoreException e) { + status = e.getStatus(); + } + if (!monitor.isCanceled()) { + monitor.setStatus(status); + monitor.done(); + } + } + } + + /** + * Returns a label for the give element in the specified context. + * + * @param element element to compute label for + * @param context presentation context + * @return label + * @exception CoreException if an exception occurrs computing label + */ + protected abstract String[] getLabels(Object element, IPresentationContext context) throws CoreException; + + /** + * Returns an image descriptor for the given element in the specified context + * or null. + * + * @param element element to compute image descriptor for + * @param context presentation context + * @return image descriptor or null + * @throws CoreException if an exception occurrs computing image descriptor + */ + protected abstract ImageDescriptor[] getImageDescriptors(Object element, IPresentationContext context) throws CoreException; + + /** + * Returns font data for the given element in the specified context or null + * to use the default font. + * + * @param element element to compute font data for + * @param context presentation context + * @return font data or null + * @throws CoreException if an exception occurrs computing font data + */ + protected abstract FontData[] getFontDatas(Object element, IPresentationContext context) throws CoreException; + + /** + * Returns a foreground color for the given element in the specified context or null + * to use the default color. + * + * @param element element to compute color for + * @param context presentation context + * @return color or null + * @throws CoreException if an exception occurrs computing color + */ + protected abstract RGB[] getForegrounds(Object element, IPresentationContext context) throws CoreException; + + /** + * Returns a background color for the given element in the specified context or null + * to use the default color. + * + * @param element element to compute color for + * @param context presentation context + * @return color or null + * @throws CoreException if an exception occurrs computing color + */ + protected abstract RGB[] getBackgrounds(Object element, IPresentationContext context) throws CoreException; +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousRequestMonitor.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousRequestMonitor.java new file mode 100644 index 000000000..b80774c99 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousRequestMonitor.java @@ -0,0 +1,194 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.progress.WorkbenchJob; + +/** + * Base implementation of an asynchronous request monitor. + *

+ * Not intended to be subclassed or instantiated by clients. For internal use + * with the AsynchronousTreeViewer implementation. + *

+ * @since 3.2 + */ +abstract class AsynchronousRequestMonitor implements IAsynchronousRequestMonitor { + + /** + * Widget the upadte is rooted at + */ + private Widget fWidget; + + /** + * Viewer the update is being performed for + */ + private AsynchronousViewer fViewer; + + /** + * Whether this request has been canelled + */ + private boolean fCanceled = false; + + /** + * Update request status or null + */ + private IStatus fStatus = null; + + /** + * Constructs an udpate rooted at the given item. + * + * @param item + */ + AsynchronousRequestMonitor(Widget item, AsynchronousViewer viewer) { + fWidget = item; + fViewer = viewer; + } + + /** + * Returns the viewer this update is being peformed for + * + * @return the viewer this update is being peformed for + */ + protected AsynchronousViewer getViewer() { + return fViewer; + } + + /** + * Returns the widget this update is rooted at + * + * @return the widget this update is rooted at + */ + protected Widget getWidget() { + return fWidget; + } + + /** + * Returns whether this update contains the given widget. + * That is, whether this update is for the same widget or a child of + * the given widget. + * + * @param widget widget to test containment on + * @return whether this update contains the given widget + */ + protected boolean contains(Widget widget) { + if (widget == getWidget()) { + return true; + } + Widget parent = getViewer().getParent(widget); + while (parent != null) { + if (parent.equals(getWidget())) { + return true; + } + parent = getViewer().getParent(parent); + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IAsynchronousRequestMonitor#setStatus(org.eclipse.core.runtime.IStatus) + */ + public void setStatus(IStatus status) { + fStatus = status; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IProgressMonitor#beginTask(java.lang.String, int) + */ + public void beginTask(String name, int totalWork) { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IProgressMonitor#internalWorked(double) + */ + public void internalWorked(double work) { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IProgressMonitor#isCanceled() + */ + public boolean isCanceled() { + return fCanceled; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IProgressMonitor#setCanceled(boolean) + */ + public void setCanceled(boolean value) { + fCanceled = true; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IProgressMonitor#setTaskName(java.lang.String) + */ + public void setTaskName(String name) { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IProgressMonitor#subTask(java.lang.String) + */ + public void subTask(String name) { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IProgressMonitor#worked(int) + */ + public void worked(int work) { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IProgressMonitor#done() + */ + public final void done() { + if (!isCanceled()) { + WorkbenchJob job = new WorkbenchJob("AsynchronousRequestMonitor.done()") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + // necessary to check if widget is disposed. The item may + // have been removed from the tree when another children update + // occured. + getViewer().updateComplete(AsynchronousRequestMonitor.this); + if (!isCanceled() && !getWidget().isDisposed()) { + if (fStatus != null && !fStatus.isOK()) { + getViewer().handlePresentationFailure(AsynchronousRequestMonitor.this, fStatus); + } + performUpdate(); + } + return Status.OK_STATUS; + } + }; + job.setSystem(true); + job.schedule(); + } + } + + /** + * Notification this update has been completed and should now be applied to + * this update's viewer. This method is called in the UI thread. + */ + protected abstract void performUpdate(); + + /** + * Returns whether this update effectively contains the given update. + * That is, whether this update will also perform the given update. + * + * @param update update to compare to + * @return whether this update will also perform the given update + */ + protected abstract boolean contains(AsynchronousRequestMonitor update); +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousTreeContentAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousTreeContentAdapter.java new file mode 100644 index 000000000..add2918e8 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousTreeContentAdapter.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.ui.IWorkbenchPart; + +/** + * Abstract implementation of an asynchronous tree contenxt adapter. + *

+ * Clients may subclass this class. + *

+ * @since 3.2 + */ +public abstract class AsynchronousTreeContentAdapter implements IAsynchronousTreeContentAdapter { + + protected static final Object[] EMPTY = new Object[0]; + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IAsynchronousTreeContentAdapter#retrieveChildren(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext, org.eclipse.debug.ui.viewers.IChildrenRequestMonitor) + */ + public void retrieveChildren(final Object parent, final IPresentationContext context, final IChildrenRequestMonitor result) { + Job job = new Job("Retrieving Children") { //$NON-NLS-1$ + protected IStatus run(IProgressMonitor monitor) { + if (!monitor.isCanceled()) { + computeChildren(parent, context, result); + } + return Status.OK_STATUS; + } + }; + job.setSystem(true); + job.schedule(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IAsynchronousTreeContentAdapter#isContainer(java.lang.Object, org.eclipse.debug.ui.viewers.IPresentationContext, org.eclipse.debug.ui.viewers.IContainerRequestMonitor) + */ + public void isContainer(final Object element, final IPresentationContext context, final IContainerRequestMonitor result) { + Job job = new Job("Computing hasChildren") { //$NON-NLS-1$ + protected IStatus run(IProgressMonitor monitor) { + if (!monitor.isCanceled()) { + computeIsContainer(element, context, result); + } + return Status.OK_STATUS; + } + }; + job.setSystem(true); + job.schedule(); + } + + /** + * Computes the children for the given parent in the specified context. + * + * @param parent parent to retrieve children for + * @param context presentation contenxt + * @param monitor result to report to + */ + protected void computeChildren(Object parent, IPresentationContext context, IChildrenRequestMonitor monitor) { + if (!monitor.isCanceled()) { + IStatus status = Status.OK_STATUS; + try { + if (supportsContext(context)) { + monitor.addChildren(getChildren(parent, context)); + } + } catch (CoreException e) { + status = e.getStatus(); + } + monitor.setStatus(status); + monitor.done(); + } + } + + /** + * Computes whether the given element is a container. + * + * @param parent potential parent + * @param context presentation contenxt + * @param monitor result to report to + */ + protected void computeIsContainer(Object parent, IPresentationContext context, IContainerRequestMonitor monitor) { + if (!monitor.isCanceled()) { + IStatus status = Status.OK_STATUS; + try { + monitor.setIsContainer(hasChildren(parent, context)); + } catch (CoreException e) { + status = e.getStatus(); + } + monitor.setStatus(status); + monitor.done(); + } + } + + /** + * Returns the children for the given parent in the specified context. + * + * @param parent element to retrieve children for + * @param context context children will be presented in + * @return children + * @throws CoreException if an exception occurrs retieving children + */ + protected abstract Object[] getChildren(Object parent, IPresentationContext context) throws CoreException; + + /** + * Returns whether the given element has children in the specified context. + * + * @param element element that may have children + * @param context context element will be presented in + * @return whether the given element has children in the specified context + * @throws CoreException if an exception occurrs determining whether the + * element has children + */ + protected abstract boolean hasChildren(Object element, IPresentationContext context) throws CoreException; + + /** + * Returns whether this adapter supports the given context. + * + * @param context + * @return whether this adapter supports the given context + */ + protected boolean supportsContext(IPresentationContext context) { + IWorkbenchPart part = context.getPart(); + if (part != null) { + return supportsPartId(part.getSite().getId()); + } + return true; + } + + /** + * Returns whether this adapter provides content in the specified part. + * + * @param id part id + * @return whether this adapter provides content in the specified part + */ + protected abstract boolean supportsPartId(String id); +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousTreeViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousTreeViewer.java new file mode 100644 index 000000000..1866a5623 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousTreeViewer.java @@ -0,0 +1,892 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.TreeEvent; +import org.eclipse.swt.events.TreeListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.progress.WorkbenchJob; + +/** + * A tree viewer that retrieves children and labels asynchronously via adapters + * and supports duplicate elements in the tree with different parents. + * Retrieving children and labels asynchrnously allows for arbitrary latency + * without blocking the UI thread. + *

+ * TODO: tree editor not implemented TODO: table tree - what implications does + * it have on IPresentationAdapter? + * + * TODO: Deprecate the public/abstract deferred workbench adapter in favor of + * the presentation adapter. + *

+ *

+ * Clients may instantiate and subclass this class. + *

+ * + * @since 3.2 + */ +public class AsynchronousTreeViewer extends AsynchronousViewer { + + /** + * A map of widget to parent widgets used to avoid requirement for parent + * access in UI thread. Currently used by update objects to detect/cancel + * updates on updates of children. + */ + private Map fItemToParentItem = new HashMap(); + + /** + * The tree + */ + private Tree fTree; + + /** + * Array of tree paths to be expanded. As paths are expanded, those entries + * are set to null. + */ + private TreePath[] fPendingExpansion; + + /** + * Creates an asynchronous tree viewer on a newly-created tree control under + * the given parent. The tree control is created using the SWT style bits + * MULTI, H_SCROLL, V_SCROLL, and BORDER. The + * viewer has no input, no content provider, a default label provider, no + * sorter, and no filters. + * + * @param parent the parent control + */ + public AsynchronousTreeViewer(Composite parent) { + this(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + } + + /** + * Creates an asynchronous tree viewer on a newly-created tree control under + * the given parent. The tree control is created using the given SWT style + * bits. The viewer has no input. + * + * @param parent the parent control + * @param style the SWT style bits used to create the tree. + */ + public AsynchronousTreeViewer(Composite parent, int style) { + this(new Tree(parent, style)); + } + + /** + * Creates an asynchronous tree viewer on the given tree control. The viewer + * has no input, no content provider, a default label provider, no sorter, + * and no filters. + * + * @param tree the tree control + */ + public AsynchronousTreeViewer(Tree tree) { + super(); + fTree = tree; + hookControl(fTree); + setUseHashlookup(false); + tree.addTreeListener(new TreeListener() { + public void treeExpanded(TreeEvent e) { + ((TreeItem) e.item).setExpanded(true); + internalRefresh(e.item.getData(), e.item); + } + + public void treeCollapsed(TreeEvent e) { + } + }); + tree.addMouseListener(new MouseListener() { + + public void mouseUp(MouseEvent e) { + } + + public void mouseDown(MouseEvent e) { + } + + public void mouseDoubleClick(MouseEvent e) { + TreeItem item = ((Tree) e.widget).getItem(new Point(e.x, e.y)); + if (item != null) { + if (item.getExpanded()) { + item.setExpanded(false); + } else { + item.setExpanded(true); + internalRefresh(item.getData(), item); + } + } + } + }); + } + + /** + * Returns the tree control for this viewer. + * + * @return the tree control for this viewer + */ + public Tree getTree() { + return fTree; + } + + /** + * Updates whether the given element has children. + * + * @param element element to update + * @param widget widget associated with the element in this viewer's tree + */ + protected void updateHasChildren(Object element, Widget widget) { + IAsynchronousTreeContentAdapter adapter = getTreeContentAdapter(element); + if (adapter != null) { + IContainerRequestMonitor update = new ContainerRequestMonitor(widget, this); + schedule(update); + adapter.isContainer(element, getPresentationContext(), update); + } + } + + /** + * Updates the children of the given element. + * + * @param parent element of which to update children + * @param widget widget associated with the element in this viewer's tree + */ + protected void updateChildren(Object parent, Widget widget) { + IAsynchronousTreeContentAdapter adapter = getTreeContentAdapter(parent); + if (adapter != null) { + IChildrenRequestMonitor update = new ChildrenRequestMonitor(widget, this); + schedule(update); + adapter.retrieveChildren(parent, getPresentationContext(), update); + } + } + + /** + * Returns the tree element adapter for the given element or + * null if none. + * + * @param element element to retrieve adapter for + * @return presentation adapter or null + */ + protected IAsynchronousTreeContentAdapter getTreeContentAdapter(Object element) { + IAsynchronousTreeContentAdapter adapter = null; + if (element instanceof IAsynchronousTreeContentAdapter) { + adapter = (IAsynchronousTreeContentAdapter) element; + } else if (element instanceof IAdaptable) { + IAdaptable adaptable = (IAdaptable) element; + adapter = (IAsynchronousTreeContentAdapter) adaptable.getAdapter(IAsynchronousTreeContentAdapter.class); + } + return adapter; + } + + /** + * Expands all elements in the given tree selection. + * + * @param selection + */ + public synchronized void expand(ISelection selection) { + if (selection instanceof TreeSelection) { + fPendingExpansion = ((TreeSelection) selection).getPaths(); + if (getControl().getDisplay().getThread() == Thread.currentThread()) { + attemptExpansion(); + } else { + WorkbenchJob job = new WorkbenchJob("attemptExpansion") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + attemptExpansion(); + return Status.OK_STATUS; + } + + }; + job.setSystem(true); + job.schedule(); + } + } + } + + /** + * Attempts to expand all pending expansions. + */ + synchronized void attemptExpansion() { + if (fPendingExpansion != null) { + for (int i = 0; i < fPendingExpansion.length; i++) { + TreePath path = fPendingExpansion[i]; + if (path != null && attemptExpansion(path)) { + fPendingExpansion[i] = null; + } + } + } + } + + /** + * Attempts to expand the given tree path and returns whether the expansion + * was completed. + * + * @param path path to exapand + * @return whether the expansion was completed + */ + synchronized boolean attemptExpansion(TreePath path) { + int segmentCount = path.getSegmentCount(); + for (int j = segmentCount - 1; j >= 0; j--) { + Object element = path.getSegment(j); + Widget[] treeItems = getWidgets(element); + if (treeItems != null) { + for (int k = 0; k < treeItems.length; k++) { + if (treeItems[k] instanceof TreeItem) { + TreeItem treeItem = (TreeItem) treeItems[k]; + TreePath treePath = getTreePath(treeItem); + if (path.startsWith(treePath)) { + if (!treeItem.getExpanded() && treeItem.getItemCount() > 0) { + update(element); + updateChildren(element, treeItem); + expand(treeItem); + if (path.getSegmentCount() == treePath.getSegmentCount()) { + return true; + } + return false; + } + } + } + } + } + } + return false; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.Viewer#getControl() + */ + public Control getControl() { + return fTree; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.StructuredViewer#unmapAllElements() + */ + protected synchronized void unmapAllElements() { + super.unmapAllElements(); + fItemToParentItem.clear(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, + * java.lang.Object) + */ + protected void inputChanged(Object input, Object oldInput) { + super.inputChanged(input, oldInput); + map(input, fTree); + refresh(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.AsynchronousViewer#map(java.lang.Object, + * org.eclipse.swt.widgets.Widget) + */ + protected void map(Object element, Widget item) { + super.map(element, item); + if (item instanceof TreeItem) { + TreeItem treeItem = (TreeItem) item; + TreeItem parentItem = treeItem.getParentItem(); + if (parentItem != null) { + fItemToParentItem.put(treeItem, parentItem); + } + } + } + + /** + * Returns all paths to the given element or null if none. + * + * @param element + * @return paths to the given element or null + */ + public synchronized TreePath[] getTreePaths(Object element) { + Widget[] widgets = getWidgets(element); + if (widgets == null) { + return null; + } + TreePath[] paths = new TreePath[widgets.length]; + for (int i = 0; i < widgets.length; i++) { + List path = new ArrayList(); + path.add(element); + Widget widget = widgets[i]; + TreeItem parent = null; + if (widget instanceof TreeItem) { + TreeItem treeItem = (TreeItem) widget; + parent = getParentItem(treeItem); + } + while (parent != null) { + Object data = getElement(parent); + if (data == null) { + // if the parent is unmapped while attempting selection + return null; + } + path.add(0, data); + parent = getParentItem(parent); + } + path.add(0, getInput()); + paths[i] = new TreePath(path.toArray()); + if (widget instanceof TreeItem) { + paths[i].setTreeItem((TreeItem) widget); + } + } + return paths; + } + + /** + * Constructs and returns a tree path for the given item. Must be called + * from the UI thread. + * + * @param item item to constuct a path for + * @return tree path for the item + */ + protected TreePath getTreePath(TreeItem item) { + TreeItem parent = item; + List path = new ArrayList(); + while (parent != null) { + path.add(0, parent.getData()); + parent = parent.getParentItem(); + } + path.add(0, fTree.getData()); + return new TreePath(path.toArray()); + } + + /** + * Called by ContainerRequestMonitor after it is determined + * if the widget contains children. + * + * @param widget + * @param containsChildren + */ + synchronized void setIsContainer(Widget widget, boolean containsChildren) { + TreeItem[] prevChildren = null; + if (widget instanceof Tree) { + Tree tree = (Tree) widget; + prevChildren = tree.getItems(); + } else { + prevChildren = ((TreeItem) widget).getItems(); + } + if (containsChildren) { + if (prevChildren.length == 0) { + if (widget instanceof Tree) { + // update root elements in the tree + updateChildren(widget.getData(), widget); + } else { + // insert new dummy node to add + + newTreeItem(widget, 0); + if (((TreeItem) widget).getExpanded()) { + updateChildren(widget.getData(), widget); + } + } + } else { + if (widget instanceof Tree || ((TreeItem) widget).getExpanded()) { + // if expanded, update the children + updateChildren(widget.getData(), widget); + } + } + } else if (prevChildren.length > 0) { + // dispose previous children + for (int i = 0; i < prevChildren.length; i++) { + TreeItem prevChild = prevChildren[i]; + unmap(prevChild.getData(), prevChild); + prevChild.dispose(); + } + } + attemptExpansion(); + } + + /** + * Called by ChildrenRequestMonitor after children have been + * retrieved. + * + * @param widget + * @param newChildren + */ + synchronized void setChildren(final Widget widget, final List newChildren) { + preservingSelection(new Runnable() { + + public void run() { + // apply filters + Object[] children = filter(newChildren.toArray()); + + // sort filtered children + ViewerSorter viewerSorter = getSorter(); + if (viewerSorter != null) { + viewerSorter.sort(AsynchronousTreeViewer.this, children); + } + + // update tree + TreeItem[] prevItems = null; + if (widget instanceof Tree) { + Tree tree = (Tree) widget; + prevItems = tree.getItems(); + } else { + prevItems = ((TreeItem) widget).getItems(); + } + + int index = 0; + for (; index < children.length; index++) { + Object kid = children[index]; + TreeItem item = null; + if (index < prevItems.length) { + item = prevItems[index]; + Object oldData = item.getData(); + if (kid.equals(oldData)) { + if (kid != oldData) { + // if equal but not identical, remap the element + remap(kid, item); + } + } else { + unmap(oldData, item); + map(kid, item); + } + } else { + item = newTreeItem(widget, index); + map(kid, item); + } + internalRefresh(kid, item); + } + // remove left over old items + while (index < prevItems.length) { + TreeItem oldItem = prevItems[index]; + unmap(oldItem.getData(), oldItem); + oldItem.dispose(); + index++; + } + } + + }); + + attemptExpansion(); + attemptSelection(true); + } + + /** + * Expands the given tree item and all of its parents. Does *not* update + * elements or retrieve children. + * + * @param child item to expand + */ + private void expand(TreeItem child) { + if (!child.getExpanded()) { + child.setExpanded(true); + + TreeItem parent = child.getParentItem(); + if (parent != null) { + expand(parent); + } + } + } + + /** + * Creates a new tree item as a child of the given widget at the specified + * index. + * + * @param parent parent widget - a Tree or TreeItem + * @param index index at which to create new child + * @return tree item + */ + protected TreeItem newTreeItem(Widget parent, int index) { + if (parent instanceof Tree) { + return new TreeItem((Tree) parent, SWT.NONE, index); + } + return new TreeItem((TreeItem) parent, SWT.NONE, index); + } + + /** + * Unmaps the given item, and unmaps and disposes of all children of that + * item. Does not dispose of the given item. + * + * @param kid + * @param oldItem + */ + protected synchronized void unmap(Object kid, Widget widget) { + if (kid == null) { + // when unmapping a dummy item + return; + } + + TreeItem[] selection = fTree.getSelection(); + if (selection.length == 1 && isChild(widget, selection[0])) { + setSelection(null); + } + + super.unmap(kid, widget); + fItemToParentItem.remove(widget); + if (widget instanceof TreeItem) { + TreeItem item = (TreeItem) widget; + TreeItem[] children = item.getItems(); + for (int i = 0; i < children.length; i++) { + TreeItem child = children[i]; + unmap(child.getData(), child); + child.dispose(); + } + } + } + + private boolean isChild(Widget parent, TreeItem child) { + if (child==null) { + return false; + } else if (parent == child) { + return true; + } + return isChild(parent, child.getParentItem()); + } + + /** + * Returns the parent item for an item or null if none. + * + * @param item item for which parent is requested + * @return parent item or null + */ + protected synchronized TreeItem getParentItem(TreeItem item) { + return (TreeItem) fItemToParentItem.get(item); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(java.lang.Object) + */ + protected Widget doFindInputItem(Object element) { + if (element.equals(getInput())) { + return fTree; + } + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object) + */ + protected Widget doFindItem(Object element) { + Widget[] widgets = getWidgets(element); + if (widgets != null && widgets.length > 0) { + return widgets[0]; + } + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection() + */ + public ISelection getSelection() { + Control control = getControl(); + if (control == null || control.isDisposed()) { + return StructuredSelection.EMPTY; + } + List list = getSelectionFromWidget(); + return new TreeSelection((TreePath[]) list.toArray()); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.StructuredViewer#getSelectionFromWidget() + */ + protected List getSelectionFromWidget() { + TreeItem[] selection = fTree.getSelection(); + TreePath[] paths = new TreePath[selection.length]; + for (int i = 0; i < selection.length; i++) { + paths[i] = getTreePath(selection[i]); + } + return Arrays.asList(paths); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.AsynchronousViewer#internalRefresh(java.lang.Object, + * org.eclipse.swt.widgets.Widget) + */ + protected void internalRefresh(Object element, Widget item) { + super.internalRefresh(element, item); + updateHasChildren(element, item); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.StructuredViewer#reveal(java.lang.Object) + */ + public void reveal(Object element) { + Widget[] widgets = getWidgets(element); + if (widgets != null && widgets.length > 0) { + // TODO: only reveals the first occurrence - should we reveal all? + TreeItem item = (TreeItem) widgets[0]; + Tree tree = (Tree) getControl(); + tree.showItem(item); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.AsynchronousViewer#doAttemptSelectionToWidget(org.eclipse.jface.viewers.ISelection, + * boolean) + */ + protected synchronized ISelection doAttemptSelectionToWidget(ISelection selection, boolean reveal) { + List remaining = new ArrayList(); + if (!selection.isEmpty()) { + List toSelect = new ArrayList(); + List theElements = new ArrayList(); + TreeSelection treeSelection = (TreeSelection) selection; + TreePath[] paths = treeSelection.getPaths(); + for (int i = 0; i < paths.length; i++) { + TreePath path = paths[i]; + if (path == null) { + continue; + } + TreePath[] treePaths = getTreePaths(path.getLastSegment()); + boolean selected = false; + if (treePaths != null) { + for (int j = 0; j < treePaths.length; j++) { + TreePath existingPath = treePaths[j]; + if (existingPath.equals(path)) { + TreeItem treeItem = existingPath.getTreeItem(); + toSelect.add(treeItem); + theElements.add(path.getLastSegment()); + selected = true; + break; + } + } + } + if (!selected) { + remaining.add(path); + } + } + if (!toSelect.isEmpty()) { + final TreeItem[] items = (TreeItem[]) toSelect.toArray(new TreeItem[toSelect.size()]); + // TODO: hack to ensure selection contains 'selected' element + // instead of 'equivalent' element. Handles synch problems + // between + // set selection & refresh + for (int i = 0; i < items.length; i++) { + TreeItem item = items[i]; + Object element = theElements.get(i); + if (item.getData() != element) { + remap(element, item); + } + } + fTree.setSelection(items); + if (reveal) { + fTree.showItem(items[0]); + } + } + } else { + fTree.setSelection(new TreeItem[0]); + } + return new TreeSelection((TreePath[]) remaining.toArray(new TreePath[remaining.size()])); + } + + /** + * Collapses all items in the tree. + */ + public void collapseAll() { + TreeItem[] items = fTree.getItems(); + for (int i = 0; i < items.length; i++) { + TreeItem item = items[i]; + if (item.getExpanded()) + collapse(item); + } + } + + /** + * Collaspes the given item and all of its children items. + * + * @param item item to collapose recursively + */ + protected void collapse(TreeItem item) { + TreeItem[] items = item.getItems(); + for (int i = 0; i < items.length; i++) { + TreeItem child = items[i]; + if (child.getExpanded()) { + collapse(child); + } + } + item.setExpanded(false); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.AsynchronousViewer#setColor(org.eclipse.swt.widgets.Widget, + * org.eclipse.swt.graphics.RGB, org.eclipse.swt.graphics.RGB) + */ + void setColors(Widget widget, RGB[] foregrounds, RGB[] backgrounds) { + if (widget instanceof TreeItem) { + TreeItem item = (TreeItem) widget; + Color[] fgs = getColor(foregrounds); + Color[] bgs = getColor(backgrounds); + for (int i = 0; i < bgs.length; i++) { + item.setForeground(i, fgs[i]); + item.setBackground(i, bgs[i]); + } + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.AsynchronousViewer#setFont(org.eclipse.swt.widgets.Widget, + * org.eclipse.swt.graphics.FontData) + */ + void setFonts(Widget widget, FontData[] fontData) { + if (widget instanceof TreeItem) { + TreeItem item = (TreeItem) widget; + Font[] fonts = getFonts(fontData); + for (int i = 0; i < fonts.length; i++) { + item.setFont(i, fonts[i]); + } + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.AsynchronousViewer#getParent(org.eclipse.swt.widgets.Widget) + */ + protected Widget getParent(Widget widget) { + return (Widget) fItemToParentItem.get(widget); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.AsynchronousViewer#acceptsSelection(org.eclipse.jface.viewers.ISelection) + */ + protected boolean acceptsSelection(ISelection selection) { + return selection instanceof TreeSelection; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.AsynchronousViewer#getEmptySelection() + */ + protected ISelection getEmptySelection() { + return new TreeSelection(new TreePath[0]); + } + + public void add(final TreePath treePath) { + WorkbenchJob job = new WorkbenchJob("AsynchronousTreeViewer.add()") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + Widget widget = getTree(); + for (int i = 0; i < treePath.getSegmentCount(); i++) { + Object segment = treePath.getSegment(i); + if (!segment.equals(getInput())) { + Widget child = findChild(widget, segment, true); + if (child == null) { + return Status.OK_STATUS; + } + widget = child; + } + } + return Status.OK_STATUS; + } + }; + + job.setSystem(true); + job.schedule(); + } + + private Widget findChild(Widget widget, Object segment, boolean create) { + TreeItem[] items = null; + if (widget instanceof Tree) { + items = ((Tree) widget).getItems(); + } else if (widget instanceof TreeItem) { + items = ((TreeItem) widget).getItems(); + } + + if (items != null) { + for (int i = 0; i < items.length; i++) { + TreeItem item = items[i]; + if (segment.equals(item.getData())) { + return item; + } + } + } + + if (create) { + // child doesn't exist. create it. + List datas = new ArrayList(); + for (int i = 0; i < items.length; i++) { + Object data = items[i].getData(); + if (data != null) + datas.add(data); + } + datas.add(segment); + setChildren(widget, datas); + + // search for the new child and return it... + Widget child = findChild(widget, segment, false); + return child; + } + + return null; + } + + public void remove(final TreePath treePath) { + WorkbenchJob job = new WorkbenchJob("AsynchronousTreeViewer.remove()") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + Object lastSegment = treePath.getLastSegment(); + TreePath[] treePaths = getTreePaths(lastSegment); + if (treePaths != null) { + for (int i = 0; i < treePaths.length; i++) { + TreePath path = treePaths[i]; + if (path.equals(treePath)) { + TreeItem treeItem = path.getTreeItem(); + unmap(lastSegment, treeItem); + treeItem.dispose(); + } + } + } + return Status.OK_STATUS; + } + }; + + } + + void setLabels(Widget widget, String[] text, ImageDescriptor[] image) { + if (widget instanceof TreeItem) { + TreeItem item = (TreeItem) widget; + item.setText(text); + item.setImage(getImages(image)); + } + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousViewer.java new file mode 100644 index 000000000..085581f3c --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousViewer.java @@ -0,0 +1,894 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.internal.ui.elements.adapters.AsynchronousDebugLabelAdapter; +import org.eclipse.debug.internal.ui.viewers.update.DefaultUpdatePolicy; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Item; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.progress.WorkbenchJob; + +/** + * A viewer that retrieves labels and content asynchronously via adapters and supports + * duplicate elements in the viewer. Retrieving conetnt and labels asynchrnously allows + * for arbitrary latency without blocking the UI thread. + *

+ * This viewer uses adapters to retreive labels and content rather than + * a label provider and content provider. As such, the label provider for this viewer + * is null by default. The content provider returned by this viewer is + * non-null to conform to the viewer specification, but performs no + * useful function. + *

+ *

+ * The selection in this viewer is also set asynchronously. When the selection is set, + * the viewer attempts to perform the selection. If the elements in the specified selection + * are not yet in the viewer, the portion of the selection that could not be honored + * becomes a pending selection. As more elements are added to viewer, the pending selection + * is attempted to be set. + *

+ * @since 3.2 + */ +public abstract class AsynchronousViewer extends StructuredViewer { + + /** + * A map of elements to associated tree items or tree + */ + private Map fElementsToWidgets = new HashMap(); + + /** + * Map of widgets to their data elements used to avoid requirement to access + * data in UI thread. + */ + private Map fWidgetsToElements = new HashMap(); + + /** + * List of updates currently being performed. + */ + private List fPendingUpdates = new ArrayList(); + + /** + * Cache of images used for elements in this tree viewer. Label updates + * use the method getImage(...) to cache images for + * image descriptors. The images are disposed when this viewer is disposed. + */ + private Map fImageCache = new HashMap(); + + /** + * Cache of the fonts used for elements in this tree viewer. Label updates + * use the method getFont(...) to cache fonts for + * FontData objects. The fonts are disposed with the viewer. + */ + private Map fFontCache = new HashMap(); + + /** + * Cache of the colors used for elements in this tree viewer. Label updates + * use the method getColor(...) to cache colors for + * RGB values. The colors are disposed with the viewer. + */ + private Map fColorCache = new HashMap(); + + /** + * The context in which this viewer is being used - i.e. what part it is contained + * in any any preference settings associated with it. + */ + private IPresentationContext fContext; + + private ISelection fPendingSelection; + + private ISelection fCurrentSelection; + + /** + * The update policy for this viewer. + */ + private IUpdatePolicy fUpdatePolicy; + + /** + * Cache of update policies keyed by element + */ + private Map fModelProxies = new HashMap(); + + /** + * Creates a presentation adapter viewer + */ + protected AsynchronousViewer() { + setContentProvider(new NullContentProvider()); + createUpdatePolicy(); + } + + /** + * Clients must call this methods when this viewer is no longer needed + * so it can perform cleanup. + */ + public synchronized void dispose() { + Iterator images = fImageCache.values().iterator(); + while (images.hasNext()) { + Image image = (Image) images.next(); + image.dispose(); + } + fImageCache.clear(); + + Iterator fonts = fFontCache.values().iterator(); + while (fonts.hasNext()) { + Font font = (Font) fonts.next(); + font.dispose(); + } + fFontCache.clear(); + + Iterator colors = fColorCache.values().iterator(); + while (colors.hasNext()) { + Color color = (Color) colors.next(); + color.dispose(); + } + fColorCache.clear(); + + disposeAllModelProxies(); + fUpdatePolicy.dispose(); + + unmapAllElements(); + fPendingUpdates.clear(); + } + + /** + * Unintalls all update policies installed in this viewer + */ + private void disposeAllModelProxies() { + Iterator updatePolicies = fModelProxies.values().iterator(); + while (updatePolicies.hasNext()) { + IModelProxy proxy = (IModelProxy)updatePolicies.next(); + proxy.dispose(); + } + fModelProxies.clear(); + } + + /** + * Updates all occurrences of the given element in this viewer. + * + * @param element element to update + */ + public void update(Object element) { + if (element == getInput()) { + return; // the input is not displayed + } + Widget[] items = getWidgets(element); + if (items != null) { + for (int i = 0; i < items.length; i++) { + updateLabel(element, items[i]); + } + } + } + + /** + * Updates the label for a specific element and item. + * + * @param element element to update + * @param item its associated item + */ + protected void updateLabel(Object element, Widget item) { + if (item instanceof Item) { + IAsynchronousLabelAdapter adapter = getLabelAdapter(element); + if (adapter != null) { + ILabelRequestMonitor labelUpdate = new LabelRequestMonitor(item, this); + schedule(labelUpdate); + adapter.retrieveLabel(element, getPresentationContext(), labelUpdate); + } + } + } + + /** + * Returns the presentation context to be used in update requests. + * Clients may override this method if required to provide special + * implementations of contexts. + * + * @return presentation contenxt + */ + public IPresentationContext getPresentationContext() { + return fContext; + } + +// /** +// * Refreshes all occurrences of the given element in this tree, and visible +// * children. +// * +// * @param element element to refresh +// */ +// public void refresh(final Object element) { +// // TODO: preserving selection currently has to be UI thread +//// preservingSelection(new Runnable() { +//// public void run() { +// internalRefresh(element); +//// } +//// }); +// } + + /** + * Returns the label adapter for the given element or null if none. + * + * @param element element to retrieve adapter for + * @return presentation adapter or null + */ + protected IAsynchronousLabelAdapter getLabelAdapter(Object element) { + IAsynchronousLabelAdapter adapter = null; + if (element instanceof IAsynchronousLabelAdapter) { + adapter = (IAsynchronousLabelAdapter) element; + } else if (element instanceof IAdaptable) { + IAdaptable adaptable = (IAdaptable) element; + adapter = (IAsynchronousLabelAdapter) adaptable.getAdapter(IAsynchronousLabelAdapter.class); + } + // if no adapter, use default (i.e. model presentation) + if (adapter == null) { + return new AsynchronousDebugLabelAdapter(); + } + return adapter; + } + + /** + * Returns the update policy adapter for the given element or null if none. + * + * @param element element to retrieve adapter for + * @return update policy adapter or null + */ +// protected IUpdatePolicyFactory getUpdatePolicyAdapter(Object element) { +// IUpdatePolicyFactory adapter = null; +// if (element instanceof IUpdatePolicyFactory) { +// adapter = (IUpdatePolicyFactory) element; +// } else if (element instanceof IAdaptable) { +// IAdaptable adaptable = (IAdaptable) element; +// adapter = (IUpdatePolicyFactory) adaptable.getAdapter(IUpdatePolicyFactory.class); +// } +// return adapter; +// } + + /** + * Returns the model proxy factory for the given element of null if none. + * + * @param element element to retrieve adapters for + * @return model proxy factory adapter or null + */ + protected IModelProxyFactory getModelProxyFactoryAdapter(Object element) { + IModelProxyFactory adapter = null; + if (element instanceof IModelProxyFactory) { + adapter = (IModelProxyFactory) element; + } else if (element instanceof IAdaptable) { + IAdaptable adaptable = (IAdaptable) element; + adapter = (IModelProxyFactory) adaptable.getAdapter(IModelProxyFactory.class); + } + return adapter; + } + /** + * Cancels any conflicting updates for children of the given item, and + * schedules the new update. + * + * @param update the update to schedule + */ + protected void schedule(IAsynchronousRequestMonitor update) { + AsynchronousRequestMonitor absUpdate = (AsynchronousRequestMonitor) update; + synchronized (fPendingUpdates) { + Iterator updates = fPendingUpdates.listIterator(); + while (updates.hasNext()) { + AsynchronousRequestMonitor pendingUpdate = (AsynchronousRequestMonitor) updates.next(); + if (absUpdate.contains(pendingUpdate)) { + pendingUpdate.setCanceled(true); + updates.remove(); + } + } + fPendingUpdates.add(update); + } + } + + /** + * Returns the widgets associated with the given element or + * null. + * + * @param element element to retrieve widgets for + * @return widgets or null if none + */ + protected synchronized Widget[] getWidgets(Object element) { + if (element == null) { + return null; + } + return (Widget[]) fElementsToWidgets.get(element); + } + + /** + * Returns the element associated with the given widget or + * null. + * + * @param widget widget to retrieve element for + * @return element or null if none + */ + protected synchronized Object getElement(Widget widget) { + return fWidgetsToElements.get(widget); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.StructuredViewer#unmapAllElements() + */ + protected synchronized void unmapAllElements() { + Iterator iterator = fElementsToWidgets.keySet().iterator(); + while (iterator.hasNext()) { + Object element = iterator.next(); + Widget[] widgets = getWidgets(element); + if (widgets != null) { + for (int i = 0; i < widgets.length; i++) { + Widget widget = widgets[i]; + if (widget instanceof Item) { + Item item = (Item) widget; + item.dispose(); + } + } + } + } + fElementsToWidgets.clear(); + fWidgetsToElements.clear(); + disposeAllModelProxies(); + } + + /** + * Cancels all pending update requests. + */ + protected synchronized void cancelPendingUpdates() { + Iterator updates = fPendingUpdates.iterator(); + while (updates.hasNext()) { + IAsynchronousRequestMonitor update = (IAsynchronousRequestMonitor) updates.next(); + update.setCanceled(true); + } + fPendingUpdates.clear(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, java.lang.Object) + */ + protected void inputChanged(Object input, Object oldInput) { + cancelPendingUpdates(); + } + + /** + * Maps the given element to the given item. Installs the elememt's + * update policy if not already installed. + * + * @param element model element + * @param item TreeItem or Tree + */ + protected void map(Object element, Widget item) { + item.setData(element); + Widget[] widgets = getWidgets(element); + fWidgetsToElements.put(item, element); + if (widgets == null) { + fElementsToWidgets.put(element, new Widget[] { item }); + } else { + Widget[] old = widgets; + Widget[] items = new Widget[old.length + 1]; + System.arraycopy(old, 0, items, 0, old.length); + items[old.length] = item; + fElementsToWidgets.put(element, items); + } + installModelProxy(element); + } + + /** + * Updates the cached information that maps the given element to the + * specified widget. This can be useful when an element is being remapped + * to an equal (but not identical) object. + * + * @param element + * @param item + */ + protected void remap(Object element, Widget item) { + item.setData(element); + fWidgetsToElements.put(item, element); + Object widgets = fElementsToWidgets.remove(element); + fElementsToWidgets.put(element, widgets); + } + + public void createUpdatePolicy() { + fUpdatePolicy = new DefaultUpdatePolicy(); + fUpdatePolicy.init(this); + } + + /** + * Installs the model proxy for the given element into this viewer + * if not already installed. + * + * @param element element to install an update policy for + */ + public void installModelProxy(Object element) { + synchronized (fModelProxies) { + if (!fModelProxies.containsKey(element)) { + IModelProxyFactory modelProxyFactory = getModelProxyFactoryAdapter(element); + if (modelProxyFactory != null) { + IModelProxy proxy = modelProxyFactory.createModelProxy(element, getPresentationContext()); + if (proxy != null) { + proxy.init(getPresentationContext()); + fModelProxies.put(element, proxy); + + if (fUpdatePolicy instanceof IModelChangedListener) { + proxy.addModelChangedListener((IModelChangedListener)fUpdatePolicy); + } + } + } + } + } + } + + + /** + * Uninstalls the model proxy installed for the given element, if any. + * + * @param element + */ + protected void disposeModelProxy(Object element) { + synchronized (fModelProxies) { + IModelProxy proxy = (IModelProxy) fModelProxies.remove(element); + if (proxy != null) { + if (fUpdatePolicy instanceof IModelChangedListener) { + proxy.removeModelChangedListener((IModelChangedListener)fUpdatePolicy); + } + + proxy.dispose(); + } + } + } + + /** + * Removes the update from the pending updates list. + * + * @param update + */ + protected void updateComplete(IAsynchronousRequestMonitor update) { + synchronized (fPendingUpdates) { + fPendingUpdates.remove(update); + } + } + + /** + * Unmaps the given item. Does not dispose of the given item, + * such that it can be reused. + * + * @param kid + * @param widget + */ + protected synchronized void unmap(Object kid, Widget widget) { + if (kid == null) { + // when unmapping a dummy item + return; + } + Widget[] widgets = getWidgets(kid); + fWidgetsToElements.remove(widget); + if (widgets != null) { + for (int i = 0; i < widgets.length; i++) { + Widget item = widgets[i]; + if (item == widget) { + if (widgets.length == 1) { + fElementsToWidgets.remove(kid); + // uninstall its update policy, if element no longer in viewer + disposeModelProxy(kid); + } else { + Widget[] newItems = new Widget[widgets.length - 1]; + System.arraycopy(widgets, 0, newItems, 0, i); + if (i < newItems.length) { + System.arraycopy(widgets, i + 1, newItems, i, newItems.length - i); + } + fElementsToWidgets.put(kid, newItems); + } + } + } + } + } + + Image[] getImages(ImageDescriptor[] descriptors) { + if (descriptors == null || descriptors.length == 0) { + return new Image[0]; + } + Image[] images = new Image[descriptors.length]; + for (int i = 0; i < images.length; i++) { + images[i] = getImage(descriptors[i]); + } + return images; + } + + /** + * Returns an image for the given image descriptor or null. Adds the image + * to a cache of images if it does not already exist. The cache is cleared when this viewer + * is disposed. + * + * @param descriptor image descriptor or null + * @return image or null + */ + Image getImage(ImageDescriptor descriptor) { + if (descriptor == null) { + return null; + } + Image image = (Image) fImageCache.get(descriptor); + if (image == null) { + image = new Image(getControl().getDisplay(), descriptor.getImageData()); + fImageCache.put(descriptor, image); + } + return image; + } + + Font[] getFonts(FontData[] fontDatas) { + if (fontDatas == null) { + return new Font[0]; + } + + Font[] fonts = new Font[fontDatas.length]; + for (int i = 0; i < fonts.length; i++) { + fonts[i] = getFont(fontDatas[i]); + } + return fonts; + } + + /** + * Returns a font for the given font data or null. Adds the font to this viewer's font + * cache which is disposed when this viewer is disposed. + * + * @param fontData font data or null + * @return font font or null + */ + Font getFont(FontData fontData) { + if (fontData == null) { + return null; + } + Font font = (Font) fFontCache.get(fontData); + if (font == null) { + font = new Font(getControl().getDisplay(), fontData); + fFontCache.put(fontData, font); + } + return font; + } + + Color[] getColor(RGB[] rgb) { + if (rgb == null) { + return new Color[0]; + } + Color[] colors = new Color[rgb.length]; + for (int i = 0; i < colors.length; i++) { + colors[i] = getColor(rgb[i]); + } + return colors; + } + /** + * Returns a color for the given RGB or null. Adds the color to this viewer's color + * cache which is disposed when this viewer is disposed. + * + * @param rgb RGB or null + * @return color or null + */ + Color getColor(RGB rgb) { + if (rgb == null) { + return null; + } + Color color = (Color) fColorCache.get(rgb); + if (color == null) { + color = new Color(getControl().getDisplay(), rgb); + fColorCache.put(rgb, color); + } + return color; + } + + /** + * Sets the context for this viewer. + * + * @param context + */ + public void setContext(IPresentationContext context) { + fContext = context; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object) + */ + protected Widget doFindItem(Object element) { + Widget[] widgets = getWidgets(element); + if (widgets != null && widgets.length > 0) { + return widgets[0]; + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(org.eclipse.swt.widgets.Widget, java.lang.Object, boolean) + */ + protected void doUpdateItem(Widget item, Object element, boolean fullMap) { + updateLabel(element, item); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object) + */ + protected void internalRefresh(Object element) { + Widget[] items = getWidgets(element); + if (items == null) { + return; + } + for (int i = 0; i < items.length; i++) { + internalRefresh(element, items[i]); + } + } + + /** + * Refreshes a specific occurrence of an element. + * + * @param element element to update + * @param item item to update + */ + protected void internalRefresh(Object element, Widget item) { + updateLabel(element, item); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.Viewer#setSelection(org.eclipse.jface.viewers.ISelection, boolean) + */ + public synchronized void setSelection(ISelection selection, final boolean reveal) { + Control control = getControl(); + if (control == null || control.isDisposed()) { + return; + } + if (!acceptsSelection(selection)) { + selection = getEmptySelection(); + } + if (!overrideSelection(fCurrentSelection, selection)) { + return; + } + fPendingSelection = selection; + if (getControl().getDisplay().getThread() == Thread.currentThread()) { + attemptSelection(reveal); + } else { + WorkbenchJob job = new WorkbenchJob("attemptSelection") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + attemptSelection(reveal); + return Status.OK_STATUS; + } + + }; + job.setSystem(true); + job.schedule(); + } + } + + /** + * Returns whether the candidate selection should override the current + * selection. + * + * @param current + * @param curr + * @return + */ + protected boolean overrideSelection(ISelection current, ISelection candidate) { + IModelSelectionPolicy selectionPolicy = getSelectionPolicy(current); + if (selectionPolicy == null) { + return true; + } + if (selectionPolicy.contains(candidate, getPresentationContext())) { + return selectionPolicy.overrides(current, candidate, getPresentationContext()); + } + return !selectionPolicy.isSticky(current, getPresentationContext()); + } + + /** + * Returns the selection policy associated with the given selection + * or null if none. + * + * @param selection or null + * @return selection policy or null + */ + protected IModelSelectionPolicy getSelectionPolicy(ISelection selection) { + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss = (IStructuredSelection) selection; + Object element = ss.getFirstElement(); + if (element instanceof IAdaptable) { + IAdaptable adaptable = (IAdaptable) element; + return (IModelSelectionPolicy) adaptable.getAdapter(IModelSelectionPolicy.class); + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(org.eclipse.jface.viewers.ISelection, boolean) + */ + final protected void setSelectionToWidget(ISelection selection, final boolean reveal) { + // NOT USED + throw new IllegalArgumentException("This method should not be called"); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java.util.List, boolean) + */ + final protected void setSelectionToWidget(List l, boolean reveal) { + // NOT USED + throw new IllegalArgumentException("This method should not be called"); //$NON-NLS-1$ + } + + /** + * Attempts to update any pending selection. + * + * @param reveal whether to reveal the selection + */ + protected synchronized void attemptSelection(boolean reveal) { + if (fPendingSelection != null) { + fPendingSelection = doAttemptSelectionToWidget(fPendingSelection, reveal); + if (fPendingSelection.isEmpty()) { + fPendingSelection = null; + } + ISelection currentSelection = getSelection(); + if (isSuppressEqualSelections() && currentSelection.equals(fCurrentSelection)) { + return; + } + fCurrentSelection = currentSelection; + updateSelection(fCurrentSelection); + } + } + + /** + * Controls whether selection change notification is sent even when + * successive selections are equal. + * + * @return whether to suppress change notification for equal successive + * selections + */ + protected boolean isSuppressEqualSelections() { + return true; + } + + /** + * Attemtps to selection the specified selection and returns a selection + * representing the portion of the selection that could not be honored + * and still needs to be selected. + * + * @param selection selection to attempt + * @param reveal whether to reveal the selection + * @return remaining selection + */ + protected abstract ISelection doAttemptSelectionToWidget(ISelection selection, boolean reveal); + + /** + * Returns whether this viewer supports the given selection. + * + * @param selection a selection + * @return whether this viewer supports the given selection + */ + protected abstract boolean acceptsSelection(ISelection selection); + + /** + * Returns an empty selection supported by this viewer. + * + * @return an empty selection supported by this viewer + */ + protected abstract ISelection getEmptySelection(); + + /** + * A content provider that does nothing. + */ + private class NullContentProvider implements IStructuredContentProvider { + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public Object[] getElements(Object inputElement) { + return null; + } + } + + /** + * Notification that a presentation update has failed. + * Subclasses may override as required. The default implementation + * does nothing. + * + * @param monitor monitor for the presentation request that failed + * @param status status of update + */ + protected void handlePresentationFailure(IAsynchronousRequestMonitor monitor, IStatus status) { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.StructuredViewer#preservingSelection(java.lang.Runnable) + */ + protected synchronized void preservingSelection(Runnable updateCode) { + if (fPendingSelection == null) { + ISelection oldSelection = null; + try { + // preserve selection + oldSelection = fCurrentSelection; + // perform the update + updateCode.run(); + } finally { + // restore selection + if (oldSelection == null) { + oldSelection = new TreeSelection(new TreePath[0]); + } + if (getControl().getDisplay().getThread() == Thread.currentThread()) { + restoreSelection(oldSelection); + } else { + final ISelection tempSelection = oldSelection; + WorkbenchJob job = new WorkbenchJob("attemptSelection") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + restoreSelection(tempSelection); + return Status.OK_STATUS; + } + + }; + job.setSystem(true); + job.schedule(); + } + } + } else { + updateCode.run(); + } + } + + protected synchronized void restoreSelection(ISelection oldSelection) { + doAttemptSelectionToWidget(oldSelection, false); + // send out notification if old and new differ + fCurrentSelection = getSelection(); + if (!fCurrentSelection.equals(oldSelection)) + handleInvalidSelection(oldSelection, fCurrentSelection); + } + /** + * Sets the color attributes of the given widget. + * + * @param widget the widget to update + * @param foreground foreground color of the widget or null if default + * @param background background color of the widget or null if default + */ + abstract void setColors(Widget widget, RGB foreground[], RGB background[]); + + /** + * Sets the label attributes of the given widget. + * + * @param widget the widget to update + * @param text label text + * @param image label image or null + */ + abstract void setLabels(Widget widget, String[] text, ImageDescriptor[] image); + + /** + * Sets the font attributes of the given widget. + * + * @param widget widget to update + * @param font font of the widget or null if default. + */ + abstract void setFonts(Widget widget, FontData[] font); + + /** + * Returns the parent widget of the give widget or null + * if none. This method can be called in a non-UI thread. + * + * @param widget widget + * @return parent widget or null + */ + protected abstract Widget getParent(Widget widget); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/ChildrenRequestMonitor.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/ChildrenRequestMonitor.java new file mode 100644 index 000000000..adbb5634c --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/ChildrenRequestMonitor.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.widgets.Widget; + +/** + * Implementation for IChildrenRequestMonitor. Collects + * children from an asynchronous tree content adapter. + *

+ * Not intended to be subclassed or instantiated by clients. For use + * speficially with AsynchronousTreeViewer. + *

+ * @since 3.2 + */ +class ChildrenRequestMonitor extends AsynchronousRequestMonitor implements IChildrenRequestMonitor { + + /** + * Collection of children retrieved + */ + private List fChildren = new ArrayList(); + + /** + * Constucts a monitor to retrieve and update the children of the given + * widget. + * + * @param widget widget to retrieve children for + */ + ChildrenRequestMonitor(Widget widget, AsynchronousTreeViewer viewer) { + super(widget, viewer); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IChildrenRequestMonitor#addChild(java.lang.Object) + */ + public void addChild(Object child) { + fChildren.add(child); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IChildrenRequestMonitor#addChildren(java.lang.Object[]) + */ + public void addChildren(Object[] children) { + for (int i = 0; i < children.length; i++) { + fChildren.add(children[i]); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousRequestMonitor#contains(org.eclipse.debug.ui.viewers.AsynchronousRequestMonitor) + */ + protected boolean contains(AsynchronousRequestMonitor update) { + return (update instanceof ChildrenRequestMonitor || update instanceof ContainerRequestMonitor) && contains(update.getWidget()); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousRequestMonitor#performUpdate() + */ + protected void performUpdate() { + ((AsynchronousTreeViewer)getViewer()).setChildren(getWidget(), fChildren); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/ContainerRequestMonitor.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/ContainerRequestMonitor.java new file mode 100644 index 000000000..c7ba88ee0 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/ContainerRequestMonitor.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.swt.widgets.Widget; + +/** + * Implementation of an IContainerRequestMonitor. Collects whether + * an element contains children. + *

+ * Not intended to be subclassed or instantiated by clients. For use + * speficially with AsynchronousTreeViewer. + *

+ * @since 3.2 + */ +class ContainerRequestMonitor extends AsynchronousRequestMonitor implements IContainerRequestMonitor { + + /** + * Whether the item has children + */ + private boolean fIsChildren = false; + + /** + * Constructs an update request for the given item in the given viewer. + * + * @param item item to update + * @param viewer viewer the update was issued for + */ + ContainerRequestMonitor(Widget item, AsynchronousTreeViewer viewer) { + super(item, viewer); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousRequestMonitor#performUpdate() + */ + protected void performUpdate() { + ((AsynchronousTreeViewer)getViewer()).setIsContainer(getWidget(), fIsChildren); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousRequestMonitor#contains(org.eclipse.debug.ui.viewers.AsynchronousRequestMonitor) + */ + protected boolean contains(AsynchronousRequestMonitor update) { + return (update instanceof ChildrenRequestMonitor || update instanceof ContainerRequestMonitor) && contains(update.getWidget()); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IContainerRequestMonitor#setIsContainer(boolean) + */ + public void setIsContainer(boolean container) { + fIsChildren = container; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/DefaultElementComparer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/DefaultElementComparer.java new file mode 100644 index 000000000..46593e6be --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/DefaultElementComparer.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.jface.viewers.IElementComparer; + +/** + * Default comparator used to compare individual elements in a tree path. + * + * @since 3.2 + * @see org.eclipse.debug.internal.ui.treeviewer.TreePath + */ +public class DefaultElementComparer implements IElementComparer { + + public static final DefaultElementComparer INSTANCE= new DefaultElementComparer(); + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IElementComparer#equals(java.lang.Object, java.lang.Object) + */ + public boolean equals(Object a, Object b) { + return a.equals(b); + } + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IElementComparer#hashCode(java.lang.Object) + */ + public int hashCode(Object element) { + return element.hashCode(); + } +} + diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IAsynchronousLabelAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IAsynchronousLabelAdapter.java new file mode 100644 index 000000000..e0bf9ac97 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IAsynchronousLabelAdapter.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +/** + * Provides labels for elements. Note that implementations + * are must provide labels asynchronously. + *

+ * Clients may implement this interface. + *

+ * @since 3.2 + */ +public interface IAsynchronousLabelAdapter { + + /** + * Asynchronously retrieves the label of the given object reporting to + * the given monitor. If unable to retrieve label information, an exception should be + * reported to the monitor with an appropriate status. + * + * @param object the element for which a label is requested + * @param context the context in which the label has been requested + * @param monitor request monitor to report the result to + */ + public void retrieveLabel(Object object, IPresentationContext context, ILabelRequestMonitor result); + + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IAsynchronousRequestMonitor.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IAsynchronousRequestMonitor.java new file mode 100644 index 000000000..8d2638e3c --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IAsynchronousRequestMonitor.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; + +/** + * Common interface for requests made on elements in an asynchronous viewer. Results + * of a request are reported to a request monitor asynchronously (usually a + * specialization of this interface). An request may be cancelled by the client + * making the request, or by the adapter fulfilling the request. + * Adapters may report failure by setting an appropriate status on this monitor. When a request + * is complete, an adapter must call done() on the monitor, no matter + * if the update succeeded or failed. The done() method does not need to be + * called if a request is canceled. + *

+ * Operations accepting a request monitor are expected to poll the + * monitor (using isCanceled) periodically and abort at their + * earliest convenience. + *

+ *

+ * This interface is not intended to be implemented by clients. + *

+ * @since 3.2 + */ +public interface IAsynchronousRequestMonitor extends IProgressMonitor { + + /** + * Sets the status of this request, possibly null. + * When a request fails, the status indicates why the request failed. + * A null status is considered to be successful. + * + * @param status request status + */ + public void setStatus(IStatus status); +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IAsynchronousTreeContentAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IAsynchronousTreeContentAdapter.java new file mode 100644 index 000000000..65f4ef6f4 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IAsynchronousTreeContentAdapter.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +/** + * Provides content for elements in a tree viewer. Note that implementations + * must provide content asynchronously. + *

+ * Clients may implement this interface. + *

+ * @since 3.2 + */ +public interface IAsynchronousTreeContentAdapter { + + /** + * Asynchronously retrieves the children of the given parent reporting to the + * given monitor. If unable to retrieve children, an exception should be reported + * to the monitor with an appropriate status. + * + * @param parent the element to retrieve children for + * @param context the context in which children have been requested + * @param monitor request monitor to report children to + */ + public void retrieveChildren(Object parent, IPresentationContext context, IChildrenRequestMonitor result); + + /** + * Asynchronously determines whether the given element contains children in the specified + * context reporting the result to the given monitor. If unable to determine + * whether the element has children, an exception should be reported to the monitor + * with an appropriate status. + * + * @param element the element on which children may exist + * @param context the context in which children may exist + * @param monitor request monitor to report the result to + */ + public void isContainer(Object element, IPresentationContext context, IContainerRequestMonitor result); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IChildrenRequestMonitor.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IChildrenRequestMonitor.java new file mode 100644 index 000000000..2acb16b64 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IChildrenRequestMonitor.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +/** + * A request monitor that collects children from an asynchronous tree content adapter. + *

+ * This interface is not intended to be implemented by clients. + *

+ * @since 3.2 + */ +public interface IChildrenRequestMonitor extends IAsynchronousRequestMonitor { + + /** + * Adds the given child to this request. + * + * @param child child to add + */ + public void addChild(Object child); + + /** + * Adds the given children to this request. + * + * @param children children to add + */ + public void addChildren(Object[] children); +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IContainerRequestMonitor.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IContainerRequestMonitor.java new file mode 100644 index 000000000..e1aff02c5 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IContainerRequestMonitor.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +/** + * A request monitor that collects whether an element contains + * children. + *

+ * This interface is not intended to be implemented by clients. + *

+ * @since 3.2 + */ +public interface IContainerRequestMonitor extends IAsynchronousRequestMonitor { + + /** + * Sets whether an element contains children. + * + * @param container whether an element contains children + */ + public void setIsContainer(boolean container); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/ILabelRequestMonitor.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/ILabelRequestMonitor.java new file mode 100644 index 000000000..b72976455 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/ILabelRequestMonitor.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.RGB; + +/** + * A request monitor that collects attributes of a element's + * label. + *

+ * This interface is not intended to be implemented by clients. + *

+ * @since 3.2 + */ +public interface ILabelRequestMonitor extends IAsynchronousRequestMonitor { + + /** + * Sets the text of the label. Cannot be null. + * + * @param text + */ + public void setLabels(String[] text); + + /** + * Sets the font of the label. + * + * @param fontData + */ + public void setFontDatas(FontData[] fontData); + + /** + * Sets the image of the label. + * + * @param image + */ + public void setImageDescriptors(ImageDescriptor[] image); + + /** + * Sets the foreground color of the label. + * + * @param foreground + */ + public void setForegrounds(RGB[] foreground); + + /** + * Sets the background color of the label. + * + * @param background + */ + public void setBackgrounds(RGB[] background); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelChangedListener.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelChangedListener.java new file mode 100644 index 000000000..c8f4eefd7 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelChangedListener.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +/** + * A model changed listener is notified of changes in a model. + * + * @since 3.2 + */ +public interface IModelChangedListener { + + /** + * Notification a model has changed as described by the given delta. + * + * @param delta model delta + */ + public void modelChanged(IModelDelta delta); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelDelta.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelDelta.java new file mode 100644 index 000000000..4e7e5e985 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelDelta.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +/** + * Describes a change within a model. A delta is a hierarchical description of a change + * within a model. It constists of a path of nodes. Each node references an element + * from a model, and desribes how that element changed. + *

+ * An element can be added, removed, or changed. As well, its possible that an element + * did not change, but that one of its children changed. When an element changes, an + * additional information describes the change. For example, and element's content may have + * changed (its children), or its state may have changed. + *

+ *

+ * Optionally, an update action is provided with a node. A node may be expanded + * or selected. + *

+ * @since 3.2 + */ +public interface IModelDelta { + + //change type + public static int NOCHANGE = 0; + public static int ADDED = 1; + public static int REMOVED = 1 << 1; + public static int CHANGED = 1 << 2; + + //how it changed. + public static int CONTENT = 1 << 10; + public static int STATE = 1 << 11; + + // action + public static int EXPAND = 1 << 12; + public static int SELECT = 1 << 13; + + // TODO: should be part of the implementation rather than the interface (i.e. + // interface should bre read-only). + public IModelDeltaNode addNode(Object element, int flags); + public IModelDeltaNode[] getNodes(); +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelDeltaNode.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelDeltaNode.java new file mode 100644 index 000000000..a672eea4a --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelDeltaNode.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.debug.internal.ui.viewers.update.ModelDeltaNode; + +/** + * + * + * @since 3.2 + */ +public interface IModelDeltaNode { + public IModelDeltaNode getParent(); + public Object getElement(); + public int getFlags(); + public ModelDeltaNode[] getNodes(); + + // TODO: should be part of the implementation rather than the interface (i.e. + // interface should bre read-only). + public IModelDeltaNode addNode(Object object, int flags); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelProxy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelProxy.java new file mode 100644 index 000000000..b1a18dd33 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelProxy.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +/** + * + * + * @since 3.2 + */ +public interface IModelProxy { + + public void init(IPresentationContext context); + public void dispose(); + public void addModelChangedListener(IModelChangedListener listener); + public void removeModelChangedListener(IModelChangedListener listener); + + // TODO: should be part of the implementation rather than the interface + public void fireModelChanged(IModelDelta delta); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelProxyFactory.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelProxyFactory.java new file mode 100644 index 000000000..9a1d64625 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelProxyFactory.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +/** + * + * + * @since 3.2 + */ +public interface IModelProxyFactory { + public IModelProxy createModelProxy(Object element, IPresentationContext context); +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelSelectionPolicy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelSelectionPolicy.java new file mode 100644 index 000000000..40f1e758b --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IModelSelectionPolicy.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.jface.viewers.ISelection; + +/** + * Resolves selection conflicts within a model. When + * a selection exists in a viewer, and a client asks + * to set another selection, the selection policy for + * that model is asked to determine whether the new + * selection should override the previous selection. + * When a selection is from a different model, the + * original selection is maintained if its model selection + * policy specifies the selection to be 'sticky'. + *

+ * A selection policy is obtained as an adapter from + * an element in a viewer, and the adapter represents + * selections from an instance of a model. + *

+ * @since 3.2 + */ +public interface IModelSelectionPolicy { + + /** + * Returns whether the given selection is contained in + * this model. + * + * @param selection + * @param context + * @return + */ + public boolean contains(ISelection selection, IPresentationContext context); + + /** + * Returns whether the candidate selection overrides the + * existing selection. The policy is only asked about selections + * that it contains. + * + * @param existing + * @param candidate + * @param context + * @return + */ + public boolean overrides(ISelection existing, ISelection candidate, IPresentationContext context); + + /** + * Returns whether the given selection should be maintained in the + * face of a selection attempt from a different model. + * + * @param selection + * @param context + * @return + */ + public boolean isSticky(ISelection selection, IPresentationContext context); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IPresentationContext.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IPresentationContext.java new file mode 100644 index 000000000..89db4618e --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IPresentationContext.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.ui.IWorkbenchPart; + +/** + * Context in which an asynchronous request has been made. + *

+ * Clients are may implement and extend this interface to provide + * special contexts. + *

+ * @since 3.2 + */ +public interface IPresentationContext { + + /** + * Returns the part for which a request is being made + * or null if none. + * + * @return the part for which a request is being made + * or null + */ + public IWorkbenchPart getPart(); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IUpdatePolicy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IUpdatePolicy.java new file mode 100644 index 000000000..0930535db --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IUpdatePolicy.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + + + +/** + * An update policy updates elements from an instance of a model + * in a viewer. + * + * @since 3.2 + */ +public interface IUpdatePolicy { + + /** + * Installs this update policy on the given viewer. + * + * @param viewer viewer to update + */ + public void init(AsynchronousViewer viewer); + + /** + * Disposes this update policy. + */ + public void dispose(); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IUpdatePolicyFactory.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IUpdatePolicyFactory.java new file mode 100644 index 000000000..ba4fb8400 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/IUpdatePolicyFactory.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + + +/** + * Used to create update policies for elements. An update policy factory + * should be registered as adapters for root elements in a model. + * + * @since 3.2 + */ +public interface IUpdatePolicyFactory { + + /** + * Creates and returns an update policy to use for the given element in the + * specified context, or null if none. + * + * @param element the element to be updated + * @param context the context in which the element is being presented + * @return update policy or null + */ + public IUpdatePolicy createUpdatePolicy(IPresentationContext context); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/LabelRequestMonitor.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/LabelRequestMonitor.java new file mode 100644 index 000000000..72cb34942 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/LabelRequestMonitor.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Widget; + +/** + * Implementation of an ILabelRequestMonitor. Collects label + * attributes from an asynchronous label adapter. + *

+ * Not intended to be subclassed or instantiated by clients. For use speficially + * with AsynchronousViewer. + *

+ * + * @since 3.2 + */ +class LabelRequestMonitor extends AsynchronousRequestMonitor implements ILabelRequestMonitor { + + /** + * Retrieved label text. Only null if cancelled or failed. + */ + private String[] fLabels; + + /** + * Retrieved image descriptor or null + */ + private ImageDescriptor[] fImageDescriptors; + + /** + * Retrieved font data or null + */ + private FontData[] fFontDatas; + + /** + * Retieved colors or null + */ + private RGB[] fForegrounds; + private RGB[] fBackgrounds; + + /** + * Cosntructs a request to upate the label of the given widget in the give + * viewer. + * + * @param widget widget to update + * @param viewer viewer containing the widget + */ + LabelRequestMonitor(Widget widget, AsynchronousViewer viewer) { + super(widget, viewer); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.AsynchronousRequestMonitor#performUpdate() + */ + protected void performUpdate() { + AsynchronousViewer viewer = getViewer(); + Widget widget = getWidget(); + viewer.setLabels(widget, fLabels, fImageDescriptors); + viewer.setColors(widget, fForegrounds, fBackgrounds); + viewer.setFonts(widget, fFontDatas); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.AsynchronousRequestMonitor#contains(org.eclipse.debug.ui.viewers.AsynchronousRequestMonitor) + */ + protected boolean contains(AsynchronousRequestMonitor update) { + return update instanceof LabelRequestMonitor && update.getWidget() == getWidget(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.ILabelRequestMonitor#setLabel(java.lang.String) + */ + public void setLabels(String[] text) { + fLabels = text; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.ILabelRequestMonitor#setFontData(org.eclipse.swt.graphics.FontData) + */ + public void setFontDatas(FontData[] fontData) { + fFontDatas = fontData; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.ILabelRequestMonitor#setImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) + */ + public void setImageDescriptors(ImageDescriptor[] image) { + fImageDescriptors = image; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.ILabelRequestMonitor#setForeground(org.eclipse.swt.graphics.RGB) + */ + public void setForegrounds(RGB[] foreground) { + fForegrounds = foreground; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.ILabelRequestMonitor#setBackground(org.eclipse.swt.graphics.RGB) + */ + public void setBackgrounds(RGB[] background) { + fBackgrounds = background; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/PresentationContext.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/PresentationContext.java new file mode 100644 index 000000000..0b07010ce --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/PresentationContext.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.ui.IWorkbenchPart; + +/** + * Presentation context. + *

+ * Clients may instantiate and subclass this class. + *

+ * @since 3.2 + */ +public class PresentationContext implements IPresentationContext { + + private IWorkbenchPart fPart; + + /** + * Constructs a presentation context for the given part. + * + * @param part workbench part + */ + public PresentationContext(IWorkbenchPart part) { + fPart = part; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IPresentationContext#getPart() + */ + public IWorkbenchPart getPart() { + return fPart; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/TreePath.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/TreePath.java new file mode 100644 index 000000000..d0145bee2 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/TreePath.java @@ -0,0 +1,179 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.viewers.IElementComparer; +import org.eclipse.swt.widgets.TreeItem; + +/** + * A tree path denotes a model element in a tree viewer. Tree path + * objects do have value semantics. A model element is represented by + * a path of elements in the tree from the root element to the leaf + * element. + *

+ * Clients may instantiate this class. Not intended to be subclassed. + *

+ * @since 3.2 + */ +public final class TreePath { + private Object[] fSegments; + private int fHash; + private TreeItem fItem; + + /** + * Constructs a path identifying a leaf node in a tree. + * + * @param segments path of elements to a leaf node in a tree, starting with the root element + */ + public TreePath(Object[] segments) { + Assert.isNotNull(segments); + for (int i= 0; i < segments.length; i++) { + Assert.isNotNull(segments[i]); + } + fSegments= segments; + } + + /** + * Returns the element at the specified index in this path. + * + * @param index index of element to return + * @return element at the specified index + */ + public Object getSegment(int index) { + return fSegments[index]; + } + + /** + * Returns the number of elements in this path. + * + * @return the number of elements in this path + */ + public int getSegmentCount() { + return fSegments.length; + } + + /** + * Returns the first element in this path. + * + * @return the first element in this path + */ + public Object getFirstSegment() { + if (fSegments.length == 0) + return null; + return fSegments[0]; + } + + /** + * Returns the last element in this path. + * + * @return the last element in this path + */ + public Object getLastSegment() { + if (fSegments.length == 0) + return null; + return fSegments[fSegments.length - 1]; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object other) { + if (!(other instanceof TreePath)) + return false; + return equals((TreePath)other, null); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + if (fHash != 0) + return fHash; + for (int i= 0; i < fSegments.length; i++) { + fHash= fHash + fSegments[i].hashCode(); + } + return fHash; + } + + /** + * Returns whether this path is equivalent to the given path using the + * specified comparator to compare individual elements. + * + * @param otherPath tree path to compare to + * @param comparer compartor to use or null if default comparator + * should be used + * @return whether the paths are equal + */ + public boolean equals(TreePath otherPath, IElementComparer comparer) { + if (comparer == null) + comparer= DefaultElementComparer.INSTANCE; + if (otherPath == null) + return false; + if (fSegments.length != otherPath.fSegments.length) + return false; + for (int i= 0; i < fSegments.length; i++) { + if (!comparer.equals(fSegments[i], otherPath.fSegments[i])) + return false; + } + return true; + } + + /** + * Used internally to set the tree item associated with the leaf element. + * + * @param item associated tree item for the leaf element + */ + void setTreeItem(TreeItem item) { + fItem = item; + } + + /** + * Used internally to return the tree item associated with the leaf element. + * + * @return tree item associated with leaf element or null + */ + TreeItem getTreeItem() { + return fItem; + } + + /** + * Returns whether this path starts with the same elements in the given path. + * This is indicates the given path is a prefix of this path, or is the same + * as this path. + * + * @param treePath path to compare to + * @return whether the given path is a prefix of this path, or the same as this + * path + */ + public boolean startsWith(TreePath treePath) { + if (treePath == null) { + return false; + } + + if (treePath.equals(this)) { + return true; + } + + int segmentCount = treePath.getSegmentCount(); + if (segmentCount >= fSegments.length) { + return false; + } + for (int i = 0; i < segmentCount; i++) { + Object segment = treePath.getSegment(i); + if (!segment.equals(fSegments[i])) { + return false; + } + } + return true; + } +} + diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/TreeSelection.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/TreeSelection.java new file mode 100644 index 000000000..1cb75346c --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/TreeSelection.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.viewers.IStructuredSelection; + +/** + * A selection in a async tree viewer. Selections in an async tree viewer + * are identified by associated tree paths. As there can be duplicate elements + * in a tree viewer, paths are required to uniquely identify which leaf + * elements are selected. + *

+ * Clients may instantiate this class. Not intended to be subclassed. + *

+ * @since 3.2 + */ +public class TreeSelection implements IStructuredSelection { + + private TreePath[] fPaths = null; + + /** + * Constructs a selection based on the elements identified by the + * given tree paths. + * + * @param paths tree paths where null indicates an + * empty selection + */ + public TreeSelection(TreePath[] paths) { + fPaths = paths; + } + + /** + * Constructs a selection based on the elements identified by the + * given tree path. + * + * @param treePath tree path where null indicates an + * empty selection. + */ + public TreeSelection(TreePath treePath) { + this(treePath != null ? new TreePath[] {treePath} : null); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IStructuredSelection#getFirstElement() + */ + public Object getFirstElement() { + if (fPaths != null && fPaths.length > 0) { + return fPaths[0].getLastSegment(); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IStructuredSelection#iterator() + */ + public Iterator iterator() { + return toList().iterator(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IStructuredSelection#size() + */ + public int size() { + if (fPaths != null) { + return fPaths.length; + } + return 0; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IStructuredSelection#toArray() + */ + public Object[] toArray() { + int size = size(); + Object[] selection = new Object[size]; + for (int i = 0; i < size; i++) { + selection[i] = fPaths[i].getLastSegment(); + } + return selection; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IStructuredSelection#toList() + */ + public List toList() { + int size = size(); + List selection = new ArrayList(size); + for (int i = 0; i < size; i++) { + selection.add(fPaths[i].getLastSegment()); + } + return selection; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ISelection#isEmpty() + */ + public boolean isEmpty() { + return size() == 0; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if (obj instanceof TreeSelection) { + TreeSelection selection = (TreeSelection) obj; + int size = size(); + if (selection.size() == size) { + if (size > 0) { + for (int i = 0; i < fPaths.length; i++) { + if (!fPaths[i].equals(selection.fPaths[i])) { + return false; + } + } + } + return true; + } + } + return false; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + int code = getClass().hashCode(); + if (fPaths != null) { + for (int i = 0; i < fPaths.length; i++) { + code+=fPaths[i].hashCode(); + } + } + return code; + } + + /** + * Returns the paths in this selection + * + * @return the paths in this selection + */ + public TreePath[] getPaths() { + return (TreePath[]) fPaths.clone(); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/AbstractUpdatePolicy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/AbstractUpdatePolicy.java new file mode 100644 index 000000000..8ead85266 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/AbstractUpdatePolicy.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers.update; + +import org.eclipse.debug.internal.ui.viewers.AsynchronousViewer; +import org.eclipse.debug.internal.ui.viewers.IUpdatePolicy; + +/** + * @since 3.2 + * + */ +public abstract class AbstractUpdatePolicy implements IUpdatePolicy { + + private AsynchronousViewer fViewer = null; + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IUpdatePolicy#init(org.eclipse.debug.ui.viewers.update.IPresentation) + */ + public void init(AsynchronousViewer viewer) { + fViewer = viewer; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IUpdatePolicy#dispose() + */ + public synchronized void dispose() { + fViewer = null; + } + + /** + * Returns the viewer this policy is installed on or null + * if disposed. + * + * @return presentation to update + */ + public AsynchronousViewer getViewer() { + return fViewer; + } + + protected synchronized boolean isDisposed() { + return fViewer == null; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DebugEventHandler.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DebugEventHandler.java new file mode 100644 index 000000000..95ee46604 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DebugEventHandler.java @@ -0,0 +1,154 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers.update; + +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.internal.ui.viewers.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.IModelProxy; + +/** + * Handles debug events for an event update policy in a viewer. + * + * @since 3.2 + */ +public abstract class DebugEventHandler { + + private IModelProxy fModelProxy; + + /** + * Constructs an event handler for the given update policy. + * + * @param policy + */ + public DebugEventHandler(IModelProxy proxy) { + fModelProxy = proxy; + } + + /** + * Disposes this event handler + */ + public void dispose() { + fModelProxy = null; + } + + /** + * Returns the viewer this event handler is updating. + * + * @return + */ + protected IModelProxy getModelProxy() { + return fModelProxy; + } + + /** + * Returns whether this event handler handles the given event + * + * @param event event to handle + * @return whether this event handler handles the given event + */ + protected abstract boolean handlesEvent(DebugEvent event); + + /** + * Handles a create event. + * + * @param event + */ + protected void handleCreate(DebugEvent event) { + refreshRoot(event); + } + + /** + * Handles a terminate event. + * + * @param event + */ + protected void handleTerminate(DebugEvent event) { + refreshRoot(event); + } + + /** + * Handles a suspend event. + * + * @param event + */ + protected void handleSuspend(DebugEvent event) { + refreshRoot(event); + } + + /** + * Handles a resume event for which a suspend is expected shortly (<500ms). + * + * @param event + */ + protected void handleResumeExpectingSuspend(DebugEvent event) { + refreshRoot(event); + } + + /** + * Handles a resume event that is not expecting an immediate suspend event + * + * @param event + */ + protected void handleResume(DebugEvent event) { + refreshRoot(event); + } + + /** + * Handles a change event. + * + * @param event + */ + protected void handleChange(DebugEvent event) { + refreshRoot(event); + } + + /** + * Handles an unknown event. + * + * @param event + */ + protected void handleOther(DebugEvent event) { + refreshRoot(event); + } + + /** + * Notification that a pending suspend event was not received for the given + * resume event within the timeout period. + * + * @param resume resume event with missing suspend event + */ + protected void handleSuspendTimeout(DebugEvent event) { + refreshRoot(event); + } + + /** + * Handles the given suspend event which caused a timeout. It is + * parired with its original resume event. + * + * @param suspend suspend event + * @param resume resume event + */ + protected void handleLateSuspend(DebugEvent suspend, DebugEvent resume) { + refreshRoot(suspend); + } + + /** + * Fires a model delta to indicate that the launch manager should be refreshed. + * Subclasses should override individual handle events to provide deltas that + * better reflect the actual change in the model. + */ + protected void refreshRoot(DebugEvent event) { + ModelDelta delta = new ModelDelta(); + delta.addNode(DebugPlugin.getDefault().getLaunchManager(), IModelDelta.CHANGED | IModelDelta.CONTENT); + getModelProxy().fireModelChanged(delta); + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DebugTargetEventHandler.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DebugTargetEventHandler.java new file mode 100644 index 000000000..fdac9e8b0 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DebugTargetEventHandler.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers.update; + +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.internal.ui.viewers.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.IModelDeltaNode; +import org.eclipse.debug.internal.ui.viewers.IModelProxy; + + +/** + * @since 3.2 + */ +public class DebugTargetEventHandler extends DebugEventHandler { + + /** + * Constructs an event handler for a debug target on the given viewer. + * + * @param viewer + */ + public DebugTargetEventHandler(IModelProxy proxy) { + super(proxy); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.viewers.update.DebugEventHandler#handlesEvent(org.eclipse.debug.core.DebugEvent) + */ + protected boolean handlesEvent(DebugEvent event) { + return event.getSource() instanceof IDebugTarget; + } + + protected void handleChange(DebugEvent event) { + fireDelta((IDebugTarget) event.getSource(), IModelDelta.CHANGED | IModelDelta.STATE); + } + + protected void handleCreate(DebugEvent event) { + fireDelta((IDebugTarget) event.getSource(), IModelDelta.ADDED | IModelDelta.CONTENT); + } + + protected void handleResume(DebugEvent event) { + fireDelta((IDebugTarget) event.getSource(), IModelDelta.CHANGED | IModelDelta.STATE); + } + + protected void handleSuspend(DebugEvent event) { + fireDelta((IDebugTarget) event.getSource(), IModelDelta.CHANGED | IModelDelta.CONTENT); + } + + protected void handleTerminate(DebugEvent event) { + fireDelta((IDebugTarget) event.getSource(), IModelDelta.CHANGED | IModelDelta.STATE); + } + + private void fireDelta(IDebugTarget target, int flags) { + ModelDelta delta = new ModelDelta(); + IModelDeltaNode node = delta.addNode(DebugPlugin.getDefault().getLaunchManager(), IModelDelta.NOCHANGE); + node = node.addNode(target.getLaunch(), IModelDelta.NOCHANGE); + node.addNode(target, flags); + getModelProxy().fireModelChanged(delta); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DebugTargetProxy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DebugTargetProxy.java new file mode 100644 index 000000000..fb79eafaf --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DebugTargetProxy.java @@ -0,0 +1,94 @@ +package org.eclipse.debug.internal.ui.viewers.update; + +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IDebugEventSetListener; +import org.eclipse.debug.core.model.IDebugElement; +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.internal.ui.viewers.AbstractModelProxy; +import org.eclipse.debug.internal.ui.viewers.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.IModelDeltaNode; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; + +public class DebugTargetProxy extends AbstractModelProxy implements IDebugEventSetListener { + + private IDebugTarget fDebugTarget; + private IPresentationContext fContext; + + public DebugTargetProxy(IDebugTarget target) { + fDebugTarget = target; + } + + public void init(IPresentationContext context) { + fContext = context; + DebugPlugin.getDefault().addDebugEventListener(this); + } + + public void dispose() { + DebugPlugin.getDefault().removeDebugEventListener(this); + fContext = null; + } + + public void handleDebugEvents(DebugEvent[] events) { + for (int i = 0; i < events.length; i++) { + DebugEvent event = events[i]; + if (containsEvent(event)) { + switch (event.getKind()) { + case DebugEvent.CREATE: + dispatchCreate(event); + break; + case DebugEvent.TERMINATE: +// dispatchTerminate(event); + break; + case DebugEvent.SUSPEND: +// dispatchSuspend(event); + break; + case DebugEvent.RESUME: +// dispatchResume(event); + break; + case DebugEvent.CHANGE: +// dispatchChange(event); + break; + default: +// dispatchOther(event); + break; + } + } + } + } + + private void dispatchCreate(DebugEvent event) { + Object source = event.getSource(); + ModelDelta delta = createDelta(source); + fireModelChanged(delta); + } + + private ModelDelta createDelta(Object source) { + ModelDelta delta = new ModelDelta(); + IModelDeltaNode node = delta.addNode(DebugPlugin.getDefault().getLaunchManager(), IModelDelta.NOCHANGE); + node = node.addNode(fDebugTarget.getLaunch(), IModelDelta.NOCHANGE); + node.addNode(fDebugTarget, IModelDelta.NOCHANGE); + + if (source instanceof IThread) { + node.addNode(source, IModelDelta.ADDED | IModelDelta.CONTENT); + } + + if (source instanceof IStackFrame) { + IStackFrame frame = (IStackFrame) source; + node.addNode(frame.getThread(), IModelDelta.NOCHANGE); + node.addNode(frame, IModelDelta.ADDED | IModelDelta.SELECT); + } + return delta; + } + + protected boolean containsEvent(DebugEvent event) { + Object source = event.getSource(); + if (source instanceof IDebugElement) { + return fDebugTarget.equals(((IDebugElement) source).getDebugTarget()); + } + return false; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultModelProxyFactory.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultModelProxyFactory.java new file mode 100644 index 000000000..ffedccc52 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultModelProxyFactory.java @@ -0,0 +1,39 @@ +package org.eclipse.debug.internal.ui.viewers.update; + +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.IProcess; +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.internal.ui.viewers.IModelProxy; +import org.eclipse.debug.internal.ui.viewers.IModelProxyFactory; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; + +public class DefaultModelProxyFactory implements IModelProxyFactory { + + public IModelProxy createModelProxy(Object element, IPresentationContext context) { + String id = context.getPart().getSite().getId(); + if (IDebugUIConstants.ID_DEBUG_VIEW.equals(id)) { + if (element instanceof IDebugTarget) { + return new EventHandlerModelProxy(); + } + if (element instanceof ILaunch) { + return new LaunchProxy((ILaunch)element); + } + if (element instanceof ILaunchManager) { + return new LaunchManagerProxy(); + } + if (element instanceof IProcess) { + return new ProcessProxy((IProcess)element); + } + } + if (IDebugUIConstants.ID_VARIABLE_VIEW.equals(id)) { + if (element instanceof IStackFrame) { + return new DefaultVariableViewModelProxy((IStackFrame)element); + } + } + return null; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultSelectionPolicy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultSelectionPolicy.java new file mode 100644 index 000000000..68db30414 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultSelectionPolicy.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers.update; + +import org.eclipse.debug.core.model.IDebugElement; +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.internal.ui.viewers.IModelSelectionPolicy; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbenchPart; + +/** + * @since 3.2 + */ +public class DefaultSelectionPolicy implements IModelSelectionPolicy { + + private IDebugElement fDebugElement; + + /** + * Constructs a new selection policy for the given debug + * element. + * + * @param element + */ + public DefaultSelectionPolicy(IDebugElement element) { + fDebugElement = element; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IModelSelectionPolicy#contains(org.eclipse.jface.viewers.ISelection, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + public boolean contains(ISelection selection, IPresentationContext context) { + IWorkbenchPart part = context.getPart(); + if (part != null) { + if (IDebugUIConstants.ID_DEBUG_VIEW.equals(part.getSite().getId())) { + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss = (IStructuredSelection) selection; + Object element = ss.getFirstElement(); + if (element instanceof IDebugElement) { + IDebugElement debugElement = (IDebugElement) element; + return fDebugElement.getDebugTarget().equals(debugElement.getDebugTarget()); + } + } + } + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IModelSelectionPolicy#overrides(org.eclipse.jface.viewers.ISelection, org.eclipse.jface.viewers.ISelection, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + public boolean overrides(ISelection existing, ISelection candidate, IPresentationContext context) { + IWorkbenchPart part = context.getPart(); + if (part != null) { + if (IDebugUIConstants.ID_DEBUG_VIEW.equals(part.getSite().getId())) { + if (existing instanceof IStructuredSelection && candidate instanceof IStructuredSelection) { + IStructuredSelection ssExisting = (IStructuredSelection) existing; + IStructuredSelection ssCandidate = (IStructuredSelection) candidate; + return overrides(ssExisting.getFirstElement(), ssCandidate.getFirstElement()); + } + } + } + return true; + } + + protected boolean overrides(Object existing, Object candidate) { + if (existing == null) { + return true; + } + if (existing.equals(candidate)) { + return true; + } + if (existing instanceof IStackFrame && candidate instanceof IStackFrame) { + IStackFrame curr = (IStackFrame) existing; + IStackFrame next = (IStackFrame) candidate; + return curr.getThread().equals(next.getThread()); + } + return !isSticky(existing); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.IModelSelectionPolicy#isSticky(org.eclipse.jface.viewers.ISelection, org.eclipse.debug.ui.viewers.IPresentationContext) + */ + public boolean isSticky(ISelection selection, IPresentationContext context) { + IWorkbenchPart part = context.getPart(); + if (part != null) { + if (IDebugUIConstants.ID_DEBUG_VIEW.equals(part.getSite().getId())) { + if (selection instanceof IStructuredSelection) { + return isSticky(((IStructuredSelection)selection).getFirstElement()); + } + } + } + return false; + } + + protected boolean isSticky(Object element) { + if (element instanceof IStackFrame) { + IStackFrame frame = (IStackFrame) element; + return frame.isSuspended(); + } + return false; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultUpdatePolicy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultUpdatePolicy.java new file mode 100644 index 000000000..f087d9d8d --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultUpdatePolicy.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers.update; + +import java.util.ArrayList; + +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; +import org.eclipse.debug.internal.ui.viewers.AsynchronousViewer; +import org.eclipse.debug.internal.ui.viewers.IModelChangedListener; +import org.eclipse.debug.internal.ui.viewers.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.IModelDeltaNode; +import org.eclipse.debug.internal.ui.viewers.TreePath; +import org.eclipse.debug.internal.ui.viewers.TreeSelection; + +/** + * Update policy for the launch manager. + * + * @since 3.2 + */ +public class DefaultUpdatePolicy extends AbstractUpdatePolicy implements IModelChangedListener { + + public DefaultUpdatePolicy() { + super(); + } + + public void init(AsynchronousViewer viewer) { + super.init(viewer); + } + + public synchronized void dispose() { + super.dispose(); + } + + public void modelChanged(IModelDelta delta) { + IModelDeltaNode[] nodes = delta.getNodes(); + updateNodes(nodes); + } + + private void updateNodes(IModelDeltaNode[] nodes) { + for (int i = 0; i < nodes.length; i++) { + IModelDeltaNode node = nodes[i]; + int flags = node.getFlags(); + + if ((flags & IModelDelta.CHANGED) != 0) { + handleChange(node); + } else if ((flags & IModelDelta.ADDED) != 0) { + handleAdd(node); + } else if ((flags & IModelDelta.REMOVED) != 0) { + handleRemove(node); + } + + IModelDeltaNode[] childNodes = node.getNodes(); + for (int j = 0; j < childNodes.length; j++) { + updateNodes(childNodes); + } + } + } + + private void handleChange(IModelDeltaNode node) { + int flags = node.getFlags(); + AsynchronousViewer viewer = getViewer(); + if (viewer != null) { + if ((flags & IModelDelta.STATE) != 0) { + viewer.update(node.getElement()); + } + if ((flags & IModelDelta.CONTENT) != 0) { + viewer.refresh(node.getElement()); + } + if ((flags & IModelDelta.SELECT) != 0) { + viewer.update(node.getElement()); + TreePath treePath = getTreePath(node); + ((AsynchronousTreeViewer) getViewer()).setSelection(new TreeSelection(treePath)); + } + if ((flags & IModelDelta.EXPAND) != 0) { + viewer.update(node.getElement()); + TreePath treePath = getTreePath(node); + ((AsynchronousTreeViewer) getViewer()).expand(new TreeSelection(treePath)); + } + } + } + + private void handleAdd(IModelDeltaNode node) { + int flags = node.getFlags(); + final TreePath treePath = getTreePath(node); + + ((AsynchronousTreeViewer) getViewer()).add(treePath); + + if ((flags & IModelDelta.STATE) != 0) { + // do nothing?? + } + if ((flags & IModelDelta.CONTENT) != 0) { + // do nothing?? + } + if ((flags & IModelDelta.SELECT) != 0) { + ((AsynchronousTreeViewer) getViewer()).setSelection(new TreeSelection(treePath)); + } + if ((flags & IModelDelta.EXPAND) != 0) { + ((AsynchronousTreeViewer) getViewer()).expand(new TreeSelection(treePath)); + } + } + + private void handleRemove(IModelDeltaNode node) { + TreePath treePath = getTreePath(node); + ((AsynchronousTreeViewer) getViewer()).remove(treePath); + } + + private TreePath getTreePath(IModelDeltaNode node) { + ArrayList list = new ArrayList(); + list.add(0, node.getElement()); + while (node.getParent() != null) { + node = node.getParent(); + list.add(0, node.getElement()); + } + + return new TreePath(list.toArray()); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultUpdatePolicyFactory.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultUpdatePolicyFactory.java new file mode 100644 index 000000000..4f265b895 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultUpdatePolicyFactory.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers.update; + +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.internal.ui.viewers.IUpdatePolicy; +import org.eclipse.debug.internal.ui.viewers.IUpdatePolicyFactory; + +/** + * @since 3.2 + */ +public class DefaultUpdatePolicyFactory implements IUpdatePolicyFactory { + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.viewers.IUpdatePolicyFactory#createUpdatePolicy(java.lang.Object, + * org.eclipse.debug.ui.viewers.IPresentationContext) + */ + public IUpdatePolicy createUpdatePolicy(IPresentationContext context) { + return new DefaultUpdatePolicy(); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultVariableViewModelProxy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultVariableViewModelProxy.java new file mode 100644 index 000000000..17e211d8b --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/DefaultVariableViewModelProxy.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers.update; + +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.model.IDebugElement; +import org.eclipse.debug.core.model.IStackFrame; + +/** + * Default update for variables view. + * + * @since 3.2 + */ +public class DefaultVariableViewModelProxy extends EventHandlerModelProxy { + + /** + * Root model element for this update policy + */ + private IStackFrame fFrame; + + /** + * Constructs an update policy on the given target. + * + * @param target + */ + public DefaultVariableViewModelProxy(IStackFrame frame) { + super(); + fFrame = frame; + } + + public void dispose() { + fFrame = null; + } + + protected DebugEventHandler[] createEventHandlers() { + return new DebugEventHandler[] { new VariablesViewEventHandler(this, fFrame) }; + } + + protected boolean containsEvent(DebugEvent event) { + Object source = event.getSource(); + if (source instanceof IDebugElement) { + return fFrame.getDebugTarget().equals(((IDebugElement) source).getDebugTarget()); + } + return false; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/EventHandlerModelProxy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/EventHandlerModelProxy.java new file mode 100644 index 000000000..d25899042 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/EventHandlerModelProxy.java @@ -0,0 +1,251 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers.update; + +import java.util.HashMap; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; + +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IDebugEventSetListener; +import org.eclipse.debug.internal.ui.viewers.AbstractModelProxy; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; + +/** + * @since 3.2 + */ +public class EventHandlerModelProxy extends AbstractModelProxy implements IDebugEventSetListener { + + /** + * Map of elements to timer tasks + */ + private Map fTimerTasks = new HashMap(); + + /** + * Timer for timer tasks + */ + private Timer fTimer = new Timer(true); + + /** + * Map of event source to resume events with a pending suspend that timed + * out. + */ + private Map fPendingSuspends = new HashMap(); + + /** + * Event handlers for specific elements + */ + private DebugEventHandler[] fHandlers = new DebugEventHandler[0]; + + private boolean fDisposed = false; + + /** + * Task used to update an element that resumed for a step or evaluation that + * took too long to suspend. + */ + private class PendingSuspendTask extends TimerTask { + + private DebugEvent fEvent; + private DebugEventHandler fHandler; + + /** + * Resume event for which there is a pending suspend. + * + * @param resume event + */ + public PendingSuspendTask(DebugEventHandler handler, DebugEvent resume) { + fHandler = handler; + fEvent = resume; + } + + /* + * (non-Javadoc) + * + * @see java.util.TimerTask#run() + */ + public void run() { + synchronized (fPendingSuspends) { + fPendingSuspends.put(fEvent.getSource(), fEvent); + } + dispatchSuspendTimeout(fHandler, fEvent); + } + + } + + /** + * Adds the given handler to this event update policy. + * + * @param handler + */ + protected DebugEventHandler[] createEventHandlers() { + return new DebugEventHandler[] { new DebugTargetEventHandler(this), new ThreadEventHandler(this) }; + } + + public synchronized void dispose() { + fDisposed = true; + fTimer.cancel(); + fTimerTasks.clear(); + DebugPlugin.getDefault().removeDebugEventListener(this); + for (int i = 0; i < fHandlers.length; i++) { + DebugEventHandler handler = fHandlers[i]; + handler.dispose(); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.internal.ui.viewers.update.AbstractUpdatePolicy#init(org.eclipse.debug.ui.viewers.update.IPresentation) + */ + public void init(IPresentationContext context) { + DebugPlugin.getDefault().addDebugEventListener(this); + fHandlers = createEventHandlers(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[]) + */ + public synchronized final void handleDebugEvents(DebugEvent[] events) { + if (isDisposed()) { + return; + } + for (int i = 0; i < events.length; i++) { + DebugEvent event = events[i]; + for (int j = 0; j < fHandlers.length; j++) { + DebugEventHandler handler = fHandlers[j]; + if (handler.handlesEvent(event)) { + switch (event.getKind()) { + case DebugEvent.CREATE: + dispatchCreate(handler, event); + break; + case DebugEvent.TERMINATE: + dispatchTerminate(handler, event); + break; + case DebugEvent.SUSPEND: + dispatchSuspend(handler, event); + break; + case DebugEvent.RESUME: + dispatchResume(handler, event); + break; + case DebugEvent.CHANGE: + dispatchChange(handler, event); + break; + default: + dispatchOther(handler, event); + break; + } + } + } + } + } + + private boolean isDisposed() { + return fDisposed; + } + + /** + * Dispatches a create event. + * + * @param event + */ + protected void dispatchCreate(DebugEventHandler handler, DebugEvent event) { + handler.handleCreate(event); + } + + /** + * Dispatches a terminate event. + * + * @param event + */ + protected void dispatchTerminate(DebugEventHandler handler, DebugEvent event) { + handler.handleTerminate(event); + } + + /** + * Dispatches a suspend event. Subclasses may override. + * + * @param event + */ + protected void dispatchSuspend(DebugEventHandler handler, DebugEvent event) { + // stop timer, if any + synchronized (fTimerTasks) { + TimerTask task = (TimerTask) fTimerTasks.remove(event.getSource()); + if (task != null) { + task.cancel(); + } + } + DebugEvent resume = null; + synchronized (fPendingSuspends) { + resume = (DebugEvent) fPendingSuspends.remove(event.getSource()); + } + if (resume == null) { + handler.handleSuspend(event); + } else { + handler.handleLateSuspend(event, resume); + } + } + + /** + * Dispatches a resume event. By default, if the resume is for an evaluation + * or a step, a timer is started to update the event source if the step or + * evaluation takes more than 500ms. Otherwise the source is refreshed. + * Subclasses may override. + * + * @param event + */ + protected void dispatchResume(DebugEventHandler handler, DebugEvent event) { + if (event.isEvaluation() || event.isStepStart()) { + // start a timer to update if the corresponding suspend does not + // come quickly + PendingSuspendTask task = new PendingSuspendTask(handler, event); + synchronized (fTimerTasks) { + fTimerTasks.put(event.getSource(), task); + } + fTimer.schedule(task, 500); + handler.handleResumeExpectingSuspend(event); + } else { + handler.handleResume(event); + } + } + + /** + * Dispatches a change event. + * + * @param event + */ + protected void dispatchChange(DebugEventHandler handler, DebugEvent event) { + handler.handleChange(event); + } + + /** + * Dispatches an unknown event. + * + * @param event + */ + protected void dispatchOther(DebugEventHandler handler, DebugEvent event) { + handler.handleOther(event); + } + + /** + * Notification that a pending suspend event was not received for the given + * resume event and handler within the timeout period. + * + * @param resume resume event with missing suspend event + */ + protected void dispatchSuspendTimeout(DebugEventHandler handler, DebugEvent resume) { + handler.handleSuspendTimeout(resume); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/LaunchManagerProxy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/LaunchManagerProxy.java new file mode 100644 index 000000000..91db2de16 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/LaunchManagerProxy.java @@ -0,0 +1,66 @@ +package org.eclipse.debug.internal.ui.viewers.update; + +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.ILaunchesListener2; +import org.eclipse.debug.internal.ui.viewers.AbstractModelProxy; +import org.eclipse.debug.internal.ui.viewers.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.IModelDeltaNode; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; + +public class LaunchManagerProxy extends AbstractModelProxy implements ILaunchesListener2 { + + private ILaunchManager fLaunchManager; + + public void init(IPresentationContext context) { + fLaunchManager = DebugPlugin.getDefault().getLaunchManager(); + fLaunchManager.addLaunchListener(this); + } + + public void dispose() { + fLaunchManager.removeLaunchListener(this); + fLaunchManager = null; + } + + public void launchesTerminated(ILaunch[] launches) { + ModelDelta delta = new ModelDelta(); + IModelDeltaNode node = delta.addNode(fLaunchManager, IModelDelta.NOCHANGE); + for (int i = 0; i < launches.length; i++) { + ILaunch launch = launches[i]; + node.addNode(launch, IModelDelta.CHANGED | IModelDelta.CONTENT); + } + fireModelChanged(delta); + } + + public void launchesRemoved(ILaunch[] launches) { + ModelDelta delta = new ModelDelta(); + IModelDeltaNode node = delta.addNode(fLaunchManager, IModelDelta.CHANGED | IModelDelta.CONTENT); + for (int i = 0; i < launches.length; i++) { + ILaunch launch = launches[i]; + node.addNode(launch, IModelDelta.REMOVED); + } + fireModelChanged(delta); + } + + public void launchesAdded(ILaunch[] launches) { + ModelDelta delta = new ModelDelta(); + IModelDeltaNode node = delta.addNode(fLaunchManager, IModelDelta.NOCHANGE); + for (int i = 0; i < launches.length; i++) { + ILaunch launch = launches[i]; + node.addNode(launch, IModelDelta.ADDED | IModelDelta.EXPAND); + } + fireModelChanged(delta); + } + + public void launchesChanged(ILaunch[] launches) { + ModelDelta delta = new ModelDelta(); + IModelDeltaNode node = delta.addNode(fLaunchManager, IModelDelta.NOCHANGE); + for (int i = 0; i < launches.length; i++) { + ILaunch launch = launches[i]; + node.addNode(launch, IModelDelta.CHANGED | IModelDelta.STATE); + } + fireModelChanged(delta); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/LaunchProxy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/LaunchProxy.java new file mode 100644 index 000000000..4300f1583 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/LaunchProxy.java @@ -0,0 +1,80 @@ +package org.eclipse.debug.internal.ui.viewers.update; + +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.ILaunchesListener2; +import org.eclipse.debug.internal.ui.viewers.AbstractModelProxy; +import org.eclipse.debug.internal.ui.viewers.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.IModelDeltaNode; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; + +public class LaunchProxy extends AbstractModelProxy implements ILaunchesListener2 { + + private ILaunchManager fLaunchManager = DebugPlugin.getDefault().getLaunchManager(); + private ILaunch fLaunch; + + LaunchProxy(ILaunch launch) { + fLaunch = launch; + } + + public void init(IPresentationContext context) { + fLaunchManager.addLaunchListener(this); + } + + public void dispose() { + fLaunchManager.removeLaunchListener(this); + } + + public void launchesTerminated(ILaunch[] launches) { + for (int i = 0; i < launches.length; i++) { + if (launches[i] == fLaunch) { + ModelDelta delta = new ModelDelta(); + IModelDeltaNode node = delta.addNode(fLaunchManager, IModelDelta.NOCHANGE); + node.addNode(fLaunch, IModelDelta.CHANGED | IModelDelta.CONTENT); + fireModelChanged(delta); + return; + } + } + + + } + + public void launchesRemoved(ILaunch[] launches) { +// for (int i = 0; i < launches.length; i++) { +// if (launches[i] == fLaunch) { +// ModelDelta delta = new ModelDelta(); +// IModelDeltaNode node = delta.addNode(fLaunchManager, IModelDelta.NOCHANGE); +// node.addNode(fLaunch, IModelDelta.REMOVED); +// fireModelChanged(delta); +// return; +// } +// } + } + + public void launchesAdded(ILaunch[] launches) { +// for (int i = 0; i < launches.length; i++) { +// if (launches[i] == fLaunch) { +// ModelDelta delta = new ModelDelta(); +// IModelDeltaNode node = delta.addNode(fLaunchManager, IModelDelta.NOCHANGE); +// node.addNode(fLaunch, IModelDelta.ADDED | IModelDelta.CONTENT | IModelDelta.EXPAND); +// node.addNode(new Object(), IModelDelta.ADDED | IModelDelta.EXPAND); +// fireModelChanged(delta); +// return; +// } +// } + } + + public void launchesChanged(ILaunch[] launches) { + for (int i = 0; i < launches.length; i++) { + if (launches[i] == fLaunch) { + ModelDelta delta = new ModelDelta(); + IModelDeltaNode node = delta.addNode(fLaunchManager, IModelDelta.NOCHANGE); + node.addNode(fLaunch, IModelDelta.CHANGED | IModelDelta.CONTENT); + fireModelChanged(delta); + return; + } + } + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ModelDelta.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ModelDelta.java new file mode 100644 index 000000000..b80c337af --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ModelDelta.java @@ -0,0 +1,23 @@ +package org.eclipse.debug.internal.ui.viewers.update; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.debug.internal.ui.viewers.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.IModelDeltaNode; + +public class ModelDelta implements IModelDelta { + + private List fNodes = new ArrayList(); + + public IModelDeltaNode addNode(Object element, int flags) { + ModelDeltaNode node = new ModelDeltaNode(element, flags); + fNodes.add(node); + return node; + } + + public IModelDeltaNode[] getNodes() { + return (ModelDeltaNode[]) fNodes.toArray(new ModelDeltaNode[0]); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ModelDeltaNode.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ModelDeltaNode.java new file mode 100644 index 000000000..d14618d94 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ModelDeltaNode.java @@ -0,0 +1,47 @@ +package org.eclipse.debug.internal.ui.viewers.update; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.debug.internal.ui.viewers.IModelDeltaNode; + +public class ModelDeltaNode implements IModelDeltaNode { + + private IModelDeltaNode fParent; + private Object fElement; + private int fFlags; + private List fNodes = new ArrayList(); + + public ModelDeltaNode(Object element, int flags) { + fElement = element; + fFlags = flags; + } + + public Object getElement() { + return fElement; + } + + public int getFlags() { + return fFlags; + } + + public IModelDeltaNode addNode(Object element, int flags) { + ModelDeltaNode node = new ModelDeltaNode(element, flags); + node.setParent(this); + fNodes.add(node); + return node; + } + + void setParent(ModelDeltaNode node) { + fParent = node; + } + + public IModelDeltaNode getParent() { + return fParent; + } + + public ModelDeltaNode[] getNodes() { + return (ModelDeltaNode[]) fNodes.toArray(new ModelDeltaNode[0]); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ProcessProxy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ProcessProxy.java new file mode 100644 index 000000000..9742b280d --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ProcessProxy.java @@ -0,0 +1,62 @@ +package org.eclipse.debug.internal.ui.viewers.update; + +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IDebugEventSetListener; +import org.eclipse.debug.core.model.IProcess; +import org.eclipse.debug.internal.ui.viewers.AbstractModelProxy; +import org.eclipse.debug.internal.ui.viewers.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.IModelDeltaNode; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; + +public class ProcessProxy extends AbstractModelProxy implements IDebugEventSetListener { + + private IProcess fProcess; + + public ProcessProxy(IProcess process) { + fProcess = process; + } + + public void init(IPresentationContext context) { + DebugPlugin.getDefault().addDebugEventListener(this); + } + + public void dispose() { + DebugPlugin.getDefault().removeDebugEventListener(this); + } + + protected synchronized boolean containsEvent(DebugEvent event) { + return fProcess.equals(event.getSource()); + } + + public void handleDebugEvents(DebugEvent[] events) { + for (int i = 0; i < events.length; i++) { + DebugEvent event = events[i]; + switch (event.getKind()) { + case DebugEvent.CREATE: + handleCreate(); + break; + default: + handleChange(); + break; + } + } + } + + private void handleChange() { + ModelDelta delta = new ModelDelta(); + IModelDeltaNode node = delta.addNode(DebugPlugin.getDefault().getLaunchManager(), IModelDelta.NOCHANGE); + node = node.addNode(fProcess.getLaunch(), IModelDelta.NOCHANGE); + node.addNode(fProcess, IModelDelta.CHANGED | IModelDelta.STATE); + fireModelChanged(delta); + } + + private void handleCreate() { + ModelDelta delta = new ModelDelta(); + IModelDeltaNode node = delta.addNode(DebugPlugin.getDefault().getLaunchManager(), IModelDelta.NOCHANGE); + node = node.addNode(fProcess.getLaunch(), IModelDelta.NOCHANGE); + node.addNode(fProcess, IModelDelta.ADDED); + fireModelChanged(delta); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ThreadEventHandler.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ThreadEventHandler.java new file mode 100644 index 000000000..c8f5feeda --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ThreadEventHandler.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers.update; + +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.model.IThread; +import org.eclipse.debug.internal.ui.viewers.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.IModelDeltaNode; +import org.eclipse.debug.internal.ui.viewers.IModelProxy; + +/** + * @since 3.2 + */ +public class ThreadEventHandler extends DebugEventHandler { + /** + * Constructs and event handler for a threads in the given viewer. + * + * @param viewer + */ + public ThreadEventHandler(IModelProxy proxy) { + super(proxy); + } + + public void dispose() { + super.dispose(); + } + + protected void handleSuspend(DebugEvent event) { + fireDelta((IThread) event.getSource(), IModelDelta.CHANGED | IModelDelta.CONTENT | IModelDelta.EXPAND); + } + + protected void handleResumeExpectingSuspend(DebugEvent event) { + fireDelta((IThread) event.getSource(), IModelDelta.CHANGED | IModelDelta.STATE); + } + + protected void handleResume(DebugEvent event) { + fireDelta((IThread) event.getSource(), IModelDelta.CHANGED | IModelDelta.STATE); + } + + protected void handleCreate(DebugEvent event) { + fireDelta((IThread) event.getSource(), IModelDelta.ADDED | IModelDelta.STATE); + } + + protected void handleTerminate(DebugEvent event) { + fireDelta((IThread) event.getSource(), IModelDelta.REMOVED); + } + + protected void handleChange(DebugEvent event) { + fireDelta((IThread) event.getSource(), IModelDelta.CHANGED | IModelDelta.STATE); + } + + protected void handleLateSuspend(DebugEvent suspend, DebugEvent resume) { + fireDelta((IThread) suspend.getSource(), IModelDelta.CHANGED | IModelDelta.CONTENT | IModelDelta.EXPAND); + } + + protected void handleSuspendTimeout(DebugEvent event) { + fireDelta((IThread) event.getSource(), IModelDelta.CHANGED | IModelDelta.CONTENT); + } + + private void fireDelta(IThread thread, int flags) { + ModelDelta delta = new ModelDelta(); + IModelDeltaNode node = delta.addNode(DebugPlugin.getDefault().getLaunchManager(), IModelDelta.NOCHANGE); + node = node.addNode(thread.getLaunch(), IModelDelta.NOCHANGE); + node = node.addNode(thread.getDebugTarget(), IModelDelta.NOCHANGE); + node = node.addNode(thread, flags); + if ((flags & IModelDelta.EXPAND) != 0) { + Object topStackFrame = null; + try { + topStackFrame = thread.getTopStackFrame(); + } catch (DebugException e) { + topStackFrame = new Object(); + } + node.addNode(topStackFrame, IModelDelta.CHANGED | IModelDelta.SELECT); + } + getModelProxy().fireModelChanged(delta); + } + + protected boolean handlesEvent(DebugEvent event) { + return event.getSource() instanceof IThread; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/VariablesViewEventHandler.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/VariablesViewEventHandler.java new file mode 100644 index 000000000..ce13ee6c6 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/VariablesViewEventHandler.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2005 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.internal.ui.viewers.update; + +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.core.model.ISuspendResume; +import org.eclipse.debug.internal.ui.viewers.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.IModelProxy; + +/** + * + * @since 3.2 + */ +public class VariablesViewEventHandler extends DebugEventHandler { + + private IStackFrame fFrame; + + public VariablesViewEventHandler(IModelProxy proxy, IStackFrame frame) { + super(proxy); + fFrame = frame; + } + + protected boolean handlesEvent(DebugEvent event) { + return true; + } + + protected void refreshRoot(DebugEvent event) { + if (event.getDetail() != DebugEvent.EVALUATION_IMPLICIT) { + // Don't refresh everytime an implicit evaluation finishes + if (event.getSource() instanceof ISuspendResume) { + if (!((ISuspendResume)event.getSource()).isSuspended()) { + // no longer suspended + return; + } + } + + ModelDelta delta = new ModelDelta(); + delta.addNode(fFrame, IModelDelta.CHANGED | IModelDelta.CONTENT); + getModelProxy().fireModelChanged(delta); + //TODO: popuplate details pane (should it be built into the viewer?) + } + } + + protected void handleResume(DebugEvent event) { + super.handleResume(event); + } + + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/AbstractDebugEventHandler.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/AbstractDebugEventHandler.java index deac03e1e..ceeb5838e 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/AbstractDebugEventHandler.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/AbstractDebugEventHandler.java @@ -21,10 +21,12 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IDebugEventSetListener; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; import org.eclipse.debug.ui.AbstractDebugView; import org.eclipse.jface.viewers.IBasicPropertyConstants; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.ui.progress.UIJob; @@ -74,7 +76,7 @@ public abstract class AbstractDebugEventHandler implements IDebugEventSetListene private static final int TIMEOUT = 200; public EventProcessingJob() { - super(DebugUIViewsMessages.AbstractDebugEventHandler_0); + super(DebugUIViewsMessages.AbstractDebugEventHandler_0); setSystem(true); setPriority(Job.INTERACTIVE); } @@ -200,13 +202,15 @@ public abstract class AbstractDebugEventHandler implements IDebugEventSetListene */ protected void insert(Object element) { if (isAvailable()) { - Object parent= ((ITreeContentProvider)getTreeViewer().getContentProvider()).getParent(element); - // a parent can be null for a debug target or process that has not yet been associated - // with a launch - if (parent != null) { - getView().showViewer(); - getTreeViewer().add(parent, element); - } + Viewer viewer = getViewer(); + if (viewer instanceof TreeViewer) { + TreeViewer tv = (TreeViewer) viewer; + Object parent = ((ITreeContentProvider)tv.getContentProvider()).getParent(element); + if (parent != null) { + getView().showViewer(); + tv.add(parent, element); + } + } } } @@ -216,7 +220,14 @@ public abstract class AbstractDebugEventHandler implements IDebugEventSetListene protected void remove(Object element) { if (isAvailable()) { getView().showViewer(); - getTreeViewer().remove(element); + Viewer viewer = getViewer(); + if (viewer instanceof TreeViewer) { + TreeViewer tv = (TreeViewer) viewer; + tv.remove(element); + } else if (viewer instanceof AsynchronousTreeViewer) { + AsynchronousTreeViewer atv = (AsynchronousTreeViewer) viewer; + atv.refresh(); + } } } @@ -226,7 +237,14 @@ public abstract class AbstractDebugEventHandler implements IDebugEventSetListene protected void labelChanged(Object element) { if (isAvailable()) { getView().showViewer(); - getTreeViewer().update(element, new String[] {IBasicPropertyConstants.P_TEXT}); + Viewer viewer = getViewer(); + if (viewer instanceof TreeViewer) { + TreeViewer tv = (TreeViewer) viewer; + tv.update(element, new String[] {IBasicPropertyConstants.P_TEXT}); + } else if (viewer instanceof AsynchronousTreeViewer) { + AsynchronousTreeViewer atv = (AsynchronousTreeViewer) viewer; + atv.update(element); + } } } @@ -236,7 +254,14 @@ public abstract class AbstractDebugEventHandler implements IDebugEventSetListene protected void refresh(Object element) { if (isAvailable()) { getView().showViewer(); - getTreeViewer().refresh(element); + Viewer viewer = getViewer(); + if (viewer instanceof TreeViewer) { + TreeViewer treeViewer = (TreeViewer) viewer; + treeViewer.refresh(element); + } else if (viewer instanceof AsynchronousTreeViewer) { + AsynchronousTreeViewer asyncTreeViewer = (AsynchronousTreeViewer) viewer; + asyncTreeViewer.refresh(element); + } } } @@ -246,7 +271,7 @@ public abstract class AbstractDebugEventHandler implements IDebugEventSetListene public void refresh() { if (isAvailable()) { getView().showViewer(); - getTreeViewer().refresh(); + getViewer().refresh(); } } @@ -299,17 +324,17 @@ public abstract class AbstractDebugEventHandler implements IDebugEventSetListene protected Viewer getViewer() { return getView().getViewer(); } - + /** - * Returns this event handler's viewer as a tree + * Returns this event handler's viewer as a structured * viewer or null if none. * - * @return this event handler's viewer as a tree + * @return this event handler's viewer as a structured * viewer or null if none */ - protected TreeViewer getTreeViewer() { - if (getViewer() instanceof TreeViewer) { - return (TreeViewer)getViewer(); + protected StructuredViewer getStructuredViewer() { + if (getViewer() instanceof StructuredViewer) { + return (StructuredViewer)getViewer(); } return null; } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/AbstractDebugEventHandlerView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/AbstractDebugEventHandlerView.java index 8cb5f3991..723ea3624 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/AbstractDebugEventHandlerView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/AbstractDebugEventHandlerView.java @@ -58,7 +58,10 @@ public abstract class AbstractDebugEventHandlerView extends AbstractDebugView { */ protected void becomesHidden() { super.becomesHidden(); - getEventHandler().viewBecomesHidden(); + AbstractDebugEventHandler eventHandler = getEventHandler(); + if (eventHandler != null) { + getEventHandler().viewBecomesHidden(); + } } /** @@ -66,7 +69,10 @@ public abstract class AbstractDebugEventHandlerView extends AbstractDebugView { */ protected void becomesVisible() { super.becomesVisible(); - getEventHandler().viewBecomesVisible(); + AbstractDebugEventHandler eventHandler = getEventHandler(); + if (eventHandler != null) { + eventHandler.viewBecomesVisible(); + } } protected void clearStatusLine() { diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/AbstractViewerState.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/AbstractViewerState.java index fab435003..6363d9aed 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/AbstractViewerState.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/AbstractViewerState.java @@ -12,11 +12,12 @@ package org.eclipse.debug.internal.ui.views; import java.util.ArrayList; import java.util.List; + import org.eclipse.core.runtime.IPath; import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.internal.ui.views.variables.VariablesViewer; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; +import org.eclipse.debug.internal.ui.viewers.TreePath; +import org.eclipse.debug.internal.ui.viewers.TreeSelection; import org.eclipse.swt.widgets.TreeItem; /** @@ -26,19 +27,15 @@ import org.eclipse.swt.widgets.TreeItem; public abstract class AbstractViewerState { // paths to expanded elements - protected List fSavedExpansion = null; - protected IPath[] fSelection; + private List fSavedExpansion = null; + private IPath[] fSelection; /** * Constructs a memento for the given viewer. */ - public AbstractViewerState(TreeViewer viewer) { + public AbstractViewerState(AsynchronousTreeViewer viewer) { saveState(viewer); } - - public AbstractViewerState() { - - } /** * Saves the current state of the given viewer into @@ -46,7 +43,7 @@ public abstract class AbstractViewerState { * * @param viewer viewer of which to save the state */ - public void saveState(TreeViewer viewer) { + public void saveState(AsynchronousTreeViewer viewer) { List expanded = new ArrayList(); fSavedExpansion = null; TreeItem[] items = viewer.getTree().getItems(); @@ -75,17 +72,30 @@ public abstract class AbstractViewerState { } } - protected void collectExpandedItems(TreeItem item, List expanded) throws DebugException { + /** + * Collects paths to expanded children of the given element and returns + * whether any paths were expanded. + * + * @param item item to collect expanded paths for + * @param expanded list to add to + * @return whether any paths were found expanded + * @throws DebugException + */ + protected boolean collectExpandedItems(TreeItem item, List expanded) throws DebugException { if (item.getExpanded()) { - IPath path = encodeElement(item); - if (path != null) { - expanded.add(path); - TreeItem[] items = item.getItems(); - for (int i = 0; i < items.length; i++) { - collectExpandedItems(items[i], expanded); - } + boolean childExpanded = false; + TreeItem[] items = item.getItems(); + for (int i = 0; i < items.length; i++) { + childExpanded = collectExpandedItems(items[i], expanded) || childExpanded; } + if (!childExpanded) { + IPath path = encodeElement(item); + expanded.add(path); + } + } else { + return false; } + return true; } /** @@ -105,45 +115,41 @@ public abstract class AbstractViewerState { * * @param viewer viewer to which state is restored */ - public void restoreState(TreeViewer viewer) { + public void restoreState(AsynchronousTreeViewer viewer) { boolean expansionComplete = true; - if (fSavedExpansion != null && fSavedExpansion.size() > 0) { - for (int i = 0; i < fSavedExpansion.size(); i++) { - IPath path = (IPath) fSavedExpansion.get(i); - if (path != null) { - if (viewer instanceof VariablesViewer) { - VariablesViewer variablesViewer = (VariablesViewer) viewer; - boolean complete = variablesViewer.expandPath(path); - if (!complete) - expansionComplete = false; - } else { - Object obj; - try { - obj = decodePath(path, viewer); - if (obj != null) { - viewer.expandToLevel(obj, 1); - } else { - expansionComplete = false; - } - } catch (DebugException e) { - } - } - } - } - if (expansionComplete) { - fSavedExpansion = null; - } - } + if (fSavedExpansion != null && fSavedExpansion.size() > 0) { + for (int i = 0; i < fSavedExpansion.size(); i++) { + IPath path = (IPath) fSavedExpansion.get(i); + if (path != null) { + try { + TreePath treePath = decodePath(path, viewer); + if (treePath != null) { + viewer.expand(new TreeSelection(new TreePath[] { treePath })); + + if (treePath.getSegmentCount()-1 != path.segmentCount()) { + expansionComplete = false; + } + } else { + expansionComplete =false; + } + } catch (DebugException e) { + } + } + } + if (expansionComplete) { + fSavedExpansion = null; + } + } boolean selectionComplete = true; if (fSelection != null && fSelection.length > 0) { List selection = new ArrayList(fSelection.length); for (int i = 0; i < fSelection.length; i++) { IPath path = fSelection[i]; - Object obj; + TreePath obj; try { obj = decodePath(path, viewer); - if (obj != null) { + if (obj != null && obj.getSegmentCount()-1 == path.segmentCount()) { selection.add(obj); } else { selectionComplete = false; @@ -152,7 +158,8 @@ public abstract class AbstractViewerState { } } if (selection.size() > 0) { - viewer.setSelection(new StructuredSelection(selection)); + TreePath[] treePaths = (TreePath[]) selection.toArray(new TreePath[0]); + viewer.setSelection(new TreeSelection(treePaths)); } if (selectionComplete) { fSelection = null; @@ -169,9 +176,6 @@ public abstract class AbstractViewerState { * @return element represented by the path, or null if none * @throws DebugException if unable to locate a variable */ - protected abstract Object decodePath(IPath path, TreeViewer viewer) throws DebugException; + protected abstract TreePath decodePath(IPath path, AsynchronousTreeViewer viewer) throws DebugException; - public abstract AbstractViewerState copy(); - - } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/IRemoteTreeViewerUpdateListener.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/IRemoteTreeViewerUpdateListener.java deleted file mode 100644 index 34d56f8ff..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/IRemoteTreeViewerUpdateListener.java +++ /dev/null @@ -1,15 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.views; - -public interface IRemoteTreeViewerUpdateListener { - public void treeUpdated(); -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeContentManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeContentManager.java deleted file mode 100644 index e6e99886e..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeContentManager.java +++ /dev/null @@ -1,335 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.views; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.internal.ui.DebugUIPlugin; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.internal.progress.PendingUpdateAdapter; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.eclipse.ui.progress.DeferredTreeContentManager; -import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; -import org.eclipse.ui.progress.IElementCollector; -import org.eclipse.ui.progress.IWorkbenchSiteProgressService; -import org.eclipse.ui.progress.WorkbenchJob; -import org.osgi.framework.Bundle; -/** - * A remote content manager that merges content into a tree rather then replacing - * its children with a "pending" node, and then the real children when they are available. - * This avoids collapsing the viewer when a refresh is performed. This implementation is - * currently tied to the RemoteTreeViewer. - * - * @since 3.1 - */ -public class RemoteTreeContentManager extends DeferredTreeContentManager { - - private RemoteTreeViewer fViewer; - private IWorkbenchSiteProgressService progressService; - - /** - * Job to fetch children - */ - private Job fFetchJob = new FetchJob(); - - /** - * Queue of parents to fetch children for, and - * associated element collectors and deferred adapters. - */ - private List fElementQueue = new ArrayList(); - private List fCollectors = new ArrayList(); - private List fAdapaters = new ArrayList(); - - /** - * Fetching children is done in a single background job. - * This makes fetching single threaded/serial per view. - */ - class FetchJob extends Job { - - public FetchJob() { - super(DebugUIViewsMessages.RemoteTreeContentManager_0); - setSystem(true); - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) - */ - protected IStatus run(IProgressMonitor monitor) { - while (!fElementQueue.isEmpty() && !monitor.isCanceled()) { - Object element = null; - IElementCollector collector = null; - IDeferredWorkbenchAdapter adapter = null; - synchronized (fElementQueue) { - // could have been cancelled after entering the while loop - if (fElementQueue.isEmpty()) { - return Status.CANCEL_STATUS; - } - element = fElementQueue.remove(0); - collector = (IElementCollector) fCollectors.remove(0); - adapter = (IDeferredWorkbenchAdapter) fAdapaters.remove(0); - } - adapter.fetchDeferredChildren(element, collector, monitor); - } - if (monitor.isCanceled()) { - return Status.CANCEL_STATUS; - } - return Status.OK_STATUS; - } - - } - - /** - * Element collector - */ - public class Collector implements IElementCollector { - // number of children added to the tree - int offset = 0; - Object fParent; - - public Collector(Object parent) { - fParent = parent; - } - /* - * (non-Javadoc) - * @see org.eclipse.jface.progress.IElementCollector#add(java.lang.Object, org.eclipse.core.runtime.IProgressMonitor) - */ - public void add(Object element, IProgressMonitor monitor) { - add(new Object[] { element }, monitor); - } - - /* - * (non-Javadoc) - * @see org.eclipse.jface.progress.IElementCollector#add(java.lang.Object[], org.eclipse.core.runtime.IProgressMonitor) - */ - public void add(Object[] elements, IProgressMonitor monitor) { - Object[] filtered = fViewer.filter(elements); - if (filtered.length > 0) { - replaceChildren(fParent, filtered, offset, monitor); - offset = offset + filtered.length; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.progress.IElementCollector#done() - */ - public void done() { - prune(fParent, offset); - } - } - - /** - * Contructs a new content manager. - * - * @param provider content provider - * @param viewer viewer - * @param site part site - */ - public RemoteTreeContentManager(ITreeContentProvider provider, RemoteTreeViewer viewer, IWorkbenchPartSite site) { - super(provider, viewer, site); - fViewer = viewer; - Object siteService = site.getAdapter(IWorkbenchSiteProgressService.class); - if (siteService != null) { - progressService = (IWorkbenchSiteProgressService) siteService; - } - } - - /** - * Create the element collector for the receiver. - *@param parent - * The parent object being filled in, - * @param placeholder - * The adapter that will be used to indicate that results are - * pending, possibly null - * @return IElementCollector - */ - protected IElementCollector createElementCollector(Object parent, PendingUpdateAdapter placeholder) { - return new Collector(parent); - } - - /** - * Returns the child elements of the given element, or in the case of a - * deferred element, returns a placeholder. If a deferred element is used, a - * job is created to fetch the children in the background. - * - * @param parent - * The parent object. - * @return Object[] or null if parent is not an instance of - * IDeferredWorkbenchAdapter. - */ - public Object[] getChildren(final Object parent) { - IDeferredWorkbenchAdapter element = getAdapter(parent); - if (element == null) - return null; - Object[] currentChildren = fViewer.getCurrentChildren(parent); - PendingUpdateAdapter placeholder = null; - if (currentChildren == null || currentChildren.length == 0) { - placeholder = new PendingUpdateAdapter(); - } - startFetchingDeferredChildren(parent, element, placeholder); - if (placeholder == null) { - return currentChildren; - } - return new Object[] { placeholder }; - } - - /** - * Create a UIJob to replace the children of the parent in the tree viewer. - * - * @param parent the parent for which children are to be replaced - * @param children the replacement children - * @param offset the offset at which to start replacing children - * @param monitor progress monitor - */ - protected void replaceChildren(final Object parent, final Object[] children, final int offset, IProgressMonitor monitor) { - if (monitor.isCanceled()) { - return; - } - WorkbenchJob updateJob = new WorkbenchJob(DebugUIViewsMessages.IncrementalDeferredTreeContentManager_0) { - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus runInUIThread(IProgressMonitor updateMonitor) { - //Cancel the job if the tree viewer got closed - if (fViewer.getControl().isDisposed()) - return Status.CANCEL_STATUS; - fViewer.replace(parent, children, offset); - return Status.OK_STATUS; - } - }; - updateJob.setSystem(true); - updateJob.setPriority(Job.INTERACTIVE); - updateJob.schedule(); - } - - /** - * Create a UIJob to prune the children of the parent in the tree viewer, starting - * at the given offset. - * - * @param parent the parent for which children should be pruned - * @param offset the offset at which children should be pruned. All children at and after - * this index will be removed from the tree. - * @param monitor - */ - protected void prune(final Object parent, final int offset) { - WorkbenchJob updateJob = new WorkbenchJob(DebugUIViewsMessages.IncrementalDeferredTreeContentManager_1) { - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus runInUIThread(IProgressMonitor updateMonitor) { - //Cancel the job if the tree viewer got closed - if (fViewer.getControl().isDisposed()) - return Status.CANCEL_STATUS; - fViewer.prune(parent, offset); - return Status.OK_STATUS; - } - }; - updateJob.setSystem(true); - updateJob.setPriority(Job.INTERACTIVE); - updateJob.schedule(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.DeferredTreeContentManager#runClearPlaceholderJob(org.eclipse.ui.internal.progress.PendingUpdateAdapter) - */ - protected void runClearPlaceholderJob(PendingUpdateAdapter placeholder) { - // the placeholder is not used when there were already children in the tree (null) - if (placeholder != null) { - super.runClearPlaceholderJob(placeholder); - } - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.DeferredTreeContentManager#getFetchJobName(java.lang.Object, org.eclipse.ui.progress.IDeferredWorkbenchAdapter) - */ - protected String getFetchJobName(Object parent, IDeferredWorkbenchAdapter adapter) { - return DebugUIViewsMessages.RemoteTreeContentManager_0; - } - - - /** - * Returns the IDeferredWorkbenchAdapter for the element, or null. - * If a client has contributed an IWorkbenchAdapter for the element, it - * should be used in place of the debug platform's IDeferredWorkbenchAdapter, - * in which case, null is returned. - * - * @param element - * @return IDeferredWorkbenchAdapter or null - */ - protected IDeferredWorkbenchAdapter getAdapter(Object element) { - if (element instanceof IDeferredWorkbenchAdapter) - return (IDeferredWorkbenchAdapter) element; - if (!(element instanceof IAdaptable)) - return null; - IAdaptable adaptable = (IAdaptable) element; - IDeferredWorkbenchAdapter deferred = (IDeferredWorkbenchAdapter) adaptable.getAdapter(IDeferredWorkbenchAdapter.class); - if (deferred == null) - return null; - - DebugUIPlugin plugin = DebugUIPlugin.getDefault(); - Bundle bundle = plugin.getBundle(deferred.getClass()); - Bundle debugBundle = plugin.getBundle(); - if (!debugBundle.equals(bundle)) { - // if client contributed, use it - return deferred; - } - // if the client provided an IWorkbenchAdapter, use it - IWorkbenchAdapter nonDeferred = (IWorkbenchAdapter) adaptable.getAdapter(IWorkbenchAdapter.class); - if (nonDeferred != null) { - bundle = plugin.getBundle(nonDeferred.getClass()); - if (!debugBundle.equals(bundle)) { - // by returning null, we'll revert to using the the object's workbench adapter - // by pretending it has no deffered adapter - return null; - } - } - return deferred; - } - - protected void startFetchingDeferredChildren(final Object parent, final IDeferredWorkbenchAdapter adapter, PendingUpdateAdapter placeholder) { - final IElementCollector collector = createElementCollector(parent, placeholder); - synchronized (fElementQueue) { - if (!fElementQueue.contains(parent)) { - fElementQueue.add(parent); - fCollectors.add(collector); - fAdapaters.add(adapter); - } - } - if (progressService == null) - fFetchJob.schedule(); - else - progressService.schedule(fFetchJob); - } - - /** - * Cancels any content this provider is currently fetching. - */ - public void cancel() { - synchronized (fElementQueue) { - fFetchJob.cancel(); - fElementQueue.clear(); - fAdapaters.clear(); - fCollectors.clear(); - } - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeViewer.java deleted file mode 100644 index 70fb9cccd..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeViewer.java +++ /dev/null @@ -1,609 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.views; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.swt.widgets.Widget; -import org.eclipse.ui.model.IWorkbenchAdapter; -import org.eclipse.ui.progress.UIJob; - -/** - * A tree viewer that displays remote content. Content is retrieved in a background - * job, and the viewer is updated incrementally on a refresh. - * - * @since 3.1 - */ -public class RemoteTreeViewer extends TreeViewer { - - private ExpansionJob fExpansionJob = null; - private SelectionJob fSelectionJob = null; - - - class ExpansionJob extends UIJob { - - private Object element; - private List parents = new ArrayList(); // top down - - /** - * Constucts a job to expand the given element. - * - * @param target the element to expand - */ - public ExpansionJob() { - super(DebugUIViewsMessages.LaunchViewer_1); - setPriority(Job.INTERACTIVE); - setSystem(true); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus runInUIThread(IProgressMonitor monitor) { - if (getControl().isDisposed() || element == null) { - return Status.OK_STATUS; - } - synchronized (RemoteTreeViewer.this) { - boolean allParentsExpanded = true; - Iterator iterator = parents.iterator(); - while (iterator.hasNext() && !monitor.isCanceled()) { - Object parent = iterator.next(); - Widget item = findItem(parent); - if (item != null) { - expandToLevel(parent, 1); - } else { - allParentsExpanded = false; - break; - } - } - if (allParentsExpanded) { - Widget item = findItem(element); - if (item != null) { - if (isExpandable(element)) { - expandToLevel(element, 1); - } - element = null; - parents.clear(); - return Status.OK_STATUS; - } - } - return Status.OK_STATUS; - } - } - - public void validate(Object object) { - if (element != null) { - if (element.equals(object) || parents.contains(object)) { - cancel(); - element = null; - } - } - } - - public void setDeferredExpansion(Object toExpand) { - element = toExpand; - parents.clear(); - addAllParents(parents, element); - } - - } - - class SelectionJob extends UIJob { - - private IStructuredSelection selection; - private Object first; - private List parents = new ArrayList(); // top down - - /** - * Constucts a job to select the given element. - * - * @param target the element to select - */ - public SelectionJob() { - super(DebugUIViewsMessages.LaunchViewer_0); - setPriority(Job.INTERACTIVE); - setSystem(true); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus runInUIThread(IProgressMonitor monitor) { - if (getControl().isDisposed() || selection == null) { - return Status.OK_STATUS; - } - synchronized (RemoteTreeViewer.this) { - boolean allParentsExpanded = true; - Iterator iterator = parents.iterator(); - while (iterator.hasNext() && !monitor.isCanceled()) { - Object parent = iterator.next(); - Widget item = findItem(parent); - if (item != null) { - expandToLevel(parent, 1); - } else { - allParentsExpanded = false; - break; - } - } - if (allParentsExpanded) { - if (findItem(first) != null) { - setSelection(selection, true); - selection = null; - first = null; - parents.clear(); - return Status.OK_STATUS; - } - } - - return Status.OK_STATUS; - } - } - - public void setDeferredSelection(IStructuredSelection sel) { - selection = sel; - first = selection.getFirstElement(); - parents.clear(); - addAllParents(parents, first); - } - - public void validate(Object object) { - if (first != null) { - if (first.equals(object) || parents.contains(object)) { - cancel(); - selection = null; - } - } - } - } - - - /** - * Constructs a remote tree viewer parented by the given composite. - * - * @param parent parent composite - */ - public RemoteTreeViewer(Composite parent) { - super(parent); - addDisposeListener(); - fExpansionJob = new ExpansionJob(); - fSelectionJob = new SelectionJob(); - } - - /** - * Constructs a remote tree viewer parented by the given composite - * with the given style. - * - * @param parent parent composite - * @param style style bits - */ - public RemoteTreeViewer(Composite parent, int style) { - super(parent, style); - addDisposeListener(); - fExpansionJob = new ExpansionJob(); - fSelectionJob = new SelectionJob(); - } - - /** - * Constructs a remote tree viewer with the given tree. - * - * @param tree tree widget - */ - public RemoteTreeViewer(Tree tree) { - super(tree); - addDisposeListener(); - fExpansionJob = new ExpansionJob(); - fSelectionJob = new SelectionJob(); - } - - private void addDisposeListener() { - getControl().addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - cancelJobs(); - } - }); - } - - protected void runDeferredUpdates() { - if (fExpansionJob != null) { - fExpansionJob.schedule(); - } - if (fSelectionJob != null) { - fSelectionJob.schedule(); - } - } - - /** - * The given element is being removed from the tree. Cancel - * any deferred updates for the element. - * - * @param element - */ - protected void validateDeferredUpdates(Object element) { - if (element != null) { - if (fExpansionJob != null) { - fExpansionJob.validate(element); - } - if (fSelectionJob != null) { - fSelectionJob.validate(element); - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.AbstractTreeViewer#add(java.lang.Object, java.lang.Object) - */ - public synchronized void add(Object parentElement, Object childElement) { - super.add(parentElement, childElement); - runDeferredUpdates(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.AbstractTreeViewer#add(java.lang.Object, java.lang.Object[]) - */ - public synchronized void add(Object parentElement, Object[] childElements) { - super.add(parentElement, childElements); - runDeferredUpdates(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.AbstractTreeViewer#remove(java.lang.Object) - */ - public synchronized void remove(Object element) { - validateDeferredUpdates(element); - super.remove(element); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.AbstractTreeViewer#remove(java.lang.Object[]) - */ - public synchronized void remove(Object[] elements) { - for (int i = 0; i < elements.length; i++) { - validateDeferredUpdates(elements[i]); - } - super.remove(elements); - } - - /** - * Cancels any deferred updates currently scheduled/running. - */ - public void cancelJobs() { - cancel(fSelectionJob); - cancel(fExpansionJob); - } - - public synchronized void deferExpansion(Object element) { - TreeItem treeItem = (TreeItem) findItem(element); - if (treeItem == null) { - fExpansionJob.setDeferredExpansion(element); - fExpansionJob.schedule(); - } else { - if (!getExpanded(treeItem)) { - fExpansionJob.setDeferredExpansion(element); - fExpansionJob.schedule(); - } - } - } - - public synchronized void deferSelection(IStructuredSelection selection) { - if (fSelectionJob == null) { - fSelectionJob = new SelectionJob(); - } - - fSelectionJob.setDeferredSelection(selection); - fSelectionJob.schedule(); - } - - public IStructuredSelection getDeferredSelection() { - if (fSelectionJob != null) { - return fSelectionJob.selection; - } - return null; - } - - private void cancel(Job job) { - if (job != null) { - job.cancel(); - } - } - - private void addAllParents(List list, Object element) { - if (element instanceof IAdaptable) { - IAdaptable adaptable = (IAdaptable) element; - IWorkbenchAdapter adapter = (IWorkbenchAdapter) adaptable.getAdapter(IWorkbenchAdapter.class); - if (adapter != null) { - Object parent = adapter.getParent(element); - if (parent != null) { - list.add(0, parent); - if (!(parent instanceof ILaunch)) - addAllParents(list, parent); - } - } - } - } - - public Object[] filter(Object[] elements) { - return super.filter(elements); - } - - public Object[] getCurrentChildren(Object parent) { - Widget widget = findItem(parent); - if (widget != null) { - Item[] items = getChildren(widget); - Object[] children = new Object[items.length]; - for (int i = 0; i < children.length; i++) { - Object data = items[i].getData(); - if (data == null) { - return null; - } - children[i] = data; - } - return children; - } - return null; - } - - public synchronized void prune(final Object parent, final int offset) { - Widget widget = findItem(parent); - if (widget != null) { - final Item[] currentChildren = getChildren(widget); - if (offset < currentChildren.length) { - preservingSelection(new Runnable() { - public void run() { - for (int i = offset; i < currentChildren.length; i++) { - if (currentChildren[i].getData() != null) { - disassociate(currentChildren[i]); - } - currentChildren[i].dispose(); - } - } - }); - } - } - } - - public synchronized void replace(final Object parent, final Object[] children, final int offset) { - preservingSelection(new Runnable() { - public void run() { - Widget[] widgets = findItems(parent); - for (int n = 0; n < widgets.length; n++) { - Widget widget = widgets[n]; - if (widget == null) { - add(parent, children); - } else { - Item[] currentChildren = getChildren(widget); - int pos = offset; - if (pos >= currentChildren.length) { - // append - add(parent, children); - } else { - // replace - for (int i = 0; i < children.length; i++) { - Object child = children[i]; - if (pos < currentChildren.length) { - // replace - Item item = currentChildren[pos]; - Object data = item.getData(); - if (!child.equals(data)) { - // no need to cancel pending updates here, the child may have shifted up/down - internalRefresh(item, child, true, true); - } else { - // If it's the same child, the label/content may still have changed - doUpdateItem(item, child); - updatePlus(item, child); - } - } else { - // add - int numLeft = children.length - i; - if (numLeft >= 1) { - Object[] others = new Object[numLeft]; - System.arraycopy(children, i, others, 0, numLeft); - internalAdd(widget, parent, others); - } - break; - } - pos++; - } - } - } - } - - runDeferredUpdates(); - } - }); - } - - protected void internalAdd(Widget widget, Object parentElement, Object[] childElements) { - - // optimization! - // if the widget is not expanded we just invalidate the subtree - if (widget instanceof Item) { - Item ti = (Item) widget; - if (!getExpanded(ti)) { - boolean needDummy = isExpandable(parentElement); - boolean haveDummy = false; - // remove all children - Item[] items = getItems(ti); - for (int i = 0; i < items.length; i++) { - if (items[i].getData() != null) { - disassociate(items[i]); - items[i].dispose(); - } else { - if (needDummy && !haveDummy) { - haveDummy = true; - } else { - items[i].dispose(); - } - } - } - // append a dummy if necessary - if (needDummy && !haveDummy) - newItem(ti, SWT.NULL, -1); - return; - } - } - - if (childElements.length > 0) { - Object[] filtered = filter(childElements); - if(getSorter() != null) - getSorter().sort(this,filtered); - createAddedElements(widget, filtered); - } - } - - - - // tree viewer hacks start here. These hacks allow us to display the same Object in a tree viewer more - // than once. Workbench does on support this (July 6, 2005) - - - private void createAddedElements(Widget widget, Object[] elements) { - - if(elements.length == 1){ - if (equals(elements[0], widget.getData())) - return; - } - - ViewerSorter sorter = getSorter (); - Item[] items = getChildren(widget); - - //As the items are sorted already we optimize for a - //start position - int lastInsertion = 0; - - //Optimize for the empty case - if(items.length == 0){ - for (int i = 0; i < elements.length; i++) { - createTreeItem(widget, elements[i], -1); - } - return; - } - - for (int i = 0; i < elements.length; i++) { - boolean newItem = true; - Object element = elements[i]; - int index; - if(sorter == null){ - index = -1; - } - else{ - lastInsertion = insertionPosition(items,sorter,lastInsertion, element); - //As we are only searching the original array we keep track of those positions only - if(lastInsertion == items.length) - index = -1; - else{//See if we should just refresh - while(lastInsertion < items.length && sorter.compare(this,element,items[lastInsertion].getData()) == 0){ - //As we cannot assume the sorter is consistent with equals() - therefore we can - // just check against the item prior to this index (if any) - if (items[lastInsertion].getData().equals(element)) { - //refresh the element in case it has new children - refresh(element); - newItem = false; - } - lastInsertion ++;//We had an insertion so increment - } - //Did we get to the end? - if(lastInsertion == items.length) - index = -1; - else - index = lastInsertion + i; //Add the index as the array is growing - } - } - if(newItem) - createTreeItem(widget, element, index); - } - } - - //copied from super class - private int insertionPosition(Item[] items, ViewerSorter sorter, int lastInsertion, Object element) { - int size = items.length; - if (sorter == null) - return size; - int min = lastInsertion, max = size - 1; - - while (min <= max) { - int mid = (min + max) / 2; - Object data = items[mid].getData(); - int compare = sorter.compare(this, data, element); - if (compare == 0) { - return mid;//Return if we already match - } - if (compare < 0) - min = mid + 1; - else - max = mid - 1; - } - return min; - } - - public void update(Object element, String[] properties) { - Assert.isNotNull(element); - Widget[] widgets = findItems(element); - for (int i = 0; i < widgets.length; i++) { - Widget widget = widgets[i]; - if (widget != null) { - internalUpdate(widget, element, properties); - } - } - } - - protected Widget[] findItems(Object target) { - List widgets = new ArrayList(); - Object root = getRoot(); - if (root != null) { - if (equals(root, target)) { - Widget widget = findItem(root); - widgets.add(widget); - } - } - Item[] children = getChildren(getControl()); - - if (children != null) { - for (int i = 0; i < children.length; i++) { - Item child = children[i]; - internalFindItems(target, child, widgets); - } - } - return (Widget[]) widgets.toArray(new Widget[widgets.size()]); - } - - private void internalFindItems(Object target, Item item, List widgets) { - if (equals(target, item.getData())) { - widgets.add(item); - } - - Item[] children = getChildren(item); - for (int i = 0; i < children.length; i++) { - Item child = children[i]; - internalFindItems(target, child, widgets); - } - } -} - - diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleRemoveAllTerminatedAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleRemoveAllTerminatedAction.java index 0677d8c8a..889bd77d8 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleRemoveAllTerminatedAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleRemoveAllTerminatedAction.java @@ -20,7 +20,7 @@ import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IDebugHelpContextIds; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; -import org.eclipse.debug.internal.ui.actions.RemoveAllTerminatedAction; +import org.eclipse.debug.internal.ui.contexts.actions.RemoveAllTerminatedAction; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.action.Action; import org.eclipse.ui.PlatformUI; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleTerminateActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleTerminateActionDelegate.java index 5cf0c116a..58991384e 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleTerminateActionDelegate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleTerminateActionDelegate.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.debug.internal.ui.views.console; -import org.eclipse.debug.internal.ui.actions.TerminateActionDelegate; +import org.eclipse.debug.internal.ui.contexts.actions.TerminateActionDelegate; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionPopupContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionPopupContentProvider.java deleted file mode 100644 index 928450515..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionPopupContentProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.views.expression; - -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; -import org.eclipse.debug.internal.ui.views.variables.VariablesView; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.ui.IWorkbenchPartSite; - - -public class ExpressionPopupContentProvider extends RemoteExpressionsContentProvider { - - private Object input = null; - - public ExpressionPopupContentProvider(RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) { - super(viewer, site, view); - } - - - /* (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) { - super.inputChanged(viewer, oldInput, newInput); - input = newInput; - } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) - */ - public Object[] getElements(Object parent) { - if (parent == input) { - return (Object[]) input; - } - return super.getElements(parent); - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java index 65c7a65f0..982535089 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java @@ -14,16 +14,11 @@ package org.eclipse.debug.internal.ui.views.expression; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IErrorReportingExpression; import org.eclipse.debug.core.model.IExpression; import org.eclipse.debug.core.model.IWatchExpression; import org.eclipse.debug.internal.ui.IDebugHelpContextIds; import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; -import org.eclipse.debug.internal.ui.views.DebugViewInterimLabelProvider; -import org.eclipse.debug.internal.ui.views.DebugViewLabelDecorator; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; import org.eclipse.debug.internal.ui.views.variables.AvailableLogicalStructuresAction; -import org.eclipse.debug.internal.ui.views.variables.RemoteVariablesContentProvider; import org.eclipse.debug.internal.ui.views.variables.VariablesView; import org.eclipse.debug.internal.ui.views.variables.VariablesViewEventHandler; import org.eclipse.debug.internal.ui.views.variables.VariablesViewMessages; @@ -32,17 +27,9 @@ import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IMemento; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPart; @@ -53,52 +40,6 @@ import org.eclipse.ui.IWorkbenchPart; */ public class ExpressionView extends VariablesView { - /** - * A decorating label provider which provides color for expressions. - */ - protected class ExpressionViewDecoratingLabelProvider extends VariablesView.VariablesViewDecoratingLabelProvider { - /** - * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object) - */ - public Color getForeground(Object element) { - boolean expressionWithError= false; - IErrorReportingExpression expression= null; - if (element instanceof IErrorReportingExpression) { - expression= (IErrorReportingExpression) element; - } else if (element instanceof String) { - Object parent= ((ITreeContentProvider)getVariablesViewer().getContentProvider()).getParent(element); - if (parent instanceof IErrorReportingExpression) { - expression= (IErrorReportingExpression) parent; - } - } - if (expression != null && expression.hasErrors()) { - expressionWithError= true; - } - if (expressionWithError) { - return Display.getDefault().getSystemColor(SWT.COLOR_RED); - } - return super.getForeground(element); - } - - public ExpressionViewDecoratingLabelProvider(StructuredViewer viewer, ILabelProvider provider, DebugViewLabelDecorator decorator) { - super(viewer, provider, decorator); - } - } - /** - * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#createLabelProvider() - */ - protected IBaseLabelProvider createLabelProvider(StructuredViewer viewer) { - return new ExpressionViewDecoratingLabelProvider(viewer, new DebugViewInterimLabelProvider(getModelPresentation()), new DebugViewLabelDecorator(getModelPresentation())); - } - - /** - * Creates this view's content provider. - * - * @return a content provider - */ - protected RemoteVariablesContentProvider createContentProvider(Viewer viewer) { - return new RemoteExpressionsContentProvider((RemoteTreeViewer)viewer, getSite(), this); - } /** * Creates this view's event handler. @@ -195,7 +136,7 @@ public class ExpressionView extends VariablesView { * * @see VariablesView#setViewerInput(IStructuredSelection) */ - protected void setViewerInput(IStructuredSelection ssel) { + protected void setViewerInput(Object obj) { } /* (non-Javadoc) diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionViewEventHandler.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionViewEventHandler.java index f87c70047..d334cfebb 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionViewEventHandler.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionViewEventHandler.java @@ -11,8 +11,6 @@ package org.eclipse.debug.internal.ui.views.expression; -import java.util.List; - import org.eclipse.core.runtime.IAdaptable; import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugPlugin; @@ -25,7 +23,6 @@ import org.eclipse.debug.core.model.IWatchExpression; import org.eclipse.debug.internal.ui.views.variables.VariablesViewEventHandler; import org.eclipse.debug.ui.AbstractDebugView; import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.jface.viewers.IContentProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; @@ -87,10 +84,10 @@ public class ExpressionViewEventHandler extends VariablesViewEventHandler implem Runnable r = new Runnable() { public void run() { if (isAvailable()) { - getTreeViewer().refresh(); + getStructuredViewer().refresh(); if (expressions.length > 0) { ISelection selection = new StructuredSelection(expressions[0]); - getTreeViewer().setSelection(selection, true); + getStructuredViewer().setSelection(selection, true); } } } @@ -102,31 +99,9 @@ public class ExpressionViewEventHandler extends VariablesViewEventHandler implem * @see IExpressionsListener#expressionsRemoved(IExpression[]) */ public void expressionsRemoved(final IExpression[] expressions) { - Runnable r = new Runnable() { - public void run() { - if (isAvailable()) { - getTreeViewer().getControl().setRedraw(false); - for (int i = 0; i < expressions.length; i++) { - IExpression expression = expressions[i]; - remove(expression); - IContentProvider provider= getTreeViewer().getContentProvider(); - if (provider instanceof RemoteExpressionsContentProvider) { - RemoteExpressionsContentProvider expressionProvider= (RemoteExpressionsContentProvider) provider; - List decendants = expressionProvider.getCachedDecendants(expression); - decendants.add(expression); - // Remove the parent cache for the expression and its children - expressionProvider.removeCache(decendants.toArray()); - IExpression[] allExpressions= DebugPlugin.getDefault().getExpressionManager().getExpressions(); - if (allExpressions.length > 0) { - getTreeViewer().setSelection(new StructuredSelection(allExpressions[0]), true); - } - } - } - getTreeViewer().getControl().setRedraw(true); - } - } - }; - getView().asyncExec(r); + if (isAvailable()) { + getStructuredViewer().refresh(); + } } /** @@ -136,7 +111,7 @@ public class ExpressionViewEventHandler extends VariablesViewEventHandler implem Runnable r = new Runnable() { public void run() { if (isAvailable()) { - getTreeViewer().getControl().setRedraw(false); + getStructuredViewer().getControl().setRedraw(false); for (int i = 0; i < expressions.length; i++) { IExpression expression = expressions[i]; refresh(expression); @@ -146,7 +121,7 @@ public class ExpressionViewEventHandler extends VariablesViewEventHandler implem getVariablesView().populateDetailPane(); } } - getTreeViewer().getControl().setRedraw(true); + getStructuredViewer().getControl().setRedraw(true); } } }; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/RemoteExpressionContentManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/RemoteExpressionContentManager.java deleted file mode 100644 index e5c60c54c..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/RemoteExpressionContentManager.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.views.expression; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IErrorReportingExpression; -import org.eclipse.debug.core.model.IExpression; -import org.eclipse.debug.core.model.IValue; -import org.eclipse.debug.core.model.IVariable; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredExpressionLogicalStructure; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; -import org.eclipse.debug.internal.ui.views.variables.RemoteVariableContentManager; -import org.eclipse.debug.internal.ui.views.variables.VariablesView; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; - -/** - * Remote content manager for variables. Creates an appropriate adapter for - * logical structures. - */ -public class RemoteExpressionContentManager extends RemoteVariableContentManager { - - private IDeferredWorkbenchAdapter fExpressionLogicalStructureAdapter = new DeferredExpressionLogicalStructure(); - - /** - * Constructs a remote content manager for a variables view. - */ - public RemoteExpressionContentManager(ITreeContentProvider provider, RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) { - super(provider, viewer, site, view); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.DeferredTreeContentManager#getAdapter(java.lang.Object) - */ - protected IDeferredWorkbenchAdapter getAdapter(Object element) { - if (element instanceof IExpression && fView !=null && fView.isShowLogicalStructure()) { - return fExpressionLogicalStructureAdapter; - } - return super.getAdapter(element); - } - - public boolean mayHaveChildren(Object element) { - if (element instanceof IErrorReportingExpression) { - IErrorReportingExpression iere = (IErrorReportingExpression) element; - if (iere.hasErrors()) { - //errors are displayed as children of the expression - return true; - } - } - - if (element instanceof IExpression) { - IExpression expression = (IExpression) element; - IValue value = expression.getValue(); - if (value != null) { - try { - IVariable[] variables = value.getVariables(); - if (variables.length > 0) { - //definitely children... - return true; - } - - //returning false because value!=null && variables.length=0 means no children - return false; - } catch (DebugException e) { - } - } - } - - //expression has not been evaluated - return super.mayHaveChildren(element); - } - - - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/RemoteExpressionsContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/RemoteExpressionsContentProvider.java deleted file mode 100644 index bae39c852..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/RemoteExpressionsContentProvider.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.views.expression; - -import org.eclipse.debug.internal.ui.views.RemoteTreeContentManager; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; -import org.eclipse.debug.internal.ui.views.variables.RemoteVariablesContentProvider; -import org.eclipse.debug.internal.ui.views.variables.VariablesView; -import org.eclipse.ui.IWorkbenchPartSite; - -public class RemoteExpressionsContentProvider extends RemoteVariablesContentProvider { - - /** - * @param viewer - * @param site - * @param view - */ - public RemoteExpressionsContentProvider(RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) { - super(viewer, site, view); - } - - protected RemoteTreeContentManager createContentManager(RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) { - return new RemoteExpressionContentManager(this, viewer, site, view); - } - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementAdapterFactory.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementAdapterFactory.java index 5575513ce..38eae9048 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementAdapterFactory.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementAdapterFactory.java @@ -14,6 +14,7 @@ import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.debug.core.IExpressionManager; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.model.IDebugElement; import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IExpression; import org.eclipse.debug.core.model.IProcess; @@ -21,16 +22,28 @@ import org.eclipse.debug.core.model.IRegisterGroup; import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.core.model.IVariable; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredExpression; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredExpressionManager; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredLaunch; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredLaunchManager; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredProcess; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredRegisterGroup; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredStackFrame; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredTarget; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredThread; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredVariable; +import org.eclipse.debug.internal.ui.elements.adapters.AsynchronousDebugLabelAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.DebugTargetTreeContentAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.ExpressionManagerTreeContentAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.ExpressionTreeContentAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.LauchManagerTreeContentAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.LaunchTreeContentAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.ProcessTreeAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.RegisterGroupTreeContentAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.StackFrameSourceDisplayAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.StackFrameTreeContentAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.ThreadTreeContentAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter; +import org.eclipse.debug.internal.ui.elements.adapters.VariableTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IAsynchronousLabelAdapter; +import org.eclipse.debug.internal.ui.viewers.IAsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IModelProxyFactory; +import org.eclipse.debug.internal.ui.viewers.IModelSelectionPolicy; +import org.eclipse.debug.internal.ui.viewers.IUpdatePolicyFactory; +import org.eclipse.debug.internal.ui.viewers.update.DefaultModelProxyFactory; +import org.eclipse.debug.internal.ui.viewers.update.DefaultSelectionPolicy; +import org.eclipse.debug.internal.ui.viewers.update.DefaultUpdatePolicyFactory; +import org.eclipse.debug.ui.contexts.ISourceDisplayAdapter; import org.eclipse.ui.model.IWorkbenchAdapter; import org.eclipse.ui.model.IWorkbenchAdapter2; import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; @@ -39,17 +52,24 @@ import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; * DebugElementAdapterFactory */ public class DebugElementAdapterFactory implements IAdapterFactory { + + private static IUpdatePolicyFactory fgUpdatePolicyFactoryAdapter = new DefaultUpdatePolicyFactory(); + private static IModelProxyFactory fgModelProxyFactoryAdapter = new DefaultModelProxyFactory(); + private static ISourceDisplayAdapter fgStackFrameSourceDisplayAdapter = new StackFrameSourceDisplayAdapter(); - private static IDeferredWorkbenchAdapter fgLaunchManagerAdapter = new DeferredLaunchManager(); - private static IDeferredWorkbenchAdapter fgLaunchAdapter = new DeferredLaunch(); - private static IDeferredWorkbenchAdapter fgDebugTargetAdapter = new DeferredTarget(); - private static IDeferredWorkbenchAdapter fgProcessAdapter = new DeferredProcess(); - private static IDeferredWorkbenchAdapter fgThreadAdapter = new DeferredThread(); - private static IDeferredWorkbenchAdapter fgFrameAdapter = new DeferredStackFrame(); - private static IDeferredWorkbenchAdapter fgRegisterGroupAdapter = new DeferredRegisterGroup(); - private static IDeferredWorkbenchAdapter fgVariableAdapter = new DeferredVariable(); - private static IDeferredWorkbenchAdapter fgExpressionAdapter = new DeferredExpression(); - private static IDeferredWorkbenchAdapter fgExpressionManagerAdapter = new DeferredExpressionManager(); + private static IAsynchronousLabelAdapter fgDebugLabelAdapter = new AsynchronousDebugLabelAdapter(); + private static IAsynchronousLabelAdapter fgVariableLabelAdapter = new VariableLabelAdapter(); + + private static IAsynchronousTreeContentAdapter fgAsyncLaunchManager = new LauchManagerTreeContentAdapter(); + private static IAsynchronousTreeContentAdapter fgAsyncLaunch = new LaunchTreeContentAdapter(); + private static IAsynchronousTreeContentAdapter fgAsyncTarget = new DebugTargetTreeContentAdapter(); + private static IAsynchronousTreeContentAdapter fgAsyncProcess = new ProcessTreeAdapter(); + private static IAsynchronousTreeContentAdapter fgAsyncThread = new ThreadTreeContentAdapter(); + private static IAsynchronousTreeContentAdapter fgAsyncFrame = new StackFrameTreeContentAdapter(); + private static IAsynchronousTreeContentAdapter fgAsyncVariable = new VariableTreeContentAdapter(); + private static IAsynchronousTreeContentAdapter fgAsyncRegisterGroup = new RegisterGroupTreeContentAdapter(); + private static IAsynchronousTreeContentAdapter fgAsyncExpressionManager = new ExpressionManagerTreeContentAdapter(); + private static IAsynchronousTreeContentAdapter fgAsyncExpression = new ExpressionTreeContentAdapter(); /* (non-Javadoc) * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) @@ -58,36 +78,70 @@ public class DebugElementAdapterFactory implements IAdapterFactory { if (adapterType.isInstance(adaptableObject)) { return adaptableObject; } - if (adapterType.equals(IWorkbenchAdapter.class) || adapterType.equals(IWorkbenchAdapter2.class) || adapterType.equals(IDeferredWorkbenchAdapter.class)) { - if (adaptableObject instanceof ILaunchManager) { - return fgLaunchManagerAdapter; - } - if (adaptableObject instanceof ILaunch) { - return fgLaunchAdapter; - } - if (adaptableObject instanceof IDebugTarget) { - return fgDebugTargetAdapter; - } - if (adaptableObject instanceof IProcess) { - return fgProcessAdapter; - } - if (adaptableObject instanceof IThread) { - return fgThreadAdapter; - } - if (adaptableObject instanceof IStackFrame) { - return fgFrameAdapter; - } + + if (adapterType.equals(IAsynchronousTreeContentAdapter.class)) { + if (adaptableObject instanceof ILaunchManager) { + return fgAsyncLaunchManager; + } + if (adaptableObject instanceof ILaunch) { + return fgAsyncLaunch; + } + if (adaptableObject instanceof IDebugTarget) { + return fgAsyncTarget; + } + if (adaptableObject instanceof IProcess) { + return fgAsyncProcess; + } + if (adaptableObject instanceof IThread) { + return fgAsyncThread; + } + if (adaptableObject instanceof IStackFrame) { + return fgAsyncFrame; + } + if (adaptableObject instanceof IVariable) { + return fgAsyncVariable; + } + if (adaptableObject instanceof IRegisterGroup) { + return fgAsyncRegisterGroup; + } + if (adaptableObject instanceof IExpressionManager) { + return fgAsyncExpressionManager; + } + if (adaptableObject instanceof IExpression) { + return fgAsyncExpression; + } + } + + if (adapterType.equals(IAsynchronousLabelAdapter.class)) { if (adaptableObject instanceof IVariable) { - return fgVariableAdapter; - } - if (adaptableObject instanceof IExpression) { - return fgExpressionAdapter; + return fgVariableLabelAdapter; } - if (adaptableObject instanceof IRegisterGroup) { - return fgRegisterGroupAdapter; + return fgDebugLabelAdapter; + } + + if (adapterType.equals(IUpdatePolicyFactory.class)) { + if (adaptableObject instanceof ILaunch || adaptableObject instanceof IDebugTarget || + adaptableObject instanceof IProcess || adaptableObject instanceof ILaunchManager || + adaptableObject instanceof IStackFrame) + return fgUpdatePolicyFactoryAdapter; + } + + if (adapterType.equals(IModelProxyFactory.class)) { + if (adaptableObject instanceof ILaunch || adaptableObject instanceof IDebugTarget || + adaptableObject instanceof IProcess || adaptableObject instanceof ILaunchManager || + adaptableObject instanceof IStackFrame) + return fgModelProxyFactoryAdapter; + } + + if (adapterType.equals(ISourceDisplayAdapter.class)) { + if (adaptableObject instanceof IStackFrame) { + return fgStackFrameSourceDisplayAdapter; } - if (adaptableObject instanceof IExpressionManager) { - return fgExpressionManagerAdapter; + } + + if (adapterType.equals(IModelSelectionPolicy.class)) { + if (adaptableObject instanceof IDebugElement) { + return new DefaultSelectionPolicy((IDebugElement)adaptableObject); } } return null; @@ -97,7 +151,8 @@ public class DebugElementAdapterFactory implements IAdapterFactory { * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() */ public Class[] getAdapterList() { - return new Class[] {IWorkbenchAdapter.class, IWorkbenchAdapter2.class, IDeferredWorkbenchAdapter.class}; + return new Class[] {IWorkbenchAdapter.class, IWorkbenchAdapter2.class, IDeferredWorkbenchAdapter.class, IAsynchronousLabelAdapter.class, IAsynchronousTreeContentAdapter.class, + IUpdatePolicyFactory.class, IModelProxyFactory.class, ISourceDisplayAdapter.class, IModelSelectionPolicy.class}; } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementHelper.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementHelper.java index 591ef9991..1e6bfa7e7 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementHelper.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementHelper.java @@ -78,7 +78,7 @@ public class DebugElementHelper { * * @return a model presentation to use to retrieve lables & images */ - private static DelegatingModelPresentation getPresentation() { + public static DelegatingModelPresentation getPresentation() { if (fgPresenetation == null) { fgPresenetation = new DelegatingModelPresentation(); } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugViewContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugViewContentProvider.java deleted file mode 100644 index 1ab49eca3..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugViewContentProvider.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.views.launch; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.debug.core.DebugException; -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.IProcess; -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.debug.core.model.IThread; -import org.eclipse.debug.internal.ui.views.RemoteTreeContentManager; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.model.BaseWorkbenchContentProvider; -import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; - -/** - * Provides deferred content for the debug view. - * @since 3.1 - */ -public class DebugViewContentProvider extends BaseWorkbenchContentProvider { - - private RemoteTreeContentManager fManager; - - public DebugViewContentProvider(LaunchViewer tree, IWorkbenchPartSite site) { - fManager = new RemoteTreeContentManager(this, tree, site); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parentElement) { - if (parentElement instanceof IStackFrame) { - return null; - } - Object[] children = fManager.getChildren(parentElement); - if (children == null) { - children = super.getChildren(parentElement); - } - return children; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) - */ - public boolean hasChildren(Object element) { - if (element instanceof IStackFrame) { - return false; - } - if (element instanceof IDebugTarget) { - try { - return ((IDebugTarget)element).hasThreads(); - } catch (DebugException e) { - return false; - } - } - if (element instanceof IThread) { - try { - return ((IThread)element).hasStackFrames(); - } catch (DebugException e) { - return false; - } - } - if (element instanceof IProcess) { - return false; - } - if (element instanceof ILaunch) { - return ((ILaunch)element).hasChildren(); - } - if (element instanceof ILaunchManager) { - return ((ILaunchManager) element).getLaunches().length > 0; - } - if (element instanceof IAdaptable) { - IAdaptable adaptable = (IAdaptable) element; - IDeferredWorkbenchAdapter adapter = (IDeferredWorkbenchAdapter) adaptable.getAdapter(IDeferredWorkbenchAdapter.class); - if (adapter != null) { - return adapter.isContainer(); - } - } - return super.hasChildren(element); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IContentProvider#dispose() - */ - public void dispose() { - fManager.cancel(); - super.dispose(); - } - -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java index a3fafdb48..bf99085f7 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java @@ -24,8 +24,10 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.debug.core.DebugException; @@ -45,19 +47,22 @@ import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.InstructionPointerManager; import org.eclipse.debug.internal.ui.actions.AddToFavoritesAction; import org.eclipse.debug.internal.ui.actions.EditLaunchConfigurationAction; +import org.eclipse.debug.internal.ui.contexts.DebugContextManager; import org.eclipse.debug.internal.ui.sourcelookup.EditSourceLookupPathAction; import org.eclipse.debug.internal.ui.sourcelookup.LookupSourceAction; import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupResult; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; +import org.eclipse.debug.internal.ui.viewers.PresentationContext; +import org.eclipse.debug.internal.ui.viewers.TreePath; +import org.eclipse.debug.internal.ui.viewers.TreeSelection; import org.eclipse.debug.internal.ui.views.AbstractDebugEventHandlerView; import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages; -import org.eclipse.debug.internal.ui.views.DebugViewDecoratingLabelProvider; -import org.eclipse.debug.internal.ui.views.DebugViewInterimLabelProvider; -import org.eclipse.debug.internal.ui.views.DebugViewLabelDecorator; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugEditorPresentation; import org.eclipse.debug.ui.IDebugModelPresentation; import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.debug.ui.contexts.IDebugContextListener; +import org.eclipse.debug.ui.contexts.IDebugContextProvider; import org.eclipse.debug.ui.sourcelookup.ISourceLookupResult; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IMenuManager; @@ -65,6 +70,7 @@ import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.ListenerList; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.ISelection; @@ -73,15 +79,11 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IMemento; import org.eclipse.ui.IPageLayout; @@ -145,6 +147,71 @@ public class LaunchView extends AbstractDebugEventHandlerView implements ISelect */ private IWorkbenchSiteProgressService fProgressService = null; + class ContextProvider implements IDebugContextProvider { + /** + * Context listeners + */ + private ListenerList fListeners = new ListenerList(); + + private ISelection fContext = null; + + protected void dispose() { + fContext = null; + fListeners.clear(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextProvider#getPart() + */ + public IWorkbenchPart getPart() { + return LaunchView.this; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextProvider#addDebugContextListener(org.eclipse.debug.ui.contexts.IDebugContextListener) + */ + public void addDebugContextListener(IDebugContextListener listener) { + fListeners.add(listener); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextProvider#removeDebugContextListener(org.eclipse.debug.ui.contexts.IDebugContextListener) + */ + public void removeDebugContextListener(IDebugContextListener listener) { + fListeners.remove(listener); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextProvider#getActiveContext() + */ + public synchronized ISelection getActiveContext() { + return fContext; + } + + protected synchronized void activate(ISelection selection) { + fContext = selection; + Object[] listeners = fListeners.getListeners(); + for (int i = 0; i < listeners.length; i++) { + final IDebugContextListener listener = (IDebugContextListener) listeners[i]; + Platform.run(new ISafeRunnable() { + public void run() throws Exception { + listener.contextActivated(fContext, ContextProvider.this.getPart()); + } + public void handleException(Throwable exception) { + DebugUIPlugin.log(exception); + } + }); + + } + } + + } + + /** + * Context provider + */ + private ContextProvider fProvider = new ContextProvider(); + /** * Context manager which automatically opens and closes views * based on debug contexts. @@ -214,43 +281,6 @@ public class LaunchView extends AbstractDebugEventHandlerView implements ISelect } - /** - * Label provider for the launch view which renders pending launches - * with italic font. - */ - private class LaunchViewLabelProvider extends DebugViewDecoratingLabelProvider { - - // The cached italic font used for pending launches - private Font fItalicFont= null; - - public LaunchViewLabelProvider(StructuredViewer viewer, IDebugModelPresentation presentation) { - super(viewer, new DebugViewInterimLabelProvider(presentation), new DebugViewLabelDecorator(presentation)); - } - - public Font getFont(Object element) { - if (element instanceof DebugUIPlugin.PendingLaunch) { - if (fItalicFont == null) { - Control control = getViewer().getControl(); - Font originalFont = control.getFont(); - FontData fontData[] = originalFont.getFontData(); - // Add the italic attribute - for (int i = 0; i < fontData.length; i++) { - fontData[i].setStyle(fontData[i].getStyle() | SWT.ITALIC); - } - fItalicFont= new Font(control.getDisplay(), fontData); - } - return fItalicFont; - } - return super.getFont(element); - } - - public void dispose() { - if (fItalicFont != null) { - fItalicFont.dispose(); - } - super.dispose(); - } - } /** * Job used for source display. @@ -299,24 +329,28 @@ public class LaunchView extends AbstractDebugEventHandlerView implements ISelect * @see org.eclipse.debug.ui.AbstractDebugView#createViewer(org.eclipse.swt.widgets.Composite) */ protected Viewer createViewer(Composite parent) { - LaunchViewer lv = new LaunchViewer(parent); - lv.addPostSelectionChangedListener(this); - lv.getControl().addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent event) { - if (event.character == SWT.DEL && event.stateMask == 0) { - handleDeleteKeyPressed(); - } - } - }); - lv.setContentProvider(new DebugViewContentProvider(lv, getSite())); - final DelegatingModelPresentation presentation = new DelegatingModelPresentation(); - lv.setLabelProvider(new LaunchViewLabelProvider(lv, presentation)); - fEditorPresentation = presentation; - // add my viewer as a selection provider, so selective re-launch works - getSite().setSelectionProvider(lv); - lv.setInput(DebugPlugin.getDefault().getLaunchManager()); - setEventHandler(new LaunchViewEventHandler(this)); - return lv; + AsynchronousTreeViewer viewer = new LaunchViewer(parent); + viewer.setContext(new PresentationContext(this)); + viewer.setInput(DebugPlugin.getDefault().getLaunchManager()); + + viewer.addSelectionChangedListener(this); + // TODO: why post and selection change listener? + // viewer.addPostSelectionChangedListener(this); + viewer.getControl().addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent event) { + if (event.character == SWT.DEL && event.stateMask == 0) { + handleDeleteKeyPressed(); + } + } + }); + final DelegatingModelPresentation presentation = new DelegatingModelPresentation(); + fEditorPresentation = presentation; + // add my viewer as a selection provider, so selective re-launch works + getSite().setSelectionProvider(viewer); + viewer.setInput(DebugPlugin.getDefault().getLaunchManager()); + //setEventHandler(new LaunchViewEventHandler(this)); + DebugContextManager.getDefault().addDebugContextProvider(fProvider); + return viewer; } private void handleDeleteKeyPressed() { @@ -337,7 +371,7 @@ public class LaunchView extends AbstractDebugEventHandlerView implements ISelect } if (itemsToTerminate) { // Prompt the user to proceed with termination - if (!MessageDialog.openQuestion(getSite().getShell(), DebugUIViewsMessages.LaunchView_Terminate_and_Remove_1, DebugUIViewsMessages.LaunchView_Terminate_and_remove_selected__2)) { // + if (!MessageDialog.openQuestion(getSite().getShell(), DebugUIViewsMessages.LaunchView_Terminate_and_Remove_1, DebugUIViewsMessages.LaunchView_Terminate_and_remove_selected__2)) { return; } } @@ -353,7 +387,7 @@ public class LaunchView extends AbstractDebugEventHandlerView implements ISelect if (!status.isOK()) { IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow(); if (window != null) { - DebugUIPlugin.errorDialog(window.getShell(), DebugUIViewsMessages.LaunchView_Terminate_and_Remove_4, DebugUIViewsMessages.LaunchView_Terminate_and_remove_failed_5, status); // + DebugUIPlugin.errorDialog(window.getShell(), DebugUIViewsMessages.LaunchView_Terminate_and_Remove_4, DebugUIViewsMessages.LaunchView_Terminate_and_remove_failed_5, status); } else { DebugUIPlugin.log(status); } @@ -406,27 +440,26 @@ public class LaunchView extends AbstractDebugEventHandlerView implements ISelect if (!isAvailable()) { return; } - TreeViewer tv = (TreeViewer)getViewer(); - tv.expandToLevel(2); - final Object[] elements = tv.getExpandedElements(); + // traverse debug model in non UI thread Job initJob = new Job(DebugUIViewsMessages.LaunchView_2) { /* (non-Javadoc) * @see org.eclipse.core.internal.jobs.InternalJob#run(org.eclipse.core.runtime.IProgressMonitor) */ protected IStatus run(IProgressMonitor monitor) { - for (int i = 0; i < elements.length; i++) { - if (elements[i] instanceof ILaunch) { - final IStackFrame frame = findFrame((ILaunch)elements[i]); - if (frame != null) { - Runnable runnable = new Runnable() { - public void run() { - autoExpand(frame, true); - } - }; - asyncExec(runnable); - } - } + ILaunchManager launchManager = (ILaunchManager) getViewer().getInput(); + ILaunch[] launches = launchManager.getLaunches(); + for (int i = 0; i < launches.length; i++) { + ILaunch launch = launches[i]; + final IStackFrame frame = findFrame(launch); + if (frame != null) { + Runnable runnable = new Runnable() { + public void run() { + autoExpand(frame, true); + } + }; + asyncExec(runnable); + } } return Status.OK_STATUS; } @@ -507,10 +540,14 @@ public class LaunchView extends AbstractDebugEventHandlerView implements ISelect * @see org.eclipse.ui.IWorkbenchPart#dispose() */ public void dispose() { - RemoteTreeViewer viewer = (RemoteTreeViewer) getViewer(); + fProvider.dispose(); + Viewer viewer = getViewer(); if (viewer != null) { viewer.removeSelectionChangedListener(this); - viewer.cancelJobs(); + if (viewer instanceof AsynchronousTreeViewer) { + AsynchronousTreeViewer asyncTreeViewer = (AsynchronousTreeViewer) viewer; + asyncTreeViewer.dispose(); + } } if (fContextListener != null) { fContextListener.dispose(); @@ -551,12 +588,21 @@ public class LaunchView extends AbstractDebugEventHandlerView implements ISelect * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) */ public void selectionChanged(SelectionChangedEvent event) { - clearStatusLine(); - updateObjects(); - showEditorForCurrentSelection(); + fProvider.activate(event.getSelection()); + +// clearStatusLine(); +// updateObjects(); +// Object element = ((IStructuredSelection) getViewer().getSelection()).getFirstElement(); +// if (element != null && !element.equals(fStackFrame)) { +// showEditorForCurrentSelection(); +// } + +// TODO: replace view conetxt stuff based on debug context if (isActive()) { - fContextListener.updateForSelection(((IStructuredSelection) getViewer().getSelection()).getFirstElement()); + Object element = ((IStructuredSelection)event.getSelection()).getFirstElement(); + fContextListener.updateForSelection(element); } + } /** @@ -603,9 +649,8 @@ public class LaunchView extends AbstractDebugEventHandlerView implements ISelect if (o == null || o instanceof IStackFrame) { return; } - TreeViewer tViewer= (TreeViewer)getViewer(); - boolean expanded= tViewer.getExpandedState(o); - tViewer.setExpandedState(o, !expanded); + StructuredViewer viewer = (StructuredViewer) getViewer(); + viewer.refresh(o); } /* (non-Javadoc) @@ -834,29 +879,27 @@ public class LaunchView extends AbstractDebugEventHandlerView implements ISelect * @param selectNeeded whether the element should be selected */ public void autoExpand(Object element, boolean selectNeeded) { - LaunchViewer launchViewer = (LaunchViewer)getViewer(); - launchViewer.deferExpansion(element); - if (selectNeeded) { - IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection(); - // if a frame is selected in a different thread, do not update selection - Iterator iterator = selection.iterator(); - while (iterator.hasNext()) { - Object object = iterator.next(); - if (object instanceof IStackFrame) { - if (element instanceof IStackFrame) { - IThread currThread = ((IStackFrame)object).getThread(); - if (!currThread.equals(((IStackFrame)element).getThread())) { - // a frame in a different thread is selected, don't change - return; - } - } else { - // a frame is selected and the new selection is not a frame - // do not change the selection - return; - } + AsynchronousTreeViewer viewer = (AsynchronousTreeViewer) getViewer(); + TreePath[] treePaths = viewer.getTreePaths(element); + if (element instanceof IStackFrame) { + IStackFrame frame = (IStackFrame) element; + if (treePaths != null) { + viewer.expand(new TreeSelection(treePaths)); + if (selectNeeded) { + viewer.setSelection(new TreeSelection(treePaths)); + } + } else { + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); + ILaunch launch = frame.getLaunch(); + IDebugTarget debugTarget = frame.getDebugTarget(); + IThread thread = frame.getThread(); + + TreePath treePath = new TreePath(new Object[] {launchManager, launch, debugTarget, thread, frame}); + viewer.expand(new TreeSelection(new TreePath[] {treePath})); + if (selectNeeded) { + viewer.setSelection(new TreeSelection(new TreePath[] {treePath})); } } - launchViewer.deferSelection(new StructuredSelection(element)); } } @@ -1102,4 +1145,5 @@ public class LaunchView extends AbstractDebugEventHandlerView implements ISelect */ public void partInputChanged(IWorkbenchPartReference partRef) { } + } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewEventHandler.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewEventHandler.java index 5fa1102a3..6a4230b05 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewEventHandler.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewEventHandler.java @@ -16,12 +16,13 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; 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.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.ILaunchesListener2; import org.eclipse.debug.core.model.IDebugElement; @@ -30,10 +31,12 @@ import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; +import org.eclipse.debug.internal.ui.viewers.TreePath; +import org.eclipse.debug.internal.ui.viewers.TreeSelection; import org.eclipse.debug.internal.ui.views.AbstractDebugEventHandler; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.ui.progress.WorkbenchJob; /** * Handles debug events, updating the launch view and viewer. @@ -85,16 +88,6 @@ public class LaunchViewEventHandler extends AbstractDebugEventHandler implements return events; } - /** - * Returns the parent for the given element. - * - * @param element - * @return parent - */ - private Object getParent(Object element) { - return ((ITreeContentProvider)getTreeViewer().getContentProvider()).getParent(element); - } - /** * @see AbstractDebugEventHandler#doHandleDebugEvents(DebugEvent[]) */ @@ -107,27 +100,41 @@ public class LaunchViewEventHandler extends AbstractDebugEventHandler implements switch (event.getKind()) { case DebugEvent.CREATE : if (source instanceof IThread) { - insert(source); + IThread thread = (IThread) source; + IDebugTarget target = thread.getDebugTarget(); + refresh(target); } else { - Object parent = getParent(source); - if (parent != null) { - refresh(parent); - } + getViewer().refresh(); if (source instanceof IDebugTarget | source instanceof IProcess) { getLaunchView().autoExpand(source, true); } } break; - case DebugEvent.TERMINATE : + case DebugEvent.TERMINATE: clearSourceSelection(source); - if (source instanceof IThread) { - fThreadTimer.getTimedOutThreads().remove(source); - remove(source); - } else { - Object parent = getParent(source); - if (parent != null) { - refresh(parent); + if (source instanceof IDebugElement) { + IDebugElement element = (IDebugElement) source; + if (source instanceof IThread) { + fThreadTimer.getTimedOutThreads().remove(source); + remove(source); + } else { + IDebugTarget debugTarget = element.getDebugTarget(); + if (debugTarget != null) { + refresh(debugTarget); + } + } + + ILaunch launch = element.getLaunch(); + if (launch.isTerminated()) { + update(launch); } + resetSelection(source, data); + } else if (source instanceof IProcess) { + IProcess process = (IProcess) source; + refresh(process); + update(process.getLaunch()); + } else { + refresh(source); } break; case DebugEvent.RESUME : @@ -141,10 +148,8 @@ public class LaunchViewEventHandler extends AbstractDebugEventHandler implements break; case DebugEvent.CHANGE : Object element = null; - IStructuredSelection selection = getLaunchViewer().getDeferredSelection(); - if (selection == null) { - selection = (IStructuredSelection) getLaunchViewer().getSelection(); - } + AsynchronousTreeViewer viewer = (AsynchronousTreeViewer) getViewer(); + IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); element = selection.getFirstElement(); IStackFrame lastFrame = null; @@ -173,6 +178,12 @@ public class LaunchViewEventHandler extends AbstractDebugEventHandler implements } } + private void update(Object element) { + AsynchronousTreeViewer viewer = (AsynchronousTreeViewer) getLaunchView().getViewer(); + viewer.update(element); + } + + /** * Handles the given resume event with the given source. */ @@ -189,25 +200,36 @@ public class LaunchViewEventHandler extends AbstractDebugEventHandler implements } return; } + fLastStackFrame = null; refresh(source); + resetSelection(source, data); + } + + private void resetSelection(Object source, Object data) { if (source instanceof IThread) { - if (data instanceof IStackFrame) { - selectAndReveal(data); - return; + AsynchronousTreeViewer viewer = (AsynchronousTreeViewer) getViewer(); + TreePath[] treePaths = null; + if (data instanceof IStackFrame) { + treePaths = viewer.getTreePaths(data); + } else { + treePaths = viewer.getTreePaths(source); + } + + if (treePaths != null && treePaths.length > 0) { + viewer.setSelection(new TreeSelection(new TreePath[] { treePaths[0] })); } - selectAndReveal(source); } } - + + /** - * Updates the stack frame icons for a running thread. - * This is useful for the case where a thread is resumed - * temporarily but the view should keep the stack frame - * visible (for example, step start or evaluation start). + * Updates the stack frame icons for a running thread. This is useful for + * the case where a thread is resumed temporarily but the view should keep + * the stack frame visible (for example, step start or evaluation start). */ protected void updateRunningThread(IThread thread) { - labelChanged(thread); - getLaunchViewer().updateStackFrameImages(thread); + labelChanged(thread); +// getLaunchViewer().updateStackFrameImages(thread); clearSourceSelection(thread); } @@ -249,33 +271,26 @@ public class LaunchViewEventHandler extends AbstractDebugEventHandler implements frame = (IStackFrame) data; } - // if the top frame is the same, only update labels and images, and re-select - // the frame to display source - if (frame != null && frame.equals(fLastStackFrame)) { - if (wasTimedOut) { - getLaunchViewer().updateStackFrameImages(thread); - } - getLaunchViewer().update(new Object[] {thread, frame}, null); - if (!evaluationEvent) { - getLaunchViewer().deferExpansion(thread); - getLaunchViewer().deferSelection(new StructuredSelection(frame)); - } else if (wasTimedOut) { - getLaunchView().showEditorForCurrentSelection(); + LaunchView launchView = getLaunchView(); + if (frame != null) { + if (frame.equals(fLastStackFrame) && !wasTimedOut) { + // if the top frame is the same, only update the frame, and re-select + // the frame to display source + refresh(frame); + } else { + refresh(thread); } - return; - } - - if (frame == null) { + fLastStackFrame = frame; + // Auto-expand the thread. Only select the thread if this wasn't + // the end of an evaluation + + launchView.autoExpand(frame, !evaluationEvent); + launchView.openEditorForStackFrame(frame); + } else { // suspend event, but no frames in the thead - fLastStackFrame = null; + fLastStackFrame = null; refresh(thread); - getLaunchView().autoExpand(thread, !evaluationEvent); - } else { - fLastStackFrame = frame; - // Auto-expand the thread. Only select the thread if this wasn't the end - // of an evaluation - refresh(thread); - getLaunchView().autoExpand(frame, !evaluationEvent); + launchView.autoExpand(thread, !evaluationEvent); } } @@ -309,15 +324,6 @@ public class LaunchViewEventHandler extends AbstractDebugEventHandler implements } } - /** - * Returns this event handler's launch viewer - * - * @return launch viewer - */ - protected LaunchViewer getLaunchViewer() { - return (LaunchViewer)getViewer(); - } - /** * Returns this event handler's launch view * @@ -471,13 +477,16 @@ public class LaunchViewEventHandler extends AbstractDebugEventHandler implements // Refresh the UI to show that the thread // is performing a long evaluation final IThread thread= (IThread)entry.getKey(); - fStopTimes.remove(thread); - getView().asyncExec(new Runnable() { - public void run() { + fStopTimes.remove(thread); + WorkbenchJob job = new WorkbenchJob("updateRunningThread") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { fTimedOutThreads.add(thread); updateRunningThread(thread); + return Status.OK_STATUS; } - }); + }; + job.setSystem(true); + job.schedule(); } else { timeToWait= Math.min(timeToWait, stopTime - currentTime); } @@ -518,8 +527,8 @@ public class LaunchViewEventHandler extends AbstractDebugEventHandler implements * @see org.eclipse.debug.core.ILaunchesListener#launchesChanged(org.eclipse.debug.core.ILaunch) */ public void launchesChanged(final ILaunch[] launches) { - Runnable r= new Runnable() { - public void run() { + WorkbenchJob job = new WorkbenchJob("LaunchViewEventHandler.launchesChanged") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { if (isAvailable()) { if (launches.length == 1) { refresh(launches[0]); @@ -532,72 +541,56 @@ public class LaunchViewEventHandler extends AbstractDebugEventHandler implements } } } + return Status.OK_STATUS; } }; - - getView().asyncExec(r); + job.setSystem(true); + job.schedule(); } /** * @see org.eclipse.debug.core.ILaunchesListener#launchesRemoved(org.eclipse.debug.core.ILaunch) */ public void launchesRemoved(final ILaunch[] launches) { - Runnable r= new Runnable() { - public void run() { + WorkbenchJob job = new WorkbenchJob("LaunchViewEventHandler.launchesRemoved") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { if (isAvailable()) { if (launches.length == 1) { - remove(launches[0]); + LaunchViewEventHandler.this.remove(launches[0]); } else { refresh(); } getLaunchView().cleanupLaunches(launches); - // auto select the next suspended thread if no current selection - if (getLaunchViewer().getSelection().isEmpty()) { - // only change selection if the thing removed is of the same type as the things still there - Set types = new HashSet(); - for (int i = 0; i < launches.length; i++) { - ILaunch launch = launches[i]; - ILaunchConfiguration configuration = launch.getLaunchConfiguration(); - if (configuration != null) { - try { - types.add(configuration.getType()); - } catch (CoreException e) { - } - } - } - ILaunchManager lm= DebugPlugin.getDefault().getLaunchManager(); - IDebugTarget[] targets= lm.getDebugTargets(); - if (targets.length > 0) { - IDebugTarget target= targets[targets.length - 1]; - ILaunchConfiguration configuration = target.getLaunch().getLaunchConfiguration(); - if (configuration != null) { - try { - if (types.contains(configuration.getType())) { - IThread[] threads= target.getThreads(); - for (int i=0; i < threads.length; i++) { - if (threads[i].isSuspended()) { - IStackFrame topStackFrame = threads[i].getTopStackFrame(); - if (topStackFrame != null) { - getLaunchView().autoExpand(topStackFrame, true); - } - return; - } - } + ILaunchManager lm= DebugPlugin.getDefault().getLaunchManager(); + IDebugTarget[] targets= lm.getDebugTargets(); + if (targets.length > 0) { + IDebugTarget target= targets[targets.length - 1]; + try { + IThread[] threads= target.getThreads(); + for (int i=0; i < threads.length; i++) { + if (threads[i].isSuspended()) { + IStackFrame topStackFrame = threads[i].getTopStackFrame(); + if (topStackFrame != null) { + getLaunchView().autoExpand(topStackFrame, true); } - } catch (CoreException e) { - DebugUIPlugin.log(e); + return Status.OK_STATUS; } - getLaunchView().autoExpand(target.getLaunch(), true); - } + } + } catch (DebugException de) { + DebugUIPlugin.log(de); } + + getLaunchView().autoExpand(target.getLaunch(), true); } } + return Status.OK_STATUS; } }; - - getView().asyncExec(r); + + job.setSystem(true); + job.schedule(); } @@ -614,12 +607,15 @@ public class LaunchViewEventHandler extends AbstractDebugEventHandler implements } } } - Runnable r= new Runnable() { - public void run() { + WorkbenchJob job = new WorkbenchJob("LaunchViewEventHandler.launchesTerminated") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { getLaunchView().cleanupLaunches(launches); + return Status.OK_STATUS; } + }; - getView().asyncExec(r); + job.setSystem(true); + job.schedule(); } /* (non-Javadoc) diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewer.java index 4ea2fcdc4..cf1c52e9b 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewer.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewer.java @@ -1,83 +1,190 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.views.launch; +import java.util.ArrayList; +import java.util.List; -import org.eclipse.debug.core.model.IThread; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.debug.core.model.IStackFrame; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; +import org.eclipse.debug.internal.ui.viewers.IAsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.swt.widgets.Widget; - -/** - * The launch viewer displays a tree of launches. - */ -public class LaunchViewer extends RemoteTreeViewer { - /** - * Overridden to fix bug 39709 - duplicate items in launch viewer. The - * workaround is required since debug creation events (which result in - * additions to the tree) are processed asynchrnously with the expanding - * of a launch/debug target in the tree. - * - * @see org.eclipse.jface.viewers.AbstractTreeViewer#add(java.lang.Object, java.lang.Object) - */ - public synchronized void add(Object parentElement, Object childElement) { - if (findItem(childElement) == null) { - super.add(parentElement, childElement); - } +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; +import org.eclipse.ui.progress.IElementCollector; +import org.osgi.framework.Bundle; + +public class LaunchViewer extends AsynchronousTreeViewer { + + public LaunchViewer(Composite parent) { + super(parent); } - public LaunchViewer(Composite parent) { - super(new Tree(parent, SWT.MULTI)); - setUseHashlookup(true); + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.treeviewer.AsynchronousTreeViewer#getTreeContentAdapter(java.lang.Object) + */ + protected IAsynchronousTreeContentAdapter getTreeContentAdapter(Object element) { + AsynchronousTreeContentAdapter legacyAdapter = getLegacyAdapter(element); + if (legacyAdapter != null) { + return legacyAdapter; + } + + IAsynchronousTreeContentAdapter presentationAdapter = super.getTreeContentAdapter(element); + if (presentationAdapter != null) { + return presentationAdapter; + } + + return new BogusTreeAdapter(); } - + /** - * Update the images for all stack frame children of the given thread. + * Returns a wrapper to the legacy workbench adapter if supported by the given object. * - * @param parentThread the thread whose frames should be updated - */ - protected void updateStackFrameImages(IThread parentThread) { - Widget parentItem= findItem(parentThread); - if (parentItem != null) { - Item[] items= getItems((Item)parentItem); - for (int i = 0; i < items.length; i++) { - updateTreeItemImage((TreeItem)items[i]); + * @param element + * @return + */ + private AsynchronousTreeContentAdapter getLegacyAdapter(Object element) { + if (element instanceof IDeferredWorkbenchAdapter) { + return new WrappedDeferredWorkbenchTreeAdapter((IDeferredWorkbenchAdapter) element, element); + } + + if (!(element instanceof IAdaptable)) { + return null; + } + + IAdaptable adaptable = (IAdaptable) element; + IDeferredWorkbenchAdapter deferred = (IDeferredWorkbenchAdapter) adaptable.getAdapter(IDeferredWorkbenchAdapter.class); + if (deferred != null) { + DebugUIPlugin plugin = DebugUIPlugin.getDefault(); + Bundle bundle = plugin.getBundle(deferred.getClass()); + Bundle debugBundle = plugin.getBundle(); + if (!debugBundle.equals(bundle)) { + // if client contributed, use it + return new WrappedDeferredWorkbenchTreeAdapter(deferred, element); } } + // if the client provided an IWorkbenchAdapter, use it + IWorkbenchAdapter nonDeferred = (IWorkbenchAdapter) adaptable.getAdapter(IWorkbenchAdapter.class); + if (nonDeferred != null) { + DebugUIPlugin plugin = DebugUIPlugin.getDefault(); + Bundle bundle = plugin.getBundle(nonDeferred.getClass()); + Bundle debugBundle = plugin.getBundle(); + bundle = plugin.getBundle(nonDeferred.getClass()); + if (!debugBundle.equals(bundle)) { + return new WrappedWorkbenchTreeAdapter(nonDeferred); + } + } + return null; } - - /** - * Updates the image of the given tree item. - * - * @param treeItem the item - */ - protected void updateTreeItemImage(TreeItem treeItem) { - ILabelProvider provider = (ILabelProvider) getLabelProvider(); - Image image = provider.getImage(treeItem.getData()); - if (image != null) { - treeItem.setImage(image); - } + + private class ElementCollector implements IElementCollector { + List children = new ArrayList(); + + public void add(Object element, IProgressMonitor monitor) { + children.add(element); + } + + public void add(Object[] elements, IProgressMonitor monitor) { + for (int i = 0; i < elements.length; i++) { + children.add(elements[i]); + } + } + + public void done() { + } + + public Object[] getChildren() { + return children.toArray(); + } + + } + + private class WrappedDeferredWorkbenchTreeAdapter extends AsynchronousTreeContentAdapter { + private IDeferredWorkbenchAdapter fAdapter; + + private Object fElement; + + public WrappedDeferredWorkbenchTreeAdapter(IDeferredWorkbenchAdapter adapter, Object element) { + fAdapter = adapter; + fElement = element; + } + + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + ElementCollector elementCollector = new ElementCollector(); + fAdapter.fetchDeferredChildren(fElement, elementCollector, new NullProgressMonitor()); + return elementCollector.getChildren(); + } + + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + if (element instanceof IStackFrame) { + return false; + } + return fAdapter.isContainer(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#supportsPartId(java.lang.String) + */ + protected boolean supportsPartId(String id) { + return IDebugUIConstants.ID_DEBUG_VIEW.equals(id); + } + } + + private class WrappedWorkbenchTreeAdapter extends AsynchronousTreeContentAdapter { + private IWorkbenchAdapter fAdapter; + + public WrappedWorkbenchTreeAdapter(IWorkbenchAdapter adapter) { + fAdapter = adapter; + } + + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + return fAdapter.getChildren(parent); + } + + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + if (element instanceof IStackFrame) { + return false; + } + return fAdapter.getChildren(element).length > 0; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#supportsPartId(java.lang.String) + */ + protected boolean supportsPartId(String id) { + return IDebugUIConstants.ID_DEBUG_VIEW.equals(id); + } + } + private class BogusTreeAdapter extends AsynchronousTreeContentAdapter { + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + return new Object[0]; + } + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + return false; + } + /* (non-Javadoc) + * @see org.eclipse.debug.ui.viewers.AsynchronousTreeContentAdapter#supportsPartId(java.lang.String) + */ + protected boolean supportsPartId(String id) { + return false; + } + } + /* (non-Javadoc) - * @see org.eclipse.jface.viewers.StructuredViewer#refresh(java.lang.Object) + * @see org.eclipse.debug.ui.viewers.AsynchronousViewer#isSuppressEqualSelections() */ - public void refresh(Object element) { - super.refresh(element); + protected boolean isSuppressEqualSelections() { + // fire activation changes all the time + return false; } - + + } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/DeferredRegisterViewStackFrame.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/DeferredRegisterViewStackFrame.java deleted file mode 100644 index 2ca1bca42..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/DeferredRegisterViewStackFrame.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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.internal.ui.views.registers; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IRegisterGroup; -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredStackFrame; - -public class DeferredRegisterViewStackFrame extends DeferredStackFrame { - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object parent) { - try { - return ((IStackFrame)parent).getRegisterGroups(); - } catch (DebugException e) { - } - return EMPTY; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.elements.adapters.DeferredStackFrame#hasChildren(java.lang.Object) - */ - protected boolean hasChildren(Object child) { - IRegisterGroup group = (IRegisterGroup) child; - try { - return group.hasRegisters(); - } catch (DebugException e) { - } - return false; - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RegistersView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RegistersView.java index e11673e54..ad3cc2e4b 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RegistersView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RegistersView.java @@ -12,31 +12,17 @@ package org.eclipse.debug.internal.ui.views.registers; import org.eclipse.debug.internal.ui.IDebugHelpContextIds; import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; -import org.eclipse.debug.internal.ui.views.AbstractViewerState; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; -import org.eclipse.debug.internal.ui.views.variables.RemoteVariablesContentProvider; import org.eclipse.debug.internal.ui.views.variables.VariablesView; import org.eclipse.debug.internal.ui.views.variables.VariablesViewEventHandler; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.Viewer; /** * Displays registers and their values with a detail area. */ public class RegistersView extends VariablesView { - /** - * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#createContentProvider() - */ - protected RemoteVariablesContentProvider createContentProvider(Viewer viewer) { - RemoteRegistersViewContentProvider cp = new RemoteRegistersViewContentProvider((RemoteTreeViewer) viewer, getSite(), this); -// TODO -// cp.setExceptionHandler(this); - return cp; - } - /** * @see org.eclipse.debug.ui.AbstractDebugView#getHelpContextId() */ @@ -67,12 +53,7 @@ public class RegistersView extends VariablesView { return RegistersViewMessages.RegistersView_0; } - /** - * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#getViewerState() - */ - protected AbstractViewerState getViewerState() { - return new RegistersViewerState(getVariablesViewer()); - } + /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#createEventHandler() diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RegistersViewerState.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RegistersViewerState.java deleted file mode 100644 index df647236c..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RegistersViewerState.java +++ /dev/null @@ -1,121 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004, 2005 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation -***********************************************************************/ -package org.eclipse.debug.internal.ui.views.registers; - -import java.util.ArrayList; -import java.util.Iterator; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IRegisterGroup; -import org.eclipse.debug.core.model.IVariable; -import org.eclipse.debug.internal.ui.views.AbstractViewerState; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.widgets.TreeItem; - -/** - * Memento of the expanded and selected items in a registers viewer. - * - */ -public class RegistersViewerState extends AbstractViewerState { - - public RegistersViewerState( TreeViewer viewer ) { - super( viewer ); - } - - public RegistersViewerState() { - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.ui.views.AbstractViewerState#encodeElement(org.eclipse.swt.widgets.TreeItem) - */ - public IPath encodeElement( TreeItem item ) throws DebugException { - Object obj = item.getData(); - String name = ( obj instanceof IRegisterGroup ) ? - ((IRegisterGroup)obj).getName() : ((IVariable)obj).getName(); - IPath path = new Path( name ); - TreeItem parent = item.getParentItem(); - while( parent != null ) { - obj = parent.getData(); - name = ( obj instanceof IRegisterGroup ) ? - ((IRegisterGroup)obj).getName() : ((IVariable)obj).getName(); - path = new Path( name ).append( path ); - parent = parent.getParentItem(); - } - return path; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.ui.views.AbstractViewerState#decodePath(org.eclipse.core.runtime.IPath, org.eclipse.jface.viewers.TreeViewer) - */ - public Object decodePath( IPath path, TreeViewer viewer ) throws DebugException { - ITreeContentProvider contentProvider = (ITreeContentProvider)viewer.getContentProvider(); - String[] names = path.segments(); - Object parent = viewer.getInput(); - Object element = null; - for( int i = 0; i < names.length; i++ ) { - element = null; - Object[] children = null; - if (viewer instanceof RemoteTreeViewer) { - children = ((RemoteTreeViewer) viewer).getCurrentChildren(parent); - } else { - children = contentProvider.getChildren(parent); - } - - if (children == null) - return null; - - String name = names[i]; - for( int j = 0; j < children.length; j++ ) { - if ( children[j] instanceof IRegisterGroup ) { - if ( name.equals( ((IRegisterGroup)children[j]).getName() ) ) { - element = children[j]; - break; - } - } - else if ( children[j] instanceof IVariable ) { - if ( name.equals( ((IVariable)children[j]).getName() ) ) { - element = children[j]; - break; - } - } - } - if ( element == null ) { - return null; - } - parent = element; - } - return element; - } - - public AbstractViewerState copy() { - RegistersViewerState copy = new RegistersViewerState(); - if (fSavedExpansion != null) { - copy.fSavedExpansion = new ArrayList(); - for (Iterator iter = fSavedExpansion.iterator(); iter.hasNext();) { - copy.fSavedExpansion.add(iter.next()); - } - } - - if (fSelection != null) { - copy.fSelection = new IPath[fSelection.length]; - for (int i = 0; i < fSelection.length; i++) { - IPath sel = fSelection[i]; - copy.fSelection[i] = sel; - } - } - return copy; - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RemoteRegisterContentManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RemoteRegisterContentManager.java deleted file mode 100644 index 83b3e51f5..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RemoteRegisterContentManager.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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.internal.ui.views.registers; - -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; -import org.eclipse.debug.internal.ui.views.variables.RemoteVariableContentManager; -import org.eclipse.debug.internal.ui.views.variables.VariablesView; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; - -public class RemoteRegisterContentManager extends RemoteVariableContentManager { - public RemoteRegisterContentManager(ITreeContentProvider provider, RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) { - super(provider, viewer, site, view); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.views.variables.RemoteVariableContentManager#getAdapter(java.lang.Object) - */ - protected IDeferredWorkbenchAdapter getAdapter(Object element) { - if (element instanceof IStackFrame) { - return new DeferredRegisterViewStackFrame(); - } - return super.getAdapter(element); - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RemoteRegistersViewContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RemoteRegistersViewContentProvider.java deleted file mode 100644 index ece2bd513..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/registers/RemoteRegistersViewContentProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004, 2005 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation -***********************************************************************/ -package org.eclipse.debug.internal.ui.views.registers; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IRegisterGroup; -import org.eclipse.debug.core.model.IStackFrame; -import org.eclipse.debug.internal.ui.DebugUIPlugin; -import org.eclipse.debug.internal.ui.views.RemoteTreeContentManager; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; -import org.eclipse.debug.internal.ui.views.variables.RemoteVariablesContentProvider; -import org.eclipse.debug.internal.ui.views.variables.VariablesView; -import org.eclipse.ui.IWorkbenchPartSite; - -/** - * Provides contents for the registers view - */ -public class RemoteRegistersViewContentProvider extends RemoteVariablesContentProvider { - - public RemoteRegistersViewContentProvider(RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) { - super(viewer, site, view); - } - - /** - * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) - */ - public boolean hasChildren(Object element) { - try { - if (element instanceof IStackFrame) { - return ((IStackFrame)element).hasRegisterGroups(); - } - if (element instanceof IRegisterGroup) { - return ((IRegisterGroup)element).hasRegisters(); - } - } catch (DebugException de) { - DebugUIPlugin.log(de); - return false; - } - return super.hasChildren(element); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.views.variables.RemoteVariablesContentProvider#createContentManager(org.eclipse.debug.internal.ui.views.RemoteTreeViewer, org.eclipse.ui.IWorkbenchPartSite, org.eclipse.debug.internal.ui.views.variables.VariablesView) - */ - protected RemoteTreeContentManager createContentManager(RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) { - return new RemoteRegisterContentManager(this, viewer, site, view); - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/AvailableLogicalStructuresAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/AvailableLogicalStructuresAction.java index 704b9b795..62644e211 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/AvailableLogicalStructuresAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/AvailableLogicalStructuresAction.java @@ -123,7 +123,7 @@ public class AvailableLogicalStructuresAction extends Action implements IMenuCre setValue(null); setTypes(null); if (getView().isShowLogicalStructure()) { - ISelection s = getView().getVariablesViewer().getSelection(); + ISelection s = getView().getViewer().getSelection(); if (s instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) s; if (selection.size() == 1) { diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/RemoteVariableContentManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/RemoteVariableContentManager.java deleted file mode 100644 index 358cddd8c..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/RemoteVariableContentManager.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.views.variables; - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.debug.core.model.IVariable; -import org.eclipse.debug.internal.ui.elements.adapters.DeferredVariableLogicalStructure; -import org.eclipse.debug.internal.ui.views.RemoteTreeContentManager; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.internal.progress.PendingUpdateAdapter; -import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; -import org.eclipse.ui.progress.IElementCollector; - -/** - * Remote content manager for variables. Creates an appropriate adapter for - * logical structures. - */ -public class RemoteVariableContentManager extends RemoteTreeContentManager { - - protected VariablesView fView; - private IDeferredWorkbenchAdapter fVariableLogicalStructureAdapter = new DeferredVariableLogicalStructure(); - - private Set fHasChildren = new HashSet(); - private Set fNoChildren = new HashSet(); - - /** - * Special collector to also collect accurate "has children" information. - */ - public class VariableCollector extends RemoteTreeContentManager.Collector { - - public VariableCollector(Object parent) { - super(parent); - } - - /** - * Notification the given element has children - * - * @param element - */ - public void setHasChildren(Object element, boolean children) { - synchronized (fHasChildren) { - if (children) { - fHasChildren.add(element); - fNoChildren.remove(element); - } else { - fNoChildren.add(element); - fHasChildren.remove(element); - } - } - } - - } - - /** - * Constructs a remote content manager for a variables view. - */ - public RemoteVariableContentManager(ITreeContentProvider provider, RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) { - super(provider, viewer, site); - fView = view; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.DeferredTreeContentManager#getAdapter(java.lang.Object) - */ - protected IDeferredWorkbenchAdapter getAdapter(Object element) { - if (element instanceof IVariable && fView !=null && fView.isShowLogicalStructure()) { - return fVariableLogicalStructureAdapter; - } - return super.getAdapter(element); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.DeferredTreeContentManager#createElementCollector(java.lang.Object, org.eclipse.ui.internal.progress.PendingUpdateAdapter) - */ - protected IElementCollector createElementCollector(Object parent, PendingUpdateAdapter placeholder) { - return new VariableCollector(parent); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.progress.DeferredTreeContentManager#mayHaveChildren(java.lang.Object) - */ - public boolean mayHaveChildren(Object element) { - synchronized (fHasChildren) { - if (fHasChildren.contains(element)) { - return true; - } else if (fNoChildren.contains(element)) { - return false; - } - } - return super.mayHaveChildren(element); - } - - /** - * Called to clear the "has children" state cache when the view input changes. - */ - public void clearHasChildrenCache() { - synchronized (fHasChildren) { - fHasChildren.clear(); - fNoChildren.clear(); - } - } -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/RemoteVariablesContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/RemoteVariablesContentProvider.java deleted file mode 100644 index 03fa80ca5..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/RemoteVariablesContentProvider.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.views.variables; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.debug.internal.ui.views.IDebugExceptionHandler; -import org.eclipse.debug.internal.ui.views.RemoteTreeContentManager; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.model.BaseWorkbenchContentProvider; - -/** - * Provide the contents for a variables viewer. - */ -public class RemoteVariablesContentProvider extends BaseWorkbenchContentProvider { - - /** - * A table that maps children to their parent element - * such that this content provider can walk back up the - * parent chain (since values do not know their - * parent). - * Map of IVariable (child) -> IVariable (parent). - */ - private HashMap fParentCache; - - /** - * Handler for exceptions as content is retrieved - */ - private IDebugExceptionHandler fExceptionHandler = null; - - /** - * Flag indicating whether contributed content providers should be used or not. - */ - private boolean fUseObjectBrowsers; - - /** - * Remote content manager to retrieve content in the background. - */ - private RemoteVariableContentManager fManager; - - /** - * Constructs a new provider - */ - public RemoteVariablesContentProvider(RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) { - fManager = (RemoteVariableContentManager)createContentManager(viewer, site, view); - fParentCache = new HashMap(10); - } - - protected RemoteTreeContentManager createContentManager(RemoteTreeViewer viewer, IWorkbenchPartSite site, VariablesView view) { - return new RemoteVariableContentManager(this, viewer, site, view); - } - - /** - * @see ITreeContentProvider#getChildren(Object) - */ - public Object[] getChildren(Object parent) { - Object[] children = fManager.getChildren(parent); - if (children == null) { - children = super.getChildren(parent); - } - if (children != null) { - cache(parent, children); - return children; - } - return new Object[0]; - } - - /** - * Caches the given elememts as children of the given - * parent. - * - * @param parent parent element - * @param children children elements - */ - protected void cache(Object parent, Object[] children) { - for (int i = 0; i < children.length; i++) { - Object child = children[i]; - // avoid cycles in the cache, which can happen for - // recursive data structures - if (!fParentCache.containsKey(child)) { - fParentCache.put(child, parent); - } - } - } - - /** - * @see ITreeContentProvider#getParent(Object) - */ - public Object getParent(Object item) { - return fParentCache.get(item); - } - - /** - * Unregisters this content provider from the debug plugin so that - * this object can be garbage-collected. - */ - public void dispose() { - fManager.clearHasChildrenCache(); - fManager.cancel(); - fParentCache= null; - setExceptionHandler(null); - } - - protected void clearCache() { - if (fParentCache != null) { - fParentCache.clear(); - } - } - - /** - * Remove the cached parent for the given children - * - * @param children for which to remove cached parents - */ - public void removeCache(Object[] children) { - if (fParentCache == null) { - return; - } - for (int i = 0; i < children.length; i++) { - fParentCache.remove(children[i]); - } - } - - /** - * @see ITreeContentProvider#hasChildren(Object) - */ - public boolean hasChildren(Object element) { - return fManager.mayHaveChildren(element); - } - - /** - * @see IContentProvider#inputChanged(Viewer, Object, Object) - */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - clearCache(); - fManager.cancel(); - fManager.clearHasChildrenCache(); - } - - /** - * Return all cached decendants of the given parent. - * - * @param parent the element whose decendants are to be calculated - * @return list of decendants that have been cached for - * the given parent - */ - public List getCachedDecendants(Object parent) { - Iterator children = fParentCache.keySet().iterator(); - List cachedChildren = new ArrayList(10); - while (children.hasNext()) { - Object child = children.next(); - if (isCachedDecendant(child, parent)) { - cachedChildren.add(child); - } - } - return cachedChildren; - } - - /** - * Returns whether the given child is a cached descendant - * of the given parent. - * - * @return whether the given child is a cached descendant - * of the given parent - */ - protected boolean isCachedDecendant(Object child, Object parent) { - Object p = getParent(child); - while (p != null) { - if (p.equals(parent)) { - return true; - } - p = getParent(p); - } - return false; - } - - /** - * Sets an exception handler for this content provider. - * - * @param handler debug exception handler or null - */ - protected void setExceptionHandler(IDebugExceptionHandler handler) { - fExceptionHandler = handler; - } - - /** - * Returns the exception handler for this content provider. - * - * @return debug exception handler or null - */ - protected IDebugExceptionHandler getExceptionHandler() { - return fExceptionHandler; - } - - /** - * Show logical structure of values - */ - public void setShowLogicalStructure(boolean flag) { - fUseObjectBrowsers = flag; - } - - public boolean isShowLogicalStructure() { - return fUseObjectBrowsers; - } - - public RemoteVariableContentManager getContentManager() { - return fManager; - } - -} - diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java index 7d77097e6..7f7f8c022 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java @@ -25,6 +25,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IDebugElement; import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IExpression; import org.eclipse.debug.core.model.IStackFrame; @@ -41,21 +42,20 @@ import org.eclipse.debug.internal.ui.VariablesViewModelPresentation; import org.eclipse.debug.internal.ui.actions.AssignValueAction; import org.eclipse.debug.internal.ui.actions.ChangeVariableValueAction; import org.eclipse.debug.internal.ui.actions.CollapseAllAction; -import org.eclipse.debug.internal.ui.actions.FindVariableAction; import org.eclipse.debug.internal.ui.actions.ShowTypesAction; import org.eclipse.debug.internal.ui.actions.ToggleDetailPaneAction; +import org.eclipse.debug.internal.ui.contexts.DebugContextManager; +import org.eclipse.debug.internal.ui.contexts.actions.FindVariableAction; import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; +import org.eclipse.debug.internal.ui.viewers.PresentationContext; import org.eclipse.debug.internal.ui.views.AbstractDebugEventHandlerView; import org.eclipse.debug.internal.ui.views.AbstractViewerState; -import org.eclipse.debug.internal.ui.views.DebugViewDecoratingLabelProvider; -import org.eclipse.debug.internal.ui.views.DebugViewInterimLabelProvider; -import org.eclipse.debug.internal.ui.views.DebugViewLabelDecorator; import org.eclipse.debug.internal.ui.views.IDebugExceptionHandler; -import org.eclipse.debug.internal.ui.views.IRemoteTreeViewerUpdateListener; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; import org.eclipse.debug.ui.IDebugModelPresentation; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.IValueDetailListener; +import org.eclipse.debug.ui.contexts.IDebugContextListener; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuListener; @@ -82,16 +82,12 @@ import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.ListenerList; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; @@ -102,22 +98,19 @@ import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Menu; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IMemento; -import org.eclipse.ui.INullSelectionListener; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.IViewPart; import org.eclipse.ui.IViewSite; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.PartInitException; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.console.actions.TextViewerAction; +import org.eclipse.ui.progress.WorkbenchJob; import org.eclipse.ui.texteditor.FindReplaceAction; import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.IUpdate; @@ -126,37 +119,11 @@ import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; /** * This view shows variables and their values for a particular stack frame */ -public class VariablesView extends AbstractDebugEventHandlerView implements ISelectionListener, +public class VariablesView extends AbstractDebugEventHandlerView implements IDebugContextListener, IPropertyChangeListener, IValueDetailListener, - IDebugExceptionHandler, - INullSelectionListener { + IDebugExceptionHandler { - /** - * A decorating label provider which adds coloring to variables to - * reflect their changed state - */ - protected class VariablesViewDecoratingLabelProvider extends DebugViewDecoratingLabelProvider { - - public VariablesViewDecoratingLabelProvider(StructuredViewer viewer, ILabelProvider provider, DebugViewLabelDecorator decorator) { - super(viewer, provider, decorator); - } - - public Color getForeground(Object element) { - if (element instanceof IVariable) { - IVariable variable = (IVariable) element; - try { - if (variable.hasValueChanged()) { - return DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CHANGED_VARIABLE_COLOR); - } - } catch (DebugException e) { - DebugUIPlugin.log(e); - } - } - return super.getForeground(element); - } - - } /** * Internal interface for a cursor listener. I.e. aggregation @@ -347,7 +314,6 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel /** Whether logical structuers are showing */ private boolean fShowLogical; - private IRemoteTreeViewerUpdateListener fUpdateListener; /** * Remove myself as a selection listener @@ -357,13 +323,17 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel */ public void dispose() { getViewSite().getActionBars().getStatusLineManager().remove(fStatusLineItem); - getSite().getPage().removeSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); + DebugContextManager.getDefault().removeDebugContextListener(this, getSite().getWorkbenchWindow()); + //getSite().getPage().removeSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); DebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); JFaceResources.getFontRegistry().removeListener(this); Viewer viewer = getViewer(); if (viewer != null) { getDetailDocument().removeDocumentListener(getDetailDocumentListener()); - ((VariablesViewer)viewer).removeUpdateListener(fUpdateListener); + if (viewer instanceof AsynchronousTreeViewer) { + AsynchronousTreeViewer asyncTreeViewer = (AsynchronousTreeViewer) viewer; + asyncTreeViewer.dispose(); + } } IAction action= getAction("FindVariable"); //$NON-NLS-1$ if (action != null && action instanceof FindVariableAction) { @@ -372,49 +342,42 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel super.dispose(); } - protected void setViewerInput(IStructuredSelection ssel) { - IStackFrame frame= null; - if (ssel.size() == 1) { - Object input= ssel.getFirstElement(); - if (input instanceof IStackFrame) { - frame= (IStackFrame)input; - } - } + protected void setViewerInput(Object context) { - getDetailViewer().setEditable(frame != null); + getDetailViewer().setEditable(context != null); Object current= getViewer().getInput(); - if (current == null && frame == null) { + if (current == null && context == null) { return; } - if (current != null && current.equals(frame)) { + if (current != null && current.equals(context)) { return; } - + if (current != null) { // save state fLastState = getViewerState(); fSelectionStates.put(current, fLastState); } - if (frame != null) { - setDebugModel(frame.getModelIdentifier()); + if (context instanceof IDebugElement) { + setDebugModel(((IDebugElement)context).getModelIdentifier()); } showViewer(); - getViewer().setInput(frame); + getViewer().setInput(context); + restoreState(); } protected void restoreState() { - VariablesViewer viewer = getVariablesViewer(); - IStackFrame frame = (IStackFrame) viewer.getInput(); - if (frame != null) { - AbstractViewerState state = (AbstractViewerState)fSelectionStates.get(frame); - if (state == null && fLastState != null) { + VariablesViewer viewer = (VariablesViewer) getViewer(); + Object context= viewer.getInput(); + if (context != null) { + AbstractViewerState state = (AbstractViewerState)fSelectionStates.get(context); + if (state == null) { // attempt to restore selection/expansion based on last frame - state = fLastState.copy(); - fLastState = state; + state = fLastState; } if (state != null) { state.restoreState(viewer); @@ -422,16 +385,12 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel } } - /** - * Returns the variables viewer for this view - */ - protected VariablesViewer getVariablesViewer() { - return (VariablesViewer)getViewer(); - } /** * Clears expanded state for stack frames which are * a child of the given thread or debug target. + * + * TODO: this was called by event handler which no longer exists */ protected void clearExpandedVariables(Object parent) { List list = null; @@ -504,7 +463,7 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel try { svc = mp.newDetailsViewerConfiguration(); } catch (CoreException e) { - DebugUIPlugin.errorDialog(getSite().getShell(), VariablesViewMessages.VariablesView_Error_1, VariablesViewMessages.VariablesView_Unable_to_configure_variable_details_area__2, e); // + DebugUIPlugin.errorDialog(getSite().getShell(), VariablesViewMessages.VariablesView_Error_1, VariablesViewMessages.VariablesView_Unable_to_configure_variable_details_area__2, e); } } ISourceViewer detailViewer = getDetailViewer(); @@ -531,7 +490,7 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel getEventHandler().refresh(); } else if (propertyName.equals(IInternalDebugUIConstants.DETAIL_PANE_FONT)) { getDetailViewer().getTextWidget().setFont(JFaceResources.getFont(IInternalDebugUIConstants.DETAIL_PANE_FONT)); - } else if (propertyName.equals(IDebugUIConstants.PREF_MAX_DETAIL_LENGTH)) { + } else if (propertyName.equals(IInternalDebugUIConstants.PREF_MAX_DETAIL_LENGTH)) { populateDetailPane(); } } @@ -540,7 +499,9 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel * @see org.eclipse.debug.ui.AbstractDebugView#createViewer(Composite) */ public Viewer createViewer(Composite parent) { - TreeViewer variablesViewer = createTreeViewer(parent); + VariablesViewer variablesViewer = (VariablesViewer) createTreeViewer(parent); + variablesViewer.setContext(new PresentationContext(this)); + createDetailsViewer(); getSashForm().setMaximizedControl(variablesViewer.getControl()); @@ -552,12 +513,6 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel } setDetailPaneOrientation(orientation); - fUpdateListener = new IRemoteTreeViewerUpdateListener() { - public void treeUpdated() { - restoreState(); - } - }; - ((VariablesViewer)variablesViewer).addUpdateListener(fUpdateListener); return variablesViewer; } @@ -608,19 +563,16 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel /** * Create and return the main tree viewer that displays variable. */ - protected TreeViewer createTreeViewer(Composite parent) { + protected Viewer createTreeViewer(Composite parent) { fModelPresentation = new VariablesViewModelPresentation(); DebugUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); JFaceResources.getFontRegistry().addListener(this); // create the sash form that will contain the tree viewer & text viewer setSashForm(new SashForm(parent, SWT.NONE)); - + // add tree viewer - final TreeViewer variablesViewer = new VariablesViewer(getSashForm(), SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, this); - RemoteVariablesContentProvider provider = createContentProvider(variablesViewer); - variablesViewer.setContentProvider(provider); - variablesViewer.setLabelProvider(createLabelProvider(variablesViewer)); - variablesViewer.setUseHashlookup(true); + final VariablesViewer variablesViewer = new VariablesViewer(getSashForm(), SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, this); + variablesViewer.setUseHashlookup(false); variablesViewer.getControl().addFocusListener(new FocusAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.FocusListener#focusGained(FocusEvent) @@ -630,31 +582,25 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel setAction(SELECT_ALL_ACTION, getAction(VARIABLES_SELECT_ALL_ACTION)); setAction(COPY_ACTION, getAction(VARIABLES_COPY_ACTION)); getViewSite().getActionBars().updateActionBars(); - setFocusViewer(getVariablesViewer()); + setFocusViewer(getViewer()); } }); variablesViewer.addPostSelectionChangedListener(getTreeSelectionChangedListener()); getVariablesViewSelectionProvider().setUnderlyingSelectionProvider(variablesViewer); getSite().setSelectionProvider(getVariablesViewSelectionProvider()); - // listen to selection in debug view - getSite().getPage().addSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); + // listen to debug context + DebugContextManager.getDefault().addDebugContextListener(this, getSite().getWorkbenchWindow()); + // getSite().getPage().addSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); VariablesViewEventHandler handler = createEventHandler(); - handler.setContentManager(provider.getContentManager()); - setEventHandler(handler); + // TODO: replaced with update policy + if (handler != null) { + setEventHandler(handler); + } return variablesViewer; } - /** - * Creates and returns a label provider for this view. - * - * @return a label provider for this view. - */ - protected IBaseLabelProvider createLabelProvider(StructuredViewer viewer) { - return new VariablesViewDecoratingLabelProvider(viewer, new DebugViewInterimLabelProvider(getModelPresentation()), new DebugViewLabelDecorator(getModelPresentation())); - } - /** * Create the widgetry for the details viewer. */ @@ -681,18 +627,7 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel setAction(COPY_ACTION, getAction(DETAIL_COPY_ACTION)); getViewSite().getActionBars().updateActionBars(); setFocusViewer((Viewer)getDetailViewer()); - IAction assist = getAction("ContentAssist"); //$NON-NLS-1$ - getSite().getKeyBindingService().registerAction(assist); } - - /* (non-Javadoc) - * @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent) - */ - public void focusLost(FocusEvent e) { - IAction assist = getAction("ContentAssist"); //$NON-NLS-1$ - getSite().getKeyBindingService().unregisterAction(assist); - } - }); // add a context menu to the detail area @@ -702,14 +637,6 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel detailsViewer.getTextWidget().addKeyListener(getCursorListener()); } - /** - * Creates this view's content provider. - * - * @return a content provider - */ - protected RemoteVariablesContentProvider createContentProvider(Viewer viewer) { - return new RemoteVariablesContentProvider((RemoteTreeViewer) viewer, getSite(), this); - } /** * Creates this view's event handler. @@ -717,7 +644,8 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel * @return an event handler */ protected VariablesViewEventHandler createEventHandler() { - return new VariablesViewEventHandler(this); + // TODO: replaced by update policy + return null; } /* (non-Javadoc) @@ -769,7 +697,7 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel * Make sure the currently selected item in the tree is visible. */ protected void revealTreeSelection() { - VariablesViewer viewer = getVariablesViewer(); + StructuredViewer viewer = (StructuredViewer) getViewer(); if (viewer != null) { ISelection selection = viewer.getSelection(); if (selection instanceof IStructuredSelection) { @@ -840,7 +768,7 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel action = new ToggleLogicalStructureAction(this); setAction("ToggleContentProviders", action); //$NON-NLS-1$ - action = new CollapseAllAction(getVariablesViewer()); + action = new CollapseAllAction((AsynchronousTreeViewer)getViewer()); setAction("CollapseAll", action); //$NON-NLS-1$ action = new ChangeVariableValueAction(this); @@ -854,6 +782,7 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel textAction.setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_CONTENT_ASSIST)); textAction.setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_DLCL_CONTENT_ASSIST)); setAction("ContentAssist", textAction); //$NON-NLS-1$ + getSite().getKeyBindingService().registerAction(textAction); textAction= new TextViewerAction(getDetailViewer(), ITextOperationTarget.SELECT_ALL); textAction.configureAction(VariablesViewMessages.VariablesView_Select__All_5, "", ""); //$NON-NLS-1$ //$NON-NLS-2$ @@ -861,7 +790,7 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel setAction(DETAIL_SELECT_ALL_ACTION, textAction); textAction= new TextViewerAction(getDetailViewer(), ITextOperationTarget.COPY); - textAction.configureAction(VariablesViewMessages.VariablesView__Copy_8, "", ""); //$NON-NLS-1$ //$NON-NLS-2$ + textAction.configureAction(VariablesViewMessages.VariablesView__Copy_8, "", ""); //$NON-NLS-1$ //$NON-NLS-2$ textAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.COPY); setAction(DETAIL_COPY_ACTION, textAction); @@ -993,7 +922,7 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel if (fTreeSelectionChangedListener == null) { fTreeSelectionChangedListener = new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { - if (event.getSelectionProvider().equals(getVariablesViewer())) { + if (event.getSelectionProvider().equals(getViewer())) { clearStatusLine(); getVariablesViewSelectionProvider().fireSelectionChanged(event); // if the detail pane is not visible, don't waste time retrieving details @@ -1053,12 +982,15 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel * detail pane. */ protected void populateDetailPaneFromSelection(final IStructuredSelection selection) { - Runnable runnable = new Runnable() { - public void run() { + WorkbenchJob wJob = new WorkbenchJob("Populate Details Pane") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { getDetailDocument().set(""); //$NON-NLS-1$ - } + return Status.OK_STATUS; + } }; - DebugUIPlugin.getStandardDisplay().asyncExec(runnable); + wJob.setSystem(true); + wJob.schedule(); + try { if (!selection.isEmpty()) { IValue val = null; @@ -1082,8 +1014,9 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel } final IValue finalVal = val; - runnable = new Runnable() { - public void run() { + + wJob = new WorkbenchJob("Populate Details Pane"){ //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { getDetailDocument().set(""); //$NON-NLS-1$ setDebugModel(finalVal.getModelIdentifier()); fValueSelection = selection; @@ -1091,16 +1024,22 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel fSelectionIterator.next(); fLastValueDetail= finalVal; getModelPresentation().computeDetail(finalVal, VariablesView.this); - } - }; - DebugUIPlugin.getStandardDisplay().asyncExec(runnable); + return Status.OK_STATUS; + } + }; + wJob.setSystem(true); + wJob.schedule(); } } catch (DebugException de) { - DebugUIPlugin.getStandardDisplay().asyncExec(new Runnable() { - public void run() { - getDetailDocument().set(VariablesViewMessages.VariablesView__error_occurred_retrieving_value__18); - } - }); + wJob = new WorkbenchJob("Populate Details Pane") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + getDetailDocument().set(VariablesViewMessages.VariablesView__error_occurred_retrieving_value__18); + return Status.OK_STATUS; + } + + }; + wJob.setSystem(true); + wJob.schedule(); } } @@ -1121,7 +1060,7 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel insert = "\n" + result; //$NON-NLS-1$ } try { - int max = DebugUIPlugin.getDefault().getPreferenceStore().getInt(IDebugUIConstants.PREF_MAX_DETAIL_LENGTH); + int max = DebugUIPlugin.getDefault().getPreferenceStore().getInt(IInternalDebugUIConstants.PREF_MAX_DETAIL_LENGTH); if (max > 0 && insert.length() > max) { insert = insert.substring(0, max) + "..."; //$NON-NLS-1$ } @@ -1145,7 +1084,7 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel getModelPresentation().computeDetail(val, VariablesView.this); } catch (DebugException e) { DebugUIPlugin.log(e); - getDetailDocument().set(VariablesViewMessages.VariablesView__error_occurred_retrieving_value__18); // + getDetailDocument().set(VariablesViewMessages.VariablesView__error_occurred_retrieving_value__18); } } else { fValueSelection = null; @@ -1333,23 +1272,19 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel protected VariablesViewSelectionProvider getVariablesViewSelectionProvider() { return fSelectionProvider; } - /** - * The VariablesView listens for selection changes in the LaunchView - * - * @see ISelectionListener#selectionChanged(IWorkbenchPart, ISelection) + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.contexts.IDebugContextListener#contextActivated(java.lang.Object, org.eclipse.ui.IWorkbenchPart) */ - public void selectionChanged(IWorkbenchPart part, ISelection selection) { + public void contextActivated(ISelection selection, IWorkbenchPart part) { if (!isAvailable() || !isVisible()) { return; } - if (selection == null) { - setViewerInput(new StructuredSelection()); - } else if (selection instanceof IStructuredSelection) { - setViewerInput((IStructuredSelection) selection); - } else { - getDetailViewer().setEditable(false); + if (selection instanceof IStructuredSelection) { + setViewerInput(((IStructuredSelection)selection).getFirstElement()); } + updateAction("ContentAssist"); //$NON-NLS-1$ updateAction("FindVariable"); //$NON-NLS-1$ } @@ -1364,19 +1299,6 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel IAction action = getAction(DOUBLE_CLICK_ACTION); if (action != null && action.isEnabled()) { action.run(); - } else { - ISelection selection= event.getSelection(); - if (!(selection instanceof IStructuredSelection)) { - return; - } - IStructuredSelection ss= (IStructuredSelection)selection; - Object o= ss.getFirstElement(); - - if (o != null) { - TreeViewer tViewer= (TreeViewer)getViewer(); - boolean expanded= tViewer.getExpandedState(o); - tViewer.setExpandedState(o, !expanded); - } } } /** @@ -1470,7 +1392,7 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel * @see org.eclipse.debug.ui.AbstractDebugView#becomesHidden() */ protected void becomesHidden() { - setViewerInput(new StructuredSelection()); + setViewerInput(null); super.becomesHidden(); } @@ -1479,11 +1401,8 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel */ protected void becomesVisible() { super.becomesVisible(); - IViewPart part = getSite().getPage().findView(IDebugUIConstants.ID_DEBUG_VIEW); - if (part != null) { - ISelection selection = getSite().getPage().getSelection(IDebugUIConstants.ID_DEBUG_VIEW); - selectionChanged(part, selection); - } + ISelection selection = DebugContextManager.getDefault().getActiveContext(getSite().getWorkbenchWindow()); + contextActivated(selection, null); } /** @@ -1495,6 +1414,10 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel return new ViewerState(getVariablesViewer()); } + private VariablesViewer getVariablesViewer() { + return (VariablesViewer) getViewer(); + } + /** * Returns this view's "cursor" listener to be installed on the view's * associated details viewer. This listener is listening to key and mouse button events. @@ -1563,4 +1486,5 @@ public class VariablesView extends AbstractDebugEventHandlerView implements ISel return ""; //$NON-NLS-1$ } } + } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewEventHandler.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewEventHandler.java index 03547626c..716e47fb3 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewEventHandler.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewEventHandler.java @@ -21,7 +21,6 @@ import org.eclipse.debug.core.model.ISuspendResume; import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.core.model.IVariable; import org.eclipse.debug.internal.ui.views.AbstractDebugEventHandler; -import org.eclipse.debug.internal.ui.views.RemoteTreeContentManager; import org.eclipse.debug.ui.AbstractDebugView; /** @@ -29,8 +28,6 @@ import org.eclipse.debug.ui.AbstractDebugView; */ public class VariablesViewEventHandler extends AbstractDebugEventHandler { - private RemoteTreeContentManager fContentManager = null; - /** * Constructs a new event handler on the given view * @@ -82,15 +79,6 @@ public class VariablesViewEventHandler extends AbstractDebugEventHandler { // clear variable expansion state getVariablesView().clearExpandedVariables(event.getSource()); } - if (!event.isEvaluation()) { - Object input = getVariablesView().getVariablesViewer().getInput(); - if (input instanceof IStackFrame) { - IStackFrame frame = (IStackFrame)input; - if (event.getSource().equals(frame.getThread())) { - fContentManager.cancel(); - } - } - } } /** @@ -188,10 +176,6 @@ public class VariablesViewEventHandler extends AbstractDebugEventHandler { return (DebugEvent[]) all.toArray(new DebugEvent[all.size()]); } - public void setContentManager(RemoteTreeContentManager manager) { - fContentManager = manager; - } - protected boolean isFiltered(DebugEvent event) { if (event.getKind() == DebugEvent.CHANGE) { Object source = event.getSource(); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewer.java index 2ba972ccf..54a4bc63e 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewer.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewer.java @@ -1,186 +1,44 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.internal.ui.views.variables; - -import java.util.ArrayList; -import java.util.Iterator; - -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IRegisterGroup; -import org.eclipse.debug.core.model.IVariable; -import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages; -import org.eclipse.debug.internal.ui.views.IRemoteTreeViewerUpdateListener; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; -import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; +import org.eclipse.debug.internal.ui.viewers.IAsynchronousRequestMonitor; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Widget; import org.eclipse.ui.progress.UIJob; -/** - * Variables viewer. As the user steps through code, this - * we ensure that newly added varibles are visible. - */ -public class VariablesViewer extends RemoteTreeViewer { - - private ArrayList fUpdateListeners = new ArrayList(); - private StateRestorationJob fStateRestorationJob = new StateRestorationJob(DebugUIViewsMessages.RemoteTreeViewer_0); - private VariablesView fView = null; - - private class StateRestorationJob extends UIJob { - public StateRestorationJob(String name) { - super(name); - setSystem(true); - } +public class VariablesViewer extends AsynchronousTreeViewer{ - /* (non-Javadoc) - * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus runInUIThread(IProgressMonitor monitor) { - restoreExpansionState(); - return Status.OK_STATUS; - } - } + private VariablesView fView; - /** - * Constructor for VariablesViewer. - * @param parent - * @param style - * @param view containing view, or null if none - */ + private UIJob fRestoreJob = new UIJob("restore viewer state") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + fView.restoreState(); + return Status.OK_STATUS; + } + }; + public VariablesViewer(Composite parent, int style, VariablesView view) { super(parent, style); fView = view; + fRestoreJob.setSystem(true); } - - /** - * @see AbstractTreeViewer#newItem(Widget, int, int) - */ - protected Item newItem(Widget parent, int style, int index) { - Item item = super.newItem(parent, style, index); - if (index != -1 && getSelection(getControl()).length == 0) { - //ignore the dummy items - showItem(item); - } - return item; - } - - /** - * @see org.eclipse.jface.viewers.AbstractTreeViewer#setExpandedElements(Object[]) - */ - public void setExpandedElements(Object[] elements) { - getControl().setRedraw(false); - super.setExpandedElements(elements); - getControl().setRedraw(true); - } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.views.RemoteTreeViewer#runDeferredUpdates() - */ - protected void runDeferredUpdates() { - super.runDeferredUpdates(); - fStateRestorationJob.schedule(); - } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.AbstractTreeViewer#collapseAll() - */ - public void collapseAll() { - //see https://bugs.eclipse.org/bugs/show_bug.cgi?id=39449 - if (getRoot() != null) { - super.collapseAll(); + protected void updateComplete(IAsynchronousRequestMonitor update) { + super.updateComplete(update); + if (fView != null) { + fRestoreJob.schedule(100); } } - - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.views.RemoteTreeViewer#restoreExpansionState() - */ - protected synchronized void restoreExpansionState() { - cancelJobs(); - for (Iterator i = fUpdateListeners.iterator(); i.hasNext();) { - IRemoteTreeViewerUpdateListener listener = (IRemoteTreeViewerUpdateListener) i.next(); - listener.treeUpdated(); - } - } - - public void addUpdateListener(IRemoteTreeViewerUpdateListener listener) { - fUpdateListeners.add(listener); - } - public void removeUpdateListener(IRemoteTreeViewerUpdateListener listener) { - fUpdateListeners.remove(listener); - } /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.views.RemoteTreeViewer#replace(java.lang.Object, java.lang.Object[], int) + * @see org.eclipse.debug.internal.ui.treeviewer.AsynchronousTreeViewer#handlePresentationFailure(org.eclipse.debug.internal.ui.treeviewer.IPresentationRequestMonitor, org.eclipse.core.runtime.IStatus) */ - public synchronized void replace(Object parent, Object[] children, int offset) { - if (fView != null) { - if (children.length == 1 && children[0] instanceof DebugException) { - IStatus status = ((DebugException)children[0]).getStatus(); - if (status != null) { - String message = status.getMessage(); - if (message != null) { - fView.showMessage(message); - } - } - return; - } - fView.showViewer(); - } - super.replace(parent, children, offset); + protected void handlePresentationFailure(IAsynchronousRequestMonitor update, IStatus status) { + fView.showMessage(status.getMessage()); } - - - public boolean expandPath(IPath path) { - String[] strings = path.segments(); - Item[] children = getChildren(getControl()); - return internalExpandPath(strings, 0, children); - - } - protected boolean internalExpandPath(String[] segments, int index, Item[] children) { - try { - String pathSegment = segments[index]; - for (int j = 0; j < children.length; j++) { - Item child = children[j]; - Object data = child.getData(); - String name = null; - if (data instanceof IVariable) { - IVariable var = (IVariable) data; - name = var.getName(); - } else if (data instanceof IRegisterGroup) { - IRegisterGroup registerGroup = (IRegisterGroup) data; - name = registerGroup.getName(); - } - - if (name != null && pathSegment.equals(name)) { - ITreeContentProvider provider = (ITreeContentProvider) getContentProvider(); - provider.getChildren(child.getData()); - setExpanded(child, true); - index++; - if (index < segments.length) { - Item[] newChildren = getChildren(child); - return internalExpandPath(segments, index, newChildren); - } - return true; - } - } - } catch (DebugException e) { - - } - return false; - } + + + } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/ViewerState.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/ViewerState.java index a014a1050..6f6429132 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/ViewerState.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/ViewerState.java @@ -12,16 +12,15 @@ package org.eclipse.debug.internal.ui.views.variables; import java.util.ArrayList; -import java.util.Iterator; +import java.util.List; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IVariable; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; +import org.eclipse.debug.internal.ui.viewers.TreePath; import org.eclipse.debug.internal.ui.views.AbstractViewerState; -import org.eclipse.debug.internal.ui.views.RemoteTreeViewer; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; /** @@ -34,88 +33,62 @@ public class ViewerState extends AbstractViewerState { /** * Constructs a memento for the given viewer. */ - public ViewerState(TreeViewer viewer) { + public ViewerState(AsynchronousTreeViewer viewer) { super(viewer); } - - public ViewerState() { - super(); - } /** * @see org.eclipse.debug.internal.ui.views.AbstractViewerState#encodeElement(org.eclipse.swt.widgets.TreeItem) */ protected IPath encodeElement(TreeItem item) throws DebugException { - Object data = item.getData(); - if (data instanceof IVariable) { - IVariable variable = (IVariable)data; - IPath path = new Path(variable.getName()); - TreeItem parent = item.getParentItem(); - while (parent != null) { - variable = (IVariable)parent.getData(); - path = new Path(variable.getName()).append(path); - parent = parent.getParentItem(); - } - return path; - } - - return null; + StringBuffer path = new StringBuffer(item.getText()); + TreeItem parent = item.getParentItem(); + while (parent != null) { + path.insert(0, parent.getText()+'/'); + parent = parent.getParentItem(); + } + return new Path(path.toString()); } /** - * @see org.eclipse.debug.internal.ui.views.AbstractViewerState#decodePath(org.eclipse.core.runtime.IPath, org.eclipse.jface.viewers.TreeViewer) + * @see org.eclipse.debug.internal.ui.views.AbstractViewerState#decodePath(org.eclipse.core.runtime.IPath, + * org.eclipse.jface.viewers.TreeViewer) */ - protected Object decodePath(IPath path, TreeViewer viewer) throws DebugException { - ITreeContentProvider contentProvider = (ITreeContentProvider)viewer.getContentProvider(); + protected TreePath decodePath(IPath path, AsynchronousTreeViewer viewer) throws DebugException { String[] names = path.segments(); - Object parent = viewer.getInput(); - IVariable variable = null; + Tree tree = viewer.getTree(); + TreeItem[] items = tree.getItems(); + + List elements = new ArrayList(); + elements.add(viewer.getInput()); + + boolean pathFound = false; + for (int i = 0; i < names.length; i++) { - variable = null; - Object[] children = null; - if (viewer instanceof RemoteTreeViewer) { - children = ((RemoteTreeViewer)viewer).getCurrentChildren(parent); - } else { - children = contentProvider.getChildren(parent); - } - if (children == null) { - return null; - } String name = names[i]; - for (int j = 0; j < children.length; j++) { - if (!(children[j] instanceof IVariable)) { - continue; - } - IVariable var = (IVariable)children[j]; - if (var.getName().equals(name)) { - variable = var; - break; - } + TreeItem item = findItem(name, items); + if (item != null) { + pathFound = true; + elements.add(item.getData()); + items = item.getItems(); } - if (variable == null) { - return null; - } - parent = variable; } - return variable; + + if (pathFound) { + return new TreePath(elements.toArray()); + } + + return null; } - - public AbstractViewerState copy() { - ViewerState copy = new ViewerState(); - if (fSavedExpansion != null) { - copy.fSavedExpansion = new ArrayList(); - for (Iterator iter = fSavedExpansion.iterator(); iter.hasNext();) { - copy.fSavedExpansion.add(iter.next()); - } - } - - if (fSelection != null) { - copy.fSelection = new IPath[fSelection.length]; - for (int i = 0; i < fSelection.length; i++) { - IPath sel = fSelection[i]; - copy.fSelection[i] = sel; - } - } - return copy; - } + + private TreeItem findItem(String name, TreeItem[] items) { + for (int i = 0; i < items.length; i++) { + TreeItem item = items[i]; + if (item.getText().equals(name)) { + return item; + } + } + return null; + } + } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/IDebugUIConstants.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/IDebugUIConstants.java index 24caa076d..a531ca0f2 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/IDebugUIConstants.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/IDebugUIConstants.java @@ -1002,6 +1002,14 @@ public interface IDebugUIConstants { * @since 3.1 */ public static final String EXTENSION_POINT_BREAKPOINT_ORGANIZERS = "breakpointOrganizers"; //$NON-NLS-1$ + + /** + * Update policies extension point identifier (value + * "updatePolicies" + * + * @since 3.2 + */ + public static final String EXTENSION_POINT_UPDATE_POLICIES = "updatePolicies"; //$NON-NLS-1$ /** * Padded string preference for renderings. Padded string is the string to be used in place of diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/InspectPopupDialog.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/InspectPopupDialog.java index e89682647..4e098f9cf 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/InspectPopupDialog.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/InspectPopupDialog.java @@ -14,6 +14,7 @@ package org.eclipse.debug.ui; import java.util.Iterator; import java.util.Map; +import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.model.IExpression; @@ -21,9 +22,12 @@ import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IVariable; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.VariablesViewModelPresentation; +import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeContentAdapter; +import org.eclipse.debug.internal.ui.viewers.IPresentationContext; +import org.eclipse.debug.internal.ui.viewers.PresentationContext; +import org.eclipse.debug.internal.ui.viewers.TreePath; +import org.eclipse.debug.internal.ui.viewers.TreeSelection; import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages; -import org.eclipse.debug.internal.ui.views.expression.ExpressionPopupContentProvider; -import org.eclipse.debug.internal.ui.views.expression.RemoteExpressionsContentProvider; import org.eclipse.debug.internal.ui.views.variables.IndexedVariablePartition; import org.eclipse.debug.internal.ui.views.variables.VariablesView; import org.eclipse.debug.internal.ui.views.variables.VariablesViewer; @@ -47,7 +51,6 @@ import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.PartInitException; public class InspectPopupDialog extends DebugPopup { @@ -57,7 +60,7 @@ public class InspectPopupDialog extends DebugPopup { private static final int MIN_HEIGHT = 200; - private IWorkbenchPage fPage; +// private IWorkbenchPage fPage; private VariablesViewer fVariablesViewer; @@ -89,17 +92,11 @@ public class InspectPopupDialog extends DebugPopup { fSashForm.setOrientation(SWT.VERTICAL); fSashForm.setLayoutData(new GridData(GridData.FILL_BOTH)); - fPage = DebugUIPlugin.getActiveWorkbenchWindow().getActivePage(); VariablesView view = getViewToEmulate(); - IWorkbenchPartSite site = null; - if (view != null) { - site = view.getSite(); - } else { - site = fPage.getActivePart().getSite(); - } fVariablesViewer = new VariablesViewer(fSashForm, SWT.NO_TRIM, null); - fVariablesViewer.setContentProvider(new ExpressionPopupContentProvider(fVariablesViewer, site, view)); + + fVariablesViewer.setContext(new PresentationContext(view)); fModelPresentation = new VariablesViewModelPresentation(); fVariablesViewer.setLabelProvider(fModelPresentation); @@ -161,7 +158,7 @@ public class InspectPopupDialog extends DebugPopup { fVariablesViewer.addFilter(filters[i]); } } - ((RemoteExpressionsContentProvider) fVariablesViewer.getContentProvider()).setShowLogicalStructure(view.isShowLogicalStructure()); + Map map = view.getPresentationAttributes(fExpression.getModelIdentifier()); Iterator iterator = map.keySet().iterator(); while (iterator.hasNext()) { @@ -169,12 +166,26 @@ public class InspectPopupDialog extends DebugPopup { fModelPresentation.setAttribute(key, map.get(key)); } } - fVariablesViewer.setInput(new Object[] { fExpression }); - fVariablesViewer.expandToLevel(2); + + TreeRoot treeRoot = new TreeRoot(); + fVariablesViewer.setInput(treeRoot); + fVariablesViewer.expand(new TreeSelection(new TreePath(new Object[] {treeRoot, fExpression}))); return fTree; } + private class TreeRoot extends AsynchronousTreeContentAdapter { + protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException { + return new Object[] { fExpression }; + } + protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { + return true; + } + protected boolean supportsPartId(String id) { + return true; + } + } + void updateValueDisplay(IValue val) { IValueDetailListener valueDetailListener = new IValueDetailListener() { public void detailComputed(IValue value, final String result) { diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/IDebugContextListener.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/IDebugContextListener.java new file mode 100644 index 000000000..e0ecd92ce --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/IDebugContextListener.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2005 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.ui.contexts; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchPart; + +/** + * + * @since 3.2 + */ +public interface IDebugContextListener { + + /** + * Notification the given selection contains the active context in the + * specified part. + * + * @param selection selection containing active context + * @param part workbench part or null + */ + public void contextActivated(ISelection selection, IWorkbenchPart part); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/IDebugContextManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/IDebugContextManager.java new file mode 100644 index 000000000..1fff05031 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/IDebugContextManager.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2005 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.ui.contexts; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchWindow; + +/** + * A debug context drives debugging - source lookup and action enablement in the + * debug user interface. The context service provides notification + * of changes in the active context specific to the workbench, a specific window, or a + * specific part. + *

+ * Cleints provide a context policy to notifiy the context service of interesting + * contexts within a model. For example the debug platform provides a context policy + * that maps debug events to suspended contexts. + *

+ *

+ * Not intended to be implemented by clients. + *

+ * @since 3.2 + */ +public interface IDebugContextManager { + + /** + * Registers the given debug context provider. + * + * @param provider + */ + public void addDebugContextProvider(IDebugContextProvider provider); + + /** + * Deregisters the given debug context provider. + * + * @param provider + */ + public void removeDebugContextProvider(IDebugContextProvider provider); + + /** + * Registers for context activation notification in the given window. + * + * @param listener + * @param window + */ + public void addDebugContextListener(IDebugContextListener listener, IWorkbenchWindow window); + /** + * Deregisters for context activation notification in this service in the + * given window. + * + * @param listener + * @param window + */ + public void removeDebugContextListener(IDebugContextListener listener, IWorkbenchWindow window); + + /** + * Registers for context activation notification in the specified part of the + * specified window. + * + * @param listener + * @param window + * @param partId + */ + public void addDebugContextListener(IDebugContextListener listener, IWorkbenchWindow window, String partId); + + /** + * Deregisters for context activation notification in the specified part of + * the specified window. + * + * @param listener + * @param partId + */ + public void removeDebugContextListener(IDebugContextListener listener, IWorkbenchWindow window, String partId); + + /** + * Returns the active context in the given window + * or null. + * + * @param window + * @return + */ + public ISelection getActiveContext(IWorkbenchWindow window); + + /** + * Returns the active context in the specified part of the given + * window or null. + * + * @param partId + * @return + */ + public ISelection getActiveContext(IWorkbenchWindow window, String partId); +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/IDebugContextProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/IDebugContextProvider.java new file mode 100644 index 000000000..1052a4e4d --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/IDebugContextProvider.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2005 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.ui.contexts; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchPart; + +/** + * Provides a debug context. + * + * @since 3.2 + */ +public interface IDebugContextProvider { + + /** + * Returns the part associated with this provider. + * + * @return + */ + public IWorkbenchPart getPart(); + + public void addDebugContextListener(IDebugContextListener listener); + public void removeDebugContextListener(IDebugContextListener listener); + + public ISelection getActiveContext(); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/ISourceDisplayAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/ISourceDisplayAdapter.java new file mode 100644 index 000000000..938e49278 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/ISourceDisplayAdapter.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2005 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.ui.contexts; + +import org.eclipse.ui.IWorkbenchPage; + +/** + * An adpater that is capable of displaying source for an object. + * The adapter is obtained from an object in a debug context. + * + * @since 3.2 + */ +public interface ISourceDisplayAdapter { + + /** + * Displays source for the given context in the specified page. + * + * @param context debug context to display source for + * @param page the page in which to display source + */ + public void displaySource(Object context, IWorkbenchPage page); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/ISuspendTrigger.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/ISuspendTrigger.java new file mode 100644 index 000000000..a5ce7e0bb --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/ISuspendTrigger.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2005 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.ui.contexts; + +/** + * Adapter retrieved from an ILaunch that notifies + * listeners when it suspends. A suspend trigger is responsible + * for cleaning itself up when it's launch is no longer capable + * of suspending. + * + * @since 3.2 + */ +public interface ISuspendTrigger { + + public void addSuspendTriggerListener(ISuspendTriggerListener listener); + public void removeSuspendTriggerListener(ISuspendTriggerListener listener); + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/ISuspendTriggerListener.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/ISuspendTriggerListener.java new file mode 100644 index 000000000..5daafe5e7 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/contexts/ISuspendTriggerListener.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2005 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.ui.contexts; + +import org.eclipse.debug.core.ILaunch; + +/** + * @since 3.2 + */ +public interface ISuspendTriggerListener { + + /** + * Notification the given launch has suspended at the + * specified context. + * + * @param launch + * @param context + */ + public void suspended(ILaunch launch, Object context); + +} -- cgit v1.2.3