[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.jdt] Re: Current ActivePage.findEditor(IEditorInput input) triggered SafeRunner

Nitin Dahyabhai wrote:
Jing Xie wrote:
Here's my code to find the current editor for the file:
IEditorPart editor = MyPlugin.getActiveWorkbenchWindow().getActivePage().findEditor(new FileEditorInput(file));


When the file is open in an editor which is activated and focused, it will return the IEditorPart. But if the file is open in an editor while the editor is not activated in the current active page, it will trigger the SafeRunner class.

I need to get the IEditorPart even if the open editor is not activated as long as the file is open in it. Can some one point me the way to work around this?

What's wrong with triggering the SafeRunner class?

You could instead get the IEditorReferences of that page and check their editor inputs yourself.

Hi Nitin,

Thanks for your reply.

Once the SafeRunner class is triggered, the program stops right there and nothing goes further.

I tried using IEditorReferences instead as you suggested and here's the code:
public static IEditorPart findEditorForFile(IFile file)
throws PartInitException {
IEditorPart editor = null;
IEditorReference[] references = InputValidationPlugin
.getActiveWorkbenchWindow().getActivePage()
.getEditorReferences();
for (int i = 0; i < references.length; i++) {
IEditorReference reference = references[i];
if (reference.getEditorInput().equals(new FileEditorInput(file))) {
editor = reference.getEditor(true);
}
}
return editor;
}


This time, when the getEditor() was invoked, the program choked there and there was never an object of IEditorPart returned.

Any other ways I can try to possibly work around this?

Thanks,
Jing