Home > Quick Search > Recipe 4: QuickSearch

Recipe 4: QuickSearch

Problem:

How do I display a QuickSearch box?

Solution:

A QuickSearch box searches for keywords you type in its text box. To add this functionality to your NetBeans RCP application you need to implement the SearchProvider service like so:

package my.package.quicksearch;
@ServiceProvider(service = SearchProvider.class)
public class MyQuickSearch implements SearchProvider {
   @Override
   public void evaluate(SearchRequest request, SearchResponse response) {
      String req = request.getText();
      // response.addResult(Runnable Action, String htmlDisplayName);
   }
}

You need to declare it in layer.xml:

<filesystem>
  <folder name="QuickSearch">
    <folder name="MyFolder">
       <file name="my-package-quicksearch-MyQuickSearch.instance"/>
       <attr name="position" intvalue="300"/>
    </folder>
  </folder>
</filesystem>

If you need to add the quicksearch filter tool to your own panel/toolbar, then follow the trick found here and here.

This article provides an example on how to use QuickSearch. In short:

  1. Right-click on your project and select New -> Other.
  2. In the New File dialog, choose Module Development -> Quick Search Provider.
  3. In the Quick Search Provider panel, set the provider class name etc.
  4. Click on Finish.

The Java stub MyQuickSearch shown above is created as well as the entry in layer.xml.

Advertisements
Categories: Quick Search
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: