为eidtor在ProjectExplorer中支持'Link with editor' 功能,需要在plug.xml中扩展 'org.eclipse.ui.navigator.linkHelper' 和 'org.eclipse.ui.navigator.viewer'
<extension point="org.eclipse.ui.navigator.linkHelper"> <linkHelper class="org.myym.MyLinkHelper" id="org.myym.mylinkhelper"> <editorInputEnablement></editorInputEnablement> <selectionEnablement> <instanceof value="org.eclipse.core.resources.IFile"> </instanceof> </selectionEnablement> </linkHelper> </extension> <extension point="org.eclipse.ui.navigator.viewer"> <viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer"> <includes> <contentExtension pattern="org.myym.mylinkhelper"> </contentExtension> </includes> </viewerContentBinding> </extension>
MyLinkHelper.java
/**
* Link Helper for editors.
*/
public class MyLinkHelper implements ILinkHelper {
/**
* Default Constructor.
*/
public MyLinkHelper() {
}
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
}
public IStructuredSelection findSelection(IEditorInput anInput) {
if (anInput instanceof MyClass) //check the IEditorInput whether are interested
IFile file = getFile(MyClass); //create method 'getFile' to get the IFile refer to this input
if (file != null) {
return new StructuredSelection(file);
}
}
return StructuredSelection.EMPTY;
}
}