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是否可用.
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是否可用.
相关文章推荐
- Eclipse Action学习 2
- EclipseAction深入学习笔记
- ActionBar-PullToRefresh 学习之导入到Eclipse
- struts1源码学习7,action处理核心ComposableRequestProcessor
- python学习之--安装IDE(eclipse+pydev)
- 系统学习Spring之Spring in action
- CentOS学习15_CentOS6.5虚拟机中,Eclipse频繁闪退问题的解决
- JAVA学习提高之----如何用Eclipse和Tomcat Plugin来建立一个开发环境(个人实践)
- Struts学习 错误:exception: cannot find actionmappings or actionformbeans collection
- Maven学习 (二) Eclipse 上安装 Maven3插件
- ActionBar基础学习之头部返回菜单
- eclipse 导入项目 app:showAsAction 错误 三方jar位置错误
- Eclipse xFire webService学习笔记
- eclipse插件开发学习的一些资源
- hadoop学习笔记2:eclipse开发MapReduce
- XML From Action Script[AS中的XML学习笔记]
- Spark学习笔记(23)Transformation、Action等源码图解
- Android NDK学习--编译和调试(Ubuntu+Eclipse+NDK)
- Unable to load configuration. - action 解决方案(struts 2 学习笔记)
- git学习五:eclipse使用git下载项目