Getting Started Plugging into the "Find in Projects" Dialog

In case you missed it amidst all the code in yesterday's blog entry, the "Find in Projects" dialog is now pluggable. I think that's really cool. The code yesterday gives you a complete example, but let's break it down a bit and deconstruct down to a very simple hello world scenario.

We'll end up with as many extra tabs in the "Find in Projects" dialog as we need, for example, three in this case: 

And clicking on any of those extra tabs will, in this simple example, simply show us this:

Once we have that, we'll be able to continue adding small bits of code over the next few blog entries until we have something more useful. So, in this blog entry, you'll literally be able to display "Hello World" within a new tab in the "Find in Projects" dialog:

import javax.swing.JComponent;
import javax.swing.JLabel;
import org.netbeans.spi.search.provider.SearchComposition;
import org.netbeans.spi.search.provider.SearchProvider;
import org.netbeans.spi.search.provider.SearchProvider.Presenter;
import org.openide.NotificationLineSupport;
import org.openide.util.lookup.ServiceProvider;

@ServiceProvider(service = SearchProvider.class)
public class ExampleSearchProvider1 extends SearchProvider {

    @Override
    public Presenter createPresenter(boolean replaceMode) {
        return new ExampleSearchPresenter(this);
    }

    @Override
    public boolean isReplaceSupported() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    @Override
    public String getTitle() {
        return "Demo Extension 1";
    }
    
    public class ExampleSearchPresenter extends SearchProvider.Presenter {

        private ExampleSearchPresenter(ExampleSearchProvider1 sp) {
            super(sp, true);
        }
        
        @Override
        public JComponent getForm() {
            return new JLabel("Hello World");
        }

        @Override
        public SearchComposition composeSearch() {
            return null;
        }

        @Override
        public boolean isUsable(NotificationLineSupport nls) {
            return true;
        }

    }

}

That's it, not much code, works fine in NetBeans IDE 7.2 Beta, and is easier to digest than the big chunk from yesterday. If you make three classes like the above in a NetBeans module, and you install it, you'll have three new tabs in the "Find in Projects" dialog. The only required dependencies are Dialogs API, Lookup API, and Search in Projects API. Read the javadoc linked above and then in next blog entries we'll continue to build out something like the sample you saw in yesterday's blog entry.

Comments:

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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today