Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top