KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > propertypages > JavaLineBreakpointPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.propertypages;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.jdt.core.IMember;
15 import org.eclipse.jdt.debug.core.IJavaLineBreakpoint;
16 import org.eclipse.jdt.debug.core.IJavaMethodBreakpoint;
17 import org.eclipse.jdt.debug.core.IJavaWatchpoint;
18 import org.eclipse.jdt.internal.debug.ui.BreakpointUtils;
19 import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds;
20 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
21 import org.eclipse.jdt.internal.debug.ui.SWTFactory;
22 import org.eclipse.jface.bindings.TriggerSequence;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.events.SelectionAdapter;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.widgets.Button;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Label;
30 import org.eclipse.swt.widgets.Text;
31 import org.eclipse.ui.PlatformUI;
32 import org.eclipse.ui.keys.IBindingService;
33 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
34
35 import com.ibm.icu.text.MessageFormat;
36
37 /**
38  * Property page for editing breakpoints of type
39  * <code>org.eclipse.jdt.debug.core.IJavaLineBreakpoint</code>.
40  */

41 public class JavaLineBreakpointPage extends JavaBreakpointPage {
42     
43     private Button fEnableConditionButton;
44     private BreakpointConditionEditor fConditionEditor;
45     private Button fConditionIsTrue;
46     private Button fConditionHasChanged;
47     private Label fSuspendWhenLabel;
48     // Watchpoint editors
49
private Button fFieldAccess;
50     private Button fFieldModification;
51     // Method breakpoint editors
52
private Button fMethodEntry;
53     private Button fMethodExit;
54     
55     private static final String JavaDoc fgWatchpointError = PropertyPageMessages.JavaLineBreakpointPage_0;
56     private static final String JavaDoc fgMethodBreakpointError = PropertyPageMessages.JavaLineBreakpointPage_1;
57
58     /* (non-Javadoc)
59      * @see org.eclipse.jdt.internal.debug.ui.propertypages.JavaBreakpointPage#doStore()
60      */

61     protected void doStore() throws CoreException {
62         IJavaLineBreakpoint breakpoint= (IJavaLineBreakpoint) getBreakpoint();
63         super.doStore();
64         if (fConditionEditor != null) {
65             boolean enableCondition = fEnableConditionButton.getSelection();
66             String JavaDoc condition = fConditionEditor.getCondition();
67             boolean suspendOnTrue= fConditionIsTrue.getSelection();
68             if (breakpoint.isConditionEnabled() != enableCondition) {
69                 breakpoint.setConditionEnabled(enableCondition);
70             }
71             if (!condition.equals(breakpoint.getCondition())) {
72                 breakpoint.setCondition(condition);
73             }
74             if (breakpoint.isConditionSuspendOnTrue() != suspendOnTrue) {
75                 breakpoint.setConditionSuspendOnTrue(suspendOnTrue);
76             }
77         }
78         if (breakpoint instanceof IJavaWatchpoint) {
79             IJavaWatchpoint watchpoint= (IJavaWatchpoint) getBreakpoint();
80             boolean access = fFieldAccess.getSelection();
81             boolean modification = fFieldModification.getSelection();
82             if (access != watchpoint.isAccess()) {
83                 watchpoint.setAccess(access);
84             }
85             if (modification != watchpoint.isModification()) {
86                 watchpoint.setModification(modification);
87             }
88         }
89         if (breakpoint instanceof IJavaMethodBreakpoint) {
90             IJavaMethodBreakpoint methodBreakpoint= (IJavaMethodBreakpoint) getBreakpoint();
91             boolean entry = fMethodEntry.getSelection();
92             boolean exit = fMethodExit.getSelection();
93             if (entry != methodBreakpoint.isEntry()) {
94                 methodBreakpoint.setEntry(entry);
95             }
96             if (exit != methodBreakpoint.isExit()) {
97                 methodBreakpoint.setExit(exit);
98             }
99         }
100     }
101
102     /* (non-Javadoc)
103      * @see org.eclipse.jdt.internal.debug.ui.propertypages.JavaBreakpointPage#createTypeSpecificLabels(org.eclipse.swt.widgets.Composite)
104      */

105     protected void createTypeSpecificLabels(Composite parent) {
106         // Line number
107
IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) getBreakpoint();
108         StringBuffer JavaDoc lineNumber = new StringBuffer JavaDoc(4);
109         try {
110             int lNumber = breakpoint.getLineNumber();
111             if (lNumber > 0) {
112                 lineNumber.append(lNumber);
113             }
114         } catch (CoreException ce) {
115             JDIDebugUIPlugin.log(ce);
116         }
117         if (lineNumber.length() > 0) {
118             createLabel(parent, PropertyPageMessages.JavaLineBreakpointPage_2);
119             Text text = SWTFactory.createText(parent, SWT.READ_ONLY, 1, lineNumber.toString());
120             text.setBackground(parent.getBackground());
121         }
122         // Member
123
try {
124             IMember member = BreakpointUtils.getMember(breakpoint);
125             if (member == null) {
126                 return;
127             }
128             String JavaDoc label = PropertyPageMessages.JavaLineBreakpointPage_3;
129             if (breakpoint instanceof IJavaMethodBreakpoint) {
130                 label = PropertyPageMessages.JavaLineBreakpointPage_4;
131             } else if (breakpoint instanceof IJavaWatchpoint) {
132                 label = PropertyPageMessages.JavaLineBreakpointPage_5;
133             }
134             createLabel(parent, label);
135             Text text = SWTFactory.createText(parent, SWT.READ_ONLY, 1, fJavaLabelProvider.getText(member));
136             text.setBackground(parent.getBackground());
137         }
138         catch (CoreException exception) {JDIDebugUIPlugin.log(exception);}
139     }
140     
141     /**
142      * Create the condition editor and associated editors.
143      * @see org.eclipse.jdt.internal.debug.ui.propertypages.JavaBreakpointPage#createTypeSpecificEditors(org.eclipse.swt.widgets.Composite)
144      */

145     protected void createTypeSpecificEditors(Composite parent) throws CoreException {
146         setTitle(PropertyPageMessages.JavaLineBreakpointPage_18);
147         IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) getBreakpoint();
148         if (breakpoint.supportsCondition()) {
149             createConditionEditor(parent);
150         }
151         if (breakpoint instanceof IJavaWatchpoint) {
152             setTitle(PropertyPageMessages.JavaLineBreakpointPage_19);
153             IJavaWatchpoint watchpoint= (IJavaWatchpoint) getBreakpoint();
154             SelectionAdapter watchpointValidator= new SelectionAdapter() {
155                 public void widgetSelected(SelectionEvent e) {
156                     validateWatchpoint();
157                 }
158             };
159             createLabel(parent, PropertyPageMessages.JavaLineBreakpointPage_6);
160             fEnabledButton.addSelectionListener(watchpointValidator);
161             fFieldAccess = createCheckButton(parent, PropertyPageMessages.JavaLineBreakpointPage_7);
162             fFieldAccess.setSelection(watchpoint.isAccess());
163             fFieldAccess.addSelectionListener(watchpointValidator);
164             fFieldModification = createCheckButton(parent, PropertyPageMessages.JavaLineBreakpointPage_8);
165             fFieldModification.setSelection(watchpoint.isModification());
166             fFieldModification.addSelectionListener(watchpointValidator);
167         }
168         if (breakpoint instanceof IJavaMethodBreakpoint) {
169             setTitle(PropertyPageMessages.JavaLineBreakpointPage_20);
170             IJavaMethodBreakpoint methodBreakpoint = (IJavaMethodBreakpoint) getBreakpoint();
171             SelectionAdapter methodBreakpointValidator= new SelectionAdapter() {
172                 public void widgetSelected(SelectionEvent e) {
173                     validateMethodBreakpoint();
174                 }
175             };
176             createLabel(parent, PropertyPageMessages.JavaLineBreakpointPage_9);
177             fEnabledButton.addSelectionListener(methodBreakpointValidator);
178             fMethodEntry = createCheckButton(parent, PropertyPageMessages.JavaLineBreakpointPage_10);
179             fMethodEntry.setSelection(methodBreakpoint.isEntry());
180             fMethodEntry.addSelectionListener(methodBreakpointValidator);
181             fMethodExit = createCheckButton(parent, PropertyPageMessages.JavaLineBreakpointPage_11);
182             fMethodExit.setSelection(methodBreakpoint.isExit());
183             fMethodExit.addSelectionListener(methodBreakpointValidator);
184         }
185     }
186     
187     /**
188      * Validates the watchpoint...if we are one
189      */

190     private void validateWatchpoint() {
191         if (fEnabledButton.getSelection() && !(fFieldAccess.getSelection() || fFieldModification.getSelection())) {
192             addErrorMessage(fgWatchpointError);
193         }
194         else {
195             removeErrorMessage(fgWatchpointError);
196         }
197     }
198     
199     /**
200      * Validates the method breakpoint, if we are one
201      */

202     private void validateMethodBreakpoint() {
203         boolean valid = true;
204         if (fEnabledButton.getSelection() && !(fMethodEntry.getSelection() || fMethodExit.getSelection())) {
205             setErrorMessage(fgMethodBreakpointError);
206             valid = false;
207         }
208         else {
209             setErrorMessage(null);
210         }
211         setValid(valid);
212     }
213     
214     /**
215      * Creates the controls that allow the user to specify the breakpoint's
216      * condition
217      * @param parent the composite in which the condition editor should be created
218      * @throws CoreException if an exception occurs accessing the breakpoint
219      */

220     private void createConditionEditor(Composite parent) throws CoreException {
221         IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) getBreakpoint();
222         String JavaDoc label = null;
223         if (BreakpointUtils.getType(breakpoint) != null) {
224             IBindingService bindingService = (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class);
225             if(bindingService != null) {
226                 TriggerSequence keyBinding = bindingService.getBestActiveBindingFor(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
227                 if (keyBinding != null) {
228                     label = MessageFormat.format(PropertyPageMessages.JavaLineBreakpointPage_12, new String JavaDoc[] {keyBinding.format()});
229                 }
230             }
231         }
232         if (label == null) {
233             label = PropertyPageMessages.JavaLineBreakpointPage_13;
234         }
235         
236         Composite conditionComposite = SWTFactory.createGroup(parent, EMPTY_STRING, 1, 1, GridData.FILL_BOTH);
237         fEnableConditionButton = createCheckButton(conditionComposite, label);
238         fEnableConditionButton.setSelection(breakpoint.isConditionEnabled());
239         fEnableConditionButton.addSelectionListener(new SelectionAdapter() {
240             public void widgetSelected(SelectionEvent e) {
241                 setConditionEnabled(fEnableConditionButton.getSelection());
242             }
243         });
244         fConditionEditor = new BreakpointConditionEditor(conditionComposite, this);
245         fSuspendWhenLabel = createLabel(conditionComposite, PropertyPageMessages.JavaLineBreakpointPage_15);
246         fConditionIsTrue = createRadioButton(conditionComposite, PropertyPageMessages.JavaLineBreakpointPage_16);
247         fConditionHasChanged = createRadioButton(conditionComposite, PropertyPageMessages.JavaLineBreakpointPage_17);
248         if (breakpoint.isConditionSuspendOnTrue()) {
249             fConditionIsTrue.setSelection(true);
250         }
251         else {
252             fConditionHasChanged.setSelection(true);
253         }
254         setConditionEnabled(fEnableConditionButton.getSelection());
255     }
256
257     /**
258      * Sets the enabled state of the condition editing controls.
259      * @param enabled
260      */

261     private void setConditionEnabled(boolean enabled) {
262         fConditionEditor.setEnabled(enabled);
263         fSuspendWhenLabel.setEnabled(enabled);
264         fConditionIsTrue.setEnabled(enabled);
265         fConditionHasChanged.setEnabled(enabled);
266     }
267     
268     /* (non-Javadoc)
269      * @see org.eclipse.jface.dialogs.DialogPage#convertHeightInCharsToPixels(int)
270      */

271     public int convertHeightInCharsToPixels(int chars) {
272         return super.convertHeightInCharsToPixels(chars);
273     }
274     
275     /* (non-Javadoc)
276      * @see org.eclipse.jface.dialogs.DialogPage#convertWidthInCharsToPixels(int)
277      */

278     public int convertWidthInCharsToPixels(int chars) {
279         return super.convertWidthInCharsToPixels(chars);
280     }
281
282     /* (non-Javadoc)
283      * @see org.eclipse.jface.dialogs.IDialogPage#dispose()
284      */

285     public void dispose() {
286         if (fConditionEditor != null) {
287             fConditionEditor.dispose();
288         }
289         super.dispose();
290     }
291     
292     /* (non-Javadoc)
293      * @see org.eclipse.jface.preference.PreferencePage#createControl(org.eclipse.swt.widgets.Composite)
294      */

295     public void createControl(Composite parent) {
296         super.createControl(parent);
297         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.JAVA_LINE_BREAKPOINT_PROPERTY_PAGE);
298     }
299 }
300
Popular Tags