brunoais
brunoais

Reputation: 6836

Add custom markers to java editor in eclipse

I've been trying to add custom markers to eclipse editor for many many hours (days) and I just can't get it to work.

I can add problem markers well and without any issues by extending them on my own plugin.xml. It does everything I want EXCEPT the icon for the marker. I want a different icon. Here's What I have:

plugin.xml

<extension
    point="org.eclipse.ui.editors.annotationTypes">
    <type
        markerType="Plugin.MyMarker"
        name="Plugin.MyMarker"/>
</extension>
<extension
    id="MyMarker"
    point="org.eclipse.core.resources.markers">
    <super type="org.eclipse.core.resources.textmarker" />
    <!-- <super type="org.eclipse.core.resources.problemmarker" /> --><!-- if I remove this comment, all works... But I don't want that icon-->
    <persistent value="true"/>
</extension>
<extension
    id="Plugin.markerAnnotationSpecifications"
    point="org.eclipse.ui.editors.markerAnnotationSpecification">
    <specification
        annotationType="Plugin.MyMarker"
        colorPreferenceKey="Plugin.markerColor"
        colorPreferenceValue="100,100,100"
        contributesToHeader="false"
        highlightPreferenceKey="Plugin.markerHighlight"
        highlightPreferenceValue="true"
        includeOnPreferencePage="true"
        icon="icons/icon_mine.gif"
        label="My beautiful label"
        overviewRulerPreferenceKey="Plugin.markerOverview"
        overviewRulerPreferenceValue="true"
        presentationLayer="0"
        symbolicIcon="warning"
        textPreferenceKey="Plugin.tarkerText"
        textPreferenceValue="true"
        textStylePreferenceKey="Plugin.textStyle"
        textStylePreferenceValue="BOX"
        verticalRulerPreferenceKey="Plugin.markerRuler"
        verticalRulerPreferenceValue="true" />

MyPlugin.java

IMarker myMarker = file.createMarker("Plugin.MyMarker");
if(!myMarker.exists()){
    Activator.myLog.log(new Status(Status.ERROR, LOG_PLUGIN_NAME, 15, "There's no marker!", null)); 
}
myMarker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
myMarker.setAttribute(IMarker.MESSAGE, "Txt:\nabc");
myMarker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
myMarker.setAttribute(IMarker.LINE_NUMBER, line);
myMarker.setAttribute(IMarker.CHAR_START, searchStart);
myMarker.setAttribute(IMarker.CHAR_END, searchEnd);

The marker image is here: icon="icons/icon_mine.gif"

If I use the code as it is above, the annotation appears in the menu under the annotations (General>Editors>TextEditors>Annotations)option with the correct image and the correct options as I would expect it to be.

Other log messages that I placed in the code confirm that that code executes well same as the results if I just change that line I commented in the XML (see the XML comment).

But still, I can't see anything telling me if the marker is actually being applied or an error (or anything in the log or the console, on that matter). It is as if I didn't setup anything and nothing is happening.
Any help is welcome

Upvotes: 2

Views: 1642

Answers (1)

brunoais
brunoais

Reputation: 6836

Please do check that the ids of each <extension> must start with the same substring as as the package of the project. I see you using Plugin as the package and packages usually start with low case letters.

Please try renaming the prefixes of the ids to plugin. (low case) instead of Plugin.

Upvotes: 1

Related Questions