This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
When I have an action on an annotation, I need to obtain the annotation object upon which the action should act. Currently I can obtain AnnotationDescr through: JTextComponent c = org.netbeans.editor.Utilities.getFocusedComponent(); BaseDocument doc = Utilities.getDocument(c); int line = Utilities.getLineOffset(doc, c.getCaretPosition()); AnnotationDesc ad = doc.getAnnotations().getActiveAnnotation(line); But I do not get my org.openide.text.Annotation object, which has the information required by the action.
Hmmm, I thought that you could get it from LineCookie -> Line -> getAnnotations(), but the method does not seem to be public. So, there probably really is no way how to get Annotations attached to a document. I'm reassigning this to openide/text, which is IMO the place where this should be implemented.
And what if there is more than one annotation on that line? How can I find which one should be the action executed on?
IMHO we should give the action access to the related Annotation object. Since the Annotation is abstract it may have some additional useful properties (besides e.g. getAttachedAnnotatable()). Added Jarda to cc if he wants to comment on this. The question is how to pass the annotation to the action. Currently the ActionEvent.getSource() is not explicitly initialized (it's likely the menu from which the action gets invoked) so it might contain the Annotation instead. But we would have to tweak the action invocation (probably wrap the original action and recreate the passed ActionEvent) or do it in MenuItem.processActionEvent() of all the create menu items. Or we could do some sort of hack e.g. have the annotation in some document property of the doc to which the action is attached etc.
If the action if ContextAwareAction, create proper context - e.g. lookup with the annotation and feed it into the action.
The use of ContextAwareAction is a nice idea. I'll try to implement that as soon as the editor gutter is fixed...
Gutter icons are back, resuming the work on a patch...
Created attachment 58631 [details] The patch that gives access to the associated Annotation object.
Can you please review the attached patch? Can I push it to fix this issue? Thanks.
Martine, the patch looks ok to me, even though I could not see any tests in it. If you could manage to write some it would be great. If not, well, business as usual. Please feel free to push and close.
Created attachment 58785 [details] New patch with test.
I had to modify the patch a little so that it will better work with gutter context actions. Functionality was mainly tested by hand, but also AnnotationsTest.java was modified to test the access to Annotation object from AnnotationDesc. Thanks for the review, I'll apply the patch.
Patch applied: http://hg.netbeans.org/main/rev/655b83e18adb