Search |
||
A simple NetBeans module, written in NB 5.0Posted by richunger on September 22, 2005 at 5:14 PM PDT
As promised, here's a recap of a simple module I built to help me test a bugfix.
There is a feature in NetBeans which allows any FileObject (including files in your project) to be served up by an embedded HTTP server. It is exposed by the API method URLMapper.findURL(FileObject, URL_TYPE). URL_TYPE may be one of three values:
I noticed that if I passed NETWORK into the function, I was getting back a file URL instead of an HTTP URL. I decided to create a simple module to help me debug the problem. The module would add an Action to the context menu of HTML files which would perform an URLMapper.findURL() and display the result in a dialog box. What surprised me, as a long-time module developer on previous versions of NetBeans, was how easy it was in 5.0....
There. That's almost everything. Now all I have to do is implement the performAction() method. The implementation will look like this:
DataObject dobj = (DataObject)activatedNodes[0].getCookie(DataObject.class);
if (dobj != null)
{
URL url = URLMapper.findURL(dobj.getPrimaryFile(), URLMapper.NETWORK);
NotifyDescriptor nd = new NotifyDescriptor.Message("URL: " + url);
DialogDisplayer.getDefault().notify(nd);
}
As I type this in, certain classes will not be found, even after a "Fix Imports" (Shift-Alt-F). The unknown classes are:
Now, if I right-click the URLMapperTest project node, and select "Properties", there's a section for "Libraries"
When I click "Add...", I'm presented with a new dialog that lets me search for these classes.
In this way, I can add dependencies on the appropriate modules (Dialogs API and File System API). Once again, I can perform "Fix Imports" in my source window, and I'm done coding! Now, when I run my project, and browse to an HTML file, I can right-click that file and select "Show URL"
...and the result is this:
Of course, that's the result before I fixed the bug! With my patched version, the URL starts with "http://"
Now, I don't know about you, but I was very impressed by how easy this was. I know how to do it the hard way, because I've been writing NetBeans modules for years. I'm very envious of the folks who are just starting now :-) »
Related Topics >>
Netbeans Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|