KickJava   Java API By Example, From Geeks To Geeks.

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


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.debug.internal.ui.preferences;
12
13
14 import org.eclipse.debug.internal.ui.DebugUIPlugin;
15 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
16 import org.eclipse.jface.preference.BooleanFieldEditor;
17 import org.eclipse.jface.preference.ColorFieldEditor;
18 import org.eclipse.jface.preference.FieldEditor;
19 import org.eclipse.jface.preference.FieldEditorPreferencePage;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.jface.preference.IntegerFieldEditor;
22 import org.eclipse.jface.util.PropertyChangeEvent;
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.widgets.Button;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.ui.IWorkbench;
29 import org.eclipse.ui.IWorkbenchPreferencePage;
30 import org.eclipse.ui.PlatformUI;
31
32 /**
33  * A page to set the preferences for the console
34  */

35 public class ConsolePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
36     
37     /**
38      * This class exists to provide visibility to the
39      * <code>refreshValidState</code> method and to perform more intelligent
40      * clearing of the error message.
41      */

42     protected class ConsoleIntegerFieldEditor extends IntegerFieldEditor {
43         
44         public ConsoleIntegerFieldEditor(String JavaDoc name, String JavaDoc labelText, Composite parent) {
45             super(name, labelText, parent);
46         }
47         
48         /**
49          * @see org.eclipse.jface.preference.FieldEditor#refreshValidState()
50          */

51         protected void refreshValidState() {
52             super.refreshValidState();
53         }
54         
55         /**
56          * Clears the error message from the message line if the error
57          * message is the error message from this field editor.
58          */

59         protected void clearErrorMessage() {
60             if (canClearErrorMessage()) {
61                 super.clearErrorMessage();
62             }
63         }
64     }
65     
66     private BooleanFieldEditor2 fWrapEditor = null;
67     private ConsoleIntegerFieldEditor fWidthEditor = null;
68     
69     private BooleanFieldEditor2 fUseBufferSize = null;
70     private ConsoleIntegerFieldEditor fBufferSizeEditor = null;
71     
72     private ConsoleIntegerFieldEditor fTabSizeEditor = null;
73     
74     /**
75      * Create the console page.
76      */

77     public ConsolePreferencePage() {
78         super(GRID);
79         setDescription(DebugPreferencesMessages.ConsolePreferencePage_Console_settings);
80         setPreferenceStore(DebugUIPlugin.getDefault().getPreferenceStore());
81     }
82
83     /* (non-Javadoc)
84      * @see org.eclipse.jface.preference.PreferencePage#createControl(Composite)
85      */

86     public void createControl(Composite parent) {
87         super.createControl(parent);
88         PlatformUI.getWorkbench().getHelpSystem().setHelp(
89             getControl(),
90             IDebugHelpContextIds.CONSOLE_PREFERENCE_PAGE );
91     }
92     
93     /**
94      * Create all field editors for this page
95      */

96     public void createFieldEditors() {
97         
98         fWrapEditor = new BooleanFieldEditor2(IDebugPreferenceConstants.CONSOLE_WRAP, DebugPreferencesMessages.ConsolePreferencePage_Wrap_text_1, SWT.NONE, getFieldEditorParent());
99         addField(fWrapEditor);
100         
101         fWidthEditor = new ConsoleIntegerFieldEditor(IDebugPreferenceConstants.CONSOLE_WIDTH, DebugPreferencesMessages.ConsolePreferencePage_Console_width, getFieldEditorParent());
102         addField(fWidthEditor);
103         fWidthEditor.setValidRange(80, 1000);
104         fWidthEditor.setErrorMessage(DebugPreferencesMessages.ConsolePreferencePage_console_width);
105         
106         fWrapEditor.getChangeControl(getFieldEditorParent()).addSelectionListener(
107             new SelectionAdapter() {
108                 public void widgetSelected(SelectionEvent e) {
109                     updateWidthEditor();
110                 }
111             }
112         );
113         
114         fUseBufferSize = new BooleanFieldEditor2(IDebugPreferenceConstants.CONSOLE_LIMIT_CONSOLE_OUTPUT, DebugPreferencesMessages.ConsolePreferencePage_Limit_console_output_1, SWT.NONE, getFieldEditorParent());
115         addField(fUseBufferSize);
116         
117         fBufferSizeEditor = new ConsoleIntegerFieldEditor(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK, DebugPreferencesMessages.ConsolePreferencePage_Console_buffer_size__characters___2, getFieldEditorParent());
118         addField(fBufferSizeEditor);
119         fBufferSizeEditor.setValidRange(1000, 1000000);
120         fBufferSizeEditor.setErrorMessage(DebugPreferencesMessages.ConsolePreferencePage_The_console_buffer_size_must_be_at_least_1000_characters__1);
121         
122         fUseBufferSize.getChangeControl(getFieldEditorParent()).addSelectionListener(
123             new SelectionAdapter() {
124                 public void widgetSelected(SelectionEvent e) {
125                     updateBufferSizeEditor();
126                 }
127             }
128         );
129         
130         fTabSizeEditor = new ConsoleIntegerFieldEditor(IDebugPreferenceConstants.CONSOLE_TAB_WIDTH, DebugPreferencesMessages.ConsolePreferencePage_12, getFieldEditorParent());
131         addField(fTabSizeEditor);
132         fTabSizeEditor.setValidRange(1,100);
133         fTabSizeEditor.setErrorMessage(DebugPreferencesMessages.ConsolePreferencePage_13);
134         
135         addField(new BooleanFieldEditor(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, DebugPreferencesMessages.ConsolePreferencePage_Show__Console_View_when_there_is_program_output_3, SWT.NONE, getFieldEditorParent()));
136         addField(new BooleanFieldEditor(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, DebugPreferencesMessages.ConsolePreferencePage_Show__Console_View_when_there_is_program_error_3, SWT.NONE, getFieldEditorParent()));
137
138         ColorFieldEditor sysout= new ColorFieldEditor(IDebugPreferenceConstants.CONSOLE_SYS_OUT_COLOR, DebugPreferencesMessages.ConsolePreferencePage_Standard_Out__2, getFieldEditorParent());
139         ColorFieldEditor syserr= new ColorFieldEditor(IDebugPreferenceConstants.CONSOLE_SYS_ERR_COLOR, DebugPreferencesMessages.ConsolePreferencePage_Standard_Error__3, getFieldEditorParent());
140         ColorFieldEditor sysin= new ColorFieldEditor(IDebugPreferenceConstants.CONSOLE_SYS_IN_COLOR, DebugPreferencesMessages.ConsolePreferencePage_Standard_In__4, getFieldEditorParent());
141         ColorFieldEditor background= new ColorFieldEditor(IDebugPreferenceConstants.CONSOLE_BAKGROUND_COLOR, DebugPreferencesMessages.ConsolePreferencePage_11, getFieldEditorParent());
142         
143         addField(sysout);
144         addField(syserr);
145         addField(sysin);
146         addField(background);
147     }
148     
149     /**
150      * @see IWorkbenchPreferencePage#init(IWorkbench)
151      */

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

158     public boolean performOk() {
159         boolean ok= super.performOk();
160         // update high water mark to be (about) 100 lines (100 * 80 chars) greater than low water mark
161
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
162         int low = store.getInt(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK);
163         int high = low + 8000;
164         store.setValue(IDebugPreferenceConstants.CONSOLE_HIGH_WATER_MARK, high);
165         return ok;
166     }
167
168     /**
169      * @see org.eclipse.jface.preference.FieldEditorPreferencePage#initialize()
170      */

171     protected void initialize() {
172         super.initialize();
173         updateWidthEditor();
174         updateBufferSizeEditor();
175     }
176     
177     /**
178      * Update enablement of width editor based on enablement of 'fixed width' editor.
179      */

180     protected void updateWidthEditor() {
181         Button b = fWrapEditor.getChangeControl(getFieldEditorParent());
182         fWidthEditor.getTextControl(getFieldEditorParent()).setEnabled(b.getSelection());
183         fWidthEditor.getLabelControl(getFieldEditorParent()).setEnabled(b.getSelection());
184     }
185
186     /**
187      * Update enablement of buffer size editor based on enablement of 'limit
188      * console output' editor.
189      */

190     protected void updateBufferSizeEditor() {
191         Button b = fUseBufferSize.getChangeControl(getFieldEditorParent());
192         fBufferSizeEditor.getTextControl(getFieldEditorParent()).setEnabled(b.getSelection());
193         fBufferSizeEditor.getLabelControl(getFieldEditorParent()).setEnabled(b.getSelection());
194     }
195     
196     /**
197      * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
198      */

199     protected void performDefaults() {
200         super.performDefaults();
201         updateWidthEditor();
202         updateBufferSizeEditor();
203     }
204     
205     protected boolean canClearErrorMessage() {
206         if (fWidthEditor.isValid() && fBufferSizeEditor.isValid()) {
207             return true;
208         }
209         return false;
210     }
211     
212     /**
213      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
214      */

215     public void propertyChange(PropertyChangeEvent event) {
216
217         if (event.getProperty().equals(FieldEditor.IS_VALID)) {
218             boolean newValue = ((Boolean JavaDoc) event.getNewValue()).booleanValue();
219             // If the new value is true then we must check all field editors.
220
// If it is false, then the page is invalid in any case.
221
if (newValue) {
222                 if (fWidthEditor != null && event.getSource() != fWidthEditor) {
223                     fWidthEditor.refreshValidState();
224                 }
225                 if (fBufferSizeEditor != null && event.getSource() != fBufferSizeEditor) {
226                     fBufferSizeEditor.refreshValidState();
227                 }
228                 checkState();
229             } else {
230                 super.propertyChange(event);
231             }
232
233         } else {
234             super.propertyChange(event);
235         }
236     }
237 }
238
Popular Tags