Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to add an Annotation (visible in TextEditor and Childs) to a File?
How to add an Annotation (visible in TextEditor and Childs) to a File? [message #332218] Sat, 11 October 2008 14:44 Go to next message
Jarod McKnight is currently offline Jarod McKnightFriend
Messages: 2
Registered: July 2009
Junior Member
Hi,
I am building a plugin to show source duplications (clones in short) in
files with text content.
I already build my own Markers (#1) and added them to the IFiles having
some clones. I also added a decorator (#2), which marks all my files and
folders in Ressources views (like the Navigator) with an icon. That both
works, but I am unable to add Annotations to the source code.

As far as I understand, it should be possible to add Annotations which
will be displayed in every Editor extending the TextEditor (so that
someone editing an java file in the default java editor can see them, for
example). For my annotations I extended AnnotationType (#3) and
markerAnnotationSpecification (#4). In the preference page under
TextEditor->Annotations my new Annotation shows up, so it looks like I
made that correct.

But now I am stuck, because I haven't found (neither in the eclipse plugin
documentations, nor in the newsgroup [maybe I just lack search-fu this
weekend]) a way to add an Annotation to the File. What I found so far is,
that I need a AnnotationModel to add Annotations. My try to build a new
Model wasn't succesfull (#5), and I haven't found a method to obtain one
for the File.

I would appreciate any hint, so thx in advance
~ Jarod

#1:
<extension
id="duplicaty.clone.marker"
name="Clone Marker"
point="org.eclipse.core.resources.markers">
<super
type="org.eclipse.core.resources.textmarker">
</super>
</extension>

#2:
<extension
point="org.eclipse.ui.decorators">
<decorator
adaptable="true"
class="duplicaty.decorators.ContainsClone"
id="duplicaty.decorators.ContainsClone"
label="Contains Clone Decorator"
lightweight="true"
state="true">
<enablement>
<and>
<objectClass
name="org.eclipse.core.resources.IResource">
</objectClass>
<or>
<objectClass
name="org.eclipse.core.resources.IFolder">
</objectClass>
<objectClass
name="org.eclipse.core.resources.IFile">
</objectClass>
</or>
</and>
</enablement>
</decorator>
</extension>

#3:
<extension
point="org.eclipse.ui.editors.annotationTypes">
<type
markerSeverity="0"
markerType="duplicaty.clone.marker"
name="duplicaty.clone.annotation">
</type>
</extension>

#4:
<extension
point="org.eclipse.ui.editors.markerAnnotationSpecification ">
<specification
annotationType="duplicaty.clone.annotation"
colorPreferenceKey="Clone_Annotation"
colorPreferenceValue="125,125,0"
contributesToHeader="false"
highlightPreferenceKey="Clone"
highlightPreferenceValue="true"
includeOnPreferencePage="true"
isGoToNextNavigationTarget="false"
isGoToPreviousNavigationTarget="false"
label="Clone"
overviewRulerPreferenceKey="Clone_Annotation"
overviewRulerPreferenceValue="true"
showInNextPrevDropdownToolbarAction="false"
textPreferenceKey="Clone_Annotation"
textPreferenceValue="true"
textStylePreferenceValue="NONE"
verticalRulerPreferenceKey="Clone_Annotation"
verticalRulerPreferenceValue="true">
</specification>
</extension>

#5:
// sourceFile is of class File (from eclipse)
ResourceMarkerAnnotationModel model = new
ResourceMarkerAnnotationModel(sourceFile);
model.addAnnotation(new
Annotation("duplicaty.clone.annotation",false,"CLONE"), new
Position(20,5));
Re: How to add an Annotation (visible in TextEditor and Childs) to a File? [message #332228 is a reply to message #332218] Mon, 13 October 2008 12:22 Go to previous message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Jarod McKnight wrote:
> Hi,
> I am building a plugin to show source duplications (clones in short)
> in files with text content.
> I already build my own Markers (#1) and added them to the IFiles
> having some clones. I also added a decorator (#2), which marks all my
> files and folders in Ressources views (like the Navigator) with an
> icon. That both works, but I am unable to add Annotations to the
> source code.
>
> As far as I understand, it should be possible to add Annotations which
> will be displayed in every Editor extending the TextEditor (so that
> someone editing an java file in the default java editor can see them,
> for example). For my annotations I extended AnnotationType (#3) and
> markerAnnotationSpecification (#4). In the preference page under
> TextEditor->Annotations my new Annotation shows up, so it looks like I
> made that correct.
>
> But now I am stuck, because I haven't found (neither in the eclipse
> plugin documentations, nor in the newsgroup [maybe I just lack
> search-fu this weekend]) a way to add an Annotation to the File. What
> I found so far is, that I need a AnnotationModel to add Annotations.
> My try to build a new Model wasn't succesfull (#5), and I haven't
> found a method to obtain one for the File.
>
> I would appreciate any hint, so thx in advance
textStylePreferenceValue="NONE"

is not valid and textStylePreferenceKey is missing. Take a look at the
contributions in org.eclipse.ui.editors/plugin.xml for working examples.

Dani
> ~ Jarod
>
> #1:
> <extension
> id="duplicaty.clone.marker"
> name="Clone Marker"
> point="org.eclipse.core.resources.markers">
> <super
> type="org.eclipse.core.resources.textmarker">
> </super>
> </extension>
>
> #2:
> <extension
> point="org.eclipse.ui.decorators">
> <decorator
> adaptable="true"
> class="duplicaty.decorators.ContainsClone"
> id="duplicaty.decorators.ContainsClone"
> label="Contains Clone Decorator"
> lightweight="true"
> state="true">
> <enablement>
> <and>
> <objectClass
> name="org.eclipse.core.resources.IResource">
> </objectClass>
> <or>
> <objectClass
> name="org.eclipse.core.resources.IFolder">
> </objectClass>
> <objectClass
> name="org.eclipse.core.resources.IFile">
> </objectClass>
> </or>
> </and>
> </enablement>
> </decorator>
> </extension>
>
> #3:
> <extension
> point="org.eclipse.ui.editors.annotationTypes">
> <type
> markerSeverity="0"
> markerType="duplicaty.clone.marker"
> name="duplicaty.clone.annotation">
> </type>
> </extension>
>
> #4:
> <extension
> point="org.eclipse.ui.editors.markerAnnotationSpecification ">
> <specification
> annotationType="duplicaty.clone.annotation"
> colorPreferenceKey="Clone_Annotation"
> colorPreferenceValue="125,125,0"
> contributesToHeader="false"
> highlightPreferenceKey="Clone"
> highlightPreferenceValue="true"
> includeOnPreferencePage="true"
> isGoToNextNavigationTarget="false"
> isGoToPreviousNavigationTarget="false"
> label="Clone"
> overviewRulerPreferenceKey="Clone_Annotation"
> overviewRulerPreferenceValue="true"
> showInNextPrevDropdownToolbarAction="false"
> textPreferenceKey="Clone_Annotation"
> textPreferenceValue="true"
> textStylePreferenceValue="NONE"
> verticalRulerPreferenceKey="Clone_Annotation"
> verticalRulerPreferenceValue="true">
> </specification>
> </extension>
>
> #5:
> // sourceFile is of class File (from eclipse)
> ResourceMarkerAnnotationModel model = new
> ResourceMarkerAnnotationModel(sourceFile);
> model.addAnnotation(new
> Annotation("duplicaty.clone.annotation",false,"CLONE"), new
> Position(20,5));
>
>
Previous Topic:Mail server for testing
Next Topic:Content Assist shortcut - am I losing my mind?
Goto Forum:
  


Current Time: Wed Jul 17 19:50:45 GMT 2024

Powered by FUDForum. Page generated in 0.03181 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top