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.

Bug 128479 - Need an access to Annotation object
Summary: Need an access to Annotation object
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Text (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Petr Nejedly
URL:
Keywords:
Depends on:
Blocks: 127758
  Show dependency tree
 
Reported: 2008-02-26 18:20 UTC by Martin Entlicher
Modified: 2008-12-22 11:52 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
The patch that gives access to the associated Annotation object. (5.04 KB, text/plain)
2008-03-19 00:32 UTC, Martin Entlicher
Details
New patch with test. (7.01 KB, text/plain)
2008-03-20 19:41 UTC, Martin Entlicher
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Entlicher 2008-02-26 18:20:29 UTC
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.
Comment 1 Vitezslav Stejskal 2008-02-27 11:06:50 UTC
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.
Comment 2 Martin Entlicher 2008-02-27 12:51:19 UTC
And what if there is more than one annotation on that line? How can I find which one should be the action executed on?
Comment 3 Miloslav Metelka 2008-02-28 09:16:45 UTC
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.
Comment 4 Jaroslav Tulach 2008-02-29 19:22:22 UTC
If the action if ContextAwareAction, create proper context - e.g. lookup with the annotation and feed it into the 
action.
Comment 5 Martin Entlicher 2008-03-16 16:31:49 UTC
The use of ContextAwareAction is a nice idea. I'll try to implement that as soon as the editor gutter is fixed...
Comment 6 Martin Entlicher 2008-03-18 16:05:18 UTC
Gutter icons are back, resuming the work on a patch...
Comment 7 Martin Entlicher 2008-03-19 00:32:15 UTC
Created attachment 58631 [details]
The patch that gives access to the associated Annotation object.
Comment 8 Martin Entlicher 2008-03-19 00:34:32 UTC
Can you please review the attached patch?
Can I push it to fix this issue?
Thanks.
Comment 9 Vitezslav Stejskal 2008-03-20 11:55:25 UTC
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.
Comment 10 Martin Entlicher 2008-03-20 19:41:44 UTC
Created attachment 58785 [details]
New patch with test.
Comment 11 Martin Entlicher 2008-03-20 19:44:53 UTC
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.
Comment 12 Martin Entlicher 2008-03-25 17:59:23 UTC
Patch applied:
http://hg.netbeans.org/main/rev/655b83e18adb