KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > ui > actions > RulerToggleBreakpointActionDelegate


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.ui.actions;
12
13 import org.eclipse.swt.widgets.Event;
14
15 import org.eclipse.jface.action.IAction;
16
17 import org.eclipse.jface.text.source.IVerticalRulerInfo;
18
19 import org.eclipse.ui.IActionDelegate2;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.texteditor.AbstractRulerActionDelegate;
22 import org.eclipse.ui.texteditor.ITextEditor;
23
24 /**
25  * Toggles a breakpoint when ruler is double-clicked. This action delegate can be
26  * contributed to an editor with the <code>editorActions</code> extension point.
27  * This action is as a factory that creates another action that performs the
28  * actual breakpoint toggling. The created action acts on the editor's
29  * <code>IToggleBreakpointsTagret</code> to toggle breakpoints.
30  * <p>
31  * Following is example plug-in XML used to contribute this action to an editor.
32  * Note that the label attribute of this action is not displayed in the editor.
33  * Instead, the label of the created action is displayed.
34  * <pre>
35  * &lt;extension point="org.eclipse.ui.editorActions"&gt;
36  * &lt;editorContribution
37  * targetID="example.editor"
38  * id="example.rulerActions"&gt;
39  * &lt;action
40  * label="Not Used"
41  * class="org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate"
42  * style="push"
43  * actionID="RulerDoubleClick"
44  * id="example.doubleClickBreakpointAction"/&gt;
45  * &lt;/editorContribution&gt;
46  * &lt;/extension&gt;
47  * </pre>
48  * </p>
49  * <p>
50  * This action can also be contributed to a vertical ruler context menu via the
51  * <code>popupMenus</code> extension point, by referencing the ruler's context
52  * menu identifier in the <code>targetID</code> attribute.
53  * <pre>
54  * &lt;extension point="org.eclipse.ui.popupMenus"&gt;
55  * &lt;viewerContribution
56  * targetID="example.rulerContextMenuId"
57  * id="example.RulerPopupActions"&gt;
58  * &lt;action
59  * label="Toggle Breakpoint"
60  * class="org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate"
61  * menubarPath="additions"
62  * id="example.rulerContextMenu.toggleBreakpointAction"&gt;
63  * &lt;/action&gt;
64  * &lt;/viewerContribution&gt;
65  * </pre>
66  * </p>
67  * <p>
68  * Clients may refer to this class as an action delegate in plug-in XML. This class
69  * is not intended to be subclassed.
70  * </p>
71  * @since 3.1
72  */

73 public class RulerToggleBreakpointActionDelegate extends AbstractRulerActionDelegate implements IActionDelegate2 {
74     
75     private IEditorPart fEditor = null;
76     private ToggleBreakpointAction fDelegate = null;
77
78     /* (non-Javadoc)
79      * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.source.IVerticalRulerInfo)
80      */

81     protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) {
82         fDelegate = new ToggleBreakpointAction(editor, null, rulerInfo);
83         return fDelegate;
84     }
85
86     /* (non-Javadoc)
87      * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
88      */

89     public void setActiveEditor(IAction callerAction, IEditorPart targetEditor) {
90         if (fEditor != null) {
91             if (fDelegate != null) {
92                 fDelegate.dispose();
93                 fDelegate = null;
94             }
95         }
96         fEditor = targetEditor;
97         super.setActiveEditor(callerAction, targetEditor);
98     }
99
100     /* (non-Javadoc)
101      * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
102      */

103     public void init(IAction action) {
104     }
105
106     /* (non-Javadoc)
107      * @see org.eclipse.ui.IActionDelegate2#dispose()
108      */

109     public void dispose() {
110         if (fDelegate != null) {
111             fDelegate.dispose();
112         }
113         fDelegate = null;
114         fEditor = null;
115     }
116
117     /* (non-Javadoc)
118      * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
119      */

120     public void runWithEvent(IAction action, Event event) {
121         run(action);
122     }
123 }
124
Popular Tags