- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Eclipse 插件开发,用velocity生成文件
在Eclipse 里用velocity模板来生成文件,原来这么简单.
IFile file = root.getFile(new Path(path.getTarget()));
path.setEncoding(file.getCharset());
monitor.setTaskName(file.getProjectRelativePath().toOSString());
if (file.exists())
{
}
ByteArrayOutputStream bos = CodeGenActivator.getDefault()
.getTemplateStream(selectInfo, path, mtables, this.mpage.getModuleDir());
{
byte[] data = bos.toByteArray();
// 这里应该有一个选项,是不是要覆盖掉原来的旧文件.
if (file.exists())
{
file.setContents(new ByteArrayInputStream(data), true, true, monitor);
} else
{
// 生成新文件.
recursiveCreateFileTree(file.getParent(), file.getParent(), monitor);
file.create(new ByteArrayInputStream(data), 1, monitor);
}
}
bos.close();
// report that 1 additional units are done
monitor.worked(1);
引入org.eclipse.core.resources插件工程
String filePaht =abx.xml
IFile firstFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromOSString(filePaht ));
IFile secondFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromPortableString(filePaht ));
这样是在Eclipse 工程里 创建了一个文件了.
注意的是,这里文件生成,要产生一个任务
还可以用JOB的方式.
Job job = new Job(My Job) {
@Override
protected IStatus run(IProgressMonitor monitor) {
// set total number of work units
monitor.beginTask(Doing something time consuming here, 100);
for (int i = 0; i 5; i++) {
try {
// sleep a second
TimeUnit.SECONDS.sleep(1);
monitor.subTask(Im doing something here + i);
// report that 20 additional units are done
monitor.worked(20);
} catch (InterruptedException e1) {
e1.printStackTrace();
return Status.CANCEL_STATUS;
}
}
System.out.println(Called save);
return Status.OK_STATUS;
}
};
job.schedule();
这样应该效率更好.不过 好象用在一般的小插件的代码里有些浪费了.
目前国人的插件水平,好象还不至于到使用线程,JOB这样的地步吧..
file.setContents(new ByteArrayInputStream(data), true, true, monitor);
file.create(new ByteArrayInputStream(data), 1,
您可能关注的文档
最近下载
- 润湿性对提高采收率的影响.ppt VIP
- 管道代号对照.doc VIP
- 离合器接合叉加工工序卡片技术报告.doc VIP
- 部编版六年级语文上册一二单元测试卷.docx VIP
- 语文部编版2024七年级初一上册第1单元测试卷 含答案.pdf VIP
- 人教版小学一年级道德与法治上册教案 全册.pdf VIP
- 基桩单桩自平衡静载荷试验试运行检测报告.doc VIP
- 良性前列腺增生诊断治疗指南(中国泌尿外科和男科疾病诊断治疗指南2022版).pdf VIP
- 2024新信息科技七年级《第三单元 便捷的互联网服务》大单元整体教学设计[2022课标].docx
- 《公路工程质量检验评定标准》JTGF801.pdf VIP
文档评论(0)