1 11 package org.eclipse.ant.internal.ui.preferences; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 16 import org.eclipse.ant.internal.ui.AntUIPlugin; 17 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds; 18 import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants; 19 import org.eclipse.jface.preference.BooleanFieldEditor; 20 import org.eclipse.jface.preference.FieldEditorPreferencePage; 21 import org.eclipse.jface.preference.IPreferenceStore; 22 import org.eclipse.jface.preference.IntegerFieldEditor; 23 import org.eclipse.jface.preference.PreferenceConverter; 24 import org.eclipse.jface.preference.StringFieldEditor; 25 import org.eclipse.jface.resource.StringConverter; 26 import org.eclipse.jface.util.PropertyChangeEvent; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.events.SelectionAdapter; 29 import org.eclipse.swt.events.SelectionEvent; 30 import org.eclipse.swt.graphics.Font; 31 import org.eclipse.swt.graphics.RGB; 32 import org.eclipse.swt.layout.GridData; 33 import org.eclipse.swt.layout.GridLayout; 34 import org.eclipse.swt.widgets.Button; 35 import org.eclipse.swt.widgets.Composite; 36 import org.eclipse.swt.widgets.Control; 37 import org.eclipse.swt.widgets.Label; 38 import org.eclipse.swt.widgets.List; 39 import org.eclipse.ui.IWorkbench; 40 import org.eclipse.ui.IWorkbenchPreferencePage; 41 import org.eclipse.ui.PlatformUI; 42 43 public class AntPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { 44 45 private List fConsoleColorList; 46 private ColorEditor fConsoleColorEditor; 47 48 private BooleanFieldEditor fToolsWarningEditor= null; 49 50 private final String [][] fAppearanceColorListModel= new String [][] { 53 {AntPreferencesMessages.AntPreferencePage__Error__2, IAntUIPreferenceConstants.CONSOLE_ERROR_COLOR, null}, 54 {AntPreferencesMessages.AntPreferencePage__Warning__3, IAntUIPreferenceConstants.CONSOLE_WARNING_COLOR, null}, 55 {AntPreferencesMessages.AntPreferencePage_I_nformation__4, IAntUIPreferenceConstants.CONSOLE_INFO_COLOR, null}, 56 {AntPreferencesMessages.AntPreferencePage_Ve_rbose__5, IAntUIPreferenceConstants.CONSOLE_VERBOSE_COLOR, null}, 57 {AntPreferencesMessages.AntPreferencePage_Deb_ug__6, IAntUIPreferenceConstants.CONSOLE_DEBUG_COLOR, null}, 58 }; 59 60 63 public AntPreferencePage() { 64 super(GRID); 65 setDescription(AntPreferencesMessages.AntPreferencePage_General); 66 setPreferenceStore(AntUIPlugin.getDefault().getPreferenceStore()); 67 } 68 69 72 protected void createFieldEditors() { 73 storeAppliedValues(); 74 75 Font font= getFieldEditorParent().getFont(); 76 Label label= new Label(getFieldEditorParent(), SWT.WRAP); 77 label.setText(AntPreferencesMessages.AntPreferencePage_Enter); 78 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 79 gd.horizontalSpan= 3; 80 gd.widthHint= convertWidthInCharsToPixels(60); 81 label.setLayoutData(gd); 82 label.setLayoutData(gd); 83 label.setFont(font); 84 85 StringFieldEditor editor = new StringFieldEditor(IAntUIPreferenceConstants.ANT_FIND_BUILD_FILE_NAMES, AntPreferencesMessages.AntPreferencePage__Names__3, getFieldEditorParent()); 86 addField(editor); 87 88 IntegerFieldEditor timeout = new IntegerFieldEditor(IAntUIPreferenceConstants.ANT_COMMUNICATION_TIMEOUT, AntPreferencesMessages.AntPreferencePage_13, getFieldEditorParent()); 89 int minValue= AntUIPlugin.getDefault().getPreferenceStore().getDefaultInt(IAntUIPreferenceConstants.ANT_COMMUNICATION_TIMEOUT); 90 int maxValue = 1200000; 91 timeout.setValidRange(minValue, maxValue); 92 timeout.setErrorMessage(MessageFormat.format(AntPreferencesMessages.AntPreferencePage_14, new Object [] {new Integer (minValue), new Integer (maxValue)})); 93 addField(timeout); 94 95 editor = new URLFieldEditor(IAntUIPreferenceConstants.DOCUMENTATION_URL, AntPreferencesMessages.AntPreferencePage_2, getFieldEditorParent()); 96 addField(editor); 97 98 createSpace(); 99 100 if (!AntUIPlugin.isMacOS()) { 101 label= new Label(getFieldEditorParent(), SWT.WRAP); 103 label.setText(AntPreferencesMessages.AntPreferencePage_0); 104 gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 105 gd.horizontalSpan= 3; 106 gd.widthHint= convertWidthInCharsToPixels(60); 107 label.setLayoutData(gd); 108 label.setFont(font); 109 fToolsWarningEditor= new BooleanFieldEditor(IAntUIPreferenceConstants.ANT_TOOLS_JAR_WARNING, AntPreferencesMessages.AntPreferencePage_1, getFieldEditorParent()); 110 addField(fToolsWarningEditor); 111 createSpace(); 112 } 113 114 addField(new BooleanFieldEditor(IAntUIPreferenceConstants.ANT_ERROR_DIALOG, AntPreferencesMessages.AntPreferencePage_12, getFieldEditorParent())); 115 createSpace(); 116 117 118 addField(new BooleanFieldEditor(IAntUIPreferenceConstants.ANT_CREATE_MARKERS, AntPreferencesMessages.AntPreferencePage_15, getFieldEditorParent())); 119 label= new Label(getFieldEditorParent(), SWT.WRAP); 120 label.setText(AntPreferencesMessages.AntPreferencePage_16); 121 gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 122 gd.horizontalSpan= 3; 123 gd.widthHint= convertWidthInCharsToPixels(60); 124 label.setLayoutData(gd); 125 label.setFont(font); 126 127 createSpace(); 128 createColorComposite(); 129 getPreferenceStore().addPropertyChangeListener(this); 130 } 131 132 private void createSpace() { 133 Label label= new Label(getFieldEditorParent(), SWT.NONE); 134 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 135 gd.horizontalSpan= 3; 136 label.setLayoutData(gd); 137 } 138 139 144 private void storeAppliedValues() { 145 IPreferenceStore store= getPreferenceStore(); 146 for (int i = 0; i < fAppearanceColorListModel.length; i++) { 147 String preference = fAppearanceColorListModel[i][1]; 148 fAppearanceColorListModel[i][2]= store.getString(preference); 149 } 150 } 151 152 private void createColorComposite() { 153 Font font= getFieldEditorParent().getFont(); 154 Label label= new Label(getFieldEditorParent(), SWT.LEFT); 155 label.setText(AntPreferencesMessages.AntPreferencePage_Ant_Color_Options__6); 156 label.setFont(font); 157 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 158 gd.horizontalSpan= 2; 159 label.setLayoutData(gd); 160 161 Composite editorComposite= new Composite(getFieldEditorParent(), SWT.NONE); 162 GridLayout layout= new GridLayout(); 163 layout.numColumns= 2; 164 layout.marginHeight= 0; 165 layout.marginWidth= 0; 166 editorComposite.setLayout(layout); 167 editorComposite.setFont(font); 168 gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); 169 gd.horizontalSpan= 2; 170 editorComposite.setLayoutData(gd); 171 172 fConsoleColorList= new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); 173 gd= new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL); 174 gd.heightHint= convertHeightInCharsToPixels(8); 175 fConsoleColorList.setLayoutData(gd); 176 fConsoleColorList.setFont(font); 177 178 Composite stylesComposite= new Composite(editorComposite, SWT.NONE); 179 layout= new GridLayout(); 180 layout.marginHeight= 0; 181 layout.marginWidth= 0; 182 layout.numColumns= 2; 183 stylesComposite.setLayout(layout); 184 stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); 185 stylesComposite.setFont(font); 186 187 label= new Label(stylesComposite, SWT.LEFT); 188 label.setText(AntPreferencesMessages.AntPreferencePage_Color__7); 189 label.setFont(font); 190 gd= new GridData(); 191 gd.horizontalAlignment= GridData.BEGINNING; 192 label.setLayoutData(gd); 193 194 fConsoleColorEditor= new ColorEditor(stylesComposite); 195 Button foregroundColorButton= fConsoleColorEditor.getButton(); 196 gd= new GridData(GridData.FILL_HORIZONTAL); 197 gd.horizontalAlignment= GridData.BEGINNING; 198 foregroundColorButton.setLayoutData(gd); 199 foregroundColorButton.setFont(font); 200 201 fConsoleColorList.addSelectionListener(new SelectionAdapter() { 202 public void widgetSelected(SelectionEvent e) { 203 handleAppearanceColorListSelection(); 204 } 205 }); 206 foregroundColorButton.addSelectionListener(new SelectionAdapter() { 207 public void widgetSelected(SelectionEvent e) { 208 int i= fConsoleColorList.getSelectionIndex(); 209 if (i == -1) { return; 211 } 212 String key= fAppearanceColorListModel[i][1]; 213 PreferenceConverter.setValue(getPreferenceStore(), key, fConsoleColorEditor.getColorValue()); 214 } 215 }); 216 } 217 218 221 public boolean performCancel() { 222 for (int i = 0; i < fAppearanceColorListModel.length; i++) { 223 String preference = fAppearanceColorListModel[i][1]; 224 PreferenceConverter.setValue(getPreferenceStore(), preference, StringConverter.asRGB(fAppearanceColorListModel[i][2])); 225 } 226 return super.performCancel(); 227 } 228 229 233 public boolean performOk() { 234 storeAppliedValues(); 235 return super.performOk(); 236 } 237 238 private void handleAppearanceColorListSelection() { 239 int i= fConsoleColorList.getSelectionIndex(); 240 if (i == -1) { return; 242 } 243 String key= fAppearanceColorListModel[i][1]; 244 RGB rgb= PreferenceConverter.getColor(getPreferenceStore(), key); 245 fConsoleColorEditor.setColorValue(rgb); 246 } 247 248 251 protected Control createContents(Composite parent) { 252 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IAntUIHelpContextIds.ANT_PREFERENCE_PAGE); 253 return super.createContents(parent); 254 } 255 256 259 public void init(IWorkbench workbench) { 260 } 261 262 265 protected void initialize() { 266 super.initialize(); 267 for (int i= 0; i < fAppearanceColorListModel.length; i++) { 268 fConsoleColorList.add(fAppearanceColorListModel[i][0]); 269 } 270 fConsoleColorList.getDisplay().asyncExec(new Runnable () { 271 public void run() { 272 if (fConsoleColorList != null && !fConsoleColorList.isDisposed()) { 273 fConsoleColorList.select(0); 274 handleAppearanceColorListSelection(); 275 } 276 } 277 }); 278 } 279 282 protected void performDefaults() { 283 for (int i = 0; i < fAppearanceColorListModel.length; i++) { 284 String key= fAppearanceColorListModel[i][1]; 285 PreferenceConverter.setValue(getPreferenceStore(), key, PreferenceConverter.getDefaultColor(getPreferenceStore(), key)); 286 } 287 handleAppearanceColorListSelection(); 288 289 super.performDefaults(); 290 } 291 292 295 public void dispose() { 296 getPreferenceStore().removePropertyChangeListener(this); 297 } 298 299 302 public void propertyChange(PropertyChangeEvent event) { 303 if (event.getProperty().equals(IAntUIPreferenceConstants.ANT_TOOLS_JAR_WARNING)) { 304 if (fToolsWarningEditor != null) { 305 fToolsWarningEditor.load(); 306 } 307 } else { 308 super.propertyChange(event); 309 } 310 } 311 } 312 | Popular Tags |