Search code examples
eclipseeclipse-plugineclipse-rcp

Eclipse: File matching strategy being called on single click of any view


I wrote my custom File matching strategy by implementing IEditorMatchingStrategy as follows:

public class FileMatchingStrategy implements IEditorMatchingStrategy {

@Override
public boolean matches(IEditorReference editorRef, IEditorInput input) {
    if (!(input instanceof IFileEditorInput))
        return false;
    if (null == input || null == editorRef) {
        return false;
    }

    IFile file = input.getAdapter(IFile.class);
    IPath rawFilePath = file == null ? null : file.getRawLocation();
    if (null == rawFilePath) {
        return false;
    }
    if("File.java".equals(rawFilePath.toOSString())){
        MessageDialog.openError(Display.getDefault().getActiveShell(),
            "Header", "Message");
        return true;
    }

    return false;
} }

Now whenever any of the view (for e.g. problems view) is clicked, the file matching strategy is being called which causes the popup to show even if file is not opened by double click.

Is it possible to filter out single clicks and handle only double clicks/Open File from project explorer?


Solution

  • No, there is no way to do that.

    The IEditorMatchingStrategy is called whenever the IWorkbenchPage openEditor or findEditor methods are trying to find an editor matching the given editor input. There is no way stop this for particular calls.

    The primary use of IEditorMatchingStrategy is for editors which support editing multiple files at once (such as the PDE plugin.xml/MANIFEST.MF/build.properties editor).

    Eclipse does not expect IEditorMatchingStrategy to do any UI interactions.