Archive

Archive for October, 2011

Recipe 5: Notifications

October 11, 2011 Leave a comment

Problem

How can I display a notification (e.g. ) in a form of ‘bubble’ that notifies the user e.g. that something went wrong?

Solution

Since NetBeans 6.7 a new class was introduced which displays a notification on the right side of the status bar:

NotificationDisplayer.getDefault().notify(String title, Icon icon, String detailsText, ActionListener detailsAction);
NotificationDisplayer.getDefault().notify(String title, Icon icon, String detailsText, ActionListener detailsAction, Priority priority);
NotificationDisplayer.getDefault().notify(String title, Icon icon, JComponent balloonDetails, JComponent popupDetails, Priority priority);
NotificationDisplayer.getDefault().notify();
Categories: Uncategorized

Recipe 4: QuickSearch

October 8, 2011 Leave a comment

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.

Categories: Quick Search