From aa357e78b41e87b7d414d1a7d0b8b7db0dfce011 Mon Sep 17 00:00:00 2001 From: Pawel Piech Date: Fri, 17 Feb 2012 09:21:15 -0800 Subject: [PATCH] Bug 369856 - [bp] Allows clients to create and extend toggle breakpoint actions --- .../IToggleBreakpointsTargetManagerListener.java | 29 ----- .../ui/actions/ToggleBreakpointsTargetManager.java | 133 ++++++++++---------- .../breakpoints/BreakpointTypesContribution.java | 6 +- .../breakpoints/RetargetBreakpointAction.java | 21 ++-- .../ToggleBreakpointObjectActionDelegate.java | 6 +- .../ui/org/eclipse/debug/ui/DebugUITools.java | 88 +++++++++---- .../actions/IToggleBreakpointsTargetFactory.java | 2 +- .../actions/IToggleBreakpointsTargetManager.java | 103 +++++++++++++++ .../IToggleBreakpointsTargetManagerListener.java | 30 +++++ .../debug/ui/actions/RulerBreakpointAction.java | 4 +- .../RulerBreakpointTypesActionDelegate.java | 2 +- .../debug/ui/actions/ToggleBreakpointAction.java | 8 +- 12 files changed, 285 insertions(+), 147 deletions(-) delete mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/IToggleBreakpointsTargetManagerListener.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetManager.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetManagerListener.java diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/IToggleBreakpointsTargetManagerListener.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/IToggleBreakpointsTargetManagerListener.java deleted file mode 100644 index ba0ca5f..0000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/IToggleBreakpointsTargetManagerListener.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Wind River 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.debug.internal.ui.actions; - -/** - * Listener for changes in the preferred toggle targets in the toggle - * breakpoints target manager. This interface allows toggle breakpoint - * actions to update their enablement when the user changes the preferred - * toggle target settings. - * - * @see ToggleBreakpointsTargetManager - * @see IToggleBreakpointsTargetFactory - * @since 3.5 - */ -public interface IToggleBreakpointsTargetManagerListener { - - /** - * Called when the preferred toggle targets have changed. - */ - public void preferredTargetsChanged(); -} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ToggleBreakpointsTargetManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ToggleBreakpointsTargetManager.java index 163c6ef..c8239d1 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ToggleBreakpointsTargetManager.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ToggleBreakpointsTargetManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Wind River Systems and others. + * Copyright (c) 2008, 2012 Wind River 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 @@ -29,6 +29,7 @@ import org.eclipse.core.expressions.Expression; import org.eclipse.core.expressions.ExpressionConverter; import org.eclipse.core.expressions.ExpressionTagNames; import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdapterManager; @@ -38,36 +39,40 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.internal.core.IConfigurationElementConstants; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; -import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetExtension; import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetFactory; +import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetManager; +import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetManagerListener; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.IVerticalRulerInfo; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.SimpleMarkerAnnotation; /** - * Organizes the toggle breakpoints target factories contributed through the - * extension point and keeps track of the toggle breakpoints target that - * the factories produce. The manager is accessed as a singleton through - * the getDefault() method. - *

- * The adapter mechanism for obtaining a toggle breakpoints target is - * still supported through a specialized toggle target factory. Targets - * contributed through this mechanism are labeled as "Default" in the UI. - *

+ * The concrete implementation of the toggle breakpoints target manager + * interface. * - * @see IToggleBreakpointsTargetFactory - * @see IToggleBreakpointsTarget - * @see IToggleBreakpointsTargetExtension * @since 3.5 */ -public class ToggleBreakpointsTargetManager { +public class ToggleBreakpointsTargetManager implements IToggleBreakpointsTargetManager { /** * Toggle breakpoints target ID which refers to a target contributed @@ -82,7 +87,7 @@ public class ToggleBreakpointsTargetManager { /** * Acts as a proxy between the toggle breakpoints target manager and the factories - * contributed to the extension point. Only loads information from the plug-in xml + * contributed to the extension point. Only loads information from the plug-in XML * and only instantiates the specified factory if required (lazy loading). */ private static class ToggleTargetFactory implements IToggleBreakpointsTargetFactory { @@ -516,40 +521,16 @@ public class ToggleBreakpointsTargetManager { return idsForSelection; } - /** - * Returns the set of String IDs of toggle breakpoint targets, - * which are enabled for the given active part and selection. The IDs can be used - * to create the {@link IToggleBreakpointsTarget} instance. - * @param part active part - * @param selection active selection in part - * @return Set of toggle target IDs or an empty set - */ public Set getEnabledToggleBreakpointsTargetIDs(IWorkbenchPart part, ISelection selection) { return getEnabledTargetIDs(getEnabledFactories(part, selection), part, selection); } - /** - * Returns the ID of the calculated preferred toggle breakpoints target for the - * given active part and selection. The returned ID is chosen based on factory - * enablement, whether the target is a default one, and on user choice. - * @param part active part - * @param selection active selection in part - * @return The toggle target IDs or null if none. - */ public String getPreferredToggleBreakpointsTargetID(IWorkbenchPart part, ISelection selection) { Set factories = getEnabledFactories(part, selection); Set possibleIDs = getEnabledTargetIDs(factories, part, selection); return chooseToggleTargetIDInSet(possibleIDs, part, selection); } - /** - * Given the ID of toggle breakpoint target, this method will try to find the factory - * that creates it and return an instance of it. - * - * @param part The workbench part in which toggle target is to be used - * @param selection The active selection to use with toggle target - * @return The instantiated target or null - */ public IToggleBreakpointsTarget getToggleBreakpointsTarget(IWorkbenchPart part, ISelection selection) { String id = getPreferredToggleBreakpointsTargetID(part, selection); IToggleBreakpointsTargetFactory factory = (IToggleBreakpointsTargetFactory)fFactoriesByTargetID.get(id); @@ -563,13 +544,6 @@ public class ToggleBreakpointsTargetManager { return null; } - /** - * Given the ID of a toggle breakpoints target, this method will try - * to find the factory that creates it and ask it for the name of it. - * - * @param id The ID of the requested toggle breakpoint target. - * @return The name of the target. - */ public String getToggleBreakpointsTargetName(String id) { IToggleBreakpointsTargetFactory factory = (IToggleBreakpointsTargetFactory)fFactoriesByTargetID.get(id); if (factory != null) { @@ -578,13 +552,6 @@ public class ToggleBreakpointsTargetManager { return null; } - /** - * Given the ID of a toggle breakpoints target, this method will try - * to find the factory that creates it and ask it for the description of it. - * - * @param id The ID of the requested toggle breakpoint target. - * @return The description of the target or null. - */ public String getToggleBreakpointsTargetDescription(String id) { IToggleBreakpointsTargetFactory factory = (IToggleBreakpointsTargetFactory)fFactoriesByTargetID.get(id); if (factory != null) { @@ -593,20 +560,10 @@ public class ToggleBreakpointsTargetManager { return null; } - /** - * Adds the given listener to the list of listeners notified when the preferred - * toggle breakpoints targets change. - * @param listener The listener to add. - */ public void addChangedListener(IToggleBreakpointsTargetManagerListener listener) { fChangedListners.add(listener); } - /** - * Removes the given listener from the list of listeners notified when the preferred - * toggle breakpoints targets change. - * @param listener The listener to add. - */ public void removeChangedListener(IToggleBreakpointsTargetManagerListener listener) { fChangedListners.remove(listener); } @@ -635,7 +592,10 @@ public class ToggleBreakpointsTargetManager { buffer.append(entry.getValue()); buffer.append('|'); } - DebugUIPlugin.getDefault().getPluginPreferences().setValue(PREF_TARGETS, buffer.toString()); + IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(DebugUIPlugin.getUniqueIdentifier()); + if(prefs != null) { + prefs.put(PREF_TARGETS, buffer.toString()); + } } /** @@ -645,7 +605,14 @@ public class ToggleBreakpointsTargetManager { */ private void loadPreferredTargets() { fPreferredTargets = new HashMap(); - String preferenceValue = DebugUIPlugin.getDefault().getPluginPreferences().getString(PREF_TARGETS); + String preferenceValue = Platform.getPreferencesService().getString( + DebugUIPlugin.getUniqueIdentifier(), + PREF_TARGETS, + null, + null); + if(preferenceValue == null) { + return; + } StringTokenizer entryTokenizer = new StringTokenizer(preferenceValue,"|"); //$NON-NLS-1$ while (entryTokenizer.hasMoreTokens()){ String token = entryTokenizer.nextToken(); @@ -744,4 +711,38 @@ public class ToggleBreakpointsTargetManager { } } + public IBreakpoint getBeakpointFromEditor(ITextEditor editor, IVerticalRulerInfo info) { + IDocumentProvider provider = editor.getDocumentProvider(); + if(provider == null) { + return null; + } + IEditorInput input = editor.getEditorInput(); + IAnnotationModel annotationModel = provider.getAnnotationModel(input); + if (annotationModel != null) { + IDocument document = provider.getDocument(input); + Iterator iterator = annotationModel.getAnnotationIterator(); + while (iterator.hasNext()) { + Object object = iterator.next(); + if (object instanceof SimpleMarkerAnnotation) { + SimpleMarkerAnnotation markerAnnotation = (SimpleMarkerAnnotation) object; + IMarker marker = markerAnnotation.getMarker(); + try { + if (marker.isSubtypeOf(IBreakpoint.BREAKPOINT_MARKER)) { + Position position = annotationModel.getPosition(markerAnnotation); + int line = document.getLineOfOffset(position.getOffset()); + if (line == info.getLineOfLastMouseButtonActivity()) { + IBreakpoint breakpoint = DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(marker); + if (breakpoint != null) { + return breakpoint; + } + } + } + } catch (CoreException e) { + } catch (BadLocationException e) { + } + } + } + } + return null; + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/BreakpointTypesContribution.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/BreakpointTypesContribution.java index 4fa2d56..f7cc32c 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/BreakpointTypesContribution.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/BreakpointTypesContribution.java @@ -16,6 +16,8 @@ import java.util.List; import java.util.Set; import org.eclipse.debug.internal.ui.actions.ToggleBreakpointsTargetManager; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetManager; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.ContributionItem; @@ -50,6 +52,8 @@ public class BreakpointTypesContribution extends CompoundContributionItem implem public void run() { if (isChecked()) { + // Note: setPreferredTarget is not declared on the + // IToggleBreakpontsTargetManager interface. ToggleBreakpointsTargetManager.getDefault().setPreferredTarget(fPossibleIDs, fID); } } @@ -91,7 +95,7 @@ public class BreakpointTypesContribution extends CompoundContributionItem implem } // Get breakpoint toggle target IDs. - ToggleBreakpointsTargetManager manager = ToggleBreakpointsTargetManager.getDefault(); + IToggleBreakpointsTargetManager manager = DebugUITools.getToggleBreakpointsTargetManager(); Set enabledIDs = manager.getEnabledToggleBreakpointsTargetIDs(part, selection); String preferredId = manager.getPreferredToggleBreakpointsTargetID(part, selection); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetBreakpointAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetBreakpointAction.java index 9bd0a0e..99650fd 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetBreakpointAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetBreakpointAction.java @@ -12,20 +12,17 @@ package org.eclipse.debug.internal.ui.actions.breakpoints; import org.eclipse.core.runtime.IAdaptable; - +import org.eclipse.debug.internal.ui.actions.RetargetAction; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; +import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetManager; +import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetManagerListener; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; - import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.debug.internal.ui.actions.IToggleBreakpointsTargetManagerListener; -import org.eclipse.debug.internal.ui.actions.RetargetAction; -import org.eclipse.debug.internal.ui.actions.ToggleBreakpointsTargetManager; - -import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; - /** * Retargettable breakpoint action. @@ -44,7 +41,7 @@ public abstract class RetargetBreakpointAction extends RetargetAction implements } protected Object getAdapter(IAdaptable adaptable) { - ToggleBreakpointsTargetManager manager = ToggleBreakpointsTargetManager.getDefault(); + IToggleBreakpointsTargetManager manager = DebugUITools.getToggleBreakpointsTargetManager(); IWorkbenchPart activePart = getActivePart(); if (activePart != null) { return manager.getToggleBreakpointsTarget(activePart, getTargetSelection()); @@ -54,16 +51,16 @@ public abstract class RetargetBreakpointAction extends RetargetAction implements public void init(IWorkbenchWindow window) { super.init(window); - ToggleBreakpointsTargetManager.getDefault().addChangedListener(this); + DebugUITools.getToggleBreakpointsTargetManager().addChangedListener(this); } public void init(IAction action) { super.init(action); - ToggleBreakpointsTargetManager.getDefault().addChangedListener(this); + DebugUITools.getToggleBreakpointsTargetManager().addChangedListener(this); } public void dispose() { - ToggleBreakpointsTargetManager.getDefault().removeChangedListener(this); + DebugUITools.getToggleBreakpointsTargetManager().removeChangedListener(this); super.dispose(); } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/ToggleBreakpointObjectActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/ToggleBreakpointObjectActionDelegate.java index e336289..5d1f09b 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/ToggleBreakpointObjectActionDelegate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/ToggleBreakpointObjectActionDelegate.java @@ -13,7 +13,7 @@ package org.eclipse.debug.internal.ui.actions.breakpoints; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.internal.ui.actions.ToggleBreakpointsTargetManager; +import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; @@ -47,7 +47,7 @@ public abstract class ToggleBreakpointObjectActionDelegate implements IObjectAct */ public void run(IAction action) { IToggleBreakpointsTarget target = - ToggleBreakpointsTargetManager.getDefault().getToggleBreakpointsTarget(fPart, fSelection); + DebugUITools.getToggleBreakpointsTargetManager().getToggleBreakpointsTarget(fPart, fSelection); if (target != null) { try { performAction(target, fPart, fSelection); @@ -79,7 +79,7 @@ public abstract class ToggleBreakpointObjectActionDelegate implements IObjectAct // Guard here against that possibility. if (fPart != null) { IToggleBreakpointsTarget target = - ToggleBreakpointsTargetManager.getDefault().getToggleBreakpointsTarget(fPart, fSelection); + DebugUITools.getToggleBreakpointsTargetManager().getToggleBreakpointsTarget(fPart, fSelection); enabled = target != null; } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java index bc97021..59b3fb5 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java @@ -13,18 +13,14 @@ package org.eclipse.debug.ui; import java.util.Set; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Shell; - import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.operations.IOperationHistory; import org.eclipse.core.commands.operations.IUndoContext; import org.eclipse.core.commands.operations.IUndoableOperation; import org.eclipse.core.commands.operations.ObjectUndoContext; - +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IConfigurationElement; @@ -33,26 +29,6 @@ import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.window.Window; - -import org.eclipse.ui.IViewSite; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.console.IConsole; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.ide.undo.DeleteMarkersOperation; -import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; - import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; @@ -70,6 +46,7 @@ import org.eclipse.debug.internal.ui.DefaultLabelProvider; import org.eclipse.debug.internal.ui.DelegatingModelPresentation; import org.eclipse.debug.internal.ui.LazyModelPresentation; import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.internal.ui.actions.ToggleBreakpointsTargetManager; import org.eclipse.debug.internal.ui.contexts.DebugContextManager; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationDialog; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; @@ -80,13 +57,32 @@ import org.eclipse.debug.internal.ui.memory.MemoryRenderingManager; import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupFacility; import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIUtils; import org.eclipse.debug.internal.ui.stringsubstitution.SelectedResourceManager; - +import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetManager; import org.eclipse.debug.ui.contexts.IDebugContextListener; import org.eclipse.debug.ui.contexts.IDebugContextManager; import org.eclipse.debug.ui.contexts.IDebugContextService; import org.eclipse.debug.ui.memory.IMemoryRenderingManager; import org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser; import org.eclipse.debug.ui.sourcelookup.ISourceLookupResult; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IViewSite; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.ide.undo.DeleteMarkersOperation; +import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; /** @@ -215,7 +211,7 @@ public class DebugUITools { } /** - * Returns the element of the currently selected context in the + * Returns the element of the currently selected context in the * active workbench window. Returns null if there is no * current debug context. *

@@ -234,6 +230,31 @@ public class DebugUITools { return null; } + /** + * Returns the currently selected context in the given part or part's + * workbench window. Returns null if there is no current + * debug context. + * @param part workbench part where the active context is to be evaluated + * @return the currently selected debug context in the given workbench part, + * or null + * @since 3.8 + * @see IDebugContextService#getActiveContext(String) + * @see IDebugContextService#getActiveContext(String, String) + */ + public static ISelection getDebugContextForPart(IWorkbenchPart part) { + IWorkbenchPartSite site = part.getSite(); + IWorkbenchWindow partWindow = site.getWorkbenchWindow(); + if (partWindow != null) { + IDebugContextService contextService = DebugUITools.getDebugContextManager().getContextService(partWindow); + if (site instanceof IViewSite) { + return contextService.getActiveContext(site.getId(), ((IViewSite)site).getSecondaryId()); + } else { + return contextService.getActiveContext(site.getId()); + } + } + return null; + } + /** * Return the undo context that should be used for operations involving breakpoints. * @@ -1073,4 +1094,15 @@ public class DebugUITools { return (ISelection) o; } + /** + * Returns the global instance of toggle breakpoints target manager. + * + * @return toggle breakpoints target manager + * + * @since 3.8 + */ + public static IToggleBreakpointsTargetManager getToggleBreakpointsTargetManager() { + return ToggleBreakpointsTargetManager.getDefault(); + } + } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetFactory.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetFactory.java index cb644d3..9913661 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetFactory.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetFactory.java @@ -59,7 +59,7 @@ import org.eclipse.ui.IWorkbenchPart; * * @see IToggleBreakpointsTarget * @see IToggleBreakpointsTargetExtension - * @see org.eclipse.debug.internal.ui.actions.ToggleBreakpointsTargetManager + * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTargetManager * @since 3.5 */ public interface IToggleBreakpointsTargetFactory { diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetManager.java new file mode 100644 index 0000000..fb8e69a --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetManager.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.ui.actions; + +import java.util.Set; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchPart; + +/** + * Organizes the toggle breakpoints target factories contributed through the + * extension point and keeps track of the toggle breakpoints target that + * the factories produce. The manager is accessed as a singleton through + * the getDefault() method. + *

+ * The adapter mechanism for obtaining a toggle breakpoints target is + * still supported through a specialized toggle target factory. Targets + * contributed through this mechanism are labeled as "Default" in the UI. + *

+ *

+ * Clients should call {@link org.eclipse.debug.ui.DebugUITools#getToggleBreakpointsTargetManager()} + * for an instance of this instance. + *

+ * + * @see IToggleBreakpointsTargetFactory + * @see IToggleBreakpointsTarget + * @see IToggleBreakpointsTargetExtension + * + * @since 3.8 + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface IToggleBreakpointsTargetManager { + + /** + * Returns the set of String IDs of toggle breakpoint targets, + * which are enabled for the given active part and selection. The IDs can be used + * to create the {@link IToggleBreakpointsTarget} instance. + * @param part active part + * @param selection active selection in part + * @return Set of toggle target IDs or an empty set + */ + public Set getEnabledToggleBreakpointsTargetIDs(IWorkbenchPart part, ISelection selection); + + /** + * Returns the ID of the calculated preferred toggle breakpoints target for the + * given active part and selection. The returned ID is chosen based on factory + * enablement, whether the target is a default one, and on user choice. + * @param part active part + * @param selection active selection in part + * @return The toggle target IDs or null if none. + */ + public String getPreferredToggleBreakpointsTargetID(IWorkbenchPart part, ISelection selection); + + /** + * Given the ID of toggle breakpoint target, this method will try to find the factory + * that creates it and return an instance of it. + * + * @param part The workbench part in which toggle target is to be used + * @param selection The active selection to use with toggle target + * @return The instantiated target or null + */ + public IToggleBreakpointsTarget getToggleBreakpointsTarget(IWorkbenchPart part, ISelection selection); + + /** + * Given the ID of a toggle breakpoints target, this method will try + * to find the factory that creates it and ask it for the name of it. + * + * @param id The ID of the requested toggle breakpoint target. + * @return The name of the target. + */ + public String getToggleBreakpointsTargetName(String id); + + /** + * Given the ID of a toggle breakpoints target, this method will try + * to find the factory that creates it and ask it for the description of it. + * + * @param id The ID of the requested toggle breakpoint target. + * @return The description of the target or null. + */ + public String getToggleBreakpointsTargetDescription(String id); + + /** + * Adds the given listener to the list of listeners notified when the preferred + * toggle breakpoints targets change. + * @param listener The listener to add. + */ + public void addChangedListener(IToggleBreakpointsTargetManagerListener listener); + + /** + * Removes the given listener from the list of listeners notified when the preferred + * toggle breakpoints targets change. + * @param listener The listener to add. + */ + public void removeChangedListener(IToggleBreakpointsTargetManagerListener listener); +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetManagerListener.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetManagerListener.java new file mode 100644 index 0000000..4538c4d --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetManagerListener.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.ui.actions; + + +/** + * Listener for changes in the preferred toggle targets in the toggle + * breakpoints target manager. This interface allows toggle breakpoint + * actions to update their enablement when the user changes the preferred + * toggle target settings. + * + * @see IToggleBreakpointsTargetManager + * @see IToggleBreakpointsTargetFactory + * @since 3.8 + */ +public interface IToggleBreakpointsTargetManagerListener { + + /** + * Called when the preferred toggle targets have changed. + */ + public void preferredTargetsChanged(); +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerBreakpointAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerBreakpointAction.java index 62ab35d..6612a9e 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerBreakpointAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerBreakpointAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2012 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 @@ -56,7 +56,7 @@ public abstract class RulerBreakpointAction extends Action { * @return breakpoint associated with activity in the ruler or null */ protected IBreakpoint getBreakpoint() { - IAnnotationModel annotationModel = fEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput()); + IAnnotationModel annotationModel = fEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput()); IDocument document = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()); if (annotationModel != null) { Iterator iterator = annotationModel.getAnnotationIterator(); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerBreakpointTypesActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerBreakpointTypesActionDelegate.java index f3fa71d..ee4083d 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerBreakpointTypesActionDelegate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerBreakpointTypesActionDelegate.java @@ -68,7 +68,7 @@ import org.eclipse.ui.texteditor.ITextEditorExtension; * Clients may refer to this class as an action delegate in plug-in XML. This class * is not intended to be subclassed. *

- * @see ToggleBreakpointsTargetManager + * @see IToggleBreakpointsTargetManager * @see IToggleBreakpointsTargetFactory * @noextend This class is not intended to be subclassed by clients. * @since 3.5 diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ToggleBreakpointAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ToggleBreakpointAction.java index 4d85011..30624bd 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ToggleBreakpointAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ToggleBreakpointAction.java @@ -14,8 +14,8 @@ package org.eclipse.debug.ui.actions; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.actions.ActionMessages; -import org.eclipse.debug.internal.ui.actions.IToggleBreakpointsTargetManagerListener; import org.eclipse.debug.internal.ui.actions.ToggleBreakpointsTargetManager; +import org.eclipse.debug.ui.DebugUITools; import org.eclipse.jface.action.Action; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; @@ -70,7 +70,7 @@ public class ToggleBreakpointAction extends Action implements IUpdate { fPart = part; fDocument = document; fRulerInfo = rulerInfo; - ToggleBreakpointsTargetManager.getDefault().addChangedListener(fListener); + DebugUITools.getToggleBreakpointsTargetManager().addChangedListener(fListener); } /* @@ -101,7 +101,7 @@ public class ToggleBreakpointAction extends Action implements IUpdate { if(line > -1) { try { ITextSelection selection = getTextSelection(document, line); - IToggleBreakpointsTarget target = ToggleBreakpointsTargetManager.getDefault().getToggleBreakpointsTarget(fPart, selection); + IToggleBreakpointsTarget target = DebugUITools.getToggleBreakpointsTargetManager().getToggleBreakpointsTarget(fPart, selection); if (target != null) { if(target instanceof IToggleBreakpointsTargetExtension2) { IToggleBreakpointsTargetExtension2 ext = (IToggleBreakpointsTargetExtension2) target; @@ -153,7 +153,7 @@ public class ToggleBreakpointAction extends Action implements IUpdate { fDocument = null; fPart = null; fRulerInfo = null; - ToggleBreakpointsTargetManager.getDefault().removeChangedListener(fListener); + DebugUITools.getToggleBreakpointsTargetManager().removeChangedListener(fListener); } /** -- 1.7.5.4