Download NetBeans!

20070430 Monday April 30, 2007

Further Cool Discoveries in the Land of Ubuntu 7.04

24 hours, give or take, since installing Linux for the first time. Am I a deeply embittered man, gnashing his teeth in regret, beating his chest in agony, rueing the hour of his folly? Nay. Especially not "nay" since discovering that my favorite mail client, "Thunderbird", is available from the Synaptic Package Manager. So I set that up and removed "Evolution", which is the standard mail client that Ubuntu gives you. Wonderfully, I also have "The Gimp", the world's best graphics program (one of the four! graphics programs that comes with Ubuntu). Or, at least, one I can use for screen grabs, which is all I use graphics programs for.

Next, I discovered that while the procrastination options given by Windows consist of a paltry two games, Ubuntu is much more generous, and even has a very authoritative-looking tooltip, giving one a plausible excuse for playing many different solitaire games:

That is a big and not to be underestimated win. I also like how you can use the "Add to Panel" menu item on the toolbar to add a very wide range of features to it:

By the way, yesterday, when I mentioned that I didn't think that NetBeans IDE 6 looks so good under JDK 6 and JDK 7, I was referring to this:

So, the bottom of the tabs in the explorer windows does not have a clear line. And there's a weird purple separator between items in the right-click pop-up menus.

In addition, I still don't have the double-click thing worked out under Linux. Double-clicking seems harder here than on Windows. Plus, the icons for cursors seem different. Probably both these can be fixed somewhere. One massive improvement is the Search functionality. Under Windows, I always had a really frustrating time. I haven't explored this part of Ubuntu yet, but it can only be better than under Windows.

In general, my biggest surprise is how user-friendly everything is. I had expected that I'd need an advanced degree in computer science to get anywhere with Linux, while all I have is a beginner's degree in law. That's kind of the vibe it seems to exude. Seriously, despite the apparent bareness of the Ubuntu distribution (a statement which I base on some of the comments in my blog entry from yesterday), I have everything I need already, within 24 hours of setting up Linux. I reckon the only thing Windows has going for it is that people don't really understand what an operating system is, so that they don't realize that they have real and, even, better alternatives. That's why Linux and OpenSolaris are confined to programming communities. Firstly, because non-programmers don't realize there are alternatives; secondly, because non-programmers don't see the benefits of at least trying an alternative; thirdly, because non-programmers assume that they will risk destroying their data if they try one of the alternatives. Maybe Linux could make some serious headway in the non-programming world if they'd simply say: "We provide far more games than Windows, out of the box and for free!" But then they'd better include Hearts. Without Hearts, they can't compete with Windows, even though Windows has only two games.

Apr 30 2007, 05:10:20 AM PDT Permalink

Download NetBeans!

20070429 Sunday April 29, 2007

Seven Nice Things About Linux Ubuntu 7.04 "Feisty Fawn"

For some work I'm doing, I needed to try some stuff out on Linux. As a long term Windows user (more out of apathy than choice) that was kind of threatening. "Where do I start? Will I end up destroying all my data? Will my disk implode? Will odd and freaky things happen? Am I stepping into a lake of despair that will lead to a waterfall of misery?" Fortunately, none of these fears turned to reality and I am now happily blogging in Linux on a partitioned multi-boot system, so that I can switch back to Windows at start up, should I want to do so. Here's the proof, showing that I've installed Linux Ubuntu 7.04 "Feisty Fawn":

Above, I am running NetBeans IDE 6, Milestone 8, on JDK 5, and things look good. (Things look less good on JDK 6 and JDK 7, though.) Here, to summarize my experience, in no particular order, are 7 very nice things about Linux Ubuntu 7.04 compared to Windows XP:

  1. Installation could not be easier. Go to http://www.ubuntu.com/download, download as instructed on the very clear website, slap the result on a disk, restart your system, and... you can then immediately see what you'll see after installing. Browse around a bit, become familiar with the desktop and menus, then (if you've liked what you've seen) click the Install icon. You'll go through a wizard, which even handles the partitioning for you, and at the end (half an hour later, max) you can restart your computer and then you'll be able to choose whether you want to use Linux or Windows. Speaking as a mostly non-technical person, I have to give the Ubuntu people a big round of applause for the simplicity of their installation procedure. It could not possibly be simpler or better. Hurray!

  2. My desktop feels bigger. And cleaner. I don't know what it is, but the desktop really feels bigger. Sure, part of that is that a dozen icons haven't been dumped there by default, as is the case on Windows, but somehow there's something else going on. The menus are... nice. Just three, "Applications", "Places", and "System". So clean and simple. I like it a lot, especially because my laptop (and therefore my screen) is small. Another nice thing is that there seems to be a different default font, used for web pages and so on. It's much nicer than what is used under Windows.

  3. Setting up Java is easy. I followed Tom Marble's excellent instructions here and, literally, 10 minutes after finishing my Linux set up, I had also set up Java, plus NetBeans IDE 5.5. This was a main reason why I chose Ubuntu 7.04, instead of the previous one (6-something), because of the Java packaging that is available for 7.04. You go through something like the NetBeans Update Center wizard and within no time everything is downloaded and installed, so that, with my zero-level Linux knowledge (since I had just set that up 10 minutes before) I didn't have to set any environment variables and so on, because the packaging does that for you. As soon as I had completed the wizard, I was able to start NetBeans IDE 5.5. That was a cool experience.

  4. Farewell "c:/Documents and Settings". Is there anything more annoying than "c:/Documents and Settings"? If so, I'd like to know what it is. That space-infested folder, which permeates everything in Windows, is now a thing of the past. At last, sane folder names and structures. Hurray.

  5. Open source. Linux is open source, Windows isn't. Linux represents all that is good in the world.

  6. Ubuntu. The name "ubuntu", signifying "humanity to others" in Zulu, resonates with me, because I grew up in South Africa and even briefly studied Zulu at university. One common saying in Zulu is: "Umuntu ngumuntu ngabantu", which means "a person is a person through other people", and the concept "ubuntu" itself is a very prevalent thought there. Also, imagine my surprise when under the Help menu I found a short quotation from Desmond Tutu, archbishop in South Africa, prominent resistance figure, and Nobel peace prize winner. Also, there's a cool little drum beat when you start Linux. Basically, the whole "African" feel about Linux Ubuntu is kind of cool.

  7. Change is good. However long or short my stay in Linux will be, change is good. Especially now that I can switch back to Windows so easily, which I'll have to since my files are still all there, getting to know Linux will be a useful exercise. And then I'll see if I can extend my multi-boot setup and include... Solaris.

The only uncomfortable thing thus far is that double-clicking seems to work differently here compared to Windows. Maybe I need to change a setting somewhere.

Apr 29 2007, 12:36:24 AM PDT Permalink

Download NetBeans!

20070428 Saturday April 28, 2007

Happy Third Birthday, blogs.sun.com

April 27th was blogs.sun.com's third birthday. Several people have already blogged about this, sharing their opinions and perspectives. My own blog, this one, began on April 1, 2005. On March 31, 2006, I wrote What One Year Of Blogging Has Done For Me. I still find those reasons pretty much valid, since they're undeniably true and verifiable.

The general point for me, and others, from what I can tell, is that blogs.sun.com has given many people a sense of ownership of a small space of the company for which they work. It's like Sun Microsystems has said to all its employees, "Look, if you want it, we will give each of you a small plot of land where you can plant a tree. Any kind of tree at all, so long as it doesn't encroach on other plots of land nor bring disrepute to the company as a whole." And then some people responded by saying: "Nah, don't want that plot of land. I'm not good with trees and it would just take up too much of my time." Others took the opportunity and learned about trees, turning them to their own benefit, which turned out to be many... certainly a lot more than was initially envisaged. And the variation of trees has turned the combined plots of land into a colorful forest, reflecting back on the owner of that forest, i.e., Sun Microsystems, to the extent that that dichotomy becomes less distinct. The more trees there are, the more they assert themselves, the more they define the forest. The more they become the forest. I find that an interesting thought.

I'm looking forward to seeing there being even more trees in the coming years. And I'm looking forward to seeing how the forest itself will change. Beyond being a place that allows the trees to stand, beyond being a place that enables the trees to become aware of each other, the forest itself is an entity that at some point should change as a result of its content. Maybe that's already happening, but I'm looking forward to seeing that happen more. And I'm also looking forward to seeing not just more trees, but how the existing trees will develop and change, which they must do to survive and flourish, over the coming years. If trees don't flourish, they die. What new flourishes will we come up with next?

Apr 28 2007, 12:47:00 AM PDT Permalink

Download NetBeans!

20070427 Friday April 27, 2007

Building a Login Screen for a NetBeans Platform Application (Part 2)

Let's go a step further than yesterday's Login screen. Yesterday, I didn't say that the buttons in the LoginForm were not part of the LoginForm itself. Instead, they were provided by a very handy NetBeans API class called NotifyDescriptor. Or, in fact, they came from one of that class's children, called NotifyDescriptor.Confirmation. These NotifyDescriptor subclasses (and there are others) provide descriptions of notifications sent to the user. Basically, they're comparable to variations of JOptionPane, just with a lot more versatility.

The statement used to define the NotifyDescriptor yesterday was as follows:

NotifyDescriptor nd = new NotifyDescriptor.Confirmation(form,"Login");

This returned a JPanel called form:

However, the JPanel looks like this in the GUI Builder:

Hence, notice, no buttons. So where do "Yes", "No", and "Cancel" come from? Answer: They are the default buttons that you get when you use NotifyDescriptor.Confirmation. Now here's the problem—how do you listen for actions on these buttons? When "No" is clicked, for example, something different should happen to when "Yes" is clicked. Presumably. How does one listen to those actions, when they relate to buttons that you didn't define yourself? Answer: NotifyDescriptor.setOptions.

Using that method, you can define your own buttons, so that you can listen to their actions. So, in the installer created in yesterday's blog entry, I now have two buttons:

JButton ok = new JButton();
ok.setText("OK");

JButton cancel = new JButton();
cancel.setText("Cancel");

Here's the action listener on the Cancel button:

cancel.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
        LifecycleManager.getDefault().exit();
    }
});

(See the NetBeans API LifecycleManager for details.)

And here, to show you some basic interaction with the LoginForm, is the action listener on the OK button:

ok.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
        String userName = form.getUserName();
        String password = form.getPassword();
        JOptionPane.showMessageDialog(null,"UserName: " + userName + 
                "\nPassword: " + password);
    }
});

And now... we simply add our buttons to the NotifyDescriptor, via the aforementioned setOptions method:

nd.setOptions(new Object[] {ok, cancel});

The final step is the same as yesterday, we display the dialog, using our notify descriptor implementation:

DialogDisplayer.getDefault().notifyLater(nd);

And that's all. Now I have control over the buttons, because I created them myself, overriding the three buttons I got for free from the NetBeans API class:

And this is the basis for creating your own authentication mechanism, i.e., a login screen.

Click here to go to Part 3 of this series.

In other news. While working through the above, I learned two interesting things about NetBeans IDE 6.0. Firstly, when you press Alt-Insert over a field, you get a very cool little pop-up leading to some cool code generation functionality:

And, secondly, I'm one of those people who always forgets which slash to use for a "forward slash" and which slash to use for a "backward slash". However, it looks like 6.0 will come to my rescue. Look at the difference between "\n" and "/n" in the following two screenshots and you'll see why I'll never screw this part of my code up again:

So, because the "\n" is shown in bold, I know that that combination is a line break, while "/n" will be interpreted as normal characters. Useful, isn't it?

Apr 27 2007, 04:18:40 AM PDT Permalink

Download NetBeans!

20070426 Thursday April 26, 2007

Building a Login Screen for a NetBeans Platform Application (Part 1)

Since the resolution of issue 92570, it is possible to show a modal dialog after the appearance of an application's splash screen, but before the appearance of an application's main window. And what would one want to put there? A login screen, of course. With this enhancement, it is possible to integrate some level of authentication into your NetBeans Platform application.

The specific method in question here is DialogDisplayer.notifyLater, which can now also be called before the main window is opened. When called from ModuleInstall.restored, the modal dialog is opened and blocks the main window until the modal dialog is closed. So, to implement this, use the Module Installer wizard, which will create a class that extends ModuleInstall (and adds relevant entries in the project.xml file and manifest file). You get a skeleton restored method for free. Fill out the method as follows:

public void restored() {
   NotifyDescriptor nd = new NotifyDescriptor.Message("Ok");
   DialogDisplayer.getDefault().notifyLater(nd);
}

You will now get a simple modal dialog, after the splash screen, where you must click OK before the main window of the application can open. See further examples in the Javadoc for Class NotifyDescriptor.

However, you can also create your own JPanel and return that in the above code, instead of "Ok". So, here's my new code:

LoginForm form = new LoginForm();
    
public void restored() {
   NotifyDescriptor nd = new NotifyDescriptor.Confirmation(form,"Login");
   DialogDisplayer.getDefault().notifyLater(nd);
}

And your LoginForm could be anything here. Mine looks like this:

It could be wired up to a database, with logic in the panel for verifying the password. So, the key to all of this is the fact that it is a modal dialog that appears after the splash screen and before the main window. Hurray!

Continue with part 2 of this series...

In other news. What?! Another new domain name in the NetBeans world? Yes. And it is... http://www.netbeans.tv/. Check it out! Hilarious adventures (e.g., "Today we’re discovering the hard way why Turkish beer is just not a morning’s best friend...") of two random American dudes from Prague delivering NetBeans IDE to some guy in Palestine who couldn't receive it by mail...

Apr 26 2007, 04:22:05 AM PDT Permalink

Download NetBeans!

20070425 Wednesday April 25, 2007

Freely Available: Samples for "Rich Client Programming: Plugging into the NetBeans Platform"

The samples for the book Rich Client Programming: Plugging into the NetBeans Platform are now available... in the 6.0 Development Update Center:

Hence, you need to start up some 6.0 IDE build (e.g., a milestone or a daily build), since these register this update center. Install from the update center and notice that the Samples category for NetBeans Plug-in Modules has been populated with many new samples:

In the help set, you'll find a new topic describing each of the samples briefly, plus which chapter in the book relates to the sample:

Anticipated questions:

  • Why are you making the samples freely available? Answer: We're doing this to support those who have bought the "rough cuts" version (i.e., the draft) of the book (as described here). These early adopters of the book currently have a PDF version (a draft version), but no samples. Several of these people have requested the samples. This action is partly a direct response to these requests. Plus, we're hoping to encourage others to buy the book too, after they've got a flavor of the kind of material we're covering, which they can now get by looking at the samples.

  • But isn't the book written for 5.5? Answer: Yes, for both 5.5 and 6.0. The same samples will be available in one of the 5.5 update centers soon, the process just takes a bit longer than putting a module in the 6.0 development update center.

  • But won't the book come with a CD that contains samples? Answer: Yes, the very same samples.

  • Since the module that installs the samples is in an update center, will you be providing enhancements and bug fixes to the samples? Answer: Yes, that's the plan (although there shouldn't be any bugs to fix, of course, but enhancements are conceivable, as well as additional samples for supplementary scenarios, such as for the Visual Library API, for example). We'll announce these on the book's site (here) and, probably, in this blog.

Apr 25 2007, 10:28:18 AM PDT Permalink

Download NetBeans!

20070424 Tuesday April 24, 2007

Found in 5.5... Replaced in 6.0

For the 6.0 release of NetBeans IDE, in the category "Gee, that'll come in handy", an honorable mention goes to.... drum roll... the "Find in Projects" dialog box...

...which will transmogrify itself into the "Find/Replace in Projects" dialog box:

Hurray!

Apr 24 2007, 08:59:50 AM PDT Permalink

Download NetBeans!

20070423 Monday April 23, 2007

Adding Nodes to an Existing Project Type's Logical View

Since a few weeks, it's been possible to add new nodes to an existing NetBeans project type's logical view. Thanks to Milos Kleint, who created this functionality, I found out how to implement it. Take the steps below, as a kind of "hello world" experience.

  1. Create a new project called "foo" with code name base "org.netbeans.foo".

  2. In the layer, specify where you want the node to appear, i.e., which project you want to extend.

    <folder name="Projects">
         <folder name="org-netbeans-modules-java-j2seproject">
            <folder name="Nodes">
                <file name="org-netbeans-foo-NodeFactoryImpl.instance"/>
            </folder>
         </folder>
    </folder>

    Note that when you expand the Important Files node, then the XML Layer node, and then the "this layer in context" node, you can see a long list of new nodes under the "Projects" node, each representing a different project type. In 5.5, only the "Actions" node was shown under the "Projects" node.

    The above view is extremely useful, because without needing any documentation you can now immediately see the required names of the other project types for use within the XML layer. As always in this visual representation, our own changes, coming from our XML layer, are shown in bold. So, above it is clear we will be adding a new node to the org-netbeans-modules-java-j2seproject project type, which is the Java SE project type.

    Notice also that there are two other nodes, aside from "Nodes", one called "Customizer" and one called "Lookup". This means you can extend an existing project's customizer (Project Properties dialog box) and Lookup. Both will be discussed in future blog entries.

  3. Set source level to 1.5 and declare dependencies on Nodes API, Project API, Project UI API, and Utilities API.

    Create the class referred to above in the layer and fill it out as follows:

    public class NodeFactoryImpl implements NodeFactory {
    
        public NodeFactoryImpl() {
        }
    
        public NodeList createNodes(Project arg0) {
            
            AbstractNode nd = new AbstractNode(Children.LEAF);
            nd.setDisplayName("Hello World!");
            
            return NodeFactorySupport.fixedNodeList(nd);
         }
    
    }

    For details on the above, see NodeFactory in the NetBeans Javadoc.

    Install the module and see your new node:

  4. You want the node to appear somewhere else? Go back to the visual representation of the XML file and drag the node that you created in the XML layer somewhere else:

    Install the module again... and now the node has been moved:

It's as simple as that...

Apr 23 2007, 02:21:31 AM PDT Permalink

Download NetBeans!

20070420 Friday April 20, 2007

Visual View for JavaHelp Table of Contents

The start of a visual view on top of a JavaHelp toc file:

My starting point for creating this visual view was to generate the beans for traversing the XML file. I used the generator described yesterday, of which I uploaded a new version (1.1) to the plugin portal. Several bugs are fixed. Plus, when you hover the mouse over a checkbox, you'll see a tooltip with the Schema2Beans parameter that is executed if the checkbox in question is selected. That could be quite useful. So, if you're one of the people who downloaded the Schema2Beans Generator Template yesterday, make sure you get the latest version, i.e., 1.1, because this one is better.

Once the above scenario (i.e., one that provides a visual view and, later, an editor, on top of the JavaHelp toc file) is completed, I will use it as the basis of a tutorial on the XML MultiView API. The JavaHelp toc DTD isn't very complex, but just complex enough to be interesting. Two beans are generated when you use Schema2Beans, one called Toc and the other called Tocitem. The former doesn't provide much, it is just a container for the items. The latter is where all the headers for the JavaHelp topics are found. The interesting bit is working out how to iterate through all the levels of the Tocitem, which is the main part that I'm still working on.

In other news. Because of popular demand, we will be releasing the samples for the Rich Client Programming book next week. We're just putting the pieces together at the moment. We need to be careful how we release them, because we also want to be able to provide enhancements and bug fixes and so on. Probably we will use, among other means, the Plugin Portal to distribute one big NBM file that will install the samples. An NBM file with the samples will also accompany the book.

Apr 20 2007, 02:51:29 PM PDT Permalink

Download NetBeans!

20070419 Thursday April 19, 2007

Schema2Beans Generator

I followed Toni's 5 part Schema2Beans tutorial in his blog today (part1, part 2, part 3, part 4, part 5). Toni wrote that tutorial all the way back in October. At the time I looked at it, but had no idea what "Schema2Beans" was, nor why I would want to deal with it. In short, Schema2Beans is a NetBeans utility for generating JavaBeans for traversing XML elements and attributes that are governed by a DTD or Schema file. And why would you want to do that? You would want to do that when using the XML MultiView API, which you would use when creating a visual editor, comparable to the IDE's editor for web.xml files. There's a lot of functionality provided by this Schema2Beans utility, as described on the Schema2Beans site. There are also a few problems with it, though, and I hear that alternatives are being considered. In the meantime, however, there's a lot that the utility does do for you, though you might find yourself tweaking the generated beans in some situations, though I haven't found the need to do so yet.

How the utility works is, you use Ant scripts or Java code to specify the DTD or Schema file and then the utility generates all the JavaBeans, one for each element in the DTD or Schema. Typically you would use an Ant script, which is considerably simpler, and since you're going to be using the utility only once per DTD or Schema, since you'll only need to generate the beans once, the Ant script approach makes more sense. And normally you would run the Ant script from the command line. This is where Toni comes in. In the first part of the 5 part blog series, he writes: "For a dedicated NetBeans user, using a command line tool is like admitting defeat, so I had to include some basic support for Schema2Beans." So... Toni, in his blog, provides ALL the code for a wizard where one selects a DTD or Schema, one sets the Schema2Beans parameters, one then clicks Finish, and then everything else is automated by the wizard. No work for you at all. At the end of the wizard, you have a package containing all the generated beans, which you can then include in your module.

So I worked through Toni's tutorial, e-mailed a bit about things that weren't clear, and turned the result into a sample. It is a module that installs a sample in the New Project wizard and not simply a module that installs the "Generate Schema2Beans" menu item because (a) it could form the basis of a more extensive wizard (which would generate stubs for all classes required by the XML MultiView API) and so making the code available could be a good start to that end, (b) there might be bugs in the code and so if you have the code available as a sample, you might simply fix the code yourself, and (c) the people using Schema2Beans are NetBeans module writers and might therefore be interested in the code of this NetBeans module anyway. So, take the following steps and soon you'll be generating JavaBeans from DTDs and Schemas too.

  1. Download org-netbeans-modules-schema2beansgeneratortemplate.nbm and install it in NetBeans IDE 5.5.

  2. Go to the New Project wizard. You should see a new template:

  3. Select the above and complete the wizard. You now see this:

    The first package is the code of the module. The second package, called "examples" contains a very long list of NetBeans DTDs that I found in the NetBeans sources. They're just there to try out the functionality, once you've installed it. Otherwise, ignore these DTDs (there's also one Schema, but it doesn't seem to work in that case, for some reason).

  4. Now install the module. After installing, right-click the node of a DTD or Schema (or right-click inside a DTD or Schema in the editor). For example, one of the DTDs included in the "examples" package is the DTD of the sun-web.xml file. Right-click it and choose the new menu item:

  5. When you choose the menu item, you should see this one-step wizard:

    I don't know what all those parameters, visualized by checkboxes, mean. They're simply the parameters provided by Schema2Beans. Read the documentation for details on them. And the recommended ones are only recommended because the documentation recommends them. The "-javabeans" flag cannot be set (there is no checkbox provided for this reason), because that would generate classes that do not extend BaseBean, which is what we need them to extend. So, some choices have been made. However, you have the same dilemma now as you would have if you weren't using this GUI—which parameters to set? The GUI doesn't help you, it just provides you with a visual view on top of the Schema2Beans JARs.

  6. After choosing the menu item and specifying a package, all the JavaBeans are generated there, one per element in the DTD or Schema, exactly as would be the case if you were using Schema2Beans via an Ant script or self-coded Java. So, for the sun-web.xml DTD, there's a VERY long list of classes that are generated (I couldn't get them all in one screenshot):

    In some cases, I've found that the tool doesn't work. I haven't investigated why this is the case yet. Bear in mind that this is a very early release of this module. Consider it "pre-Alpha". One thing I have found is that attribute lists should be like this:

    <!ATTLIST bindings
           name    CDATA #REQUIRED >

    But, not empty like this:

    <!ATTLIST bindings >

    Maybe one of the many parameters should be set to avoid this problem.

That's it, thanks to Toni's great blog tutorial. You're done and, for now, you're on your own. Take the classes and put them in the module where you're going to be creating your multiview editor. First thing to do after that, as explained yesterday, is to change the data object's extension class from whatever it is to XmlMultiViewDataObject. And then read Vadiraj's blog entries on the BookMultiView Sample (links to these blog entries are in my blog entry from yesterday). Vadiraj, Toni, and I are planning to extend this functionality further, so that in the short term the wizard will generate stubs for all the basic classes needed to implement the XML MultiView API. In the longer term, we're thinking about using the Visual Library API to let the user (i.e., a NetBeans module writer) design the layout of the nodes for their multiview editor. But don't hold your breath—it might take some time... By that time though, there could be a different/better/easier API for this. How about "Schliemann for MultiView Editors". Now that would be cool and makes complete sense, since the only difference between one multiview editor and the next is the content...

Apr 19 2007, 10:24:39 AM PDT Permalink

Download NetBeans!

20070418 Wednesday April 18, 2007

xwork.xml in MultiView Editor

A simplistic start to creating a multiview editor for the xwork.xml file:

Most of it works, but there are several bugs to fix. An editor such as this only makes sense when (a) all elements/attributes are exposed and (b) no bugs remain. So those are the two things I'm striving for.

Want to create a multiview editor for an XML file too? The principles of getting started are easy. Here are some resources:

  • NetBeans: schema2beans library - User Documentation
  • Toni Epple's blog has some really good resources about getting started with Schema2Beans. His blog is here. He and Vadiraj, who has been very helpful to me over the past few days, are thinking of writing a wizard that will generate all the beans via Schema2Beans, as well as some basic implementation classes from the XML MultiView API. That would be really brilliant to have. Anyone out there want to help them? You can get in touch with them via their blogs.

Writing a multiview editor for XML files is not exactly easy, but it could also be a lot harder than it is. There's a lot to become comfortable with. The most obvious question is: "Where do I start?" Well, you start by generating Java classes from the Schema or DTD to which the XML file conforms. So, you are not really writing a multiview editor for an XML file. You are writing it for a Schema or DTD file. Using the Schema2Beans JAR provided by NetBeans, here, you can use either Java code or Ant scripts to generate your Java classes. These Java classes form the basis of your implementation of the XML Multiview API. In other words, they are the model of your application.

Once you have these classes, of which there could be about 10 (in fact, one class per element in the Schema or DTD), put them in your module. Then go to your DataObject and change its extension class from whatever it is to XmlMultiViewDataObject. This means you'll have to create a dependency on the XML MultiView API. After that, you will have to implement many many many methods, over several classes. The best way to go about this, in my humble opinion, is to (a) get the BookMultiView Sample from my update center (or get it from Vadiraj, because he has fixed an annoying bug in the module) and (b) read these of Vadiraj's blog entries extremely carefully. They introduce you to the sample, as well as to the API as a whole. They're excellent and describe the whole picture on a very technical yet readable level:

With all of the above resources, you'll be off to an excellent start. My own approach is to gradually merge the BookMultiView Sample with my own scenario, bit by bit and piece by piece. What is also helpful is that if you go here in the NetBeans sources...

netbeans-sources\j2ee\ddloaders\src\org\netbeans\modules\j2ee\ddloaders\web

...you will find several other multiview editors, such as the editor used by the web.xml file. You can open the forms in the IDE and then... you can let them "inspire" you. Or just do what I did and copy whatever makes sense to your own scenario.

Apr 18 2007, 07:28:03 AM PDT Permalink

Download NetBeans!

20070417 Tuesday April 17, 2007

xwork.xml in Configuration Files Node

I worked out how to put the xwork.xml file in the Configuration Files node, by looking at how it is done for Struts, and (for the first time) implemented WebFrameworkProvider.getConfigurationFiles. This is the result:

The only purpose of the Configuration Files node is that it provides a centralized location for all configuration files, which must first be found somewhere else, after which they are copied (programmatically, by the module that provides them) to the Configuration Files node. However, xwork.xml must end up in WEB-INF/classes, so initially I had that file in WEB-INF/classes or in the default Java package. Neither is very satisfactory. The point of a logical view is that you should have as few folders as possible in the Projects window, which is a project's logical view. So, having WEB-INF/classes is not ideal (and using the default package is just plain messy). Therefore, I write the file to WEB-INF, but I add a target to the build.xml file, which moves the xwork.xml file to WEB-INF/classes from the build/web/WEB-INF folder. That's a sneaky way of moving the file to the correct location at compile time. However, the down side is that the user has an odd looking Ant target in the build.xml file. Not sure if there is a nicer way of handling this (maybe I should smuggle the Ant target into build-impl.xml instead, so the user will not notice it at all). Is there Java code for copying files at compile time (or after compile time)? In the absence of that, I chose the Ant route.

In other news. This morning I received a cool tip about the Rich Client Programming book, from Fred Griggs, via e-mail. He writes: "Aside from the technical value of the book, there's tremendous monetary benefit to ordering through this -- Safari Books Online -- mechanism. For $35 worth of book, I paid $35; and I got to read the book within minutes of my request. This contrasts sharply with my order from Amazon, where $33 worth of book will cost me $52 – and that's when I eventually get it (with an estimated 1 to two months' delivery)! I like to annotate my books, and until we all read all on-line, this is the way to buy!" And then Fred attached his Amazon shipping form which shows he'd have to pay $18,99 for shipping, on top of the $32.99 for the book...

Apr 17 2007, 03:03:26 PM PDT Permalink

Download NetBeans!

20070416 Monday April 16, 2007

Some Advances in the NBWebWorkSupport Module

I've added a few things to the NBWebWorkSupport module. First, I've put most of the samples from the 2.2.4 WebWork distribution into the New Project wizard as samples:

For example, the ShoppingCart sample is pretty cool. Here's how it looks in the Projects window:

Just run it and it deploys (because the module registers the applicable JARs in the Library Manager) straight away, with this result:

In addition, there are also two file templates, one creates a simple 'Hello World' Action, while the other creates a 'Login' Action...

The related Action elements are not added to the xwork.xml file by the wizard, because it's so easy to do via the menu items that appear on all Java nodes within a WebWork project, with one recent change—the deregistration menu item now shows the number of Actions that are registered:

That's it. A next step is to fix some problems with the hyperlinks and to add some new features, such as those suggested by hantsy in the comments in my last blog entry—a visual editor for the xwork.xml file and integration of the xwork.xml file in the Configuration Files node.

Apr 16 2007, 11:26:19 AM PDT Permalink

Download NetBeans!

20070414 Saturday April 14, 2007

Menu Items for Registering/Deregistering WebWork Actions

For the NBWebWorkSupport project, I need highly versatile menu items, for registering/deregistering Actions in the xwork.xml configuration file. They need to meet the following requirements:

  • First, they need to appear on Java nodes, but only for projects that support WebWork. This requirement, and its solution, was discussed in Show/Hide Menu Items Based on Deployment Descriptor Content.

  • Second, the menu item for deregistering a Java class's Actions needs to be enabled only when there are Actions to be deregistered. When there are no Actions registered for the current class, the menu item for deregistering them needs to be disabled.

For the second requirement, to understand it better, look at the screenshot below. In the xwork.xml file, there are no Actions for the selected class in the xwork.xml file. In other words, the class "Login" is selected, the right-click contextual menu appears, and shows the "Deregister from WebWork Actions" menu item is disabled. Why? Well, look in the xwork.xml file below... it shows there is one Action and the class attribute's value is "com.acme.action.HelloWorld":

Hence, there are no Actions registered for the Login class and, for that reason, the menu item is disabled. As soon as an Action is registered for the class, which is done using this (currently very rudimentary) dialog box...

...the menu item becomes enabled. Everything is done, on this point, based on the Action's "class" attribute in the Action's Action element. That required heavy use of regular expressions. When the menu item for deregistration of Actions is chosen (after I registered three Actions for the Login class), this dialog box is shown, just as a confirmation of the event that is about to happen:

Again, a lot of regular expressions were needed to get the Action names into the drop-down above. Right now, the code works exactly as it should. As soon as there are no more related Actions in the xwork.xml file, the deregistration menu item automatically disables. As soon as a Java class is registered, just once, the deregistration menu item enables automatically. Pretty cool. The code is in the project's CVS directory, if you're interested.

In other news. My colleague Troy completed the world's best, most detailed, and funniest MySQL tutorial for web applications in NetBeans IDE. Read Creating a Simple Web Application in NetBeans Using MySQL and laugh while you learn!

Apr 14 2007, 02:19:55 PM PDT Permalink

Download NetBeans!

20070413 Friday April 13, 2007

Library List in the IDE's Toolbar

On the face of it, this isn't the most useful functionality. A JComboBox, with a filter, in the IDE's toolbar, for displaying all the libraries in the IDE's Library Manager:

However, knowing how to get the libraries from the Library Manager is pretty useful in some cases. For example, in the Frameworks panel in the New Project wizard for web applications, you might want to show all the libraries (or a filtered list, meeting certain criteria), so that the user can choose one of them to be put on the classpath.

So, in the above scenario, you need to declare a dependency on "External Libraries". This is the code, called from the JPanel's constructor, as well as in the (optional) filter's keyPressed event:

private void initLibraries(){

    Library libraries[] = LibraryManager.getDefault().getLibraries();
    Vector  items = new Vector();
    ArrayList  allLibraries = new ArrayList();

    String filter = jTextField1.getText();

    for (int i = 0; i < libraries.length; i++) {
        if (libraries[i].getName().startsWith(filter)){    //NOI18N
            String displayName = libraries[i].getDisplayName();
            items.add(displayName);
            allLibraries.add(libraries[i]);
        }
    }

    jComboBox1.setModel(new DefaultComboBoxModel(items));
    if (items.size() == 0){
        jComboBox1.setEnabled(false);
    } else {
        jComboBox1.setEnabled(true);
    }
    
    repaint();
}

And how do you create the toolbar in the first place? See the Google Toolbar Module Tutorial for details.

Apr 13 2007, 04:02:04 AM PDT Permalink