1 11 package org.eclipse.jdt.internal.ui.preferences; 12 13 import java.io.BufferedReader ; 14 import java.io.IOException ; 15 import java.io.InputStreamReader ; 16 import java.util.ArrayList ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 20 import org.eclipse.core.runtime.Assert; 21 import org.eclipse.core.runtime.IStatus; 22 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.events.DisposeEvent; 25 import org.eclipse.swt.events.DisposeListener; 26 import org.eclipse.swt.events.SelectionAdapter; 27 import org.eclipse.swt.events.SelectionEvent; 28 import org.eclipse.swt.events.SelectionListener; 29 import org.eclipse.swt.graphics.Color; 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.Link; 39 40 import org.eclipse.jface.dialogs.Dialog; 41 import org.eclipse.jface.preference.ColorSelector; 42 import org.eclipse.jface.preference.IPreferenceStore; 43 import org.eclipse.jface.preference.PreferenceConverter; 44 import org.eclipse.jface.preference.PreferencePage; 45 import org.eclipse.jface.resource.JFaceResources; 46 import org.eclipse.jface.util.IPropertyChangeListener; 47 import org.eclipse.jface.util.PropertyChangeEvent; 48 import org.eclipse.jface.viewers.IColorProvider; 49 import org.eclipse.jface.viewers.ISelectionChangedListener; 50 import org.eclipse.jface.viewers.IStructuredContentProvider; 51 import org.eclipse.jface.viewers.IStructuredSelection; 52 import org.eclipse.jface.viewers.LabelProvider; 53 import org.eclipse.jface.viewers.SelectionChangedEvent; 54 import org.eclipse.jface.viewers.StructuredSelection; 55 import org.eclipse.jface.viewers.TableViewer; 56 import org.eclipse.jface.viewers.Viewer; 57 58 import org.eclipse.jface.text.Document; 59 import org.eclipse.jface.text.IDocument; 60 import org.eclipse.jface.text.source.SourceViewer; 61 62 import org.eclipse.ui.IWorkbench; 63 import org.eclipse.ui.IWorkbenchPreferencePage; 64 import org.eclipse.ui.PlatformUI; 65 import org.eclipse.ui.dialogs.PreferencesUtil; 66 import org.eclipse.ui.model.WorkbenchViewerSorter; 67 import org.eclipse.ui.texteditor.ChainedPreferenceStore; 68 69 import org.eclipse.jdt.ui.PreferenceConstants; 70 import org.eclipse.jdt.ui.text.IColorManager; 71 72 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 73 import org.eclipse.jdt.internal.ui.JavaPlugin; 74 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; 75 import org.eclipse.jdt.internal.ui.dialogs.StatusUtil; 76 import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer; 77 import org.eclipse.jdt.internal.ui.propertiesfileeditor.IPropertiesFilePartitions; 78 import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileDocumentSetupParticipant; 79 import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileSourceViewerConfiguration; 80 import org.eclipse.jdt.internal.ui.text.JavaColorManager; 81 import org.eclipse.jdt.internal.ui.util.PixelConverter; 82 83 88 public class PropertiesFileEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { 89 90 91 private static class SourcePreviewerUpdater { 92 93 100 SourcePreviewerUpdater(final SourceViewer viewer, final PropertiesFileSourceViewerConfiguration configuration, final IPreferenceStore preferenceStore) { 101 Assert.isNotNull(viewer); 102 Assert.isNotNull(configuration); 103 Assert.isNotNull(preferenceStore); 104 final IPropertyChangeListener fontChangeListener= new IPropertyChangeListener() { 105 108 public void propertyChange(PropertyChangeEvent event) { 109 if (event.getProperty().equals(PreferenceConstants.PROPERTIES_FILE_EDITOR_TEXT_FONT)) { 110 Font font= JFaceResources.getFont(PreferenceConstants.PROPERTIES_FILE_EDITOR_TEXT_FONT); 111 viewer.getTextWidget().setFont(font); 112 } 113 } 114 }; 115 final IPropertyChangeListener propertyChangeListener= new IPropertyChangeListener() { 116 119 public void propertyChange(PropertyChangeEvent event) { 120 if (configuration.affectsTextPresentation(event)) { 121 configuration.handlePropertyChangeEvent(event); 122 viewer.invalidateTextPresentation(); 123 } 124 } 125 }; 126 viewer.getTextWidget().addDisposeListener(new DisposeListener() { 127 130 public void widgetDisposed(DisposeEvent e) { 131 preferenceStore.removePropertyChangeListener(propertyChangeListener); 132 JFaceResources.getFontRegistry().removeListener(fontChangeListener); 133 } 134 }); 135 JFaceResources.getFontRegistry().addListener(fontChangeListener); 136 preferenceStore.addPropertyChangeListener(propertyChangeListener); 137 } 138 } 139 140 141 144 private static class HighlightingColorListItem { 145 146 private String fDisplayName; 147 148 private String fColorKey; 149 150 private String fBoldKey; 151 152 private String fItalicKey; 153 157 private String fStrikethroughKey; 158 162 private String fUnderlineKey; 163 164 private Color fItemColor; 165 166 177 public HighlightingColorListItem(String displayName, String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey, Color itemColor) { 178 fDisplayName= displayName; 179 fColorKey= colorKey; 180 fBoldKey= boldKey; 181 fItalicKey= italicKey; 182 fStrikethroughKey= strikethroughKey; 183 fUnderlineKey= underlineKey; 184 fItemColor= itemColor; 185 } 186 187 190 public String getBoldKey() { 191 return fBoldKey; 192 } 193 194 197 public String getItalicKey() { 198 return fItalicKey; 199 } 200 204 public String getStrikethroughKey() { 205 return fStrikethroughKey; 206 } 207 208 212 public String getUnderlineKey() { 213 return fUnderlineKey; 214 } 215 216 219 public String getColorKey() { 220 return fColorKey; 221 } 222 223 226 public String getDisplayName() { 227 return fDisplayName; 228 } 229 230 233 public Color getItemColor() { 234 return fItemColor; 235 } 236 } 237 238 241 private class ColorListLabelProvider extends LabelProvider implements IColorProvider { 242 243 246 public String getText(Object element) { 247 return ((HighlightingColorListItem)element).getDisplayName(); 248 } 249 250 253 public Color getForeground(Object element) { 254 return ((HighlightingColorListItem)element).getItemColor(); 255 } 256 257 260 public Color getBackground(Object element) { 261 return null; 262 } 263 } 264 265 268 private class ColorListContentProvider implements IStructuredContentProvider { 269 270 273 public Object [] getElements(Object inputElement) { 274 return ((java.util.List )inputElement).toArray(); 275 } 276 277 280 public void dispose() { 281 } 282 283 286 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 287 } 288 } 289 290 private static final String BOLD= PreferenceConstants.EDITOR_BOLD_SUFFIX; 291 294 private static final String ITALIC= PreferenceConstants.EDITOR_ITALIC_SUFFIX; 295 296 300 private static final String STRIKETHROUGH= PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX; 301 302 306 private static final String UNDERLINE= PreferenceConstants.EDITOR_UNDERLINE_SUFFIX; 307 308 309 private final String [][] fSyntaxColorListModel= new String [][] { 310 { PreferencesMessages.PropertiesFileEditorPreferencePage_key, PreferenceConstants.PROPERTIES_FILE_COLORING_KEY }, 311 { PreferencesMessages.PropertiesFileEditorPreferencePage_value, PreferenceConstants.PROPERTIES_FILE_COLORING_VALUE }, 312 { PreferencesMessages.PropertiesFileEditorPreferencePage_assignment, PreferenceConstants.PROPERTIES_FILE_COLORING_ASSIGNMENT }, 313 { PreferencesMessages.PropertiesFileEditorPreferencePage_argument, PreferenceConstants.PROPERTIES_FILE_COLORING_ARGUMENT }, 314 { PreferencesMessages.PropertiesFileEditorPreferencePage_comment, PreferenceConstants.PROPERTIES_FILE_COLORING_COMMENT } 315 }; 316 317 private OverlayPreferenceStore fOverlayStore; 318 319 private ColorSelector fSyntaxForegroundColorEditor; 320 private Button fBoldCheckBox; 321 322 325 private Button fItalicCheckBox; 326 327 331 private Button fStrikethroughCheckBox; 332 333 337 private Button fUnderlineCheckBox; 338 339 private SourceViewer fPreviewViewer; 340 341 344 private boolean fFieldsInitialized= false; 345 346 351 private ArrayList fMasterSlaveListeners= new ArrayList (); 352 353 356 private final List fHighlightingColorList= new ArrayList (); 357 360 private TableViewer fHighlightingColorListViewer; 361 362 365 private IColorManager fColorManager; 366 367 368 371 public PropertiesFileEditorPreferencePage() { 372 setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore()); 373 374 fOverlayStore= new OverlayPreferenceStore(getPreferenceStore(), createOverlayStoreKeys()); 375 } 376 377 private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() { 378 379 ArrayList overlayKeys= new ArrayList (); 380 381 for (int i= 0; i < fSyntaxColorListModel.length; i++) { 382 String colorKey= fSyntaxColorListModel[i][1]; 383 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, colorKey)); 384 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, colorKey + BOLD)); 385 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, colorKey + ITALIC)); 386 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, colorKey + STRIKETHROUGH)); 387 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, colorKey + UNDERLINE)); 388 } 389 390 OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; 391 overlayKeys.toArray(keys); 392 return keys; 393 } 394 395 398 public void init(IWorkbench workbench) { 399 } 400 401 404 public void createControl(Composite parent) { 405 super.createControl(parent); 406 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.PROPERTIES_FILE_EDITOR_PREFERENCE_PAGE); 407 } 408 409 private void handleSyntaxColorListSelection() { 410 HighlightingColorListItem item= getHighlightingColorListItem(); 411 RGB rgb= PreferenceConverter.getColor(fOverlayStore, item.getColorKey()); 412 fSyntaxForegroundColorEditor.setColorValue(rgb); 413 fBoldCheckBox.setSelection(fOverlayStore.getBoolean(item.getBoldKey())); 414 fItalicCheckBox.setSelection(fOverlayStore.getBoolean(item.getItalicKey())); 415 fStrikethroughCheckBox.setSelection(fOverlayStore.getBoolean(item.getStrikethroughKey())); 416 fUnderlineCheckBox.setSelection(fOverlayStore.getBoolean(item.getUnderlineKey())); 417 418 fSyntaxForegroundColorEditor.getButton().setEnabled(true); 419 fBoldCheckBox.setEnabled(true); 420 fItalicCheckBox.setEnabled(true); 421 fStrikethroughCheckBox.setEnabled(true); 422 fUnderlineCheckBox.setEnabled(true); 423 } 424 425 private Control createSyntaxPage(Composite parent) { 426 427 Label label= new Label(parent, SWT.LEFT); 428 label.setText(PreferencesMessages.PropertiesFileEditorPreferencePage_foreground); 429 label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 430 431 Composite editorComposite= new Composite(parent, SWT.NONE); 432 GridLayout layout= new GridLayout(); 433 layout.numColumns= 2; 434 layout.marginHeight= 0; 435 layout.marginWidth= 0; 436 editorComposite.setLayout(layout); 437 GridData gd= new GridData(SWT.FILL, SWT.BEGINNING, true, false); 438 editorComposite.setLayoutData(gd); 439 440 fHighlightingColorListViewer= new TableViewer(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); 441 fHighlightingColorListViewer.setLabelProvider(new ColorListLabelProvider()); 442 fHighlightingColorListViewer.setContentProvider(new ColorListContentProvider()); 443 fHighlightingColorListViewer.setComparator(new WorkbenchViewerSorter()); 444 gd= new GridData(SWT.BEGINNING, SWT.FILL, false, true); 445 gd.heightHint= convertHeightInCharsToPixels(5); 446 fHighlightingColorListViewer.getControl().setLayoutData(gd); 447 448 Composite stylesComposite= new Composite(editorComposite, SWT.NONE); 449 layout= new GridLayout(); 450 layout.marginHeight= 0; 451 layout.marginWidth= 0; 452 layout.numColumns= 2; 453 stylesComposite.setLayout(layout); 454 stylesComposite.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false)); 455 456 gd= new GridData(GridData.FILL_HORIZONTAL); 457 gd.horizontalAlignment= GridData.BEGINNING; 458 gd.horizontalSpan= 2; 459 460 label= new Label(stylesComposite, SWT.LEFT); 461 label.setText(PreferencesMessages.PropertiesFileEditorPreferencePage_color); 462 gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); 463 gd.horizontalIndent= 20; 464 label.setLayoutData(gd); 465 466 fSyntaxForegroundColorEditor= new ColorSelector(stylesComposite); 467 Button foregroundColorButton= fSyntaxForegroundColorEditor.getButton(); 468 gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); 469 foregroundColorButton.setLayoutData(gd); 470 471 fBoldCheckBox= new Button(stylesComposite, SWT.CHECK); 472 fBoldCheckBox.setText(PreferencesMessages.PropertiesFileEditorPreferencePage_bold); 473 gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); 474 gd.horizontalIndent= 20; 475 gd.horizontalSpan= 2; 476 fBoldCheckBox.setLayoutData(gd); 477 478 fItalicCheckBox= new Button(stylesComposite, SWT.CHECK); 479 fItalicCheckBox.setText(PreferencesMessages.PropertiesFileEditorPreferencePage_italic); 480 gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); 481 gd.horizontalIndent= 20; 482 gd.horizontalSpan= 2; 483 fItalicCheckBox.setLayoutData(gd); 484 485 fStrikethroughCheckBox= new Button(stylesComposite, SWT.CHECK); 486 fStrikethroughCheckBox.setText(PreferencesMessages.PropertiesFileEditorPreferencePage_strikethrough); 487 gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); 488 gd.horizontalIndent= 20; 489 gd.horizontalSpan= 2; 490 fStrikethroughCheckBox.setLayoutData(gd); 491 492 fUnderlineCheckBox= new Button(stylesComposite, SWT.CHECK); 493 fUnderlineCheckBox.setText(PreferencesMessages.PropertiesFileEditorPreferencePage_underline); 494 gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); 495 gd.horizontalIndent= 20; 496 gd.horizontalSpan= 2; 497 fUnderlineCheckBox.setLayoutData(gd); 498 499 label= new Label(parent, SWT.LEFT); 500 label.setText(PreferencesMessages.PropertiesFileEditorPreferencePage_preview); 501 label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 502 503 Control previewer= createPreviewer(parent); 504 gd= new GridData(GridData.FILL_BOTH); 505 gd.widthHint= convertWidthInCharsToPixels(20); 506 gd.heightHint= convertHeightInCharsToPixels(5); 507 previewer.setLayoutData(gd); 508 509 510 fHighlightingColorListViewer.addSelectionChangedListener(new ISelectionChangedListener() { 511 public void selectionChanged(SelectionChangedEvent event) { 512 handleSyntaxColorListSelection(); 513 } 514 }); 515 516 foregroundColorButton.addSelectionListener(new SelectionListener() { 517 public void widgetDefaultSelected(SelectionEvent e) { 518 } 520 public void widgetSelected(SelectionEvent e) { 521 HighlightingColorListItem item= getHighlightingColorListItem(); 522 PreferenceConverter.setValue(fOverlayStore, item.getColorKey(), fSyntaxForegroundColorEditor.getColorValue()); 523 } 524 }); 525 526 fBoldCheckBox.addSelectionListener(new SelectionListener() { 527 public void widgetDefaultSelected(SelectionEvent e) { 528 } 530 public void widgetSelected(SelectionEvent e) { 531 HighlightingColorListItem item= getHighlightingColorListItem(); 532 fOverlayStore.setValue(item.getBoldKey(), fBoldCheckBox.getSelection()); 533 } 534 }); 535 536 fItalicCheckBox.addSelectionListener(new SelectionListener() { 537 public void widgetDefaultSelected(SelectionEvent e) { 538 } 540 public void widgetSelected(SelectionEvent e) { 541 HighlightingColorListItem item= getHighlightingColorListItem(); 542 fOverlayStore.setValue(item.getItalicKey(), fItalicCheckBox.getSelection()); 543 } 544 }); 545 546 fStrikethroughCheckBox.addSelectionListener(new SelectionListener() { 547 public void widgetDefaultSelected(SelectionEvent e) { 548 } 550 public void widgetSelected(SelectionEvent e) { 551 HighlightingColorListItem item= getHighlightingColorListItem(); 552 fOverlayStore.setValue(item.getStrikethroughKey(), fStrikethroughCheckBox.getSelection()); 553 } 554 }); 555 556 fUnderlineCheckBox.addSelectionListener(new SelectionListener() { 557 public void widgetDefaultSelected(SelectionEvent e) { 558 } 560 public void widgetSelected(SelectionEvent e) { 561 HighlightingColorListItem item= getHighlightingColorListItem(); 562 fOverlayStore.setValue(item.getUnderlineKey(), fUnderlineCheckBox.getSelection()); 563 } 564 }); 565 566 parent.layout(); 567 568 return parent; 569 } 570 571 private Control createPreviewer(Composite parent) { 572 573 IPreferenceStore store= new ChainedPreferenceStore(new IPreferenceStore[] { fOverlayStore, JavaPlugin.getDefault().getCombinedPreferenceStore()}); 574 fPreviewViewer= new JavaSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, store); 575 fColorManager= new JavaColorManager(false); 576 PropertiesFileSourceViewerConfiguration configuration= new PropertiesFileSourceViewerConfiguration(fColorManager, store, null, IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING); 577 fPreviewViewer.configure(configuration); 578 Font font= JFaceResources.getFont(PreferenceConstants.PROPERTIES_FILE_EDITOR_TEXT_FONT); 579 fPreviewViewer.getTextWidget().setFont(font); 580 new SourcePreviewerUpdater(fPreviewViewer, configuration, store); 581 fPreviewViewer.setEditable(false); 582 583 String content= loadPreviewContentFromFile("PropertiesFileEditorColorSettingPreviewCode.txt"); IDocument document= new Document(content); 585 PropertiesFileDocumentSetupParticipant.setupDocument(document); 586 fPreviewViewer.setDocument(document); 587 588 return fPreviewViewer.getControl(); 589 } 590 591 private static void indent(Control control) { 592 GridData gridData= new GridData(); 593 gridData.horizontalIndent= 20; 594 control.setLayoutData(gridData); 595 } 596 597 private void createDependency(final Button master, String masterKey, final Control slave) { 598 indent(slave); 599 boolean masterState= fOverlayStore.getBoolean(masterKey); 600 slave.setEnabled(masterState); 601 SelectionListener listener= new SelectionListener() { 602 public void widgetSelected(SelectionEvent e) { 603 slave.setEnabled(master.getSelection()); 604 } 605 606 public void widgetDefaultSelected(SelectionEvent e) {} 607 }; 608 master.addSelectionListener(listener); 609 fMasterSlaveListeners.add(listener); 610 } 611 612 615 protected Control createContents(Composite parent) { 616 fOverlayStore.load(); 617 fOverlayStore.start(); 618 619 Composite contents= new Composite(parent, SWT.NONE); 620 GridLayout layout= new GridLayout(); 621 layout.marginHeight= 0; 622 layout.marginWidth= 0; 623 contents.setLayout(layout); 624 contents.setLayoutData(new GridData(GridData.FILL_BOTH)); 625 626 createHeader(contents); 627 628 createSyntaxPage(contents); 629 630 initialize(); 631 632 Dialog.applyDialogFont(contents); 633 return contents; 634 } 635 636 private void createHeader(Composite contents) { 637 String text= PreferencesMessages.PropertiesFileEditorPreferencePage_link; 638 Link link= new Link(contents, SWT.NONE); 639 link.setText(text); 640 link.addSelectionListener(new SelectionAdapter() { 641 public void widgetSelected(SelectionEvent e) { 642 PreferencesUtil.createPreferenceDialogOn(getShell(), "org.eclipse.ui.preferencePages.GeneralTextEditor", null, null); } 644 }); 645 link.setToolTipText(PreferencesMessages.PropertiesFileEditorPreferencePage_link_tooltip); 648 649 650 GridData gridData= new GridData(SWT.FILL, SWT.BEGINNING, true, false); 651 gridData.widthHint= 150; link.setLayoutData(gridData); 653 654 addFiller(contents); 655 } 656 657 private void addFiller(Composite composite) { 658 PixelConverter pixelConverter= new PixelConverter(composite); 659 660 Label filler= new Label(composite, SWT.LEFT ); 661 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); 662 gd.horizontalSpan= 2; 663 gd.heightHint= pixelConverter.convertHeightInCharsToPixels(1) / 2; 664 filler.setLayoutData(gd); 665 } 666 667 private void initialize() { 668 669 initializeFields(); 670 671 for (int i= 0, n= fSyntaxColorListModel.length; i < n; i++) 672 fHighlightingColorList.add(new HighlightingColorListItem (fSyntaxColorListModel[i][0], fSyntaxColorListModel[i][1], fSyntaxColorListModel[i][1] + BOLD, fSyntaxColorListModel[i][1] + ITALIC, fSyntaxColorListModel[i][1] + STRIKETHROUGH, fSyntaxColorListModel[i][1] + UNDERLINE, null)); 673 674 fHighlightingColorListViewer.setInput(fHighlightingColorList); 675 fHighlightingColorListViewer.setSelection(new StructuredSelection(fHighlightingColorListViewer.getElementAt(0))); 676 } 677 678 private void initializeFields() { 679 fFieldsInitialized= true; 680 updateStatus(new StatusInfo()); 681 682 Iterator iter= fMasterSlaveListeners.iterator(); 684 while (iter.hasNext()) { 685 SelectionListener listener= (SelectionListener)iter.next(); 686 listener.widgetSelected(null); 687 } 688 } 689 690 693 public boolean performOk() { 694 fOverlayStore.propagate(); 695 JavaPlugin.getDefault().savePluginPreferences(); 696 return true; 697 } 698 699 702 protected void performDefaults() { 703 704 fOverlayStore.loadDefaults(); 705 706 initializeFields(); 707 708 handleSyntaxColorListSelection(); 709 710 super.performDefaults(); 711 712 fPreviewViewer.invalidateTextPresentation(); 713 } 714 715 718 public void dispose() { 719 720 if (fOverlayStore != null) { 721 fOverlayStore.stop(); 722 fOverlayStore= null; 723 } 724 725 fColorManager.dispose(); 726 727 super.dispose(); 728 } 729 730 private String loadPreviewContentFromFile(String filename) { 731 String line; 732 String separator= System.getProperty("line.separator"); StringBuffer buffer= new StringBuffer (512); 734 BufferedReader reader= null; 735 try { 736 reader= new BufferedReader (new InputStreamReader (getClass().getResourceAsStream(filename))); 737 while ((line= reader.readLine()) != null) { 738 buffer.append(line); 739 buffer.append(separator); 740 } 741 } catch (IOException io) { 742 JavaPlugin.log(io); 743 } finally { 744 if (reader != null) { 745 try { reader.close(); } catch (IOException e) {} 746 } 747 } 748 return buffer.toString(); 749 } 750 751 void updateStatus(IStatus status) { 752 if (!fFieldsInitialized) 753 return; 754 755 setValid(!status.matches(IStatus.ERROR)); 756 StatusUtil.applyToStatusLine(this, status); 757 } 758 759 764 private HighlightingColorListItem getHighlightingColorListItem() { 765 IStructuredSelection selection= (IStructuredSelection) fHighlightingColorListViewer.getSelection(); 766 return (HighlightingColorListItem) selection.getFirstElement(); 767 } 768 } 769 | Popular Tags |