Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4464795
  • 博文数量: 192
  • 博客积分: 10014
  • 博客等级: 上将
  • 技术积分: 8232
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-21 00:22
文章分类

全部博文(192)

文章存档

2011年(4)

2009年(14)

2008年(174)

我的朋友

分类: Java

2008-09-24 10:36:08

 
最近里问这个问题的人特别多,所以在这里将自己用到的几个方法写出来。假如以后还有其他的方法,会进行更新。

从插件中获得绝对路径:
       
AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());



通过文件得到Project:

IProject project = ((IFile)o).getProject();



通过文件得到全路径:

String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath();



得到整个Workspace的根:

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();



从根来查找资源:

IResource resource = root.findMember(new Path(containerName));


从Bundle来查找资源:

Bundle bundle = Platform.getBundle(pluginId);
URL fullPathString 
= BundleUtility.find(bundle, filePath);



得到Appliaction workspace:

Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath();


得到runtimeworkspace:
 
Platform.getInstanceLocation().getURL().getPath();


从编辑器来获得编辑文件
IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();
IEditorInput input 
= editor.getEditorInput();
if(input instanceof IFileEditorInput){
  IFile file 
= ((IFileEditorInput)input).getFile();
}
阅读(2167) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~