0

I would like to open file specified by its path in NetBeans editor at specific line and row. I would like the same functionality as is when some Java/C/C++ or any other programming language prints an Exception. As far as I went for now:

  1. Write Exception in console
  2. By using OutputListener resolve what should be printed as hypertext
  3. OutputListener.outputLineAction that defines what to do when clicked on hypertext
  4. ---HERE I DONT KNOW WHAT TO DO---

An example of error message I need to resolve:

E ERRORCODE: error definition; line=2; column=30; source='file:/C:/...'

How can I open file in my plugin in text editor and point to specific line and column?

MartinZ
  • 65
  • 4

1 Answers1

0

See http://wiki.netbeans.org/DevFaqOpenFileAtLine

LineCookie - see https://forums.netbeans.org/topic59253.html

or

NbDocument#openDocument() - see http://bits.netbeans.org/dev/javadoc/org-openide-text/org/openide/text/NbDocument.html#openDocument(org.openide.util.Lookup.Provider, int, int, org.openide.text.Line.ShowOpenType, org.openide.text.Line.ShowVisibilityType)


Example using LineCookie

    FileObject fo = null;
    LineCookie lc = DataObject.find(fo).getLookup().lookup(LineCookie.class);
    int lineNumber=42;
    int colNumber=43;
    Line line = lc.getLineSet().getOriginal(lineNumber);
    line.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FRONT, colNumber);

More examples at

Ben
  • 2,235
  • 18
  • 17
  • I belive the NbDocument.openDocument might be the right way. However I really dont know how to use that Lookup and Lookup.provider. As the lookup i use `Lookup lookup = Lookups.forPath(path_ref);` where path_ref is String path to the file I would like to open and then the Lookup.Provider uses this lookup. The problem is, that the openDocument() method doesnt return true (and doesnt show anything). – MartinZ Mar 15 '14 at 10:48
  • See the code sample above. LineCookie should do the job. – Ben Mar 15 '14 at 13:26
  • It took a while to get back to my computer, but I must thank you! The FileObject can be obtained by `File f = new File(path_ref); FileObject fo = FileUtil.toFileObject(f);` The rest is the same. Thank you very much! – MartinZ Mar 18 '14 at 19:07