|
|
||
Rich Unger's BlogSeptember 2005 ArchivesA simple NetBeans module, written in NB 5.0Posted by richunger on September 22, 2005 at 05:14 PM | Permalink | Comments (1)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 :-)
Real, supported, module development has arrivedPosted by richunger on September 12, 2005 at 12:57 PM | Permalink | Comments (3)Other folks have been blogging about the new support for NetBeans module development in the 5.0 stream. However, as the guy who put together the "cluster build harness" for (unofficially) supporting module development in 4.1, I just thought I'd chime in with my own words of praise. If I were starting a project based on the netbeans platform now, I would not use my cluster build harness. I'd use 5.0 builds, and I'd begin with Geertjan's (most finished) tutorial. The new UI for module development is very effective. How effective? Well, when I get a few moments I'll write another entry about how I was able to create a module in about 5 minutes to test my fix for http://www.netbeans.org/issues/show_bug.cgi?id=64012 It would have been a lot more work with the cluster build harness! I prefer my JARs sunny-side up: reduxPosted by richunger on September 05, 2005 at 02:16 PM | Permalink | Comments (3)In a previous entry, I vented my frustration at scrambled JARs in the netbeans build process. Well, they're gone. I'd like to think I had some small part to play in that. I probably didn't, but I'll go on thinking I did :) | ||
|
|