Markus
Markus

Reputation: 1482

Eclispe RCP: Is there an extension point that notifies me that an editor is opened?

When opening an editor in my Eclipse RCP I may want to close it again based on the content of the editor.

Where is the best spot for closing an editor that has just been opened? Is there some kind of extension point available for this or is there a way to avoid opening the editor at all?

The editor itself is added via the extension point org.eclipse.ui.editors.

I tried to hook myself in the connect method of the editor but I didn't manage to avoid the opening of the editor.

Solution: Thanks greg for pointing me into the right direction!

My Editor implements IPartListener now and the implementation works like that:

@Override
public void partOpened(IWorkbenchPart part) {
    if (part instanceof MyEditor) {
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(this, false);
    }
}

This will close the editor after opening it.

Upvotes: 1

Views: 54

Answers (1)

greg-449
greg-449

Reputation: 111216

You can use IPartListener to listen for all parts opening, closing and being activated.

IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

window.getPartService().addPartListener(partListener);

Upvotes: 1

Related Questions