org.eclipse.ui.editors.templates扩展点
来源:互联网 发布:全球域名商排行榜 编辑:程序博客网 时间:2024/05/19 06:36
在plugin.xml中添加扩展点org.eclipse.ui.editors.templates
<!--模板--> <extension point="org.eclipse.ui.editors.templates"> <!--定义不同的上下文--> <contextType class="com.workflow.javascript.preferences.ExprTemplateContextType" id="com.workflow.javascript.preferences.ExprTemplateContextType" name="ExprTemplateContextType"> </contextType> <contextType class="com.workflow.javascript.preferences.SwtTemplateContextType" id="com.workflow.swt.statements" name="Swt-statements"> </contextType> <!--直接编写模板内容--> <template autoinsert="true" contextTypeId="com.workflow.javascript.preferences.ExprTemplateContextType" description="打印当前流程信息" id="com.workflow.javascript.template.printCurProcInfo" name="printCurProcInfo"> <pattern> var process = ProcessObj.getCurProc();java.lang.System.out.println("---------------curProcessid:"+process.getId()+" curProcessName:"+process.getName()+"-------------------------"); </pattern> </template> <!--通过include,将编辑好的模板引入--> <include file="templates/default-templates.xml" translations="$nl$/templates/default-templates.properties"> </include> <include file="templates/default-swttemplates.xml" translations="templates/default-templates.properties"> </include> </extension>创建模板上下文用于管理自己的模板参数
<pre name="code" class="html">SwtTemplateContextType类 参考 ExprTemplateContextType 实现
package com.workflow.javascript.preferences;import org.eclipse.jface.text.templates.GlobalTemplateVariables;import org.eclipse.jface.text.templates.TemplateContextType;/** * 模板上下文类型用于管理自己的模板参数 * @author lww * */public class ExprTemplateContextType extends TemplateContextType {public ExprTemplateContextType() {addGlobalResolvers();}/** * We add support for global variables */private void addGlobalResolvers() {addResolver(new GlobalTemplateVariables.Cursor());addResolver(new GlobalTemplateVariables.WordSelection());addResolver(new GlobalTemplateVariables.LineSelection());addResolver(new GlobalTemplateVariables.Dollar());addResolver(new GlobalTemplateVariables.Date());addResolver(new GlobalTemplateVariables.Year());addResolver(new GlobalTemplateVariables.Time());addResolver(new GlobalTemplateVariables.User());}}
在项目中创建文件夹templates里面存放模板文件相关的文件
default-swttemplates文件内容如下:
<?xml version="1.0" encoding="UTF-8"?><templates><template name="TreeColumn" description="%SWTTemplates.treecolumn" id="com.workflow.ui.text.codetemplates.swt.treecolumn" context="com.workflow.swt.statements" enabled="true" autoinsert="false">${type:newType(org.eclipse.swt.widgets.TreeColumn)} ${column:newName(org.eclipse.swt.widgets.TreeColumn)}= new ${type}(${parent:var(org.eclipse.swt.widgets.Tree)}, ${style:link(SWT.LEAD, SWT.CENTER, SWT.TRAIL)});${column}.setText(${word_selection}${});${imp:import(org.eclipse.swt.SWT)}${cursor}</template></templates>
注意:上面编写模板时,context的内容为plugin.xml中定义contextType的ID值。
WorkFlowActivator 类继承AbstractUIPlugin
在该类中
// template storeprivate TemplateStore store = null;// template context type registryprivate ContributionContextTypeRegistry registry = null;public final static String TEMPLATES_KEY = "MyDesigner.template";public static final String EXPR_CONTEXT_TYPE = "com.workflow.javascript.preferences.ExprTemplateContextType";public static final String SWT_CONTEXT_TYPE = "com.workflow.swt.statements";<pre name="code" class="java">/** * Return compute template store */public TemplateStore getTemplateStore() {if (store == null) {store = new ContributionTemplateStore(getContextTypeRegistry(),getDefault().getPreferenceStore(), TEMPLATES_KEY);try {store.load();} catch (IOException e) {getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "",e));}}return store;}/** * Return template context type registry */public ContextTypeRegistry getContextTypeRegistry() {if (registry == null) {// create an configure the contexts available in the template editorregistry = new ContributionContextTypeRegistry();registry.addContextType(EXPR_CONTEXT_TYPE);registry.addContextType(SWT_CONTEXT_TYPE);}return registry;}
ExprTemplatePreferencePage
package com.workflow.javascript.preferences;import mydesigner.WorkFlowActivator;import org.eclipse.ui.IWorkbenchPreferencePage;import org.eclipse.ui.texteditor.templates.TemplatePreferencePage;/** * 模板首选项页面 * @author lww * */public class ExprTemplatePreferencePage extends TemplatePreferencePage implements IWorkbenchPreferencePage {public ExprTemplatePreferencePage() {setPreferenceStore(WorkFlowActivator.getDefault().getPreferenceStore());setTemplateStore(WorkFlowActivator.getDefault().getTemplateStore());setContextTypeRegistry(WorkFlowActivator.getDefault().getContextTypeRegistry());}protected boolean isShowFormatterSetting() {return false;}public boolean performOk() {boolean ok = super.performOk();WorkFlowActivator.getDefault().savePluginPreferences();return ok;}}效果图:
0 0
- org.eclipse.ui.editors.templates扩展点
- org.eclipse.ui.editors插入点
- 扩展点:org.eclipse.ui.actionSets
- org.eclipse.ui.startup扩展点介绍
- org.eclipse.ui.startup扩展点介绍
- Eclipse editor extension point : org.eclipse.ui.editors
- Eclipse扩展点总结之org.eclipse.ui.exportWizards
- [Eclipse plug-in] org.eclipse.ui.perspectives扩展点
- org.eclipse.ui.editors 卡死 解决步骤
- 扩展点总结之org.eclipse.ui.newWizards
- 扩展点总结之org.eclipse.ui.perspectiveExtensions
- 扩展点总结之org.eclipse.ui.importWizards
- org.eclipse.ui.activities过滤不适用的扩展点
- Eclipse,打开后一直卡在“Loading org.eclipse.ui.editors”
- eclipse非正常关闭,再次启动界面一直停在Loading org.eclipse.ui.editors 的解决办法
- RCP中利用扩展点org.eclipse.ui.actionSets创建菜单和工具栏
- org.eclipse.ui.actionSets扩展点(zz自javaeye hoodman的博客)
- rcp(插件开发)org.eclipse.ui.propertyPages 扩展点使用
- 常用定义总结
- Oracle trunc()函数的详细使用介绍
- 两个会话上同时执行如下创建Procedure的脚本引发的library cache lock
- 查看so库的方法
- 尚硅谷Java基础学习笔记五
- org.eclipse.ui.editors.templates扩展点
- c# 正则表达式
- 定义结构体与类组合的区别和如何用它们
- 数学之美系列十八:矩阵运算和文本处理中的分类问题
- library cache pin和library cache lock
- magento获取当前路径
- Codeforces 445B. DZY Loves Chemistry
- 软解析和硬解析
- xcode APP 打包以及提交apple审核详细流程(新版本更新提交审核)