1 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 35 public class ConsolePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { 36 37 42 protected class ConsoleIntegerFieldEditor extends IntegerFieldEditor { 43 44 public ConsoleIntegerFieldEditor(String name, String labelText, Composite parent) { 45 super(name, labelText, parent); 46 } 47 48 51 protected void refreshValidState() { 52 super.refreshValidState(); 53 } 54 55 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 77 public ConsolePreferencePage() { 78 super(GRID); 79 setDescription(DebugPreferencesMessages.ConsolePreferencePage_Console_settings); 80 setPreferenceStore(DebugUIPlugin.getDefault().getPreferenceStore()); 81 } 82 83 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 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 152 public void init(IWorkbench workbench) { 153 } 154 155 158 public boolean performOk() { 159 boolean ok= super.performOk(); 160 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 171 protected void initialize() { 172 super.initialize(); 173 updateWidthEditor(); 174 updateBufferSizeEditor(); 175 } 176 177 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 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 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 215 public void propertyChange(PropertyChangeEvent event) { 216 217 if (event.getProperty().equals(FieldEditor.IS_VALID)) { 218 boolean newValue = ((Boolean ) event.getNewValue()).booleanValue(); 219 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 |