KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > preferences > LaunchingPreferencePage


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.debug.internal.ui.preferences;
12
13 import org.eclipse.debug.internal.ui.DebugUIPlugin;
14 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
15 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
16 import org.eclipse.debug.internal.ui.SWTFactory;
17 import org.eclipse.debug.ui.IDebugUIConstants;
18 import org.eclipse.jface.dialogs.MessageDialogWithToggle;
19 import org.eclipse.jface.preference.BooleanFieldEditor;
20 import org.eclipse.jface.preference.FieldEditor;
21 import org.eclipse.jface.preference.FieldEditorPreferencePage;
22 import org.eclipse.jface.preference.IntegerFieldEditor;
23 import org.eclipse.jface.preference.RadioGroupFieldEditor;
24 import org.eclipse.jface.preference.StringFieldEditor;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.SelectionEvent;
27 import org.eclipse.swt.events.SelectionListener;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Control;
33 import org.eclipse.swt.widgets.Group;
34 import org.eclipse.ui.IWorkbench;
35 import org.eclipse.ui.IWorkbenchPreferencePage;
36 import org.eclipse.ui.PlatformUI;
37
38 import com.ibm.icu.text.MessageFormat;
39
40 /**
41  * A preference page for configuring launching preferences.
42  *
43  * @since 3.0.0
44  */

45 public class LaunchingPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
46     
47     private Button fUseContextLaunching;
48     private Button fUseOldLaunching;
49     private Button fLaunchLastIfNotLaunchable;
50     private Button fCheckParent;
51     
52     /**
53      * The default constructor
54      */

55     public LaunchingPreferencePage() {
56         super();
57         setPreferenceStore(DebugUIPlugin.getDefault().getPreferenceStore());
58     }
59     
60     /* (non-Javadoc)
61      * @see org.eclipse.jface.preference.PreferencePage#createControl(org.eclipse.swt.widgets.Composite)
62      */

63     public void createControl(Composite parent) {
64         super.createControl(parent);
65         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.LAUNCHING_PREFERENCE_PAGE);
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
70      */

71     protected Control createContents(Composite parent) {
72         Composite comp = SWTFactory.createComposite(parent, 1, 1, GridData.FILL_HORIZONTAL);
73         //save dirty editors
74
FieldEditor edit = new RadioGroupFieldEditor(IInternalDebugUIConstants.PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH, DebugPreferencesMessages.LaunchingPreferencePage_2, 3,
75                  new String JavaDoc[][] {{DebugPreferencesMessages.LaunchingPreferencePage_3, MessageDialogWithToggle.ALWAYS},
76                  {DebugPreferencesMessages.LaunchingPreferencePage_4, MessageDialogWithToggle.NEVER},
77                  {DebugPreferencesMessages.LaunchingPreferencePage_5, MessageDialogWithToggle.PROMPT}},
78                  comp,
79                  true);
80         addField(edit);
81         
82         //wait for build
83
edit = new RadioGroupFieldEditor(IInternalDebugUIConstants.PREF_WAIT_FOR_BUILD,
84                  DebugPreferencesMessages.LaunchingPreferencePage_6, 3,
85                  new String JavaDoc[][] {{DebugPreferencesMessages.LaunchingPreferencePage_7, MessageDialogWithToggle.ALWAYS},
86                  {DebugPreferencesMessages.LaunchingPreferencePage_8, MessageDialogWithToggle.NEVER},
87                  {DebugPreferencesMessages.LaunchingPreferencePage_9, MessageDialogWithToggle.PROMPT}},
88                  comp,
89                  true);
90         addField(edit);
91         
92         //re-launch in debug mode
93
edit = new RadioGroupFieldEditor(IInternalDebugUIConstants.PREF_RELAUNCH_IN_DEBUG_MODE,
94                  DebugPreferencesMessages.LaunchingPreferencePage_15, 3,
95                  new String JavaDoc[][] {{DebugPreferencesMessages.LaunchingPreferencePage_16, MessageDialogWithToggle.ALWAYS},
96                  {DebugPreferencesMessages.LaunchingPreferencePage_17, MessageDialogWithToggle.NEVER},
97                  {DebugPreferencesMessages.LaunchingPreferencePage_18, MessageDialogWithToggle.PROMPT}},
98                  comp,
99                  true);
100         addField(edit);
101         
102         //continue with compile errors
103
edit = new RadioGroupFieldEditor(IInternalDebugUIConstants.PREF_CONTINUE_WITH_COMPILE_ERROR,
104                  DebugPreferencesMessages.LaunchingPreferencePage_21, 2,
105                  new String JavaDoc[][] {{DebugPreferencesMessages.LaunchingPreferencePage_22, MessageDialogWithToggle.ALWAYS},
106                  {DebugPreferencesMessages.LaunchingPreferencePage_23, MessageDialogWithToggle.PROMPT}},
107                  comp,
108                  true);
109         addField(edit);
110         
111         //filtering options
112
Group group = SWTFactory.createGroup(comp, DebugPreferencesMessages.LaunchingPreferencePage_36, 1, 1, GridData.FILL_HORIZONTAL);
113         Composite spacer = SWTFactory.createComposite(group, 1, 1, GridData.FILL_HORIZONTAL);
114         edit = new BooleanFieldEditor(IDebugUIConstants.PREF_BUILD_BEFORE_LAUNCH, DebugPreferencesMessages.LaunchingPreferencePage_1, SWT.NONE, spacer);
115         edit.fillIntoGrid(spacer, 2);
116         addField(edit);
117         edit = new BooleanFieldEditor(IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES, DebugPreferencesMessages.LaunchingPreferencePage_10, SWT.NONE, spacer);
118         edit.fillIntoGrid(spacer, 2);
119         addField(edit);
120         
121         //history list size preference
122
IntegerFieldEditor editor = new IntegerFieldEditor(IDebugUIConstants.PREF_MAX_HISTORY_SIZE, DebugPreferencesMessages.DebugPreferencePage_10, spacer);
123         editor.fillIntoGrid(spacer, 2);
124         addField(editor);
125         int historyMax = IDebugPreferenceConstants.MAX_LAUNCH_HISTORY_SIZE;
126         editor.setTextLimit(Integer.toString(historyMax).length());
127         editor.setErrorMessage(MessageFormat.format(DebugPreferencesMessages.DebugPreferencePage_11, new Object JavaDoc[] { new Integer JavaDoc(1), new Integer JavaDoc(historyMax)}));
128         editor.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE);
129         editor.setValidRange(1, historyMax);
130         editor.setEmptyStringAllowed(false);
131         
132         //CONTEXTLAUNCHING
133
createContextLaunchingControls(comp);
134         initialize();
135         checkState();
136         return comp;
137     }
138
139     /**
140      * Creates the context launching portion of the page, which includes two radio buttons and
141      * a nested check box
142      * @param parent the parent to add this control to
143      *
144      * @since 3.3.0
145      * CONTEXTLAUNCHING
146      */

147     private void createContextLaunchingControls(Composite parent) {
148         Group group = SWTFactory.createGroup(parent, DebugPreferencesMessages.LaunchingPreferencePage_40, 1, 1, GridData.FILL_HORIZONTAL);
149         fUseOldLaunching = SWTFactory.createRadioButton(group, DebugPreferencesMessages.LaunchingPreferencePage_37);
150         fUseContextLaunching = SWTFactory.createRadioButton(group, DebugPreferencesMessages.LaunchingPreferencePage_38);
151         fUseContextLaunching.addSelectionListener(new SelectionListener() {
152             public void widgetDefaultSelected(SelectionEvent e) {}
153             public void widgetSelected(SelectionEvent e) {
154                 boolean enabled = ((Button)e.widget).getSelection();
155                 fCheckParent.setEnabled(enabled);
156                 fLaunchLastIfNotLaunchable.setEnabled(enabled);
157             }
158         });
159         Composite space = SWTFactory.createComposite(group, 1, 1, GridData.FILL_HORIZONTAL);
160         GridData gd = (GridData) space.getLayoutData();
161         gd.horizontalIndent = 10;
162         GridLayout layout = (GridLayout) space.getLayout();
163         layout.marginHeight = 0;
164         fCheckParent = SWTFactory.createRadioButton(space, DebugPreferencesMessages.LaunchingPreferencePage_39);
165         fLaunchLastIfNotLaunchable = SWTFactory.createRadioButton(space, DebugPreferencesMessages.LaunchingPreferencePage_41);
166         
167         //initialize the buttons
168
boolean value = getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH);
169         fUseOldLaunching.setSelection(!value);
170         fUseContextLaunching.setSelection(value);
171         boolean enable = getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_LAUNCH_PARENT_PROJECT);
172         fCheckParent.setSelection(enable);
173         fCheckParent.setEnabled(value);
174         fLaunchLastIfNotLaunchable.setSelection(!enable);
175         fLaunchLastIfNotLaunchable.setEnabled(value);
176     }
177     
178     /* (non-Javadoc)
179      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
180      */

181     public void init(IWorkbench workbench) {}
182     
183     /* (non-Javadoc)
184      * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
185      */

186     protected void performDefaults() {
187         boolean value = getPreferenceStore().getDefaultBoolean(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH);
188         fUseOldLaunching.setSelection(!value);
189         fUseContextLaunching.setSelection(value);
190         boolean parent = getPreferenceStore().getDefaultBoolean(IInternalDebugUIConstants.PREF_LAUNCH_PARENT_PROJECT);
191         fCheckParent.setSelection(parent);
192         fCheckParent.setEnabled(value);
193         fLaunchLastIfNotLaunchable.setSelection(!parent);
194         fLaunchLastIfNotLaunchable.setEnabled(value);
195         super.performDefaults();
196     }
197     
198     /* (non-Javadoc)
199      * @see org.eclipse.jface.preference.PreferencePage#performOk()
200      */

201     public boolean performOk() {
202         getPreferenceStore().setValue(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH, fUseContextLaunching.getSelection());
203         getPreferenceStore().setValue(IInternalDebugUIConstants.PREF_LAUNCH_PARENT_PROJECT, fCheckParent.getSelection());
204         getPreferenceStore().setValue(IInternalDebugUIConstants.PREF_LAUNCH_LAST_IF_NOT_LAUNCHABLE, fLaunchLastIfNotLaunchable.getSelection());
205         return super.performOk();
206     }
207
208     /**
209      * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
210      */

211     protected void createFieldEditors() {
212         //do nothing we overload the create contents method
213
}
214 }
215
Popular Tags