Searching for Shakespeare on Groovy and the NetBeans Platform

Since writing How to Create a Swing CRUD Application on NetBeans Platform 6.8, I've come to realize that more end-to-end scenarios like that are needed. So here's the next one I'm working on—a Shakespeare quote client. The web service is accessed via Groovy, which is also used to parse the result. All that (two Groovy JARs, plus a JAR containing the Groovy class that defines the interaction with the web service) is in one module. In a second module, the UI is provided, i.e., the window where the search string is entered and sent to the "Groovy" code (because, at compilation, your Groovy is Java):

The result is displayed in a BeanTreeView, using BeanNodes, synchronized with the Properties window. Double-click a node and you bring up a dialog containing the retrieved text, as shown above. There's also a progress bar to avoid the situation where the UI is blocked during the processing of the web service.

private void findButtonActionPerformed(java.awt.event.ActionEvent evt) {                                         
   Thread t = new Thread(new WSRunnable());
   t.start();
}

private class WSRunnable implements Runnable {
    @Override
    public void run() {
        ProgressHandle p = ProgressHandleFactory.createHandle(
                "Fetching the Shakespeare quote for " +
                "'" +searchField.getText() + "'");
        p.start();
        QuoteBean bean = new QuoteBean();
        ShakesWsClient client = new ShakesWsClient();
        bean.setName(client.getSpeaker(searchField.getText()));
        bean.setPlay(client.getPlay(searchField.getText()));
        bean.setSpeech(client.getSpeech(searchField.getText()));
        bean.setSearch(searchField.getText());
        content.add(bean);
        p.finish();
    }
}

Above, in bold, is all the code needed to integrate with the progress bar!

And here's the same scenario as above, using an AbstractNode instead of a BeanNode, which gives you more freedom, but also more responsibility:

A full tutorial to describe all of the above will be on NetBeans Zone soon.

In other news. All the code for the above, plus a bit more, is available here on Кеnai: http://kenai.com/projects/shakespeareannotater

Comments:

Thanks for the example. I downloaded it from Kenai. I found however that the groovy code doesn't seem to be in the download. When you look in ShakesLibs there is no source. I see the lib for ShakesGroovy.jar. How did you go about making that one. Anything special?

Also, I've been trying to use Java and Groovy in the latest 6.8 release with Platform and get all kinds of 'symbol not found' and dual compilation issues. I followed your post from earlier this year about adding the groovyc taskdef, etc. but I still get issues with NB's telling me it can't find the symbol for the class even though the groovy file is in the same package. If there are only groovy files I can follow your post but if you try to mix them I can't seem to figure it out.

Additonally, it seems that when you create a new project (Module) and then put a groovy file with a newly defined package in that new module, there is no way to set the public packages in that Module.

Posted by Sam Griffith Jr. on December 13, 2009 at 04:10 PM PST #

Steps to take for recreating the Groovy sample described in this blog entry are here:
http://netbeans.dzone.com/websvc-on-netbeans-platform

If you encounter problems with the Groovy editor, create an issue in Issuezilla, describing the full steps to take to reproduce the problem. Adding groovyc taskdef, or whatever, is completely a waste of time, that should not be done at all. Follow the steps in the first part of the article above and you should be fine.

Posted by Geertjan on December 14, 2009 at 12:36 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today