Sunday September 30, 2007
FreeMarker: Baked into NetBeans IDE 6.0 (Part 2)
In Part 1, I talked about FreeMarker support in NetBeans IDE 6. It is definitely very cool in the context of code generation. I'm pretty sure that it has a big impact on chapter 19 of Rich Client Programming: Plugging into the NetBeans Platform. There, a whole bunch of Wicket-related artifacts are generated at the end of the New Web Application wizard. At the time, in the absence of FreeMarker, we had to create a pretty clumsy artifice that replaces macros in template files with values set by the user in the wizard. Now, however, with FreeMarker, not only will we be using an external approach to this, i.e., not an internal hacked approach, but also many things are much easier than before, which I hope to illustrate in this blog entry.
Let's say we have this wizard:
Now, the info from that wizard could be the input for a wide variety of outputs. Here's the FreeMarker template that defines my output:
Notice especially the highlighted bit, because there we have a bit of iteration going on! That's really cool, because now I don't have to handle that in my code. FreeMarker does it for me. I simply need to send some kind of array called 'types' (or anything else, of course, so long as the object I send has a name that is the same as the name used in the FreeMarker template) and then FreeMarker will iterate through it for me. I like that. I like that a lot.
Now, how to assign the above template to the wizard? Here's how my template is defined in the layer, notice the two bits in bold. The first bit points to the location of the template, which is in the same folder, in this case, as the layer file. The second highlighted bit tells the IDE to treat the template as a FreeMarker template:
<folder name="Other">
<file name="letter.html" url="letter.template">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.newfiletemplate.Bundle"/>
<attr name="instantiatingIterator" newvalue="org.netbeans.modules.newfiletemplate.letter.LetterWizardIterator"/>
<attr name="template" boolvalue="true"/>
<attr name="templateWizardURL" urlvalue="nbresloc:/org/netbeans/modules/newfiletemplate/letter/letter.html"/>
<attr name="javax.script.ScriptEngine" stringvalue="freemarker"/>
</file>
</folder>
A second thing to discuss is how the values from the wizard end up being used in the FreeMarker template. If you use the Wizard wizard to generate the basic artifacts required by every NetBeans wizard, one of your new classes will be an iterator. In the iterator's instantiate() method, the generation process takes place, by means of the createFromTemplate(dataFolder, targetName) method. However, now you can include a map containing the objects that you want to pass. And where are they passed? To the FreeMarker template of course. Here's the instantiate() method for the above template:
public Set instantiate() throws IOException {
FileObject dir = Templates.getTargetFolder(wizard);
String targetName = Templates.getTargetName(wizard);
DataFolder df = DataFolder.findFolder(dir);
Object[] data = (Object[]) wizard.getProperty(LetterVisualPanel1.PRODUCTS.toString());
hashMap = new HashMap();
hashMap.put("url", wizard.getProperty(LetterVisualPanel1.URL));
hashMap.put("name", wizard.getProperty(LetterVisualPanel1.NAME));
hashMap.put("types", data);
FileObject template = Templates.getTemplate(wizard);
DataObject dTemplate = DataObject.find(template);
DataObject dobj = dTemplate.createFromTemplate(df, targetName, hashMap);
FileObject createdFile = dobj.getPrimaryFile();
return Collections.singleton(createdFile);
}
Note the line in bold above. There my hashMap is included. And the map consists of a "url", a "name", and a "types", which are used in the FreeMarker template. Now, when the user completes the wizard, for the values shown above, they will see this:
There's quite a bit more possible with FreeMarker, and obviouly we need syntax coloring and so on, that I'm still investigating, such as something to do with the product license that I need to figure out. But I can already see the benefits of FreeMarker support in NetBeans IDE 6.0. And it's all really pretty cool and clever.
Sep 30 2007, 02:22:50 AM PDT Permalink
Hello Hudson
I've been looking at setting up continuous builds for the JFugue Music NotePad via Hudson. Definitely haven't figured it all out yet, but I've definitely come some of the way already. The absolute bible for all of this in relation to the NetBeans Platform is the perfectly titled Continuous Testing of NetBeans Platform Based Applications. It is definitely the one you want to refer to from start to finish. I had everything in there set up, up to the part where Hudson starts being used. This already looks quite impressive, I feel:
So, to start off, I got the hudson.war and downloaded it into my GlassFish domain's 'autodeploy' directory:
Then when I started up the server, inside the IDE, I could see a node for Hudson, indicating that it was deployed:
(Yes, Hudson is nothing more than a web application.) That was encouraging, especially when I went to http://localhost:8080/hudson/ and immediately saw what I would expect to see:
And all that had taken a couple of minutes. After that it got tougher. One thing I learned is that I automatically had home/geertjan/.hudson as my home directory, which is hidden, i.e., this is on Ubuntu Linux. There I saw the following, at the start, without doing anything myself:
Now, some time later, I do have builds taking place and a few other things that I configured making sense, so that I now have a small set of build results, although the workspace gets built, instead of the application, which means I need to reconfigure some things to get this part right:
At the very least, this is helping me in demystifying how NetBeans IDE gets built, since it also makes use of Hudson:
Hope I'll be able to get further with this, if only to understand how it works. One way to do so is... to open Hudson in the IDE, as a web application, which is what it is:

Sep 29 2007, 12:21:09 AM PDT Permalink
FreeMarker: Baked into NetBeans IDE 6.0 (Part 1)
If you're a fan of FreeMarker, then there's good news for you. In fact, three pieces of good news. To really get the point, look at the following pics. The first comes from NetBeans IDE 5.5, when you open the Java Class template in the editor:
This is that same entry in the Template Manager, but this time in NetBeans IDE 6.0:
What's going on here?! Well, that's FreeMarker. As you can see, the Java class template in NetBeans IDE 6.0 is defined in FreeMarker. Once you have opened that file in the editor, you can change and save it, and from then onwards your additional FreeMarker script will be used to generate Java classes. You can also create new templates in FreeMarker and then save them in that Template Manager for reuse.
How about some syntax coloring and other editor support? That's the second bit of good news. I've looked around in the Plugin Manager, but couldn't find anything related to this. However, it seems that our good friend Schliemann is in the process of learning FreeMarker, judging from a quick inspection of the NetBeans sources:
Now, what is really interesting is understanding how it all works. NetBeans IDE 6.0 provides built in support for scripting languages. (Read all about it here.) Of all the scripting engines, FreeMarker comes bundled with the IDE out of the box. However, you can also create templates in other scripting languages covered by JSR 223. I, of course, immediately started looking at Groovy in this context, but haven't got very far yet. But isn't this basically one of the purposes of scripting languages—to quickly throw some scripts together and to try them out? Then why not keep them as templates. FreeMarker is specifically created for this, but other scripting languages could be used in this way too. But that's something that requires new modules to be added, i.e., modules that provide the scripting engine of the language in question. And so that's the third piece of good news—conceivably, you could end up writing templates in a whole host of scripting languages.
For more on FreeMarker in NetBeans IDE 6.0, read Migrate to Freemarker from Velocity template engine in your NetBeans Module and FreeMarker support in NetBeans?.
In other news. Want to see how to create a module that provides a FreeMarker file template? Go here and download the sample.
Sep 28 2007, 06:58:07 AM PDT Permalink
GUI Testing on the NetBeans Platform (Part 2)
Let's create a realistic functional test for the JFugue Music NotePad, i.e., a test that runs through a complete user scenario, rather than just simply invoking a single action. In the end, we'll type this on the command line:
ant -Dxtest.testtype=qa-functional
And then the application will start, the New action will be invoked, various selections will be made in the wizard, and then a number of notes will be added to the music sheet. The Output window will provide information like the following:
And when you go to the file indicated above, you will see info similar to the first screenshot in yesterday's blog entry. So, clearly, this could be part of some batch process, where the call to the Ant script is done as part of a larger process.
So, here's our test, everything is the same as yesterday, except the test1() is now called testComposition() (it is important that test methods begin with the word test), with this content:
public void testComposition() {
// use main menu File -> New to open New Composition modal dialog
new ActionNoBlock("File|New", null).perform();
// wait for the New Composition dialog
WizardOperator newCompositionOper = new WizardOperator("New Composition");
// set title
new JTextFieldOperator(newCompositionOper).setText("My Composition");
// set tempo
new JTextFieldOperator(newCompositionOper, 2).setText("100");
newCompositionOper.finish();
// wait for composition pane
TopComponentOperator compositionOper = new TopComponentOperator("My Composition");
// find half note
JToggleButtonOperator halfNoteOper = new JToggleButtonOperator(compositionOper,
new ToolbarButtonChooser("Half note"));
// find quarter note
JToggleButtonOperator quarterNoteOper = new JToggleButtonOperator(compositionOper,
new ToolbarButtonChooser("Quarter note"));
// note constants
int a5 = 85;
int g5 = 90;
int f5 = 95;
int e5 = 100;
// click quarter note
quarterNoteOper.push();
// click to put note
compositionOper.clickMouse(compositionOper.getWidth()-10, g5, 1);
compositionOper.clickMouse(compositionOper.getWidth()-10, g5, 1);
halfNoteOper.push();
compositionOper.clickMouse(compositionOper.getWidth()-10, e5, 1);
quarterNoteOper.push();
compositionOper.clickMouse(compositionOper.getWidth()-10, g5, 1);
compositionOper.clickMouse(compositionOper.getWidth()-10, g5, 1);
halfNoteOper.push();
compositionOper.clickMouse(compositionOper.getWidth()-10, e5, 1);
quarterNoteOper.push();
compositionOper.clickMouse(compositionOper.getWidth()-10, g5, 1);
compositionOper.clickMouse(compositionOper.getWidth()-10, g5, 1);
compositionOper.clickMouse(compositionOper.getWidth()-10, a5, 1);
compositionOper.clickMouse(compositionOper.getWidth()-10, g5, 1);
halfNoteOper.push();
compositionOper.clickMouse(compositionOper.getWidth()-10, g5, 1);
compositionOper.clickMouse(compositionOper.getWidth()-10, f5, 1);
}
private static class ToolbarButtonChooser implements ComponentChooser {
private String buttonTooltip;
private StringComparator comparator;
public ToolbarButtonChooser(String buttonTooltip) {
this.buttonTooltip = buttonTooltip;
this.comparator = Operator.getDefaultStringComparator();
}
public boolean checkComponent(Component comp) {
return comparator.equals(((JComponent)comp).getToolTipText(), buttonTooltip);
}
public String getDescription() {
return "Toolbar button with tooltip \""+buttonTooltip+"\".";
}
}
Thanks to Jiri Skrivanek, who created this test as an illustration of how you can write Jelly tests in NetBeans IDE. When the test has completed its run, the application is closed. In the meantime, however, it has played Skákal pes, which Roumen helpfully pointed me to, about a dog jumping over oats...
Sep 27 2007, 12:47:55 AM PDT Permalink
GUI Testing on the NetBeans Platform (Part 1)
Your wonderful Swing application is reaching completion, or is at some intermediate stage where you think it should be kind of solid, and you're wondering: "Hmmm. I have a very complex user interface. How do I know that all those menu items, toolbar buttons, dialogs, palettes, windows, and wizards actually work? Some of them come from modules provided by others, some come from modules provided by people who no longer work here, some come from modules that I wrote in a hurry... I really don't know how reliable all of it is anymore. Should I maybe get an intern to click every piece of u.i. in order to find out whether everything is working as expected?"
And the answer is, of course, "Yes". Just kidding. The answer is, in fact, of course, "No". If you're building your application on the NetBeans Platform, you'll be able to type this on the command line:
ant -Dxtest.testtype=qa-functional
And then your application will start up and little tests such as the following will be run:
public void test1() {
new Action("File|New", null).perform();
}
So, above, after starting up the application, your test infrastructure will automate the choosing of the "New" menu item under the "File" menu. If you're around at the time, it's quite fun to watch, because you'll see it happening in front of your eyes, without you doing anything at all. If you're not around, and you're running the Ant script as part of some batch process, then that's also okay, because the results of the test are written to an HTML file, that looks like this:
Tests such as these are called functional tests, as opposed to unit tests. Typically, with a functional test you're trying to establish whether a scenario works or not. Clicking the New menu item under the File menu isn't really a scenario. A scenario is a complete user task, such as "Creating a music sheet" (which means, clicking the New menu item under the File menu, filling in the wizard page, clicking Next, filling in the next page, and clicking Finish) or "Adding notes" (which means, clicking a button in a palette, dragging it to the music sheet, dropping it on the music sheet), etc. So, you're trying to simulate a user task by means of small tests that the test infrastructure processes for you. My earlier blog entry Testing... Testing... One, Two Three introduces the various test tools available to you in the NetBeans world. When it comes to functional testing, one should immediately think two words: "Jemmy" and "Jelly". This blog entry is about these two, how to set them up, and how to write your first Jelly test, which will invoke the "New" action, by choosing the "New" menu item under the "File" menu in the JFugue Music NotePad. You will be able to run the test either from the IDE or from the command line, using Ant.
- Start up NetBeans IDE 6.0 Beta 1.
- Go to the Plugin Manager and install the Testing tools:
It's really cool that they're now in the Plugin Manager. Previously, as I explained here, you had to go elsewhere.
- Once you've installed them, go to the IDE's installation folder. Not the user folder! The installation folder i.e., the parent folder of the folder where the IDE's launcher is found. You will see a brand new folder called "testtools":
Notice that it also contains the xtest-distribution folder.
When you expand the modules folder, you'll see all the JAR files containing the functionality you will need for testing:
- Now, in the IDE, let's set up the testing infrastructure, after which we'll write our first test. In the Projects window, right-click on the module project that you want to test. In the New File wizard, choose "XTest Infrastructure", in your new "Testing Tools" category:
When you do so, the IDE shows you where everything that it will create for you will be put:
- Click Finish. Now open the Files window. You should see that your module has a new subfolder called "test":
That's your testing infrastructure.
- Let's now create our first GUI test. Back in the New File wizard, choose "JellyTestCase Test", as shown here:
- On the next page, make sure that you select "Functional Test Packages" in the "Location" drop-down, as shown below:
- Click Finish. You now have a skeleton for a new Jelly test. In the Projects window, you have logical nodes for your testing locations, giving you easy access to your test case, i.e., without needing to dig around for it as you need to do in the Files window:
- Now add the single line shown at the start of this blog entry to the test1() method, and get the correct import statement, both of which are shown in bold below, all the rest was generated for me by the wizard mentioned above.
package org.netbeans.modules.musician.test; import org.netbeans.junit.NbTestSuite; import org.netbeans.jellytools.JellyTestCase; import org.netbeans.jellytools.actions.Action; /** * A Test based on JellyTestCase. JellyTestCase redirects Jemmy output * to a log file provided by NbTestCase. It can be inspected in results. * It also sets timeouts necessary for NetBeans GUI testing. * * Any JemmyException (which is normally thrown as a result of an unsuccessful * operation in Jemmy) going from a test is treated by JellyTestCase as a test * failure; any other exception - as a test error. * * Additionally it: * - closes all modal dialogs at the end of the test case (property jemmy.close.modal - default true) * - generates component dump (XML file containing components information) in case of * test failure (property jemmy.screen.xmldump - default false) * - captures screen into a PNG file in case of test failure (property jemmy.screen.capture - default true) * - waits at least 1000 ms between test cases (property jelly.wait.no.event - default true) * * @author gw152771 * Created on September 26, 2007, 10:08 AM */ public class NewJellyTestCaseTest extends JellyTestCase { /** Constructor required by JUnit */ public NewJellyTestCaseTest(String name) { super(name); } /** Creates suite from particular test cases. You can define order of testcases here. */ public static NbTestSuite suite() { NbTestSuite suite = new NbTestSuite(); suite.addTest(new NewJellyTestCaseTest("test1")); suite.addTest(new NewJellyTestCaseTest("test2")); return suite; } /* Method allowing test execution directly from the IDE. */ public static void main(java.lang.String[] args) { // run whole suite junit.textui.TestRunner.run(suite()); // run only selected test case //junit.textui.TestRunner.run(new NewJellyTestCaseTest("test1")); } /** Called before every test case. */ public void setUp() { System.out.println("######## "+getName()+" #######"); } /** Called after every test case. */ public void tearDown() { } // Add test methods here, they have to start with 'test' name. /** Test case 1. */ public void test1() { new Action("File|New", null).perform(); } /** Test case 2. */ public void test2() { } } - Next, I needed to close the IDE and restart it (a known bug, because the right libraries are not put on the classpath until the IDE is restarted). Without doing this, compilation of the test case, shown above, failed. So, if it fails for you, you will, for now, need to restart the IDE.
- Now... right-click the project node, choose XTest, and then choose "Run qa-functional Tests", from the menus shown below:
The tests defined as functional tests (based on their location, which you defined when you created the JellyTestCase Test in the New File wizard) are run. Alternatively, go to the command line, browse to the module's "test" folder and run the Ant script, as shown earlier:
ant -Dxtest.testtype=qa-functional
Note: When you run the Ant script, make sure that the application is built. If it isn't built, the application will not start up. Instead the module will be tested within the development IDE.
Results are written to the 'results' folder, accessible in the Files window:
- Finally, read Writing Jelly Tests in NetBeans, as well as all other documents under "Version for NetBeans Dev" on the Jellytools Documentation page. (The FAQ is excellent.) Remember, as pointed out in earlier blog entries on testing tools support for the NetBeans Platform, that a very handy overview can be found here. Also, have a look at Writing tests for XTest. For another sample, go to the New Project wizard and then inspect the two samples under Samples | Testing Tools, especially the second one, which is a NetBeans Platform application.
Thanks a lot to the NetBeans team's testing guru, Jiri Skrivanek, for helping me understand all of the above. While writing this blog entry, I received an e-mail from him containing a complete test for the JFugue Music NotePad. Apparently it automates the playing of the "famous song for children, 'Dog jumps over oats'". Hmmm. Not famous in Holland, where I'm from, anyway. Read this blog tomorrow and you'll find out what it's all about. :-)
In other news. This blog entry is dedicated to Tom Wheeler... who frequently asked me to research this and I apologize for taking so long to do it.
Sep 26 2007, 03:56:25 AM PDT Permalink
Collaboration Plugin in NetBeans IDE 6.0 Beta 1: It Just Works!
Hardcore NetBeans Platform developer Sven Reimers (in Germany) and NetBeans evangelist Dave Botterill (in the US) found themselves in a collab session with me (in the Czech Republic) today, after I logged in to the free shared server, inspired by the following words in Iwan Eising's blog:
"I still can't believe collaboration is not part of the standard installation. It is probably the plugin I use most apart from the obvious plugins that are part of the standard install. Collaboration is really important as I develop the game together with a friend of mine. He lives about 100 km away from me, so we meet in NB, discuss our progress in NB etc."
The cool thing is that neither Sven, Dave, nor myself had arranged to meet each other there. Sven was already there, then I joined, and then suddenly Dave showed up, for his first collaboration session ever. And here's a short snippet of our conversation:

Notice also that I've shared one of the Filthy Rich Client samples with Dave and Sven. So, they can inspect my code, make changes in my code, build my application, and run it. How cool is that?! But if they run it, only I get to see the result. One excellent improvement (if it is possible) would be for Dave and Sven to be able to see (via an emulator or something?) the application running on their side.
Sep 25 2007, 08:55:33 AM PDT Permalink
Enhancements to the Multiple Project Template (Part 2)
I was talking to the head of the NetBeans docs team, John, yesterday about the Filthy Rich Client samples that we're planning to put in the NetBeans Sample Catalog. John said: "It would be cool if, when the user pulls the sample out of the New Project wizard, a description of the sample would appear." (Or words to that effect.) So, a cool way to implement this requirement is to... enhance the Multiple Project Template even further. For each sample that the Multiple Project Template bundles into a module (i.e., this could be 82 samples, as in the case where one might want to bundle all of the Filthy Rich Client samples), we want to have the Multiple Project Template wizard create the following:
- A new TopComponent, containing a JEditorPane, for viewing the description HTML file.
- The TopComponent's settings file and WSTCREF file, which must specify that the TopComponent should be closed by default.
- Code in the iterator used to create the sample, so that when the New Project wizard is completed, the TopComponent will open automatically, i.e., at the end of the instantiate method.
- A new action, to be invoked from a menu item under the Help menu, for displaying the TopComponent, in the scenario where the user has closed it after the IDE opened it when the wizard instantiated the sample.
This means creating several new template files and then getting the Multiple Project Template wizard to use those template files at the right point in time. In the case of all these TopComponent-related template files, the thing to do is "ransack" (as Toni so nicely puts it in his rather brilliant Visual Datbase Explorer Tutorial) code from the templates that the IDE already provides. So, I used the Window Component wizard to create all the TopComponent-related files and then copied all the code from these files into my template files (i.e., the code for the action, for the settings file, for the WSTCREF file, for the TopComponent form file, and for the TopComponent Java class), which I then forced the Multiple Project Template to generate, together with all the other files. On the generated TopComponent, I added a JEditorPane, set the HTMLEditorKit, and referred to the description HTML file that I defined in the Bundle file, which is also done via the iterator, as shown in the snippet that follows. So, now, in the template that is used to create the TopComponent, I have this in the constructor:
jEditorPane1.setEditorKit(new HTMLEditorKit());
try {
String s = NbBundle.getMessage(@@TEMPLATENAME@@DescTopComponent.class, "DescDocument");
URL demoDetailsURL = new URL(s);
jEditorPane1.setPage(demoDetailsURL);
} catch (IOException ex) {
ex.printStackTrace();
}
And then, in the iterator, I have this line, which adds the correct entry in the Bundle file, when the Multiple Project Template wizard wraps the selected samples into the module as project templates:
fileChanges.add(fileChanges.bundleKey(bundlePath, "DescDocument", "nbresloc:/"
+ packageName.replace('.', '/') + "/" + name
+ "/" + name + "Description.html"));
Of course, the above (as well as everything else involving the creation of your own apisupport wizards) entails an implementation dependency on the NetBeans Module Project module, since that module does not expose an API yet.
However, in the end, we implemented it in a much simpler way (so as to be consistent with existing samples that provide readmes), without TopComponents, just using the IDE's default browser, at the end of the instantiate() method:
URL descURL = new URL("file:////"+dir.getPath()+"/" + "@@TEMPLATENAME@@Description.html"); // NOI18N
URLDisplayer.getDefault().showURL(descURL);
So now, when the sample's wizard completes, the HTML file defined above opens in the IDE's default browser. The HTML file is in the root folder of the sample in question. All the templates I described above are thus superfluous...
Sep 25 2007, 05:54:26 AM PDT Permalink
Enhancements to the Multiple Project Template (Part 1)
Several cool enhancements to the Multiple Project Template:
- The folder search now is smarter than before. Instead of needing to select the folder that contains the NetBeans projects, you can go one folder higher. So, for example, below I've chosen the 'filthyrichclients' folder:
And now all NetBeans projects within the selected folder, as well as all NetBeans projects within folders that are one level below the selected folder (no more than that) are found and appear in the 'Available' list:
- And, as you can see above, I have added 'Add all' and 'Remove all' buttons, so that you can select all applications in one go, instead of having to select them one by one, or in selected groups.
- The next enhancement is that the generated package names now, instead of being named module.package.name.1, module.package.name.2, etc, are now named after the name of the application (i.e., module.package.name.name-of-application), as shown here:
- Finally, the wizard adds the correct icon to each project. It does this by identifying the type of project (e.g., web or mobility or ejb, etc) and then sets the related icon in the layer file, defaulting to the Java application's icon, if the project's type does not match one of those supported by the wizard. As a result, all of Chet and Romain's samples get the IDE's Java application icon automatically attached to all their projects, when the module shown above is installed:
So, as the pictures and words above indicate, I am now able to create a module that contains all of the Filthy Rich Client samples, all 82 in one go, using one single iteration of the new Multiple Project Template wizard. I have incremented the plugin to 2.0 and made it available in the Plugin Portal:
http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=3688
In other news. Here's Dave and my presentation on JFugue API.
Sep 24 2007, 05:20:57 AM PDT Permalink
Multiple Project Template
We've been talking with Chet and Romain, about putting some of their Filthy Rich Client samples in the NetBeans Sample catalog, and also in the IDE's New Project wizard. That would make it easy for them to be accessed by NetBeans users, which would be especially useful for those who are reading Filthy Rich Clients. Registering a sample in the New Project wizard is easy, thanks to the Project Template wizard, which is described in quite some detail in NetBeans Project Sample Module Tutorial. However, the problem (to me) with the Project Template wizard is that one can only deal with one sample at a time. So, if I have six samples to register in the New Project wizard, then I need to go through the Project Template wizard six times. That, of course, is a lot better than having no Project Template wizard at all, but it isn't optimal.
So, I've created a new wizard, called "Multiple Project Template". If you go here, you can install it:
http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=3688
Make sure you install it in NetBeans IDE 6.0 Beta 1. It could possibly work in other versions, and development builds, too, but no promises. Especially since I needed to set an implementation dependency on the "NetBeans Module Projects" module (because it currently does not provide an API), there is no guarantee that it will work in anything other than NetBeans IDE 6.0 Beta 1.
Once you have it, create a module project. (Or, use an existing module project.) Then go to the New Project wizard and choose "Multiple Project Template" from the NetBeans Module Development category, as shown here:
Click Next. Now you see the wizard panel below, where you can browse to folders that contain NetBeans projects (any kind of NetBeans project, so long as it is a NetBeans project) and, from those projects, select the ones that you want to register as samples:
Once you're happy with your choices, click Next, choose a category and a package, and the IDE shows you a long list of all the new files that will be created or changed:

Finally, click Finish. The IDE zips up the selected applications and adds all Java classes, files, layer registration entries, and Bundle keys needed, as well as setting all the required project dependencies. The result, for the six samples by Chet and Romain shown above, is as follows:
You can install the module immediately, no post processing of any kind is necessary. For the samples selected above, the result is as follows, i.e., they are added to the Java samples category, supplementing the 4 existing ones:
Next, you can go back to the generated module sources and use the dummy HTML files to add descriptions for your samples. You can also change the icons in the New Project wizard, as described in the tutorial referenced at the start of this blog entry. And that's it. You're done and your samples are good to go. Hurray, that will save me a lot of time when bundling samples from now onwards!
Update. See Enhancements to the Multiple Project Template for enhancements, provided by the 2.0 version of this plugin.
Sep 23 2007, 07:44:26 AM PDT Permalink
Visual Database Explorer
I went through Toni Epple's Visual Database Explorer Tutorial for the first time. I built the whole module, on a NetBeans IDE 6.0 development build from yesterday. Everything worked pretty much as described in Toni's tutorial, except that the Visual Library API is now part of the NetBeans Platform, so that you don't need to take any special steps to include it in the module. No need to download anything from the Visual Library source ZIP, except that the images are useful. The result is that you can choose a menu item, after selecting a connection in the Services node, and then the database structure is visually reflected in a new window:
I'd like to turn it into one of the official NetBeans tutorials. But, I guess, the Database Explorer API would need to be stabilized first, which I don't think it is currently. I needed to set an implementation dependency on it. Also, maybe the final plugin could be included in the Plugin Portal, because clearly this is a very useful piece of functionality that adds real value to the user's database activities when working with the IDE.
In other news. Tried it successfully in 6.0 Beta 1 and got permission from Toni to put it in the Plugin Portal, as a sample. Go here to get it. (By the way, I updated yesterday's Feature Viewer, to 1.5, and now there isn't a problem with dependencies anymore, although the Print Preview is disabled now.)
Sep 21 2007, 06:58:24 AM PDT Permalink
Feature Viewer (Part 2)
I expanded the Feature Viewer so that I can now see everything in the Plugin Manager, both installed and available modules, as well as a distinction between those that are shown in the Plugin Manager (yellow background) and those that are hidden (white background):

Those that are hidden support those that are shown, but cannot be installed independently. They're installed automatically together with one of the shown modules, depending on what the plugin author defined in the update center.
If you have the full IDE installation, i.e., including the SOA pack, you also have Print and Print Preview functionality for the viewer:

Go here to get this plugin which, of course, could be used by any application that is based on the NetBeans Platform.
Update. I incremented the module version to 1.5 and removed the dependencies that were causing problems, with the result that you can now get the window, but not the Print and Print Preview anymore. Still, better than nothing.
Sep 20 2007, 03:46:22 PM PDT Permalink
Enabling Undo/Redo Functionality on the NetBeans Platform
I've been looking through a draft of Heiko Böck's "NetBeans 6 - Rich-Client-Entwicklung mit Java" (which you can already preorder from Amazon, right here). Lots of interesting bits of code in there, quite a lot that I hadn't seen before. Some of them involve the UndoRedo.Manager. The basics are quite simple—declare the manager, override the getUndoRedo() method in the TopComponent or MultiviewElement and then, as shown in the highlighted line in the constructor below, assign the manager as an UndoableEditListener to the component's Document object:
private UndoRedo.Manager manager = new UndoRedo.Manager();
private DemoTopComponent() {
initComponents();
setName(NbBundle.getMessage(DemoTopComponent.class, "CTL_DemoTopComponent"));
setToolTipText(NbBundle.getMessage(DemoTopComponent.class, "HINT_DemoTopComponent"));
jEditorPane1.getDocument().addUndoableEditListener(manager);
}
@Override
public UndoRedo getUndoRedo() {
return manager;
}
Once you've done that, the IDE's (or your own application's) Undo and Redo functionality is enabled for your component—the menu items and toolbar buttons are enabled when you expect them to be, i.e., after making changes to the component's document, such as in the JEditorPane in the example below, where changes to the "Failed New Year's Resolutions" list result in the undo/redo actions being enabled/disabled:
I know there are more complex scenarios, and that those scenarios are often a cause of frustration, but at least, in this simple scenario, I'm happy to say that things work really nicely and exactly as I would expect, and clearly for very little coding.
In other news. Recently, the NetBeans Web team made a small but significant improvement—they've provided a constant URL pointing to the latest NetBeans weekly newsletter. In the past, each week's newsletter had a different URL, based on the day the newsletter was published. So, in the left sidebar of this blog, where I have a link to the latest newsletter, I used to have to change that link each week. Now there's just a standard URL that will always bring you to the latest newsletter. Why not add it to your blog or correspondence, or wherever, to publicize this extremely useful resource, that will always keep you up to date with the latest and coolest info coming out of the NetBeans project? Here it is: http://www.netbeans.org/community/news/newsletter/latest.html.
Sep 19 2007, 07:24:21 AM PDT Permalink
Four For The Price Of One
In NetBeans IDE 6.0 Beta 1, when you go to the Samples section of the New Project wizard, two of the samples you'll find are these:
These are two samples for the 'Quality of Service' (QoS) area, formerly known as WSIT. The samples are described in a brand new tutorial, called Web Service "Quality of Service" in NetBeans IDE 6.0, where you'll principally learn about web service security.
However, the interesting thing is that when you complete the wizard for each of the above samples, you'll end up with TWO projects. (In other words, if you create both the samples above, you will have four projects, instead of two.) That makes sense, because these samples each deal with a client AND with a service. Hence, rather than forcing you to complete the wizard twice, the IDE lets you generate both projects at the same time, when you complete the above wizard. This is an innovation by Martin Grebac, the NetBeans tooling engineer in the QoS area. The scenario where a sample requires two projects is pretty unique to the Java EE area, in general. So today I tried to learn how to create this kind of multi-project sample, for the brand new End-to-End Web Service Creation and Consumption in NetBeans IDE 6.0 tutorial, which deals with FOUR interrelated projects—an EJB module, a web service, a Java EE application, and a Java Swing application.
So now I have a new sample in the same category as the previous two:
Currently, there's still something I don't understand, because when the wizard completes, the projects do not open in the IDE. However, they're available on disk, as shown here:
So for now, you need to open the 4 projects from disk (after finishing the wizard by pressing Cancel, because it hangs there for some reason, currently), and once you've done so you'll find the four new projects, all generated from the one wizard, in your Projects window as follows:
Despite the error markings you see above, which refer to dependencies that are generated at compile-time, the projects are good to go as they are. I was able to deploy the Java EE application to GlassFish, after which I ran the Swing application, which (a moment or two later) displayed the flower pictures, described here and based on Milan's recent blog entry.
If you'd like to try the wizard that produces these four projects, download and install the plugin below, into NetBeans IDE 6.0 Beta 1:
org-netbeans-modules-flowerpluginsample.nbm
Once they've been tested a bit, I'll put them on the Plugin Portal or somewhere else that is more public than my blog.
Update: The above link now goes to the Plugin Portal.
And how was the wizard created that produces these four projects? I simply copied from Martin's sources, in the websvc module. I don't understand much of it, haven't tried yet, which explains why it doesn't completely work. But it clearly does most of the job already. The amount of classes and files involved might seem a bit daunting, but really are identical per implementation, I really only copied them into my NetBeans module and then tweaked the layer file. Here's my whole module:
I am looking forward to the day when the current Project Template wizard will be extended to... allow you to select multiple projects simultaneously, instead of just the one that you can currently select, which would then wrap up all selected projects into a single module. After 6.0, this kind of 'apisupport' activity will hopefully become something that NetBeans engineers will be able to focus on.
Sep 18 2007, 09:46:48 AM PDT Permalink
Never Eat The Yellow Snow
My IDE is even more helpful than before, now. Because I've been playing with the IDE's JGlassPane (as a result of some questions about this), I am now ready for winter:
Don't say I didn't warn you. I have found Chet and Romain's book very helpful in this instance too. Somewhere I read that their book is supposedly aimed at advanced Swing developers. Well, if that's true, why is there a detailed section on Threading (amongst several other interesting intro topics) at the start of the book? And not just a paragraph or two, but really in detail. Anyway, read page 34 of their book, create a module installer (helpful wizard generates practically everything you need) and then fill out the restored() method as follows:
private MyGlassPane glassPane = new MyGlassPane();
@Override
public void restored() {
new Thread(new Runnable() {
public void run() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final JFrame mainWin = (JFrame) WindowManager.getDefault().getMainWindow();
mainWin.setGlassPane(glassPane);
glassPane.setVisible(true);
}
});
}
}).start();
}
The highlighted lines above come directly from the book, for posting nonblocking new tasks to the EDT. The bit in between the highlighted lines is... me grabbing the IDE's main window. And, from there, you can get the menu bar, the content pane, and, as in this case, the glass pane. Here, a TopComponent (yes! that tiny JTextField comes from a TopComponent) is set as the glass pane, with setOpaque(false) in its constructor, and, as you can see above, the typical call to setVisible on the glass pane. And, what does the TopComponent contain? Nothing but a JTextField, in the bottom right hand corner. So the TopComponent ends up being placed transparently over the surface of the IDE, with the JTextField fitting snugly into the bottom right corner.
And, remember, never eat the yellow snow.
In other news. I've been very slow in responding to several people over the last few days. I apologize! It's been a busy time in NetBeans land, what with the release of NetBeans IDE 6.0 Beta 1, and all the related loose ends that needed to be tied in the world of documentation (which is where I live). I hope to catch up with my correspondence in the next few days.
Sep 17 2007, 11:49:10 PM PDT Permalink
Flowers
There is a very cool recent blog entry by Milan Kuchtiak, called JAX-WS Tutorial: Working With Binary Data. Milan is one of the NetBeans engineers in the Java EE team, and currently on the Web Services Core team, responsible for several web features in the IDE, such as the web.xml editor, among many others. Milan's blog entry shows you how to use the IDE to create a web application that exposes a web service that delegates to a session bean to provide photos. The photos are retrieved by a standard Java Swing application, with the result shown below:
The very cool thing about his instructions are that you cover a lot of the IDE and, more importantly, many aspects of the related technologies, including MTOM, which stands for Message Transmission Optimization Mechanism. I am working on turning his blog entry into a tutorial, so that you can follow the entire application step by step, which will be published on netbeans.org for the 6.0 release. At the end of the tutorial, you will have three different projects in the IDE, all working together:
But, all the instructions you will need for this are already described in Milan's blog. In fact, I managed to build the entire application from scratch, based on the instructions in that blog entry. So, that's a fun thing to do over the weekend, to introduce yourself to Java EE 5 technologies in NetBeans IDE 6.0 Beta 1. (Most things described should also work in 5.5, except for the MTOM part at the end, which is applicable to 6.0 only, at least, in the way it is described in the blog entry.)
Sep 14 2007, 03:18:54 AM PDT Permalink


