http://www.24xuexi.com/w/2011-06-08/91464.html
org.eclipse.ui.navigator.linkHelper扩展点的本意是用来在Editor和Navigator之间互相选中的支持。
勇哥问了我这个扩展点的使用,结果我也不会用。最后勇哥找出来了为啥不能用。因为还需要定义viewContentBinding。
跟踪代码,查到了这部分源码:
在org.eclipse.ui.internal.navigator.extensions.Binding类中有三个变量:
private final Set includePatterns = new HashSet();
private final Set excludePatterns = new HashSet();
private final Map knownIds = new HashMap();
其中knowIds用来在存储所有org.eclipse.ui.navigator.linkHelper扩展的id;includePatterns 用于存储当前Navigator中包含的linkHelper的支持;excludePatterns包含所有当前Navigator不支持的linkHelper。
缺省情况下,是不支持的。所以如果我们只是简单的声明了一下linkHelper的扩展,如下:
<extension point="org.eclipse.ui.navigator.linkHelper">
<linkHelper class="org.eclipse.ui.internal.navigator.resources.workbench.ResourceLinkHelper"id="org.eclipse.ui.navigator.resources.linkHelper">
<selectionEnablement>
<instanceof value="org.eclipse.core.resources.IFile"/>
</selectionEnablement>
<editorInputEnablement>
<instanceof value="org.eclipse.ui.IFileEditorInput"/>
</editorInputEnablement>
</linkHelper>
</extension>
由于不知道它要用在哪个Navigator上,所以是不被任何一个Navigator支持的。也就是点"Link Editor"那个按钮没反应。
如果需要把它用在ResourceNavigator上,那需要再定义如下 :
<extension point="org.eclipse.ui.navigator.viewer">
<viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer">
<includes>
<contentExtension pattern="org.eclipse.ui.navigator.resources.linkHelper">
</contentExtension>
<actionExtension pattern="org.eclipse.ui.navigator.resources.linkHelper">
</actionExtension>
</includes>
</viewerContentBinding>
</extension>
这样一来,当处在ResourceNavigator时,并且"link Editor"按钮可用时,linkHelper的实现类就会被调到:
public void activateEditor(IWorkbenchPage aPage,IStructuredSelection aSelection) {}
public IStructuredSelection findSelection(IEditorInput anInput) {return null;}
这两个方法的逻辑需要自己实现,以完成link操作.