시소당
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...
[2008년 03월 10일 11:32:55 수정되었습니다.]