1) Fixed issue #776.
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.ui / src / net / sourceforge / phpeclipse / xdebug / ui / actions / RulerEnableDisableXDebugBreakpointAction.java
1 /*******************************************************************************
2  * Copyright (c) 2005, 2008 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  *     PHPEclipse team
11  *     Mauro "Incastrix" Casciari
12  *******************************************************************************/
13 package net.sourceforge.phpeclipse.xdebug.ui.actions;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.debug.core.model.IBreakpoint;
17 import net.sourceforge.phpeclipse.xdebug.ui.XDebugUIPlugin;
18 import org.eclipse.debug.ui.actions.RulerBreakpointAction;
19 import org.eclipse.jface.text.source.IVerticalRulerInfo;
20 import org.eclipse.ui.texteditor.ITextEditor;
21 import org.eclipse.ui.texteditor.IUpdate;
22
23 /**
24  * @since 3.2
25  *
26  */
27 public class RulerEnableDisableXDebugBreakpointAction extends RulerBreakpointAction implements IUpdate {
28         private static final String ENABLE_XDEBUG_BREAKPOINT_LABEL = "EnableXDebugBreakpoint.label"; //$NON-NLS-1$
29         private static final String DISABLE_XDEBUG_BREAKPOINT_LABEL = "DisableXDebugBreakpoint.label"; //$NON-NLS-1$
30         private static final String RULER_ENABLE_EDISABLE_BREAKPOINT_ACTION_0 = "RulerEnableDisableBreakpointAction_0"; //$NON-NLS-1$
31         private static final String RULER_ENABLE_EDISABLE_BREAKPOINT_ACTION_1 = "RulerEnableDisableBreakpointAction_1"; //$NON-NLS-1$
32
33         private IBreakpoint fBreakpoint;
34         
35         public RulerEnableDisableXDebugBreakpointAction(ITextEditor editor, IVerticalRulerInfo info) {
36                 super(editor, info);
37         }
38
39         /* (non-Javadoc)
40          * @see org.eclipse.jface.action.Action#run()
41          */
42         public void run() {
43                 if (fBreakpoint != null) {
44                         try {
45                                 fBreakpoint.setEnabled(!fBreakpoint.isEnabled());
46                         } catch (CoreException e) {
47                                 XDebugUIPlugin.errorDialog(getEditor().getSite().getShell(), XDebugUIPlugin.getString(RULER_ENABLE_EDISABLE_BREAKPOINT_ACTION_0), XDebugUIPlugin.getString(RULER_ENABLE_EDISABLE_BREAKPOINT_ACTION_1), e.getStatus());
48                         }
49                 }
50         }
51
52         /* (non-Javadoc)
53          * @see org.eclipse.ui.texteditor.IUpdate#update()
54          */
55         public void update() {
56                 fBreakpoint = getBreakpoint();
57                 setEnabled(fBreakpoint != null);
58                 if (fBreakpoint != null) {
59                         try {
60                                 if (fBreakpoint.isEnabled()) {
61                                         setText(XDebugUIPlugin.getString(DISABLE_XDEBUG_BREAKPOINT_LABEL));
62                                 } else {
63                                         setText(XDebugUIPlugin.getString(ENABLE_XDEBUG_BREAKPOINT_LABEL));
64                                 }
65                         } catch (CoreException e) {
66                         }
67                 } else {
68                         setText(XDebugUIPlugin.getString(ENABLE_XDEBUG_BREAKPOINT_LABEL));
69                 }
70         }
71
72 }