Geertjan is a DZone Zone Leader and has posted 466 posts at DZone. You can read more from them at their website. View Full User Profile

How to Create a Web Service Client with Groovy and NetBeans Platform 6.8

  • submit to reddit

Wrapping Up

In this section, you bind a "Delete" action to the quotation nodes. You also create a new "root node", which will replace the default "AbstractNode" that you're currently using to define the node that contains the child nodes (i.e., the quotation nodes).

  1. To define the "Delete" menu item on the quotation nodes, you need to delete the currently selected node in the "BeanTreeView". Below, if OK is clicked in the confirmation dialog, the "QuoteBean" is found in the local "Lookup" of the currently selected "Node". We then use the speech as the unique ID of the "QuoteBean" (not a great approach, but we don't have real unique IDs in this example), to identify the corresponding "ShakesWsClient" object, which we remove from the "InstanceContent". Therefore, you need to pass the "InstanceContent" into your "ChildFactory" and set it as a class variable. From then onwards, you can use the "InstanceContent" within your code, as done below to remove the "ShakesWsClient" object from the "InstanceContent", after which the node hierarchy is recreated.
    private class DeleteAction extends AbstractAction {

    private final Node node;

    public DeleteAction(String name, Node node) {
    this.node = node;

    public void actionPerformed(ActionEvent e) {
    NotifyDescriptor.Confirmation msg = new NotifyDescriptor.Confirmation(
    "Are you sure?",
    "Delete Quote Item",
    Object result = DialogDisplayer.getDefault().notify(msg);
    if (NotifyDescriptor.YES_OPTION.equals(result)) {
    QuoteBean quoteBean = node.getLookup().lookup(QuoteBean.class);
    for (ShakesWsClient client : quotes) {
    if (client.getWords().equals(quoteBean.getSpeech())) {


    Note: You need to set a dependency on the NetBeans Platform "Dialogs API", which provides a number of standard dialogs, such as "NotifyDescriptor.Confirmation", which you're using in the code above, which will create this dialog:

  2. Now we hook the action above into our Node, where we pass in the label of the menu item together with the current Node so that the correct object can be removed from the "InstanceContent":
    public class QuoteNode extends AbstractNode {

    protected QuoteNode(QuoteBean quoteBean) {
    super(Children.LEAF, Lookups.fixed(quoteBean));

    public Action[] getActions(boolean bln) {
    Action[] actions = new Action[]{
    new DeleteAction("Delete", this),};
    return actions;

  3. Next, let's create a custom root node, which will replace the default "AbstractNode" we're currently using. Within your "TopComponent", define the root node as an inner class, making sure that you have a 16x16 image at "/org/shakes/viewer/shakes.png":
    class RootNode extends AbstractNode {
    public RootNode(Children chldrn) {

    And then use the "RootNode" defined above when creating the child nodes. The "ExplorerManager.setRootContext" should now be as follows:

    em.setRootContext(new RootNode(Children.create(new QuoteChildFactory(content), true)));

    Note: Not only are we using the "RootNode" instead of the "AbstractNode", above we are now also passing the "content" (i.e., the "InstanceContent" defined in the "TopComponent") into the "ChildFactory" object, so that we can delete it there, when applicable.

  4. Next remove the tab in the "TopComponent", since here we're not dealing with a multi-document interface, hence no tabs are needed. Follow the related instructions provided here.

  5. Optionally, as an exercise, enable the Undo/Redo buttons, as well as the Save functionality, as described in How to Create a Swing CRUD Application on NetBeans Platform 6.8.

When you run the application, you should now see something that looks like this:

Notice that a display name and image are displayed with your root node and that, when you right-click a child node, the "Delete" menu item is available.

Congratulations, you have completed this article. For more tutorials, see the NetBeans Platform Learning Trail.


Published at DZone with permission of its author, Geertjan Wielenga.


Cej Hah replied on Mon, 2009/12/14 - 2:40pm

Geeez, it's almost 2010, can't we get away from Big Web Services already?!  REST is your friend.  SOAP is your enemy.

Ning Sun replied on Wed, 2009/12/16 - 3:49am

Really nice article.

I have a question about the code when binding mouse listener to bean tree view. That is step 8 in "Using NetBeans Platform Swing Components", line 15. How you got the reference of resultPane in MyBTV? Is there any trick?

Thank u for your great article.



Sven Alfred replied on Thu, 2009/12/31 - 3:38pm

Great walkthrough. SOAP or not... doesnt matter.

Combining the power of the platform with the simplicity of Groovy. I will use this as recipe for my own platform experiments.



Jeff Schwartz replied on Fri, 2010/01/29 - 9:16am


Very groovy to see these examples in Groovy. IMO Groovy is the gem of the Java virtual machine. I find myself using it a lot. I fall back to Java when I can find a legitimate reason to, such as when addressing critical performance issues. Otherwise, Groovy just makes more sense to me.

A lot of the developers I speak with believe Oracle's purchase of Sun doesn't bode well for Netbeans. Nothing that I have read leads me to believe that Oracle intends to throw their 'official' support behind it. Maybe now is time to set Netbeans free from any single corporate sponsor and before Oracle kills it with neglect.

 Be well.

 Jeff @

Mateo Gomez replied on Tue, 2012/04/17 - 12:30am

 You just made my life easier


 mexican dessert recipes

Matt Coleman replied on Tue, 2012/04/17 - 12:43am


 this makes want to get to know netbeans...great job you guys

graphic design buffalo

Eugenios Ampelius replied on Mon, 2013/09/30 - 10:49am

 Groovy does a great job. What's the deal with REST, though? I haven't used it. Is it really better than SOAP? Thank you.

Cata Nic replied on Mon, 2013/09/02 - 4:10am

 The platform can be extended to something custom and dedicated do the client's needs ?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.