您的位置:首页 > 编程语言 > Java开发

Eclipse Action学习 3

2014-02-12 00:00 162 查看
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的, 它集selection和visibility两个元素的强大于一身,举个例子就明白了:

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也关联, 那么我们就需要通过对xml的DTD声明进行判断是否可以关联, 为了处理这种情况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是否可用.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息