Programming eclipse plugin for searching file within a project (basic help needed)

I have to program an Eclipse-Plugin but I have never done this before so I have some questions. The plugin should appear in the context menu when you right click a Java project in the project explorer of Eclipse. It should open a dialog where the user can enter a file name he is looking for within the selected project and then the file gets highlighted (if there is a file with this name). What I managed to do so far is to setup the plugin development project, the extension point for the plugin and the dialog. But now I don't know how to get access to the selected project. Can you tell me how this is done or a link to the corresponding API? Thanks in advance :)


I assume you have a Handler class for the right-click action in your plugin. The Handler extends the AbstractHandler and overrides the method execute(..).

Then you can do something like this:

public class YourHandler extends AbstractHandler {

private ExecutionEvent event;

public Object execute(ExecutionEvent event) throws ExecutionException {

    // First get the tree of the right-clicked project.
    ISelection sel = HandlerUtil.getActiveMenuSelection(event);

    IResource resource = null;
    IProject project = null;

    try {
        IStructuredSelection selection = (IStructuredSelection) sel;

        // Get the first element of the tree (return type Object).
        Object firstElement = selection.getFirstElement();

        // Get the IResource and from this the IProject of the selection.
        if (firstElement instanceof IAdaptable) {
            IResource resource = (IResource) (((IAdaptable) firstElement)

            project = res.getProject();
    } catch (ClassCastException e) {
        // Do nothing.

    // Then you can do something with the project.

    return project;

Look also at the Eclipse API for IProject for what you can do:

For example getting a file from name:

IFile getFile(String name)

Returns a handle to the file with the given name in this project.

Hope this helps.

By the way: if you need some nice tutorials about developing Eclipse plugins, I can recommend this website


Need Your Help

Durandal Weyland optimizations doesn't handle the require function

javascript requirejs durandal durandal-2.0 weyland

I've found out that weyland optimizer replaces the paths in the javascript files with their real values. But it doesn't replace the paths used in middle of the code using require function.

Differences between NSTableView and NSCollectionView

cocoa cocoa-bindings nstableview nscollectionview

I'm trying to decide which path to take for developing my Snow Leopard app. First, I should preface with the obvious differences: