1 /******************************************************************************* 2 * Copyright (c) 2000, 2008 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.ui.texteditor; 15 16 import java.util.HashMap; 17 import java.util.Map; 18 19 import org.osgi.framework.Bundle; 20 21 import org.eclipse.swt.graphics.RGB; 22 23 import org.eclipse.core.runtime.CoreException; 24 import org.eclipse.core.runtime.IConfigurationElement; 25 import org.eclipse.core.runtime.Platform; 26 27 import org.eclipse.jface.resource.ImageDescriptor; 28 29 import org.eclipse.ui.internal.texteditor.TextEditorPlugin; 30 31 32 /** 33 * An annotation preference provides all the information required for handing 34 * the preferences for the presentation of annotations of a specified type. The 35 * type can be changed and retrieved using the <code>getAnnotationType</code> 36 * and <code>setAnnotationType</code> methods. For each preference, getter and 37 * setter methods are provided. 38 * <p> 39 * Preferences that may be changed by the user also have a corresponding key 40 * that can be used to obtain the currently set value from an 41 * <code>IPreferenceStore</code>. 42 * </p> 43 * <h3>The following annotation preferences are covered:</h3> 44 * <h4>Display Preferences controlling how and where annotations are shown</h4> 45 * <ul> 46 * <li>as text background highlighting (and respective preference key),</li> 47 * <li>as text decorations (and respective preference key),</li> 48 * <li>on the overview ruler (and respective preference key),</li> 49 * <li>on the overview ruler header,</li> 50 * <li>on the vertical ruler (and respective preference key),</li> 51 * </ul> 52 * <h4>Additional Display Preferences</h4> 53 * <ul> 54 * <li>the base color for annotations of this type (and respective preference 55 * key), 56 * <li>the style of text decorations that are drawn (and respective preference 57 * key),</li> 58 * <li>the annotation image provider,</li> 59 * <li>the quick fix image descriptor,</li> 60 * <li>the image descriptor,</li> 61 * <li>the symbolic image name,</li> 62 * <li>the presentation layer.</li> 63 * </ul> 64 * <h4>Navigation Preferences</h4> 65 * <ul> 66 * <li>whether included in the "Go to Next Annotation" navigation action (and 67 * respective preference key),</li> 68 * <li>whether included in the "Go to Previous Annotation" navigation action 69 * (and respective preference key),</li> 70 * <li>whether to be shown in the "Go to Next/Previous Annotation" navigation 71 * toolbar drop down (and respective preference key).</li> 72 * </ul> 73 * <h4>Preference Page Preferences</h4> 74 * <ul> 75 * <li>whether the annotation type should be included on the generic annotation 76 * preference page,</li> 77 * <li>preference label.</li> 78 * </ul> 79 * 80 * @since 2.1 81 */ 82 public class AnnotationPreference { 83 84 /* String constants for style enumeration */ 85 86 /** 87 * Constant defining no decoration for the show in text style preference. 88 * @since 3.0 89 */ 90 public static final String STYLE_NONE= "NONE"; //$NON-NLS-1$ 91 /** 92 * Constant defining squiggly decoration for the show in text style preference. 93 * @since 3.0 94 */ 95 public static final String STYLE_SQUIGGLES= "SQUIGGLES"; //$NON-NLS-1$ 96 /** 97 * Constant defining the native problem underline decoration for the show in 98 * text style preference. 99 * <p> 100 * The look of this style is platform dependent. 101 * </p> 102 * @since 3.4 103 */ 104 public static final String STYLE_PROBLEM_UNDERLINE= "PROBLEM_UNDERLINE"; //$NON-NLS-1$ 105 106 /** 107 * Constant defining box decoration for the show in text style preference. 108 * @since 3.0 109 */ 110 public static final String STYLE_BOX= "BOX"; //$NON-NLS-1$ 111 112 /** 113 * Constant defining dashed box decoration for the show in text style preference. 114 * @since 3.3 115 */ 116 public static final String STYLE_DASHED_BOX= "DASHED_BOX"; //$NON-NLS-1$ 117 118 /** 119 * Constant defining underline decoration for the show in text style preference. 120 * @since 3.0 121 */ 122 public static final String STYLE_UNDERLINE= "UNDERLINE"; //$NON-NLS-1$ 123 /** 124 * Constant defining i-beam decoration for the show in text style preference. 125 * @since 3.0 126 */ 127 public static final String STYLE_IBEAM= "IBEAM"; //$NON-NLS-1$ 128 129 /* IDs for presentation preference attributes */ 130 131 /** 132 * The image to be used for drawing in the vertical ruler. 133 * @since 3.0 134 */ 135 protected static final Object IMAGE_DESCRIPTOR= new Object(); 136 /** 137 * The Quick Fix image to be used for drawing in the vertical ruler. 138 * @since 3.2 139 */ 140 protected static final Object QUICK_FIX_IMAGE_DESCRIPTOR= new Object(); 141 /** 142 * The preference label. 143 * @since 3.0 144 */ 145 protected static final Object PREFERENCE_LABEL= new Object(); 146 /** 147 * The presentation layer. 148 * @since 3.0 149 */ 150 protected static final Object PRESENTATION_LAYER= new Object(); 151 /** 152 * The symbolic name of the image to be drawn in the vertical ruler. 153 * @since 3.0 154 */ 155 protected static final Object SYMBOLIC_IMAGE_NAME= new Object(); 156 /** 157 * Indicates whether the annotation type contributed to the overview ruler's header. 158 * @since 3.0 159 */ 160 protected static final Object HEADER_VALUE= new Object(); 161 /** 162 * The annotation image provider. 163 * @since 3.0 164 */ 165 protected static final Object IMAGE_PROVIDER= new Object(); 166 /** 167 * The value for the includeOnPreferencePage property. 168 * @since 3.0 169 */ 170 protected static final Object INCLUDE_ON_PREFERENCE_PAGE= new Object(); 171 172 /* IDs for preference store access and initialization */ 173 174 /** 175 * The preference key for the visibility inside text. 176 * @since 3.0 177 */ 178 protected static final Object TEXT_PREFERENCE_KEY= new Object(); 179 /** 180 * The visibility inside text. 181 * @since 3.0 182 */ 183 protected static final Object TEXT_PREFERENCE_VALUE= new Object(); 184 /** 185 * The preference key for the presentation color. 186 * @since 3.0 187 */ 188 protected static final Object COLOR_PREFERENCE_KEY= new Object(); 189 /** The presentation color. 190 * @since 3.0 191 */ 192 protected static final Object COLOR_PREFERENCE_VALUE= new Object(); 193 /** 194 * The preference key for highlighting inside text. 195 * @since 3.0 196 */ 197 protected static final Object HIGHLIGHT_PREFERENCE_KEY= new Object(); 198 /** 199 * The value for highlighting inside text. 200 * @since 3.0 201 */ 202 protected static final Object HIGHLIGHT_PREFERENCE_VALUE= new Object(); 203 /** 204 * The preference key for go to next navigation enablement. 205 * @since 3.0 206 */ 207 protected static final Object IS_GO_TO_NEXT_TARGET_KEY= new Object(); 208 /** 209 * The value for go to next navigation enablement. 210 * @since 3.0 211 */ 212 protected static final Object IS_GO_TO_NEXT_TARGET_VALUE= new Object(); 213 /** 214 * The preference key for go to previous navigation enablement. 215 * @since 3.0 216 */ 217 protected static final Object IS_GO_TO_PREVIOUS_TARGET_KEY= new Object(); 218 /** 219 * The value for go to previous navigation enablement. 220 * @since 3.0 221 */ 222 protected static final Object IS_GO_TO_PREVIOUS_TARGET_VALUE= new Object(); 223 /** 224 * The preference key for the visibility in the vertical ruler. 225 * @since 3.0 226 */ 227 protected static final Object VERTICAL_RULER_PREFERENCE_KEY= new Object(); 228 /** 229 * The visibility in the vertical ruler. 230 * @since 3.0 231 */ 232 protected static final Object VERTICAL_RULER_PREFERENCE_VALUE= new Object(); 233 /** 234 * The preference key for the visibility in the overview ruler. 235 * @since 3.0 236 */ 237 protected static final Object OVERVIEW_RULER_PREFERENCE_KEY= new Object(); 238 /** 239 * The visibility in the overview ruler. 240 * @since 3.0 241 */ 242 protected static final Object OVERVIEW_RULER_PREFERENCE_VALUE= new Object(); 243 /** 244 * The preference key for the visibility in the next/previous drop down toolbar action. 245 * @since 3.0 246 */ 247 protected static final Object SHOW_IN_NAVIGATION_DROPDOWN_KEY= new Object(); 248 /** 249 * The value for the visibility in the next/previous drop down toolbar action. 250 * @since 3.0 251 */ 252 protected static final Object SHOW_IN_NAVIGATION_DROPDOWN_VALUE= new Object(); 253 /** 254 * The preference key for the decoration style. 255 * @since 3.0 256 */ 257 protected static final Object TEXT_STYLE_PREFERENCE_KEY= new Object(); 258 /** 259 * The value for the text decoration style. 260 * @since 3.0 261 */ 262 protected static final Object TEXT_STYLE_PREFERENCE_VALUE= new Object(); 263 264 /** 265 * Array of all supported attributes. 266 * @since 3.0 267 */ 268 protected static final Object[] ATTRIBUTES= new Object[] { 269 IMAGE_DESCRIPTOR, 270 QUICK_FIX_IMAGE_DESCRIPTOR, 271 PREFERENCE_LABEL, 272 PRESENTATION_LAYER, 273 SYMBOLIC_IMAGE_NAME, 274 HEADER_VALUE, 275 IMAGE_PROVIDER, 276 TEXT_PREFERENCE_KEY, 277 TEXT_PREFERENCE_VALUE, 278 COLOR_PREFERENCE_KEY, 279 COLOR_PREFERENCE_VALUE, 280 HIGHLIGHT_PREFERENCE_KEY, 281 HIGHLIGHT_PREFERENCE_VALUE, 282 IS_GO_TO_NEXT_TARGET_KEY, 283 IS_GO_TO_NEXT_TARGET_VALUE, 284 IS_GO_TO_PREVIOUS_TARGET_KEY, 285 IS_GO_TO_PREVIOUS_TARGET_VALUE, 286 VERTICAL_RULER_PREFERENCE_KEY, 287 VERTICAL_RULER_PREFERENCE_VALUE, 288 OVERVIEW_RULER_PREFERENCE_KEY, 289 OVERVIEW_RULER_PREFERENCE_VALUE, 290 SHOW_IN_NAVIGATION_DROPDOWN_KEY, 291 SHOW_IN_NAVIGATION_DROPDOWN_VALUE, 292 TEXT_STYLE_PREFERENCE_KEY, 293 TEXT_STYLE_PREFERENCE_VALUE, 294 INCLUDE_ON_PREFERENCE_PAGE 295 }; 296 297 /** The annotation type */ 298 private Object fAnnotationType; 299 /** The marker type */ 300 private String fMarkerType; 301 /** The marker severity */ 302 private int fSeverity; 303 /** 304 * The annotation image provider. 305 * @since 3.0 306 */ 307 public IAnnotationImageProvider fAnnotationImageProvider; 308 /** 309 * The configuration element from which to create the annotation image provider. 310 * @since 3.0 311 */ 312 public IConfigurationElement fConfigurationElement; 313 /** 314 * The name of the attribute used to load the annotation image provider 315 * from the configuration element. 316 * @since 3.0 317 */ 318 public String fAnnotationImageProviderAttribute; 319 /** 320 * The map of attributes. 321 * @since 3.0 322 */ 323 private Map<Object, Object> fAttributes= new HashMap<>(); 324 325 326 327 /** 328 * Creates a new un-initialized annotation preference. Note that instances 329 * with a <code>null</code> annotation type are invalid and should not be 330 * used. 331 */ AnnotationPreference()332 public AnnotationPreference() { 333 } 334 335 /** 336 * Creates a new annotation preference for the given annotation type. 337 * 338 * @param annotationType the annotation type 339 * @param colorKey the preference key for the presentation color 340 * @param textKey the preference key for the visibility inside text 341 * @param overviewRulerKey the preference key for the visibility in the 342 * overview ruler 343 * @param presentationLayer the presentation layer 344 */ AnnotationPreference(Object annotationType, String colorKey, String textKey, String overviewRulerKey, int presentationLayer)345 public AnnotationPreference(Object annotationType, String colorKey, String textKey, String overviewRulerKey, int presentationLayer) { 346 fAnnotationType= annotationType; 347 setValue(COLOR_PREFERENCE_KEY, colorKey); 348 setValue(TEXT_PREFERENCE_KEY, textKey); 349 setValue(OVERVIEW_RULER_PREFERENCE_KEY, overviewRulerKey); 350 setValue(PRESENTATION_LAYER, presentationLayer); 351 } 352 353 /** 354 * Sets the given value for the given attribute. 355 * 356 * @param attribute the attribute 357 * @param value the attribute value 358 * @since 3.0 359 */ setValue(Object attribute, Object value)360 protected void setValue(Object attribute, Object value) { 361 fAttributes.put(attribute, value); 362 } 363 364 /** 365 * Sets the given value for the given attribute. 366 * 367 * @param attribute the attribute 368 * @param value the attribute value 369 * @since 3.0 370 */ setValue(Object attribute, int value)371 protected void setValue(Object attribute, int value) { 372 fAttributes.put(attribute, Integer.valueOf(value)); 373 } 374 375 /** 376 * Sets the given value for the given attribute. 377 * 378 * @param attribute the attribute 379 * @param value the attribute value 380 * @since 3.0 381 */ setValue(Object attribute, boolean value)382 protected void setValue(Object attribute, boolean value) { 383 fAttributes.put(attribute, value ? Boolean.TRUE : Boolean.FALSE); 384 } 385 386 /** 387 * Returns the value of the given attribute as string. 388 * 389 * @param attribute the attribute 390 * @return the attribute value 391 * @since 3.0 392 */ getStringValue(Object attribute)393 protected String getStringValue(Object attribute) { 394 Object value= fAttributes.get(attribute); 395 if (value instanceof String) 396 return (String) value; 397 return null; 398 } 399 400 /** 401 * Returns the value of the given attribute as boolean. 402 * 403 * @param attribute the attribute 404 * @return the attribute value 405 * @since 3.0 406 */ getBooleanValue(Object attribute)407 protected boolean getBooleanValue(Object attribute) { 408 Object value= fAttributes.get(attribute); 409 if (value instanceof Boolean) 410 return ((Boolean) value).booleanValue(); 411 return false; 412 } 413 414 /** 415 * Returns the value of the given attribute as integer. 416 * 417 * @param attribute the attribute 418 * @return the attribute value 419 * @since 3.0 420 */ getIntegerValue(Object attribute)421 protected int getIntegerValue(Object attribute) { 422 Object value= fAttributes.get(attribute); 423 if (value instanceof Integer) 424 return ((Integer) value).intValue(); 425 return 0; 426 } 427 428 /** 429 * Returns the value of the given attribute. 430 * 431 * @param attribute the attribute 432 * @return the attribute value 433 * @since 3.0 434 */ getValue(Object attribute)435 public Object getValue(Object attribute) { 436 return fAttributes.get(attribute); 437 } 438 439 /** 440 * Returns whether the given attribute is defined. 441 * 442 * @param attribute the attribute 443 * @return <code>true</code> if the attribute has a value <code>false</code> otherwise 444 * @since 3.0 445 */ hasValue(Object attribute)446 public boolean hasValue(Object attribute) { 447 return fAttributes.get(attribute) != null; 448 } 449 450 /** 451 * Returns whether the given string is a preference key. 452 * 453 * @param key the string to test 454 * @return <code>true</code> if the string is a preference key 455 */ isPreferenceKey(String key)456 public boolean isPreferenceKey(String key) { 457 if (key == null) 458 return false; 459 460 return key.equals(getStringValue(COLOR_PREFERENCE_KEY)) || 461 key.equals(getStringValue(OVERVIEW_RULER_PREFERENCE_KEY)) || 462 key.equals(getStringValue(TEXT_PREFERENCE_KEY)) || 463 key.equals(getStringValue(HIGHLIGHT_PREFERENCE_KEY)) || 464 key.equals(getStringValue(TEXT_STYLE_PREFERENCE_KEY)) || 465 key.equals(getStringValue(VERTICAL_RULER_PREFERENCE_KEY)); 466 } 467 468 /** 469 * Returns the annotation type. Should not be null in a completely set up 470 * instance. 471 * 472 * @return the annotation type, <code>null</code> if the receiver has not 473 * been initialized yet 474 */ getAnnotationType()475 public Object getAnnotationType() { 476 return fAnnotationType; 477 } 478 479 /** 480 * Returns the marker type. 481 * 482 * @return the marker type, or <code>null</code> if none is set 483 * @deprecated since 3.0 484 */ 485 @Deprecated getMarkerType()486 public String getMarkerType() { 487 return fMarkerType; 488 } 489 490 /** 491 * Returns the marker severity. 492 * 493 * @return the marker severity 494 * @deprecated since 3.0 495 */ 496 @Deprecated getSeverity()497 public int getSeverity() { 498 return fSeverity; 499 } 500 501 /** 502 * Sets the annotation type. Note that instances with a <code>null</code> 503 * annotation type are considered invalid and should not be used with the 504 * framework. 505 * 506 * @param annotationType the annotation type 507 */ setAnnotationType(Object annotationType)508 public void setAnnotationType(Object annotationType) { 509 fAnnotationType= annotationType; 510 } 511 512 /** 513 * Sets the marker type. 514 * 515 * @param markerType the marker type 516 */ setMarkerType(String markerType)517 public void setMarkerType(String markerType) { 518 fMarkerType= markerType; 519 } 520 521 /** 522 * Sets the marker severity. 523 * 524 * @param severity the marker severity 525 */ setSeverity(int severity)526 public void setSeverity(int severity) { 527 fSeverity= severity; 528 } 529 530 /** 531 * Returns the preference key for the presentation color. 532 * 533 * @return the preference key for the presentation color or <code>null</code> 534 * if none is set 535 */ getColorPreferenceKey()536 public String getColorPreferenceKey() { 537 return getStringValue(COLOR_PREFERENCE_KEY); 538 } 539 540 /** 541 * Returns the default presentation color. 542 * 543 * @return the default presentation color or <code>null</code> if none is 544 * set 545 */ getColorPreferenceValue()546 public RGB getColorPreferenceValue() { 547 return (RGB) getValue(COLOR_PREFERENCE_VALUE); 548 } 549 550 /** 551 * Returns the presentation string for this annotation type. 552 * 553 * @return the presentation string for this annotation type or <code>null</code> 554 * if none is set 555 */ getPreferenceLabel()556 public String getPreferenceLabel() { 557 return getStringValue(PREFERENCE_LABEL); 558 } 559 560 /** 561 * Returns the preference key for the visibility in the overview ruler. 562 * 563 * @return the preference key for the visibility in the overview ruler or 564 * <code>null</code> if none is set 565 */ getOverviewRulerPreferenceKey()566 public String getOverviewRulerPreferenceKey() { 567 return getStringValue(OVERVIEW_RULER_PREFERENCE_KEY); 568 } 569 570 /** 571 * Returns the default visibility in the overview ruler. 572 * 573 * @return the default visibility in the overview ruler 574 */ getOverviewRulerPreferenceValue()575 public boolean getOverviewRulerPreferenceValue() { 576 return getBooleanValue(OVERVIEW_RULER_PREFERENCE_VALUE); 577 } 578 579 /** 580 * Returns the preference key for the visibility in the vertical ruler. 581 * 582 * @return the preference key for the visibility in the vertical ruler or 583 * <code>null</code> if none is set 584 * @since 3.0 585 */ getVerticalRulerPreferenceKey()586 public String getVerticalRulerPreferenceKey() { 587 return getStringValue(VERTICAL_RULER_PREFERENCE_KEY); 588 } 589 590 /** 591 * Returns the default visibility in the vertical ruler. 592 * 593 * @return the default visibility in the vertical ruler 594 * @since 3.0 595 */ getVerticalRulerPreferenceValue()596 public boolean getVerticalRulerPreferenceValue() { 597 return getBooleanValue(VERTICAL_RULER_PREFERENCE_VALUE); 598 } 599 600 /** 601 * Returns the presentation layer. 602 * 603 * @return the presentation layer 604 */ getPresentationLayer()605 public int getPresentationLayer() { 606 return getIntegerValue(PRESENTATION_LAYER); 607 } 608 609 /** 610 * Returns the preference key for the visibility inside text. 611 * 612 * @return the preference key for the visibility inside text or <code>null</code> 613 * if none is set 614 */ getTextPreferenceKey()615 public String getTextPreferenceKey() { 616 return getStringValue(TEXT_PREFERENCE_KEY); 617 } 618 619 /** 620 * Returns the default visibility inside text. 621 * 622 * @return the default visibility inside text 623 */ getTextPreferenceValue()624 public boolean getTextPreferenceValue() { 625 return getBooleanValue(TEXT_PREFERENCE_VALUE); 626 } 627 628 /** 629 * Returns the preference key for highlighting inside text. 630 * 631 * @return the preference key for highlighting inside text or <code>null</code> 632 * if none is set 633 * @since 3.0 634 */ getHighlightPreferenceKey()635 public String getHighlightPreferenceKey() { 636 return getStringValue(HIGHLIGHT_PREFERENCE_KEY); 637 } 638 639 /** 640 * Returns the default value for highlighting inside text. 641 * 642 * @return the default value for highlighting inside text 643 * @since 3.0 644 */ getHighlightPreferenceValue()645 public boolean getHighlightPreferenceValue() { 646 return getBooleanValue(HIGHLIGHT_PREFERENCE_VALUE); 647 } 648 649 /** 650 * Returns whether the annotation type contributes to the header of the overview ruler. 651 * 652 * @return <code>true</code> if the annotation type contributes to the header of the overview ruler 653 */ contributesToHeader()654 public boolean contributesToHeader() { 655 return getBooleanValue(HEADER_VALUE); 656 } 657 658 /** 659 * Sets the preference key for the presentation color. 660 * 661 * @param colorKey the preference key 662 */ setColorPreferenceKey(String colorKey)663 public void setColorPreferenceKey(String colorKey) { 664 setValue(COLOR_PREFERENCE_KEY, colorKey); 665 } 666 667 /** 668 * Sets the default presentation color. 669 * 670 * @param colorValue the default color 671 */ setColorPreferenceValue(RGB colorValue)672 public void setColorPreferenceValue(RGB colorValue) { 673 setValue(COLOR_PREFERENCE_VALUE, colorValue); 674 } 675 676 /** 677 * Sets the presentation label of this annotation type. 678 * 679 * @param label the presentation label 680 */ setPreferenceLabel(String label)681 public void setPreferenceLabel(String label) { 682 setValue(PREFERENCE_LABEL, label); 683 } 684 685 /** 686 * Sets the preference key for the visibility in the overview ruler. 687 * 688 * @param overviewRulerKey the preference key 689 */ setOverviewRulerPreferenceKey(String overviewRulerKey)690 public void setOverviewRulerPreferenceKey(String overviewRulerKey) { 691 setValue(OVERVIEW_RULER_PREFERENCE_KEY, overviewRulerKey); 692 } 693 694 /** 695 * Sets the default visibility in the overview ruler. 696 * 697 * @param overviewRulerValue <code>true</code> if visible by default, <code>false</code> otherwise 698 */ setOverviewRulerPreferenceValue(boolean overviewRulerValue)699 public void setOverviewRulerPreferenceValue(boolean overviewRulerValue) { 700 setValue(OVERVIEW_RULER_PREFERENCE_VALUE, overviewRulerValue); 701 } 702 703 /** 704 * Sets the preference key for the visibility in the vertical ruler. 705 * 706 * @param verticalRulerKey the preference key 707 * @since 3.0 708 */ setVerticalRulerPreferenceKey(String verticalRulerKey)709 public void setVerticalRulerPreferenceKey(String verticalRulerKey) { 710 setValue(VERTICAL_RULER_PREFERENCE_KEY, verticalRulerKey); 711 } 712 713 /** 714 * Sets the default visibility in the vertical ruler. 715 * 716 * @param verticalRulerValue <code>true</code> if visible by default, <code>false</code> otherwise 717 * @since 3.0 718 */ setVerticalRulerPreferenceValue(boolean verticalRulerValue)719 public void setVerticalRulerPreferenceValue(boolean verticalRulerValue) { 720 setValue(VERTICAL_RULER_PREFERENCE_VALUE, verticalRulerValue); 721 } 722 723 /** 724 * Sets the presentation layer. 725 * 726 * @param presentationLayer the presentation layer 727 */ setPresentationLayer(int presentationLayer)728 public void setPresentationLayer(int presentationLayer) { 729 setValue(PRESENTATION_LAYER, presentationLayer); 730 } 731 732 /** 733 * Sets the preference key for the visibility of squiggles inside text. 734 * 735 * @param textKey the preference key 736 */ setTextPreferenceKey(String textKey)737 public void setTextPreferenceKey(String textKey) { 738 setValue(TEXT_PREFERENCE_KEY, textKey); 739 } 740 741 /** 742 * Sets the default visibility inside text. 743 * 744 * @param textValue <code>true</code> if visible by default, <code>false</code> otherwise 745 */ setTextPreferenceValue(boolean textValue)746 public void setTextPreferenceValue(boolean textValue) { 747 setValue(TEXT_PREFERENCE_VALUE, textValue); 748 } 749 750 /** 751 * Sets the preference key for highlighting inside text. 752 * 753 * @param highlightKey the preference key 754 * @since 3.0 755 */ setHighlightPreferenceKey(String highlightKey)756 public void setHighlightPreferenceKey(String highlightKey) { 757 setValue(HIGHLIGHT_PREFERENCE_KEY, highlightKey); 758 } 759 760 /** 761 * Sets the default value for highlighting inside text. 762 * 763 * @param highlightValue <code>true</code> if highlighted in text by default, <code>false</code> otherwise 764 * @since 3.0 765 */ setHighlightPreferenceValue(boolean highlightValue)766 public void setHighlightPreferenceValue(boolean highlightValue) { 767 setValue(HIGHLIGHT_PREFERENCE_VALUE, highlightValue); 768 } 769 770 /** 771 * Sets whether the annotation type contributes to the overview ruler's header. 772 * 773 * @param contributesToHeader <code>true</code> if in header, <code>false</code> otherwise 774 */ setContributesToHeader(boolean contributesToHeader)775 public void setContributesToHeader(boolean contributesToHeader) { 776 setValue(HEADER_VALUE, contributesToHeader); 777 } 778 779 /** 780 * Returns the default value for go to next navigation enablement. 781 * 782 * @return <code>true</code> if enabled by default 783 * @since 3.0 784 */ isGoToNextNavigationTarget()785 public boolean isGoToNextNavigationTarget() { 786 return getBooleanValue(IS_GO_TO_NEXT_TARGET_VALUE); 787 } 788 789 /** 790 * Sets the default value for go to next navigation enablement. 791 * 792 * @param isGoToNextNavigationTarget <code>true</code> if enabled by default 793 * @since 3.0 794 */ setIsGoToNextNavigationTarget(boolean isGoToNextNavigationTarget)795 public void setIsGoToNextNavigationTarget(boolean isGoToNextNavigationTarget) { 796 setValue(IS_GO_TO_NEXT_TARGET_VALUE, isGoToNextNavigationTarget); 797 } 798 799 /** 800 * Returns the preference key for go to next navigation enablement. 801 * 802 * @return the preference key or <code>null</code> if the key is undefined 803 * @since 3.0 804 */ getIsGoToNextNavigationTargetKey()805 public String getIsGoToNextNavigationTargetKey() { 806 return getStringValue(IS_GO_TO_NEXT_TARGET_KEY); 807 } 808 809 /** 810 * Sets the preference key for go to next navigation enablement. 811 * 812 * @param isGoToNextNavigationTargetKey <code>true</code> if enabled by default 813 * @since 3.0 814 */ setIsGoToNextNavigationTargetKey(String isGoToNextNavigationTargetKey)815 public void setIsGoToNextNavigationTargetKey(String isGoToNextNavigationTargetKey) { 816 setValue(IS_GO_TO_NEXT_TARGET_KEY, isGoToNextNavigationTargetKey); 817 } 818 819 /** 820 * Returns the default value for go to previous navigation enablement. 821 * 822 * @return <code>true</code> if enabled by default 823 * @since 3.0 824 */ isGoToPreviousNavigationTarget()825 public boolean isGoToPreviousNavigationTarget() { 826 return getBooleanValue(IS_GO_TO_PREVIOUS_TARGET_VALUE); 827 } 828 829 /** 830 * Sets the default value for go to previous navigation enablement. 831 * 832 * @param isGoToPreviousNavigationTarget <code>true</code> if enabled by default 833 * @since 3.0 834 */ setIsGoToPreviousNavigationTarget(boolean isGoToPreviousNavigationTarget)835 public void setIsGoToPreviousNavigationTarget(boolean isGoToPreviousNavigationTarget) { 836 setValue(IS_GO_TO_PREVIOUS_TARGET_VALUE, isGoToPreviousNavigationTarget); 837 } 838 839 /** 840 * Returns the preference key for go to previous navigation enablement. 841 * 842 * @return the preference key or <code>null</code> if the key is undefined 843 * @since 3.0 844 */ getIsGoToPreviousNavigationTargetKey()845 public String getIsGoToPreviousNavigationTargetKey() { 846 return getStringValue(IS_GO_TO_PREVIOUS_TARGET_KEY); 847 } 848 849 /** 850 * Sets the preference key for go to previous navigation enablement. 851 * 852 * @param isGoToPreviousNavigationTargetKey the preference key 853 * @since 3.0 854 */ setIsGoToPreviousNavigationTargetKey(String isGoToPreviousNavigationTargetKey)855 public void setIsGoToPreviousNavigationTargetKey(String isGoToPreviousNavigationTargetKey) { 856 setValue(IS_GO_TO_PREVIOUS_TARGET_KEY, isGoToPreviousNavigationTargetKey); 857 } 858 859 /** 860 * Returns the preference key for the visibility in the next/previous drop down toolbar action. 861 * 862 * @return the preference key or <code>null</code> if the key is undefined 863 * @since 3.0 864 */ getShowInNextPrevDropdownToolbarActionKey()865 public String getShowInNextPrevDropdownToolbarActionKey() { 866 return getStringValue(SHOW_IN_NAVIGATION_DROPDOWN_KEY); 867 } 868 869 /** 870 * Sets the preference key for the visibility in the next/previous drop down toolbar action. 871 * 872 * @param showInNextPrevDropdownToolbarActionKey the preference key 873 * @since 3.0 874 */ setShowInNextPrevDropdownToolbarActionKey(String showInNextPrevDropdownToolbarActionKey)875 public void setShowInNextPrevDropdownToolbarActionKey(String showInNextPrevDropdownToolbarActionKey) { 876 setValue(SHOW_IN_NAVIGATION_DROPDOWN_KEY, showInNextPrevDropdownToolbarActionKey); 877 } 878 879 /** 880 * Returns the default value for the visibility in the next/previous drop down toolbar action. 881 * 882 * @return <code>true</code> if enabled by default 883 * @since 3.0 884 */ isShowInNextPrevDropdownToolbarAction()885 public boolean isShowInNextPrevDropdownToolbarAction() { 886 return getBooleanValue(SHOW_IN_NAVIGATION_DROPDOWN_VALUE); 887 } 888 889 /** 890 * Sets the default value for the visibility in the next/previous drop down toolbar action. 891 * 892 * @param showInNextPrevDropdownToolbarAction <code>true</code> if enabled by default 893 * @since 3.0 894 */ setShowInNextPrevDropdownToolbarAction(boolean showInNextPrevDropdownToolbarAction)895 public void setShowInNextPrevDropdownToolbarAction(boolean showInNextPrevDropdownToolbarAction) { 896 setValue(SHOW_IN_NAVIGATION_DROPDOWN_VALUE, showInNextPrevDropdownToolbarAction); 897 } 898 899 /** 900 * Sets the preference key for the text style property. 901 * 902 * @param key the new key 903 * @since 3.0 904 */ setTextStylePreferenceKey(String key)905 public void setTextStylePreferenceKey(String key) { 906 setValue(TEXT_STYLE_PREFERENCE_KEY, key); 907 } 908 909 /** 910 * Returns the preference key for the decoration style used when the annotation is shown in text. 911 * 912 * @return the preference key for the decoration style or <code>null</code> if the key is undefined 913 * @since 3.0 914 */ getTextStylePreferenceKey()915 public String getTextStylePreferenceKey() { 916 return getStringValue(TEXT_STYLE_PREFERENCE_KEY); 917 } 918 919 /** 920 * Returns the value for the decoration style used when the annotation is shown in text. 921 * 922 * @return the value for the decoration style or <code>null</code> if the key is undefined 923 * @since 3.0 924 */ getTextStyleValue()925 public String getTextStyleValue() { 926 return getStringValue(TEXT_STYLE_PREFERENCE_VALUE); 927 } 928 929 /** 930 * Sets the value for the text style property. 931 * 932 * @param value the new text decoration style 933 * @since 3.0 934 */ setTextStyleValue(String value)935 public void setTextStyleValue(String value) { 936 if (!STYLE_NONE.equals(value) && !STYLE_BOX.equals(value) && !STYLE_DASHED_BOX.equals(value) 937 && !STYLE_IBEAM.equals(value) && !STYLE_SQUIGGLES.equals(value) 938 && !STYLE_PROBLEM_UNDERLINE.equals(value) && !STYLE_UNDERLINE.equals(value)) 939 throw new IllegalArgumentException(); 940 941 setValue(TEXT_STYLE_PREFERENCE_VALUE, value); 942 } 943 944 /** 945 * Returns the image descriptor for the image to be drawn in the vertical ruler. The provided 946 * image is only used, if <code>getAnnotationImageProvider</code> returns <code>null</code>. 947 * 948 * @return the image descriptor or <code>null</code> 949 * @since 3.0 950 */ getImageDescriptor()951 public ImageDescriptor getImageDescriptor() { 952 return (ImageDescriptor) getValue(IMAGE_DESCRIPTOR); 953 } 954 955 /** 956 * Sets the image descriptor for the image to be drawn in the vertical ruler. 957 * 958 * @param descriptor the image descriptor 959 * @since 3.0 960 */ setImageDescriptor(ImageDescriptor descriptor)961 public void setImageDescriptor(ImageDescriptor descriptor) { 962 setValue(IMAGE_DESCRIPTOR, descriptor); 963 } 964 965 /** 966 * Returns the symbolic name of the image to be drawn in the vertical ruler. 967 * The image is only used if <code>getImageDescriptor</code> returns <code>null</code>. 968 * 969 * @return the symbolic name of the image or <code>null</code> 970 * @since 3.0 971 */ getSymbolicImageName()972 public String getSymbolicImageName() { 973 return getStringValue(SYMBOLIC_IMAGE_NAME); 974 } 975 976 /** 977 * Sets the symbolic name of the image to be drawn in the vertical ruler. 978 * 979 * @param symbolicImageName the symbolic image name 980 * @since 3.0 981 */ setSymbolicImageName(String symbolicImageName)982 public void setSymbolicImageName(String symbolicImageName) { 983 setValue(SYMBOLIC_IMAGE_NAME, symbolicImageName); 984 } 985 986 /** 987 * Returns the annotation image provider. If no default annotation image 988 * provider has been set, this method checks whether the annotation image 989 * provider data has been set. If so, an annotation image provider is 990 * created if the configuration element's plug-in is loaded. When an 991 * annotation image provider has been created successfully, it is set as 992 * the default annotation image provider. 993 * 994 * @return the annotation image provider 995 * @since 3.0 996 */ getAnnotationImageProvider()997 public IAnnotationImageProvider getAnnotationImageProvider() { 998 if (fAnnotationImageProvider == null) { 999 if (fConfigurationElement != null && fAnnotationImageProviderAttribute != null) { 1000 Bundle bundle= Platform.getBundle( fConfigurationElement.getContributor().getName()); 1001 if (bundle != null && bundle.getState() == Bundle.ACTIVE) { 1002 try { 1003 fAnnotationImageProvider= (IAnnotationImageProvider) fConfigurationElement.createExecutableExtension(fAnnotationImageProviderAttribute); 1004 } catch (CoreException x) { 1005 TextEditorPlugin.getDefault().getLog().log(x.getStatus()); 1006 } 1007 } 1008 } 1009 } 1010 return fAnnotationImageProvider; 1011 } 1012 1013 /** 1014 * Sets the annotation image provider who provides images for annotations 1015 * of the specified annotation type. 1016 * 1017 * @param provider the annotation image provider 1018 * @since 3.0 1019 */ setAnnotationImageProvider(IAnnotationImageProvider provider)1020 public void setAnnotationImageProvider(IAnnotationImageProvider provider) { 1021 fAnnotationImageProvider= provider; 1022 setValue(IMAGE_PROVIDER, provider != null); 1023 } 1024 1025 /** 1026 * Sets the data needed to create the annotation image provider. 1027 * 1028 * @param configurationElement the configuration element 1029 * @param annotationImageProviderAttribute the attribute of the 1030 * configuration element 1031 * @since 3.0 1032 */ setAnnotationImageProviderData(IConfigurationElement configurationElement, String annotationImageProviderAttribute)1033 public void setAnnotationImageProviderData(IConfigurationElement configurationElement, String annotationImageProviderAttribute) { 1034 fConfigurationElement= configurationElement; 1035 fAnnotationImageProviderAttribute= annotationImageProviderAttribute; 1036 setValue(IMAGE_PROVIDER, annotationImageProviderAttribute != null); 1037 } 1038 1039 /** 1040 * Sets the property of this annotation preference whether it should be included 1041 * on the default annotation preference page. 1042 * 1043 * @param includeOnPreferencePage the new value 1044 * @since 3.0 1045 */ setIncludeOnPreferencePage(boolean includeOnPreferencePage)1046 public void setIncludeOnPreferencePage(boolean includeOnPreferencePage) { 1047 setValue(INCLUDE_ON_PREFERENCE_PAGE, includeOnPreferencePage); 1048 } 1049 1050 /** 1051 * Returns the property of the receiver of whether it should be included on 1052 * the default annotation preference page. 1053 * 1054 * @return the includeOnPreferencePage property 1055 * @since 3.0 1056 */ isIncludeOnPreferencePage()1057 public boolean isIncludeOnPreferencePage() { 1058 Object value= fAttributes.get(INCLUDE_ON_PREFERENCE_PAGE); 1059 if (value instanceof Boolean) 1060 return ((Boolean) value).booleanValue(); 1061 return true; 1062 } 1063 1064 /** 1065 * Merges the values of the given preference into this preference. Existing 1066 * values will not be overwritten. Subclasses may extend. 1067 * 1068 * @param preference the preference to merge into this preference 1069 * @since 3.0 1070 */ merge(AnnotationPreference preference)1071 public void merge(AnnotationPreference preference) { 1072 if (!getAnnotationType().equals(preference.getAnnotationType())) 1073 return; 1074 1075 for (int i= 0; i < ATTRIBUTES.length; i++) { 1076 if (!hasValue(ATTRIBUTES[i])) 1077 setValue(ATTRIBUTES[i], preference.getValue(ATTRIBUTES[i])); 1078 } 1079 1080 if (fAnnotationImageProvider == null) 1081 fAnnotationImageProvider= preference.fAnnotationImageProvider; 1082 if (fConfigurationElement == null) 1083 fConfigurationElement= preference.fConfigurationElement; 1084 if (fAnnotationImageProviderAttribute == null) 1085 fAnnotationImageProviderAttribute= preference.fAnnotationImageProviderAttribute; 1086 } 1087 1088 /** 1089 * Sets the Quick Fix image descriptor for the image to be drawn in the vertical ruler. 1090 * 1091 * @param descriptor the image descriptor 1092 * @since 3.2 1093 */ setQuickFixImageDescriptor(ImageDescriptor descriptor)1094 public void setQuickFixImageDescriptor(ImageDescriptor descriptor) { 1095 setValue(QUICK_FIX_IMAGE_DESCRIPTOR, descriptor); 1096 } 1097 1098 /** 1099 * Returns the Quick Fix image descriptor for the image to be drawn in the vertical ruler. The provided 1100 * image is only used, if <code>getAnnotationImageProvider</code> returns <code>null</code>. 1101 * 1102 * @return the image descriptor or <code>null</code> 1103 * @since 3.2 1104 */ getQuickFixImageDescriptor()1105 public ImageDescriptor getQuickFixImageDescriptor() { 1106 return (ImageDescriptor) getValue(QUICK_FIX_IMAGE_DESCRIPTOR); 1107 } 1108 1109 } 1110