Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Piech2012-03-02 00:40:30 -0500
committerPawel Piech2012-03-02 00:44:40 -0500
commit3c08aeeb1e0759e8fc8bca29a20e7d5ae79d504e (patch)
tree565fdb9d4003cc7ab67c229326803c941ad6f4c7 /org.eclipse.debug.ui/ui/org/eclipse/debug/ui
parentb8a6d681c35fc32520e868052315e993b782c7ec (diff)
downloadeclipse.platform.debug-3c08aeeb1e0759e8fc8bca29a20e7d5ae79d504e.tar.gz
eclipse.platform.debug-3c08aeeb1e0759e8fc8bca29a20e7d5ae79d504e.tar.xz
eclipse.platform.debug-3c08aeeb1e0759e8fc8bca29a20e7d5ae79d504e.zip
Bug 373030 - [breakpoints] Make BreakpointTypesContribution to a public package
Diffstat (limited to 'org.eclipse.debug.ui/ui/org/eclipse/debug/ui')
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/BreakpointTypesContribution.java153
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerBreakpointTypesActionDelegate.java3
2 files changed, 156 insertions, 0 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/BreakpointTypesContribution.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/BreakpointTypesContribution.java
new file mode 100644
index 000000000..dec47e0cd
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/BreakpointTypesContribution.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.debug.internal.ui.actions.ToggleBreakpointsTargetManager;
+import org.eclipse.debug.internal.ui.actions.breakpoints.Messages;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.ui.IPartService;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.actions.CompoundContributionItem;
+import org.eclipse.ui.menus.IWorkbenchContribution;
+import org.eclipse.ui.services.IServiceLocator;
+
+/**
+ * Breakpoint ruler pop-up action that creates a sub-menu to select the currently
+ * active breakpoint type. This menu contribution can be added to an editor
+ * with the <code>org.eclipse.ui.menus</code> extension point. The breakpoint
+ * types are calculated based on the toggle breakpoint target factories
+ * contributed through the <code>toggleBreakpointsTargetFactories</code> extension point.
+ * <p>
+ * Following is example plug-in XML used to contribute this action to an editor's
+ * vertical ruler context menu.
+ * <pre>
+ * &lt;extension point="org.eclipse.ui.menus"&gt;
+ * &lt;menuContribution
+ * locationURI="popup:#CEditorRulerContext?after=additions"
+ * id="example.RulerPopupActions"&gt;
+ * &lt;menu\
+ * id="breakpointTypes"
+ * label="Toggle Breakpoint"&gt;
+ * &lt;dynamic\
+ * id="example.rulerContextMenu.breakpointTypesAction"&gt;
+ * class="org.eclipse.debug.ui.actions.BreakpointTypesContribution"
+ * menubarPath="additions"&gt;/
+ * &lt;/menu&gt;
+ * &lt;/menuContribution&gt;
+ * </pre>
+ * </p>
+ * <p>
+ * Clients may refer to this class in plug-in XML. This class
+ * is not intended to be subclassed.
+ * </p>
+ * @since 3.8
+ * @noextend
+ */
+public class BreakpointTypesContribution extends CompoundContributionItem implements IWorkbenchContribution {
+
+ private class SelectTargetAction extends Action {
+ private final Set fPossibleIDs;
+ private final String fID;
+ SelectTargetAction(String name, Set possibleIDs, String ID) {
+ super(name, AS_RADIO_BUTTON);
+ fID = ID;
+ fPossibleIDs = possibleIDs;
+ }
+
+ public void run() {
+ if (isChecked()) {
+ // Note: setPreferredTarget is not declared on the
+ // IToggleBreakpontsTargetManager interface.
+ ToggleBreakpointsTargetManager.getDefault().setPreferredTarget(fPossibleIDs, fID);
+ }
+ }
+ }
+
+ private IServiceLocator fServiceLocator;
+
+ private static IContributionItem[] NO_BREAKPOINT_TYPES_CONTRIBUTION_ITEMS = new IContributionItem[] {
+ new ContributionItem() {
+ public void fill(Menu menu, int index) {
+ MenuItem item = new MenuItem(menu, SWT.NONE);
+ item.setEnabled(false);
+ item.setText(Messages.BreakpointTypesContribution_0);
+ }
+
+ public boolean isEnabled() {
+ return false;
+ }
+ }
+ };
+
+ protected IContributionItem[] getContributionItems() {
+ IWorkbenchPart part = null;
+ ISelection selection = null;
+
+ ISelectionService selectionService =
+ (ISelectionService)fServiceLocator.getService(ISelectionService.class);
+ if (selectionService != null) {
+ selection = selectionService.getSelection();
+ }
+ IPartService partService = (IPartService)fServiceLocator.getService(IPartService.class);
+ if (partService != null) {
+ part = partService.getActivePart();
+ }
+
+ // If no part or selection, disable all.
+ if (part == null || selection == null) {
+ return NO_BREAKPOINT_TYPES_CONTRIBUTION_ITEMS;
+ }
+
+ // Get breakpoint toggle target IDs.
+ IToggleBreakpointsTargetManager manager = DebugUITools.getToggleBreakpointsTargetManager();
+ Set enabledIDs = manager.getEnabledToggleBreakpointsTargetIDs(part, selection);
+ String preferredId = manager.getPreferredToggleBreakpointsTargetID(part, selection);
+
+ List actions = new ArrayList(enabledIDs.size());
+ for (Iterator i = enabledIDs.iterator(); i.hasNext();) {
+ String id = (String) i.next();
+ Action action = new SelectTargetAction(manager.getToggleBreakpointsTargetName(id), enabledIDs, id);
+ if (id.equals(preferredId)) {
+ action.setChecked(true);
+ }
+ actions.add(action);
+ }
+
+ if ( enabledIDs.isEmpty() ) {
+ return NO_BREAKPOINT_TYPES_CONTRIBUTION_ITEMS;
+ }
+
+ IContributionItem[] items = new IContributionItem[enabledIDs.size()];
+ for (int i = 0; i < actions.size(); i++) {
+ items[i] = new ActionContributionItem((Action) actions.get(i));
+ }
+ return items;
+ }
+
+ public void initialize(IServiceLocator serviceLocator) {
+ fServiceLocator = serviceLocator;
+ }
+
+}
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 ee4083dad..a6ff4db4d 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
@@ -73,6 +73,7 @@ import org.eclipse.ui.texteditor.ITextEditorExtension;
* @noextend This class is not intended to be subclassed by clients.
* @since 3.5
*
+ * @deprecated Should use BreakpointTypesContribution instead.
*/
public class RulerBreakpointTypesActionDelegate implements IEditorActionDelegate, IMenuListener, IMenuCreator {
private ITextEditor fEditor = null;
@@ -150,6 +151,7 @@ public class RulerBreakpointTypesActionDelegate implements IEditorActionDelegate
}
public void menuAboutToShow(IMenuManager manager) {
+ System.out.println("about to show");
fSelection = StructuredSelection.EMPTY;
if (fEditor != null && fRulerInfo != null) {
@@ -166,6 +168,7 @@ public class RulerBreakpointTypesActionDelegate implements IEditorActionDelegate
}
ToggleBreakpointsTargetManager toggleTargetManager = ToggleBreakpointsTargetManager.getDefault();
Set enabledIDs = toggleTargetManager.getEnabledToggleBreakpointsTargetIDs(fEditor, fSelection);
+ System.out.println(enabledIDs.toString());
fCallerAction.setEnabled(enabledIDs.size() > 0);
} else {
fCallerAction.setEnabled(false);

Back to the top