1 11 package org.eclipse.ant.internal.ui.preferences; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 import org.eclipse.ant.internal.ui.AntSourceViewerConfiguration; 20 import org.eclipse.ant.internal.ui.AntUIPlugin; 21 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds; 22 import org.eclipse.ant.internal.ui.editor.text.AntDocumentSetupParticipant; 23 import org.eclipse.ant.internal.ui.editor.text.IAntEditorColorConstants; 24 import org.eclipse.jface.preference.IPreferenceStore; 25 import org.eclipse.jface.preference.PreferenceConverter; 26 import org.eclipse.jface.resource.JFaceResources; 27 import org.eclipse.jface.text.Document; 28 import org.eclipse.jface.text.IDocument; 29 import org.eclipse.jface.text.source.SourceViewer; 30 import org.eclipse.jface.viewers.IColorProvider; 31 import org.eclipse.jface.viewers.ISelectionChangedListener; 32 import org.eclipse.jface.viewers.IStructuredContentProvider; 33 import org.eclipse.jface.viewers.IStructuredSelection; 34 import org.eclipse.jface.viewers.LabelProvider; 35 import org.eclipse.jface.viewers.SelectionChangedEvent; 36 import org.eclipse.jface.viewers.StructuredSelection; 37 import org.eclipse.jface.viewers.TableViewer; 38 import org.eclipse.jface.viewers.Viewer; 39 import org.eclipse.swt.SWT; 40 import org.eclipse.swt.events.SelectionAdapter; 41 import org.eclipse.swt.events.SelectionEvent; 42 import org.eclipse.swt.events.SelectionListener; 43 import org.eclipse.swt.graphics.Color; 44 import org.eclipse.swt.graphics.Font; 45 import org.eclipse.swt.graphics.RGB; 46 import org.eclipse.swt.layout.GridData; 47 import org.eclipse.swt.layout.GridLayout; 48 import org.eclipse.swt.widgets.Button; 49 import org.eclipse.swt.widgets.Combo; 50 import org.eclipse.swt.widgets.Composite; 51 import org.eclipse.swt.widgets.Control; 52 import org.eclipse.swt.widgets.Label; 53 import org.eclipse.swt.widgets.Link; 54 import org.eclipse.swt.widgets.TabFolder; 55 import org.eclipse.swt.widgets.TabItem; 56 import org.eclipse.swt.widgets.Text; 57 import org.eclipse.swt.widgets.Widget; 58 import org.eclipse.ui.PlatformUI; 59 import org.eclipse.ui.dialogs.PreferencesUtil; 60 import org.eclipse.ui.editors.text.EditorsUI; 61 import org.eclipse.ui.model.WorkbenchViewerComparator; 62 import org.eclipse.ui.texteditor.ChainedPreferenceStore; 63 64 67 public class AntEditorPreferencePage extends AbstractAntEditorPreferencePage { 68 69 protected static class ControlData { 70 private String fKey; 71 private String [] fValues; 72 73 public ControlData(String key, String [] values) { 74 fKey= key; 75 fValues= values; 76 } 77 78 public String getKey() { 79 return fKey; 80 } 81 82 public String getValue(boolean selection) { 83 int index= selection ? 0 : 1; 84 return fValues[index]; 85 } 86 87 public String getValue(int index) { 88 return fValues[index]; 89 } 90 91 public int getSelection(String value) { 92 if (value != null) { 93 for (int i= 0; i < fValues.length; i++) { 94 if (value.equals(fValues[i])) { 95 return i; 96 } 97 } 98 } 99 return fValues.length -1; } 101 } 102 103 108 private class HighlightingColorListItem { 109 110 private String fDisplayName; 111 112 private String fColorKey; 113 114 private String fBoldKey; 115 116 private String fItalicKey; 117 118 private Color fItemColor; 119 120 129 public HighlightingColorListItem(String displayName, String colorKey, String boldKey, String italicKey, Color itemColor) { 130 fDisplayName= displayName; 131 fColorKey= colorKey; 132 fBoldKey= boldKey; 133 fItalicKey= italicKey; 134 fItemColor= itemColor; 135 } 136 137 140 public String getBoldKey() { 141 return fBoldKey; 142 } 143 144 147 public String getItalicKey() { 148 return fItalicKey; 149 } 150 151 154 public String getColorKey() { 155 return fColorKey; 156 } 157 158 161 public String getDisplayName() { 162 return fDisplayName; 163 } 164 165 168 public Color getItemColor() { 169 return fItemColor; 170 } 171 } 172 173 178 private class ColorListLabelProvider extends LabelProvider implements IColorProvider { 179 180 183 public String getText(Object element) { 184 return ((HighlightingColorListItem)element).getDisplayName(); 185 } 186 187 190 public Color getForeground(Object element) { 191 return ((HighlightingColorListItem)element).getItemColor(); 192 } 193 194 197 public Color getBackground(Object element) { 198 return null; 199 } 200 } 201 202 207 private class ColorListContentProvider implements IStructuredContentProvider { 208 209 212 public Object [] getElements(Object inputElement) { 213 return ((java.util.List )inputElement).toArray(); 214 } 215 216 219 public void dispose() { 220 } 221 222 225 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 226 } 227 } 228 229 230 private String [][] fSyntaxColorListModel; 231 232 private final String [] fProblemPreferenceKeys= new String [] { 233 AntEditorPreferenceConstants.PROBLEM_CLASSPATH, 234 AntEditorPreferenceConstants.PROBLEM_PROPERTIES, 235 AntEditorPreferenceConstants.PROBLEM_IMPORTS, 236 AntEditorPreferenceConstants.PROBLEM_TASKS, 237 AntEditorPreferenceConstants.PROBLEM_SECURITY 238 }; 239 240 private ColorEditor fSyntaxForegroundColorEditor; 241 private Button fBoldCheckBox; 242 private Button fItalicCheckBox; 243 244 private TableViewer fHighlightingColorListViewer; 245 private final java.util.List fHighlightingColorList= new ArrayList (5); 246 247 private SourceViewer fPreviewViewer; 248 private AntPreviewerUpdater fPreviewerUpdater; 249 250 private SelectionListener fSelectionListener; 251 protected Map fWorkingValues; 252 protected List fComboBoxes; 253 private List fProblemLabels; 254 255 private Button fIgnoreAllProblems; 256 257 private Text fBuildFilesToIgnoreProblems; 258 private Label fBuildFilesToIgnoreProblemsLabel; 259 260 private Label fSeverityLabel; 261 262 private Label fBuildFilesToIgnoreProblemsDescription; 263 264 public AntEditorPreferencePage() { 265 super(); 266 setDescription(AntPreferencesMessages.AntEditorPreferencePage_description); 267 } 268 269 protected OverlayPreferenceStore createOverlayStore() { 270 fSyntaxColorListModel= new String [][] { 271 {AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_text_1, IAntEditorColorConstants.TEXT_COLOR, null}, 272 {AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_processing_instuctions_2, IAntEditorColorConstants.PROCESSING_INSTRUCTIONS_COLOR, null}, 273 {AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_constant_strings_3, IAntEditorColorConstants.STRING_COLOR, null}, 274 {AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_tags_4, IAntEditorColorConstants.TAG_COLOR, null}, 275 {AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_comments_5, IAntEditorColorConstants.XML_COMMENT_COLOR, null}, 276 {AntPreferencesMessages.AntEditorPreferencePage_26, IAntEditorColorConstants.XML_DTD_COLOR, null} 277 }; 278 ArrayList overlayKeys= new ArrayList (); 279 280 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION)); 281 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY)); 282 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.CODEASSIST_AUTOINSERT)); 283 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND)); 284 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND)); 285 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS)); 286 287 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_ENABLED)); 288 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_COMMENTS)); 289 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_DTD)); 290 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_DEFINING)); 291 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_TARGETS)); 292 293 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_MARK_OCCURRENCES)); 294 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_STICKY_OCCURRENCES)); 295 296 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL)); 297 298 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.BUILDFILE_NAMES_TO_IGNORE)); 299 300 for (int i= 0; i < fSyntaxColorListModel.length; i++) { 301 String colorKey= fSyntaxColorListModel[i][1]; 302 addTextKeyToCover(overlayKeys, colorKey); 303 } 304 305 OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; 306 overlayKeys.toArray(keys); 307 return new OverlayPreferenceStore(getPreferenceStore(), keys); 308 } 309 310 private void addTextKeyToCover(ArrayList overlayKeys, String mainKey) { 311 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, mainKey)); 312 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, mainKey + AntEditorPreferenceConstants.EDITOR_BOLD_SUFFIX)); 313 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, mainKey + AntEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX)); 314 } 315 316 private Control createAppearancePage(Composite parent) { 317 Font font= parent.getFont(); 318 319 Composite appearanceComposite= new Composite(parent, SWT.NONE); 320 appearanceComposite.setFont(font); 321 GridLayout layout= new GridLayout(); 322 layout.numColumns= 2; 323 appearanceComposite.setLayout(layout); 324 325 String labelText= AntPreferencesMessages.AntEditorPreferencePage_2; 326 addCheckBox(appearanceComposite, labelText, AntEditorPreferenceConstants.EDITOR_MARK_OCCURRENCES, 0); 327 328 labelText= AntPreferencesMessages.AntEditorPreferencePage_4; 329 addCheckBox(appearanceComposite, labelText, AntEditorPreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0); 330 331 return appearanceComposite; 332 } 333 334 337 protected Control createContents(Composite parent) { 338 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IAntUIHelpContextIds.ANT_EDITOR_PREFERENCE_PAGE); 339 getOverlayStore().load(); 340 getOverlayStore().start(); 341 342 createHeader(parent); 343 344 TabFolder folder= new TabFolder(parent, SWT.NONE); 345 folder.setLayout(new TabFolderLayout()); 346 folder.setLayoutData(new GridData(GridData.FILL_BOTH)); 347 348 TabItem item= new TabItem(folder, SWT.NONE); 349 item.setText(AntPreferencesMessages.AntEditorPreferencePage_general); 350 item.setControl(createAppearancePage(folder)); 351 352 item= new TabItem(folder, SWT.NONE); 353 item.setText(AntPreferencesMessages.AntEditorPreferencePage_1); 354 item.setControl(createSyntaxPage(folder)); 355 356 item= new TabItem(folder, SWT.NONE); 357 item.setText(AntPreferencesMessages.AntEditorPreferencePage_10); 358 item.setControl(createProblemsTabContent(folder)); 359 360 item= new TabItem(folder, SWT.NONE); 361 item.setText(AntPreferencesMessages.AntEditorPreferencePage_19); 362 item.setControl(createFoldingTabContent(folder)); 363 364 initialize(); 365 366 applyDialogFont(parent); 367 return folder; 368 } 369 370 private Control createFoldingTabContent(TabFolder folder) { 371 Composite composite= new Composite(folder, SWT.NULL); 372 373 GridLayout layout= new GridLayout(); 374 layout.numColumns= 2; 375 composite.setLayout(layout); 376 377 addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_20, AntEditorPreferenceConstants.EDITOR_FOLDING_ENABLED, 0); 378 379 Label label= new Label(composite, SWT.LEFT); 380 label.setText(AntPreferencesMessages.AntEditorPreferencePage_21); 381 382 addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_22, AntEditorPreferenceConstants.EDITOR_FOLDING_DTD, 0); 383 addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_23, AntEditorPreferenceConstants.EDITOR_FOLDING_COMMENTS, 0); 384 addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_24, AntEditorPreferenceConstants.EDITOR_FOLDING_DEFINING, 0); 385 addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_25, AntEditorPreferenceConstants.EDITOR_FOLDING_TARGETS, 0); 386 return composite; 387 } 388 389 private void initialize() { 390 391 initializeFields(); 392 393 for (int i= 0, n= fSyntaxColorListModel.length; i < n; i++) { 394 fHighlightingColorList.add( 395 new HighlightingColorListItem (fSyntaxColorListModel[i][0], fSyntaxColorListModel[i][1], 396 fSyntaxColorListModel[i][1] + AntEditorPreferenceConstants.EDITOR_BOLD_SUFFIX, 397 fSyntaxColorListModel[i][1] + AntEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX, null)); 398 } 399 fHighlightingColorListViewer.setInput(fHighlightingColorList); 400 fHighlightingColorListViewer.setSelection(new StructuredSelection(fHighlightingColorListViewer.getElementAt(0))); 401 } 402 403 406 protected void handleDefaults() { 407 handleSyntaxColorListSelection(); 408 restoreWorkingValuesToDefaults(); 409 updateControlsForProblemReporting(!AntUIPlugin.getDefault().getCombinedPreferenceStore().getBoolean(AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL)); 410 } 411 412 private Control createSyntaxPage(Composite parent) { 413 414 Composite colorComposite= new Composite(parent, SWT.NONE); 415 colorComposite.setLayout(new GridLayout()); 416 417 Label label= new Label(colorComposite, SWT.LEFT); 418 label.setText(AntPreferencesMessages.AntEditorPreferencePage_5); 419 label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 420 421 Composite editorComposite= new Composite(colorComposite, SWT.NONE); 422 GridLayout layout= new GridLayout(); 423 layout.numColumns= 2; 424 layout.marginHeight= 0; 425 layout.marginWidth= 0; 426 editorComposite.setLayout(layout); 427 GridData gd= new GridData(GridData.FILL_BOTH); 428 editorComposite.setLayoutData(gd); 429 430 fHighlightingColorListViewer= new TableViewer(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); 431 fHighlightingColorListViewer.setLabelProvider(new ColorListLabelProvider()); 432 fHighlightingColorListViewer.setContentProvider(new ColorListContentProvider()); 433 fHighlightingColorListViewer.setComparator(new WorkbenchViewerComparator()); 434 gd= new GridData(GridData.FILL_BOTH); 435 gd.heightHint= convertHeightInCharsToPixels(5); 436 fHighlightingColorListViewer.getControl().setLayoutData(gd); 437 438 Composite stylesComposite= new Composite(editorComposite, SWT.NONE); 439 layout= new GridLayout(); 440 layout.marginHeight= 0; 441 layout.marginWidth= 0; 442 layout.numColumns= 2; 443 stylesComposite.setLayout(layout); 444 stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); 445 446 label= new Label(stylesComposite, SWT.LEFT); 447 label.setText(AntPreferencesMessages.AntEditorPreferencePage_6); 448 gd= new GridData(); 449 gd.horizontalAlignment= GridData.BEGINNING; 450 label.setLayoutData(gd); 451 452 fSyntaxForegroundColorEditor= new ColorEditor(stylesComposite); 453 Button foregroundColorButton= fSyntaxForegroundColorEditor.getButton(); 454 gd= new GridData(GridData.FILL_HORIZONTAL); 455 gd.horizontalAlignment= GridData.BEGINNING; 456 foregroundColorButton.setLayoutData(gd); 457 458 fBoldCheckBox= new Button(stylesComposite, SWT.CHECK); 459 fBoldCheckBox.setText(AntPreferencesMessages.AntEditorPreferencePage_7); 460 gd= new GridData(GridData.FILL_HORIZONTAL); 461 gd.horizontalAlignment= GridData.BEGINNING; 462 gd.horizontalSpan= 2; 463 fBoldCheckBox.setLayoutData(gd); 464 465 fItalicCheckBox= new Button(stylesComposite, SWT.CHECK); 466 fItalicCheckBox.setText(AntPreferencesMessages.AntEditorPreferencePage_8); 467 gd= new GridData(GridData.FILL_HORIZONTAL); 468 gd.horizontalAlignment= GridData.BEGINNING; 469 gd.horizontalSpan= 2; 470 fItalicCheckBox.setLayoutData(gd); 471 472 label= new Label(colorComposite, SWT.LEFT); 473 label.setText(AntPreferencesMessages.AntEditorPreferencePage_9); 474 label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 475 476 Control previewer= createPreviewer(colorComposite); 477 gd= new GridData(GridData.FILL_BOTH); 478 gd.widthHint= convertWidthInCharsToPixels(20); 479 gd.heightHint= convertHeightInCharsToPixels(5); 480 previewer.setLayoutData(gd); 481 482 fHighlightingColorListViewer.addSelectionChangedListener(new ISelectionChangedListener() { 483 public void selectionChanged(SelectionChangedEvent event) { 484 handleSyntaxColorListSelection(); 485 } 486 }); 487 488 foregroundColorButton.addSelectionListener(new SelectionListener() { 489 public void widgetDefaultSelected(SelectionEvent e) { 490 } 492 public void widgetSelected(SelectionEvent e) { 493 HighlightingColorListItem item= getHighlightingColorListItem(); 494 PreferenceConverter.setValue(getOverlayStore(), item.getColorKey(), fSyntaxForegroundColorEditor.getColorValue()); 495 } 496 }); 497 498 fBoldCheckBox.addSelectionListener(new SelectionListener() { 499 public void widgetDefaultSelected(SelectionEvent e) { 500 } 502 public void widgetSelected(SelectionEvent e) { 503 HighlightingColorListItem item= getHighlightingColorListItem(); 504 getOverlayStore().setValue(item.getBoldKey(), fBoldCheckBox.getSelection()); 505 } 506 }); 507 508 fItalicCheckBox.addSelectionListener(new SelectionListener() { 509 public void widgetDefaultSelected(SelectionEvent e) { 510 } 512 public void widgetSelected(SelectionEvent e) { 513 HighlightingColorListItem item= getHighlightingColorListItem(); 514 getOverlayStore().setValue(item.getItalicKey(), fItalicCheckBox.getSelection()); 515 } 516 }); 517 518 return colorComposite; 519 } 520 521 private Control createPreviewer(Composite parent) { 522 fPreviewViewer = new SourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); 523 524 AntSourceViewerConfiguration configuration = new AntSourceViewerConfiguration(); 525 526 fPreviewViewer.configure(configuration); 527 fPreviewViewer.setEditable(false); 528 Font font= JFaceResources.getFont(JFaceResources.TEXT_FONT); 529 fPreviewViewer.getTextWidget().setFont(font); 530 531 IPreferenceStore store= new ChainedPreferenceStore(new IPreferenceStore[] { getOverlayStore(), EditorsUI.getPreferenceStore() }); 532 fPreviewerUpdater= new AntPreviewerUpdater(fPreviewViewer, configuration, store); 533 534 String content= loadPreviewContentFromFile("SyntaxPreviewCode.txt"); IDocument document = new Document(content); 536 new AntDocumentSetupParticipant().setup(document); 537 fPreviewViewer.setDocument(document); 538 539 return fPreviewViewer.getControl(); 540 } 541 542 private void handleSyntaxColorListSelection() { 543 HighlightingColorListItem item= getHighlightingColorListItem(); 544 RGB rgb= PreferenceConverter.getColor(getOverlayStore(), item.getColorKey()); 545 fSyntaxForegroundColorEditor.setColorValue(rgb); 546 fBoldCheckBox.setSelection(getOverlayStore().getBoolean(item.getBoldKey())); 547 fItalicCheckBox.setSelection(getOverlayStore().getBoolean(item.getItalicKey())); 548 } 549 550 556 private HighlightingColorListItem getHighlightingColorListItem() { 557 IStructuredSelection selection= (IStructuredSelection) fHighlightingColorListViewer.getSelection(); 558 return (HighlightingColorListItem) selection.getFirstElement(); 559 } 560 561 564 public void dispose() { 565 super.dispose(); 566 if (fPreviewerUpdater != null) { 567 fPreviewerUpdater.dispose(); 568 } 569 } 570 571 private Composite createProblemsTabContent(TabFolder folder) { 572 fComboBoxes= new ArrayList (); 573 fProblemLabels= new ArrayList (); 574 initializeWorkingValues(); 575 576 String [] errorWarningIgnoreLabels= new String [] { 577 AntPreferencesMessages.AntEditorPreferencePage_11, AntPreferencesMessages.AntEditorPreferencePage_12, AntPreferencesMessages.AntEditorPreferencePage_13}; 578 String [] errorWarningIgnore= new String [] { 579 AntEditorPreferenceConstants.BUILDFILE_ERROR, 580 AntEditorPreferenceConstants.BUILDFILE_WARNING, 581 AntEditorPreferenceConstants.BUILDFILE_IGNORE }; 582 583 int nColumns= 3; 584 585 GridLayout layout= new GridLayout(); 586 layout.numColumns= nColumns; 587 588 Composite othersComposite= new Composite(folder, SWT.NULL); 589 othersComposite.setLayout(layout); 590 591 String labelText= AntPreferencesMessages.AntEditorPreferencePage_28; 592 fIgnoreAllProblems= addCheckBox(othersComposite, labelText, AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL, 0); 593 594 fIgnoreAllProblems.addSelectionListener(getSelectionListener()); 595 596 fBuildFilesToIgnoreProblemsDescription = new Label(othersComposite, SWT.WRAP); 597 fBuildFilesToIgnoreProblemsDescription.setText(AntPreferencesMessages.AntEditorPreferencePage_29); 598 GridData gd= new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); 599 gd.horizontalSpan= nColumns; 600 fBuildFilesToIgnoreProblemsDescription.setLayoutData(gd); 601 602 Control[] controls= addLabelledTextField(othersComposite, AntPreferencesMessages.AntEditorPreferencePage_30, AntEditorPreferenceConstants.BUILDFILE_NAMES_TO_IGNORE, -1, 0, null); 603 fBuildFilesToIgnoreProblems= getTextControl(controls); 604 fBuildFilesToIgnoreProblemsLabel= getLabelControl(controls); 605 606 fSeverityLabel= new Label(othersComposite, SWT.WRAP); 607 fSeverityLabel.setText(AntPreferencesMessages.AntEditorPreferencePage_14); 608 gd= new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); 609 gd.horizontalSpan= nColumns; 610 fSeverityLabel.setLayoutData(gd); 611 612 String label= AntPreferencesMessages.AntEditorPreferencePage_18; 613 addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_TASKS, errorWarningIgnore, errorWarningIgnoreLabels, 0); 614 615 label= AntPreferencesMessages.AntEditorPreferencePage_15; 616 addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_CLASSPATH, errorWarningIgnore, errorWarningIgnoreLabels, 0); 617 618 label= AntPreferencesMessages.AntEditorPreferencePage_16; 619 addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_PROPERTIES, errorWarningIgnore, errorWarningIgnoreLabels, 0); 620 621 label= AntPreferencesMessages.AntEditorPreferencePage_17; 622 addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_IMPORTS, errorWarningIgnore, errorWarningIgnoreLabels, 0); 623 624 label= AntPreferencesMessages.AntEditorPreferencePage_27; 625 addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_SECURITY, errorWarningIgnore, errorWarningIgnoreLabels, 0); 626 627 updateControlsForProblemReporting(!AntUIPlugin.getDefault().getCombinedPreferenceStore().getBoolean(AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL)); 628 return othersComposite; 629 } 630 631 private void initializeWorkingValues() { 632 fWorkingValues= new HashMap (fProblemPreferenceKeys.length); 633 for (int i = 0; i < fProblemPreferenceKeys.length; i++) { 634 String key = fProblemPreferenceKeys[i]; 635 fWorkingValues.put(key, getPreferenceStore().getString(key)); 636 } 637 } 638 639 private void restoreWorkingValuesToDefaults() { 640 fWorkingValues= new HashMap (fProblemPreferenceKeys.length); 641 for (int i = 0; i < fProblemPreferenceKeys.length; i++) { 642 String key = fProblemPreferenceKeys[i]; 643 fWorkingValues.put(key, getPreferenceStore().getDefaultString(key)); 644 } 645 updateControls(); 646 } 647 648 protected Combo addComboBox(Composite parent, String label, String key, String [] values, String [] valueLabels, int indent) { 649 ControlData data= new ControlData(key, values); 650 651 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); 652 gd.horizontalIndent= indent; 653 654 Label labelControl= new Label(parent, SWT.LEFT | SWT.WRAP); 655 labelControl.setText(label); 656 labelControl.setLayoutData(gd); 657 658 Combo comboBox= new Combo(parent, SWT.READ_ONLY); 659 comboBox.setItems(valueLabels); 660 comboBox.setData(data); 661 comboBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); 662 comboBox.addSelectionListener(getSelectionListener()); 663 664 Label placeHolder= new Label(parent, SWT.NONE); 665 placeHolder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 666 667 String currValue= (String )fWorkingValues.get(key); 668 comboBox.select(data.getSelection(currValue)); 669 670 fProblemLabels.add(labelControl); 671 fComboBoxes.add(comboBox); 672 return comboBox; 673 } 674 675 protected SelectionListener getSelectionListener() { 676 if (fSelectionListener == null) { 677 fSelectionListener= new SelectionListener() { 678 public void widgetDefaultSelected(SelectionEvent e) {} 679 680 public void widgetSelected(SelectionEvent e) { 681 controlChanged(e.widget); 682 } 683 }; 684 } 685 return fSelectionListener; 686 } 687 688 protected void controlChanged(Widget widget) { 689 ControlData data= (ControlData) widget.getData(); 690 String newValue= null; 691 if (widget instanceof Button) { 692 if (widget == fIgnoreAllProblems) { 693 updateControlsForProblemReporting(!((Button)widget).getSelection()); 694 return; 695 } 696 newValue= data.getValue(((Button)widget).getSelection()); 697 } else if (widget instanceof Combo) { 698 newValue= data.getValue(((Combo)widget).getSelectionIndex()); 699 } else { 700 return; 701 } 702 fWorkingValues.put(data.getKey(), newValue); 703 } 704 705 private void updateControlsForProblemReporting(boolean reportProblems) { 706 for (int i= fComboBoxes.size() - 1; i >= 0; i--) { 707 ((Control) fComboBoxes.get(i)).setEnabled(reportProblems); 708 ((Control) fProblemLabels.get(i)).setEnabled(reportProblems); 709 } 710 fSeverityLabel.setEnabled(reportProblems); 711 fBuildFilesToIgnoreProblems.setEnabled(reportProblems); 712 fBuildFilesToIgnoreProblemsDescription.setEnabled(reportProblems); 713 fBuildFilesToIgnoreProblemsLabel.setEnabled(reportProblems); 714 } 715 716 protected void updateControls() { 717 for (int i= fComboBoxes.size() - 1; i >= 0; i--) { 719 Combo curr= (Combo) fComboBoxes.get(i); 720 ControlData data= (ControlData) curr.getData(); 721 722 String currValue= (String ) fWorkingValues.get(data.getKey()); 723 curr.select(data.getSelection(currValue)); 724 } 725 } 726 727 730 public boolean performOk() { 731 Iterator iter= fWorkingValues.keySet().iterator(); 732 IPreferenceStore store= getPreferenceStore(); 733 while (iter.hasNext()) { 734 String key = (String ) iter.next(); 735 store.putValue(key, (String )fWorkingValues.get(key)); 736 } 737 if (store.needsSaving()) { 738 store.putValue(AntEditorPreferenceConstants.PROBLEM, "changed"); store.setToDefault(AntEditorPreferenceConstants.PROBLEM); 743 } 744 return super.performOk(); 745 } 746 747 private void createHeader(Composite contents) { 748 final Link link= new Link(contents, SWT.NONE); 749 final String target= "org.eclipse.ui.preferencePages.GeneralTextEditor"; link.setText(AntPreferencesMessages.AntEditorPreferencePage_0); 751 link.addSelectionListener(new SelectionAdapter() { 752 public void widgetSelected(SelectionEvent e) { 753 PreferencesUtil.createPreferenceDialogOn(link.getShell(), target, null, null); 754 } 755 }); 756 String linktooltip= AntPreferencesMessages.AntEditorPreferencePage_3; 757 link.setToolTipText(linktooltip); 758 } 759 } 760 | Popular Tags |