I have an Eclipse editor that modifies multiple files. When there is an error in any one of these files, I want it to open MyEditor instead of the standard text editor that it might otherwise open.
I forced the marker to open MyEditor by setting the marker attribute:
marker.setAttribute(IDE.EDITOR_ID_ATTR, "com.example.xyz.MyEditorID");
Now, within MyEditor.setInput()
, I have the following code to switch the input from the incoming file to the main file:
protected void setInput(final IEditorInput input) {
FileEditorInput fileEditorInput = (FileEditorInput) input;
final IFile file = (IFile) input.getAdapter(IFile.class);
if( file.getName().endsWith(mySuffix) ) {
// this is a coded values type file. It needs to be opened with the default profile
fileEditorInput = new FileEditorInput(theCorrectFileName);
}
...
super.setInput(fileEditorInput);
...
}
I changed the Editor's equals method to return true if the inputs are equal
public boolean equals(final Object obj) {
if(obj == null) {
return false;
}
if(this == obj) {
return true;
}
if( !getClass().isInstance(obj) ) {
return false;
}
final MyEdior otherEditor = (MyEditor) obj;
return getEditorInput().equals( otherEditor.getEditorInput() );
}
But when I click on my error marker, it still opens up a new editor every time. What am I doing wrong?
The
equals
method is not used to match the editor to the editor input. Instead you need to use anIEditorMatchingStrategy
class to match your editor to the input.You specify this class on your
org.eclipse.ui.editors
extension point using thematchingStrategy
attribute.For example, this is the Manifest.mf / plugin.xml / build.properties editor:
The matching strategy just has the one method to match a editor reference to the input:
All this is intended for editors (such as the Manifest.mf editor) which edit several files at once, but I think you may be able to use it.