Eclipse Action学习 3

filter元素是用来指定当前的contribution是否可用, 它的用法跟visibility中的objectState类似, 比如只有选择的对象为只写才可用, 那么可以这样写:

xml 代码

<objectContribution ...>  

   <filter name="readOnly" value="false"/>  

   ... the other stuff here ...   

objectContribution>  

objectState 一样,filter使用的进行测试的对象必须实现IActionFilter接口或者能适配为IActionFilter, 然后调用testAttribute()方法来跟指定的name/value进行比对, 对于Resource来说, 它提供了下列属性让我们来进行比对
name,
表示对文件名进行比对, 可使用*这种正则表达式
extension
表示后缀名比对
path
路径比对, 可使用*
readOnly
只读比对

projectNature
nature比对
persistentProperty
对选择的资源的持久属性进行比对, 如果他的值只是一个字符串,那么就对该资源已有的属性值拿出来进行比对, 如果是propertyName=propertyValue这种形式,那么先根据name从选择的对象中取出值,然后再跟指定的value进行比对
projectPersistentProperty
对选中对象所在工程的持久性属性进行比对
sessionProperty
对对象中对的session属性进行比对
projectSessionProperty
选中对象所在工程的session属性进行比对

selection 元素主要针对contribution中某个action是否可见来进行判断,比如说下面这样写:

xml 代码

<objectContribution  

      objectClass="java.lang.Object"  

      id="com.qualityeclipse.favorites.popupMenu">  

   <action  

         label="Add to Favorites"  

         tooltip="Add the selected resource(s) to the   

                  Favorites view"   

         class="com.qualityeclipse.favorites.actions.   

                AddToFavoritesActionDelegate"   

         menubarPath="additions"  

         enablesFor="+"  

         id="com.qualityeclipse.favorites.addToFavorites">  

      <selection  

            class="org.eclipse.core.resources.IResource"  

            name="*.java"/>  

   action>  

objectContribution>  

这里的意思是com.qualityeclipse.favorites.popupMenu下的action在任何情况下都是可见的,只有Add to Favorites只有在选中的对象实现了IResource接口且文件名后缀为java才可见

enablement元素 也是针对单个action, 它集selectionvisibility两个元素的强大于一身,举个例子就明白了:

 

xml 代码

 

<objectContribution  

      objectClass="java.lang.Object"  

      id="com.qualityeclipse.favorites.popupMenu">  

   <action  

         label="Add to Favorites"  

         tooltip="Add the selected resource(s)   

                  to the Favorites view"   

         class="com.qualityeclipse.favorites.actions.   

                AddToFavoritesActionDelegate"   

         menubarPath="additions"  

         enablesFor="+"  

         id="com.qualityeclipse.favorites.addToFavorites">  

      <enablement>  

         <and>  

            <objectClass  

               name="org.eclipse.core.resources.IResource"/>  

             <objectState name="name" value="*.java"/>  

         and>  

      enablement>  

   action>  

objectContribution>  

根据文件内容关联contribution
比如一般我们的Run Ant...菜单项是跟build.xml文件关联的, 如果要跟export.xml也关联, 那么我们就需要通过对xmlDTD声明进行判断是否可以关联, 为了处理这种情况org.eclipse.ant.core 定义了一种叫antBuildFile content type:

xml 代码

<extension point="org.eclipse.core.runtime.contentTypes">  

   <content-type  

      id="antBuildFile"  

      name="%antBuildFileContentType.name"  

      base-type="org.eclipse.core.runtime.xml"  

      file-names="build.xml"  

      file-extensions="macrodef,ent,xml"  

      priority="normal">  

      <describer  

         class="org.eclipse.ant.internal.core.   

            contentDescriber.AntBuildfileContentDescriber">  

      describer>  

   content-type>  

extension>  

AntBuildfileContentDescriber 类中将判断xml文件是否是ant内容, 接下来我们就可以通过使用antBuildFile来指定contibution是否可用.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值