org.eclipse.ui.navigator.linkHelper的使用

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操作.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值