KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > EnableDisableBreakpointRulerAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.debug.ui.actions;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.core.runtime.jobs.Job;
18 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
19 import org.eclipse.jface.dialogs.ErrorDialog;
20 import org.eclipse.jface.text.source.IVerticalRulerInfo;
21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.ui.texteditor.ITextEditor;
23
24 public class EnableDisableBreakpointRulerAction extends AbstractBreakpointRulerAction {
25
26     /**
27      * Creates the action to enable/disable breakpoints
28      */

29     public EnableDisableBreakpointRulerAction(ITextEditor editor, IVerticalRulerInfo info) {
30         setInfo(info);
31         setTextEditor(editor);
32         setText(ActionMessages.EnableDisableBreakpointRulerAction__Enable_Breakpoint_1); //$NON-NLS-1$
33
}
34
35     /**
36      * @see Action#run()
37      */

38     public void run() {
39         if (getBreakpoint() != null) {
40             new Job(ActionMessages.EnableDisableBreakpointRulerAction_0) { //$NON-NLS-1$
41
protected IStatus run(IProgressMonitor monitor) {
42                     try {
43                         getBreakpoint().setEnabled(!getBreakpoint().isEnabled());
44                         return Status.OK_STATUS;
45                     } catch (final CoreException e) {
46                         Display.getDefault().asyncExec(new Runnable JavaDoc(){
47                             public void run() {
48                                 ErrorDialog.openError(getTextEditor().getEditorSite().getShell(), ActionMessages.EnableDisableBreakpointRulerAction_Enabling_disabling_breakpoints_2, ActionMessages.EnableDisableBreakpointRulerAction_Exceptions_occurred_enabling_disabling_the_breakpoint_3, e.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$
49
}
50                         });
51                     }
52                     return Status.CANCEL_STATUS;
53                 }
54             }.schedule();
55         }
56     }
57
58     /**
59      * @see IUpdate#update()
60      */

61     public void update() {
62         setBreakpoint(determineBreakpoint());
63         if (getBreakpoint() == null) {
64             setEnabled(false);
65             return;
66         }
67         setEnabled(true);
68         try {
69             boolean enabled = getBreakpoint().isEnabled();
70             setText(enabled ? ActionMessages.EnableDisableBreakpointRulerAction__Disable_Breakpoint_4 : ActionMessages.EnableDisableBreakpointRulerAction__Enable_Breakpoint_5); //$NON-NLS-1$ //$NON-NLS-2$
71
} catch (CoreException ce) {
72             JDIDebugUIPlugin.log(ce);
73         }
74     }
75 }
76
Popular Tags