Geertjan's Blog

  • September 6, 2010

Search for UNHCR on the NetBeans Platform

Geertjan Wielenga
Product Manager
It turns out that not just UNESCO, but also the UNHCR is working with the NetBeans Platform. I've known this for a while, because I've been in touch with Stanyslas Tamayo from the UNHCR , who's been asking questions off and on for some time already. Then Alexis Moussine-Pouchkine mentioned the UNHCR project in his recent trip report from the jCertif conference in Congo:
"Stanyslas from Kinshasa presented the NetBeans Platform for building rich applications and in particular the RAMS (Refugee Assistance Management System) application he's building for the United Nations' HCR (refugee organization)."

That's all pretty cool, hope to see some screenshots soon. All this brings me to the topic for today, which was a question from Stanyslas in relation to the JSR-296-port-to-the-NetBeans-Platform I've been writing about off and on for a few weeks. The original AMSWin application contained a search feature and Stanyslas wanted to know how to port that feature to the NetBeans Platform.

Well, it turns out that the NetBeans Platform has its very own search feature with which you can integrate, as described in the NetBeans Platform Quick Search Tutorial. I mentioned this feature during the recent training in Stellenbosch, where it turned out that several of the students were interested in using it in their own applications.

Ernest Lotter from ISSI even wrote a nice integration of the quick search, into the AMSWin application:

As you can see, above, I can search for business accounts via the "Quick Search" toolbar, which is a standard part of NetBeans IDE, but which could also be integrated into your own application. And here's Ernest's code, you'll notice that a particular Node is found via the ExplorerManager:

public class BusinessAccountsSearch implements SearchProvider {
\* Search business accounts by parts of first name and last name
\* @param request Search request object that contains information what to search for
\* @param response Search response object that stores search results. Note that it's
\* important to react to return value of SearchResponse.addResult(...) method and stop
\* computation if false value is returned.
public void evaluate(SearchRequest request, SearchResponse response) {
// nasty, JPA stuff!
EntityManagerFactory emf = Persistence.createEntityManagerFactory("AMSWinJPU");
EntityManager em = emf.createEntityManager();
Query query = em.createQuery("SELECT c from BusAcct c"); // em.createNamedQuery("BusAcct.findAll");
List resultList = query.getResultList();
List<BusAcct> businessAccounts = new ArrayList<BusAcct>();
// build up search results
for (final BusAcct ba : businessAccounts) {
if (accept(ba, request)) {
Runnable r = new Runnable() {
public void run() {
TopComponent tc = WindowManager.getDefault().findTopComponent("BusinessAccountTopComponent");
ExplorerManager em = ((ExplorerManager.Provider) tc).getExplorerManager();
Node root = em.getRootContext();
for (final Node node : root.getChildren().getNodes()) {
if (node.getLookup().lookup(BusAcct.class).equals(ba)) {
try {
em.setSelectedNodes(new Node[]{node});
} catch (PropertyVetoException ex) {
Logger.getLogger(BusinessAccountsSearch.class.getName()).log(Level.SEVERE, null, ex);
if (!response.addResult(r, ba.getNameFirst() + " " + ba.getNameLast(), null, null)) {
private boolean accept(BusAcct account, SearchRequest request) {
if (account.getNameFirst() != null && account.getNameFirst().contains(request.getText())) {
return true;
if (account.getNameLast() != null && account.getNameLast().contains(request.getText())) {
return true;
return false;


To use the above code, you'd first need to use the tutorial referred to above. Then you'd replace the code discussed in the tutorial with the code above. Thanks Ernest and hope it is useful to Stanyslas.

Join the discussion

Comments ( 1 )
  • Stanyslas Matayo Tuesday, September 7, 2010

    Dear Geertjan,

    Very Fantastic!!! This feature is very impressive.

    Thanks a lot

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.