Which eclipse listener should I use to add annotations to a text editor - eclipse

I am an eclipse newbie. I have a long term goal which is to add my own annotations to the java editor: a bit like FindBugs. I want my own static code analysers, and to be able to add markers/annotations to resources.
So I have read a lot of excellent documentation, and undertaken a load of tutorials. The most helpful was probably http://www.ibm.com/developerworks/opensource/tutorials/os-ecl-commplgin2/section9.html. A lot of the Lars Vogel documents have been useful too. I can now make TextEditors with syntax highlighters. I am however struggling with the best approach for adding annotations.
I understand roughly how to do this: the text editor has a DocumentProvider. The DocumentProvider has an AnnotationModel. It is possible to add annotations to the annotation model.
My question is "where do I put this code" specifically the code that scans the text in the editor and updates the annotation model. It seems clear that this should be in response to a listener...but which one?
I have tried a ResourceChangeListener. This seems to only fire on a save option, rather than when text is typed. In addition I don't know how to get the editor from the resource. ("The" editor is probably a misnomer as presumably the resource can be open in multiple editors). I can find the current editor via IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor(), but this seems the wrong approach, as I want to update all relevant annotation models.
I have tried adding an ElementStateListener to the text editor. None of the events seem to be the one I want.
I've looked at DamageRepairers...these seem to nearly be what I want, except that long term I want to tie into the JavaEditor, so I don't want to change the default DamageRepair.
Thanks for all the help

I found that this question can be answered, by mentioning the following resource: www.ibm.com/developerworks/opensource/tutorials/os-eclipse-plugin-guide/index.html
The question author also mentions here:
I add the annotations to the resource, and the annotations are
auto-magically added to the editor.
So when my plugin starts I run through the active resources, add
annotations to them if needed, then add a resource changed listener
which adds them as the resource is opened.

Related

Is there an easy way to search Snippets in SQL Developer?

I find that my collection of snippets has grown far beyond what can be managed by assigning a Category and Name. "I know I wrote this code before, it's probably in one of these three categories but it definitely hit table T and used function F; should my time be spent clicking thru each likely category and dragging out each snippet, reinventing it, or searching the snippets.xml?" is a conversation I have with myself far too often.
I tend to copy the snippet body into the tag so I can hover and see some of what's in there but still, being able to actually search the snippets (like we can do with SQL History) would be amazing. Is there a way?
No, there is no way today.
I'm happy to log an enhancement request on your behalf for that feature.
In the meantime, maybe consider trying the Code Templates instead?
You can 'search' either by the name of your code template, or by the first word of the code template 'source'
type the word, and then ctrl+enter to bring up the list of 'hits'

Can Emmet Be Used to Create FXML?

I have a scalaFX app that currently has its views created programmatically. I am wondering if I can use the Emmet tool to create FXML (particularly ScalaFXML) because I want to recreate my views in ScalaFXML to separate my views from my controllers more effectively. I have searched the internet and cannot find out if this is possible. So far I have only used Emmet for HTML. Thanks in advance for the help!
I have been looking around for something for PrimeFaces; I had trouble finding anything. I guess maybe it's because people who are using it are actually writing "normal" HTML with JS frameworks.
The good news is, it's completely (and easily!) customizable: just find the installation directory, and edit the "snippets.json" file, or create a new one called (for example) snippets-scalaFX.json. Mine on a Windows 10 machine, installed as a plugin for NPP, was C:\Program Files (x86)\Notepad++\plugins\EmmetNPP\emmet\snippets.json.
It's pretty obvious once you get in there, but inside the "snippets" object just add some more fields for yourself. For example, to make a PrimeFaces commandButton tag I added:
"pc": "p:commandButton"
You can use $0 or ${<placeholder text>} to define tabstops for expanded snippets, and | to define the caret starting point.
Full docs on editing snippets are here.

Missing captioned images feature in TinyMCE and Plone5

I'm missing the function to enable captioned images in TinyMCE/Plone5. It was possible to enable that in the control panel with Plone4 (https://plone.org/documentation/manual/plone-4-user-manual/using-tinymce-as-visual-editor/images).
Now I'm using the new Plone5rc3 with TinyMCE 1.4.3, but the properties of TinyMCE in the control panel don't have the needed checkbox.
Does anybody know how to get that?
Thanks a lot!
So here's an answer in parts: you need several things for the captions to work:
Your <img> tags need to have the class captioned. I still need to find a good way to do that. The image picker will remove all other classes everytime you open it, so I guess a good way would be to change the classes that are added by the inline/left/right selection, but I've not easily found where those are defined.
You need the output filter, but fortunately, that is still there. However, the filter wants to see an IImageCaptioningEnabler, which is essentially a flag to turn the captioning mechanism on, and the old editors used to have that and currently, nothing in standard Plone does provide such a beast. If you're comfortable with add-on development, the class you want is
from plone.outputfilters.filters.resolveuid_and_caption import IImageCaptioningEnabler
from zope.interface import implements
class CaptioningAlwaysEnabled(object):
implements(IImageCaptioningEnabler)
available = True
with corresponding configure.zcml stanza
<utility factory=".resolveuid_and_caption.CaptioningAlwaysEnabled"
name="plone5-captions-always-enabled"
zcml:condition="have plone-5" />
(you can tell I patched buildout-cache/plone.outputfilters-2.1-py2.7.egg/plone/outputfilters/filters/configure.zcml and resolveuid_and_caption.py to include that, but of course, you shouldn't do that.)
If you're not comfortable with add-on development, you could, bizarrely enough, see if another editor provides that global switch, you don't need to have it set as your editor or the default editor. (Products.kupu would, but it doesn't install in 5.0. collective.ckeditor might, I can't try that right now due to missing dependencies.)
So, summary: no, you can't easily turn it on; you can turn it on with a bit of hacking; and if you file it as a feature request, it's the kind of thing that takes about fifteen minutes to fix for somebody who knows their way around the code.

Displaying an XML string with formatting and syntax highlighting in an Eclipse RCP view

I am currently stuck on what I feel like should be an easy solution, but I am not really getting anywhere with this. I am new to Eclipse RCP. I am trying to implement a view in which, all it does, is display a string, which has been formatted to XML. As in, my application does what it is meant to do, and when the user clicks Save, it saves all the info as an xml. I can get this xml as one long, unformatted string. I want a pane where the user can see (only see, not edit) the XML code that is going to be saved.
The reason I want a view is because this view is a multi-instance view, dependent on the perspective it is in. And I want it to display in XML format, with syntax highlighting. It would be nice for it to look like in an editor with line numbers and such, but with good formatting I am satisfied.
Does anyone know the best (any) way to implement this? Even some 3rd party widget is perfect for me.
Thanks!!
IIRC, the Plug-In editor example does basic syntax coloring and you can use the javax.transform packages to go from a stream to a DOM and back to a (formatted) stream.
just make your editor inherit from StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor.StructuredTextEditor)
For further details here:
FAQ How do I provide syntax coloring in an editor?
Platform Plug-in Developer Guide > Programmer's Guide > Editors

Customizing IMarker behavior

I'm trying to make an Eclipse plugin that will highlight certain lines certain colors based on outside input. Is there any way to specify the behavior of a new IMarker rather than rely on basic implementation of bookmarks, problems, etc?
Thanks
I don't have the complete solution, but I think, I can give you some starting points.
The basic idea is to create custom annotations for your custom markers. You can define your own marker types, and register constant formatting rules for it (the latter one is a shameless link to one of my own blog posts). In this case, if your code creates the correct marker types, you can add the different formatting regarding the output.
On the other hand, if you have only a single problem type, I don't know the correct answer, but the Annotation Model Creation extension seems to be the answer. For details look at the Eclipse help.