KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > JavaDebugPreferencePage


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;
12
13  
14 import org.eclipse.core.runtime.Preferences;
15 import org.eclipse.jdt.debug.core.IJavaBreakpoint;
16 import org.eclipse.jdt.debug.core.JDIDebugModel;
17 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
18 import org.eclipse.jdt.launching.JavaRuntime;
19 import org.eclipse.jface.preference.FieldEditor;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.jface.preference.IntegerFieldEditor;
22 import org.eclipse.jface.preference.PreferencePage;
23 import org.eclipse.jface.preference.StringFieldEditor;
24 import org.eclipse.jface.util.IPropertyChangeListener;
25 import org.eclipse.jface.util.PropertyChangeEvent;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.layout.GridData;
28 import org.eclipse.swt.widgets.Button;
29 import org.eclipse.swt.widgets.Combo;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Group;
33 import org.eclipse.ui.IWorkbench;
34 import org.eclipse.ui.IWorkbenchPreferencePage;
35 import org.eclipse.ui.PlatformUI;
36 import org.eclipse.ui.dialogs.PreferenceLinkArea;
37 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
38
39 import com.ibm.icu.text.MessageFormat;
40
41 /**
42  * Preference page for debug preferences that apply specifically to
43  * Java Debugging.
44  */

45 public class JavaDebugPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, IPropertyChangeListener {
46     
47     /**
48      * This class exists to provide visibility to the
49      * <code>refreshValidState</code> method and to perform more intelligent
50      * clearing of the error message.
51      */

52     protected class JavaDebugIntegerFieldEditor extends IntegerFieldEditor {
53         
54         public JavaDebugIntegerFieldEditor(String JavaDoc name, String JavaDoc labelText, Composite parent) {
55             super(name, labelText, parent);
56         }
57
58         protected void refreshValidState() {
59             super.refreshValidState();
60         }
61
62         protected void clearErrorMessage() {
63             if (canClearErrorMessage()) {
64                 super.clearErrorMessage();
65             }
66         }
67     }
68     
69     // Suspend preference widgets
70
private Button fSuspendButton;
71     private Button fSuspendOnCompilationErrors;
72     private Button fSuspendDuringEvaluations;
73     private Button fOpenInspector;
74     private Button fPromptUnableToInstallBreakpoint;
75     private Combo fSuspendVMorThread;
76     
77     // Hot code replace preference widgets
78
private Button fAlertHCRButton;
79     private Button fAlertHCRNotSupportedButton;
80     private Button fAlertObsoleteButton;
81     private Button fPerformHCRWithCompilationErrors;
82     // Timeout preference widgets
83
private JavaDebugIntegerFieldEditor fTimeoutText;
84     private JavaDebugIntegerFieldEditor fConnectionTimeoutText;
85
86     public JavaDebugPreferencePage() {
87         super();
88         setPreferenceStore(JDIDebugUIPlugin.getDefault().getPreferenceStore());
89         setDescription(DebugUIMessages.JavaDebugPreferencePage_description);
90     }
91
92     /* (non-Javadoc)
93      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
94      */

95     protected Control createContents(Composite parent) {
96         //The main composite
97
Composite composite = SWTFactory.createComposite(parent, parent.getFont(), 1, 1, 0, 0, GridData.FILL);
98         new PreferenceLinkArea(composite, SWT.NONE,
99                 "org.eclipse.debug.ui.DebugPreferencePage", DebugUIMessages.JavaDebugPreferencePage_0, //$NON-NLS-1$
100
(IWorkbenchPreferenceContainer) getContainer(),null);
101         
102         Group group = SWTFactory.createGroup(composite, DebugUIMessages.JavaDebugPreferencePage_Suspend_Execution_1, 2, 1, GridData.FILL_HORIZONTAL);
103         fSuspendButton = SWTFactory.createCheckButton(group, DebugUIMessages.JavaDebugPreferencePage_Suspend__execution_on_uncaught_exceptions_1, null, false, 2);
104         fSuspendOnCompilationErrors = SWTFactory.createCheckButton(group, DebugUIMessages.JavaDebugPreferencePage_Suspend_execution_on_co_mpilation_errors_1, null, false, 2);
105         fSuspendDuringEvaluations = SWTFactory.createCheckButton(group, DebugUIMessages.JavaDebugPreferencePage_14, null, false, 2);
106         fOpenInspector = SWTFactory.createCheckButton(group, DebugUIMessages.JavaDebugPreferencePage_20, null, false, 2);
107         
108         SWTFactory.createLabel(group, DebugUIMessages.JavaDebugPreferencePage_21, 1);
109         fSuspendVMorThread = new Combo(group, SWT.BORDER|SWT.READ_ONLY);
110         fSuspendVMorThread.setItems(new String JavaDoc[]{DebugUIMessages.JavaDebugPreferencePage_22, DebugUIMessages.JavaDebugPreferencePage_23});
111             
112         group = SWTFactory.createGroup(composite, DebugUIMessages.JavaDebugPreferencePage_Hot_Code_Replace_2, 1, 1, GridData.FILL_HORIZONTAL);
113         fAlertHCRButton = SWTFactory.createCheckButton(group, DebugUIMessages.JavaDebugPreferencePage_Alert_me_when_hot_code_replace_fails_1, null, false, 1);
114         fAlertHCRNotSupportedButton = SWTFactory.createCheckButton(group, DebugUIMessages.JavaDebugPreferencePage_Alert_me_when_hot_code_replace_is_not_supported_1, null, false, 1);
115         fAlertObsoleteButton = SWTFactory.createCheckButton(group, DebugUIMessages.JavaDebugPreferencePage_Alert_me_when_obsolete_methods_remain_1, null, false, 1);
116         fPerformHCRWithCompilationErrors = SWTFactory.createCheckButton(group, DebugUIMessages.JavaDebugPreferencePage_Replace_classfiles_containing_compilation_errors_1, null, false, 1);
117
118         group = SWTFactory.createGroup(composite, DebugUIMessages.JavaDebugPreferencePage_Communication_1, 1, 1, GridData.FILL_HORIZONTAL);
119         Composite space = SWTFactory.createComposite(group, group.getFont(), 1, 1, GridData.FILL_HORIZONTAL);
120         int minValue;
121         Preferences coreStore= JDIDebugModel.getPreferences();
122         Preferences runtimeStore= JavaRuntime.getPreferences();
123         fTimeoutText = new JavaDebugIntegerFieldEditor(JDIDebugModel.PREF_REQUEST_TIMEOUT, DebugUIMessages.JavaDebugPreferencePage_Debugger__timeout__2, space);
124         fTimeoutText.setPage(this);
125         fTimeoutText.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE);
126         minValue= coreStore.getDefaultInt(JDIDebugModel.PREF_REQUEST_TIMEOUT);
127         fTimeoutText.setValidRange(minValue, Integer.MAX_VALUE);
128         fTimeoutText.setErrorMessage(MessageFormat.format(DebugUIMessages.JavaDebugPreferencePage_Value_must_be_a_valid_integer_greater_than__0__ms_1, new Object JavaDoc[] {new Integer JavaDoc(minValue)}));
129         fTimeoutText.load();
130         fConnectionTimeoutText = new JavaDebugIntegerFieldEditor(JavaRuntime.PREF_CONNECT_TIMEOUT, DebugUIMessages.JavaDebugPreferencePage__Launch_timeout__ms___1, space);
131         fConnectionTimeoutText.setPage(this);
132         fConnectionTimeoutText.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE);
133         minValue= runtimeStore.getDefaultInt(JavaRuntime.PREF_CONNECT_TIMEOUT);
134         fConnectionTimeoutText.setValidRange(minValue, Integer.MAX_VALUE);
135         fConnectionTimeoutText.setErrorMessage(MessageFormat.format(DebugUIMessages.JavaDebugPreferencePage_Value_must_be_a_valid_integer_greater_than__0__ms_1, new Object JavaDoc[] {new Integer JavaDoc(minValue)}));
136         fConnectionTimeoutText.load();
137         
138         SWTFactory.createVerticalSpacer(composite, 1);
139         fPromptUnableToInstallBreakpoint = SWTFactory.createCheckButton(composite, DebugUIMessages.JavaDebugPreferencePage_19, null, false, 1);
140         
141         setValues();
142         fTimeoutText.setPropertyChangeListener(this);
143         fConnectionTimeoutText.setPropertyChangeListener(this);
144         applyDialogFont(composite);
145         PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IJavaDebugHelpContextIds.JAVA_DEBUG_PREFERENCE_PAGE);
146         return composite;
147     }
148         
149     /* (non-Javadoc)
150      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
151      */

152     public void init(IWorkbench workbench) {}
153     
154     /* (non-Javadoc)
155      * @see org.eclipse.jface.preference.PreferencePage#performOk()
156      */

157     public boolean performOk() {
158         IPreferenceStore store = getPreferenceStore();
159         Preferences coreStore = JDIDebugModel.getPreferences();
160         Preferences runtimeStore = JavaRuntime.getPreferences();
161         
162         store.setValue(IJDIPreferencesConstants.PREF_SUSPEND_ON_UNCAUGHT_EXCEPTIONS, fSuspendButton.getSelection());
163         store.setValue(IJDIPreferencesConstants.PREF_SUSPEND_ON_COMPILATION_ERRORS, fSuspendOnCompilationErrors.getSelection());
164         coreStore.setValue(JDIDebugModel.PREF_SUSPEND_FOR_BREAKPOINTS_DURING_EVALUATION, fSuspendDuringEvaluations.getSelection());
165         int selectionIndex = fSuspendVMorThread.getSelectionIndex();
166         int policy = IJavaBreakpoint.SUSPEND_THREAD;
167         if (selectionIndex > 0) {
168             policy = IJavaBreakpoint.SUSPEND_VM;
169         }
170         coreStore.setValue(JDIDebugPlugin.PREF_DEFAULT_BREAKPOINT_SUSPEND_POLICY, policy);
171         store.setValue(IJDIPreferencesConstants.PREF_ALERT_HCR_FAILED, fAlertHCRButton.getSelection());
172         store.setValue(IJDIPreferencesConstants.PREF_ALERT_HCR_NOT_SUPPORTED, fAlertHCRNotSupportedButton.getSelection());
173         store.setValue(IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS, fAlertObsoleteButton.getSelection());
174         coreStore.setValue(JDIDebugModel.PREF_HCR_WITH_COMPILATION_ERRORS, fPerformHCRWithCompilationErrors.getSelection());
175         coreStore.setValue(JDIDebugModel.PREF_REQUEST_TIMEOUT, fTimeoutText.getIntValue());
176         runtimeStore.setValue(JavaRuntime.PREF_CONNECT_TIMEOUT, fConnectionTimeoutText.getIntValue());
177         store.setValue(IJDIPreferencesConstants.PREF_ALERT_UNABLE_TO_INSTALL_BREAKPOINT, fPromptUnableToInstallBreakpoint.getSelection());
178         store.setValue(IJDIPreferencesConstants.PREF_OPEN_INSPECT_POPUP_ON_EXCEPTION, fOpenInspector.getSelection());
179         JDIDebugModel.savePreferences();
180         JavaRuntime.savePreferences();
181         return true;
182     }
183     
184     /* (non-Javadoc)
185      * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
186      */

187     protected void performDefaults() {
188         IPreferenceStore store = getPreferenceStore();
189         Preferences coreStore= JDIDebugModel.getPreferences();
190         Preferences runtimeStore= JavaRuntime.getPreferences();
191         
192         fSuspendButton.setSelection(store.getDefaultBoolean(IJDIPreferencesConstants.PREF_SUSPEND_ON_UNCAUGHT_EXCEPTIONS));
193         fSuspendOnCompilationErrors.setSelection(store.getDefaultBoolean(IJDIPreferencesConstants.PREF_SUSPEND_ON_COMPILATION_ERRORS));
194         fSuspendDuringEvaluations.setSelection(coreStore.getDefaultBoolean(JDIDebugModel.PREF_SUSPEND_FOR_BREAKPOINTS_DURING_EVALUATION));
195         int value = coreStore.getDefaultInt(JDIDebugPlugin.PREF_DEFAULT_BREAKPOINT_SUSPEND_POLICY);
196         fSuspendVMorThread.select((value == IJavaBreakpoint.SUSPEND_THREAD) ? 0 : 1);
197         fAlertHCRButton.setSelection(store.getDefaultBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_FAILED));
198         fAlertHCRNotSupportedButton.setSelection(store.getDefaultBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_NOT_SUPPORTED));
199         fAlertObsoleteButton.setSelection(store.getDefaultBoolean(IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS));
200         fPerformHCRWithCompilationErrors.setSelection(coreStore.getDefaultBoolean(JDIDebugModel.PREF_HCR_WITH_COMPILATION_ERRORS));
201         fTimeoutText.setStringValue(new Integer JavaDoc(coreStore.getDefaultInt(JDIDebugModel.PREF_REQUEST_TIMEOUT)).toString());
202         fConnectionTimeoutText.setStringValue(new Integer JavaDoc(runtimeStore.getDefaultInt(JavaRuntime.PREF_CONNECT_TIMEOUT)).toString());
203         fPromptUnableToInstallBreakpoint.setSelection(store.getDefaultBoolean(IJDIPreferencesConstants.PREF_ALERT_UNABLE_TO_INSTALL_BREAKPOINT));
204         fOpenInspector.setSelection(store.getDefaultBoolean(IJDIPreferencesConstants.PREF_OPEN_INSPECT_POPUP_ON_EXCEPTION));
205         super.performDefaults();
206     }
207     
208     /**
209      * Set the values of the component widgets based on the
210      * values in the preference store
211      */

212     private void setValues() {
213         IPreferenceStore store = getPreferenceStore();
214         Preferences coreStore = JDIDebugModel.getPreferences();
215         Preferences runtimeStore = JavaRuntime.getPreferences();
216         
217         fSuspendButton.setSelection(store.getBoolean(IJDIPreferencesConstants.PREF_SUSPEND_ON_UNCAUGHT_EXCEPTIONS));
218         fSuspendOnCompilationErrors.setSelection(store.getBoolean(IJDIPreferencesConstants.PREF_SUSPEND_ON_COMPILATION_ERRORS));
219         fSuspendDuringEvaluations.setSelection(coreStore.getBoolean(JDIDebugModel.PREF_SUSPEND_FOR_BREAKPOINTS_DURING_EVALUATION));
220         int value = coreStore.getInt(JDIDebugPlugin.PREF_DEFAULT_BREAKPOINT_SUSPEND_POLICY);
221         fSuspendVMorThread.select((value == IJavaBreakpoint.SUSPEND_THREAD ? 0 : 1));
222         fAlertHCRButton.setSelection(store.getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_FAILED));
223         fAlertHCRNotSupportedButton.setSelection(store.getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_NOT_SUPPORTED));
224         fAlertObsoleteButton.setSelection(store.getBoolean(IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS));
225         fPerformHCRWithCompilationErrors.setSelection(coreStore.getBoolean(JDIDebugModel.PREF_HCR_WITH_COMPILATION_ERRORS));
226         fTimeoutText.setStringValue(new Integer JavaDoc(coreStore.getInt(JDIDebugModel.PREF_REQUEST_TIMEOUT)).toString());
227         fConnectionTimeoutText.setStringValue(new Integer JavaDoc(runtimeStore.getInt(JavaRuntime.PREF_CONNECT_TIMEOUT)).toString());
228         fPromptUnableToInstallBreakpoint.setSelection(store.getBoolean(IJDIPreferencesConstants.PREF_ALERT_UNABLE_TO_INSTALL_BREAKPOINT));
229         fOpenInspector.setSelection(store.getBoolean(IJDIPreferencesConstants.PREF_OPEN_INSPECT_POPUP_ON_EXCEPTION));
230     }
231
232     /* (non-Javadoc)
233      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
234      */

235     public void propertyChange(PropertyChangeEvent event) {
236         if (event.getProperty().equals(FieldEditor.IS_VALID)) {
237             boolean newValue = ((Boolean JavaDoc) event.getNewValue()).booleanValue();
238             // If the new value is true then we must check all field editors.
239
// If it is false, then the page is invalid in any case.
240
if (newValue) {
241                 if (fTimeoutText != null && event.getSource() != fTimeoutText) {
242                     fTimeoutText.refreshValidState();
243                 }
244                 if (fConnectionTimeoutText != null && event.getSource() != fConnectionTimeoutText) {
245                     fConnectionTimeoutText.refreshValidState();
246                 }
247             }
248             setValid(fTimeoutText.isValid() && fConnectionTimeoutText.isValid());
249             getContainer().updateButtons();
250             updateApplyButton();
251         }
252     }
253
254     /**
255      * if the error message can be cleared or not
256      * @return true if the error message can be cleared, false otherwise
257      */

258     protected boolean canClearErrorMessage() {
259         if (fTimeoutText.isValid() && fConnectionTimeoutText.isValid()) {
260             return true;
261         }
262         return false;
263     }
264 }
265
Popular Tags