偷香 小说下载:从插件/RCP中取得文件路径的方法 中国Eclipse社区
来源:百度文库 编辑:中财网 时间:2024/05/11 02:29:56
从插件/RCP中取得文件路径的方法
作者:hopeshared
引用地址:http://www.blogjava.net/hopeshared/archive/2005/12/20/24798.html
最近社区里问这个问题的人特别多,所以在这里将自己用到的几个方法写出来。假如以后还有其他的方法,会进行更新。
从插件中获得绝对路径:
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();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
得到项目的绝对路径:
FileLocator.toFileURL(
Platform.getBundle(Application.PLUGIN_ID).getEntry(""))
.getPath()
///////////////////////////////////////////////////////////////////////////////////////////////////////////
从插件中获得绝对路径:
AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());
getStateLocation() 报错NullPointerException!
///////////////////////////////////////////////////////////////////////////////////////////////////////////
Location installLoc = LocationManager.getInstallLocation();
String path = null;
String installPath = null;
if (installLoc != null)
{
URL installURL = installLoc.getURL();
// assume install URL is file: based
path = installURL.getPath();
}
installPath = path.substring(1, path.length());
这个方法不错,我花了一个下午看源代码找到的。
如果你的RCP工程没有发布,得到的是eclipse的路径。如果你的RCP工程已经发布(假如在D:\RCP\下面),得到的路径就是D:/RCP/。
大家可以试试看 。
///////////////////////////////////////////////////////////////////////////////////////////////////////////
请问IEditorPart editor =((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();这一句里面的parent是什么?我直接用下面的代码取代parent.getViewer().getEditDomain()这一句可不可以?
IWorkbenchPage workbenchPage = VecasCompile.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = workbenchPage.getActiveEditor();
作者:hopeshared
引用地址:http://www.blogjava.net/hopeshared/archive/2005/12/20/24798.html
最近社区里问这个问题的人特别多,所以在这里将自己用到的几个方法写出来。假如以后还有其他的方法,会进行更新。
从插件中获得绝对路径:
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();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
得到项目的绝对路径:
FileLocator.toFileURL(
Platform.getBundle(Application.PLUGIN_ID).getEntry(""))
.getPath()
///////////////////////////////////////////////////////////////////////////////////////////////////////////
从插件中获得绝对路径:
AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());
getStateLocation() 报错NullPointerException!
///////////////////////////////////////////////////////////////////////////////////////////////////////////
Location installLoc = LocationManager.getInstallLocation();
String path = null;
String installPath = null;
if (installLoc != null)
{
URL installURL = installLoc.getURL();
// assume install URL is file: based
path = installURL.getPath();
}
installPath = path.substring(1, path.length());
这个方法不错,我花了一个下午看源代码找到的。
如果你的RCP工程没有发布,得到的是eclipse的路径。如果你的RCP工程已经发布(假如在D:\RCP\下面),得到的路径就是D:/RCP/。
大家可以试试看 。
///////////////////////////////////////////////////////////////////////////////////////////////////////////
请问IEditorPart editor =((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();这一句里面的parent是什么?我直接用下面的代码取代parent.getViewer().getEditDomain()这一句可不可以?
IWorkbenchPage workbenchPage = VecasCompile.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = workbenchPage.getActiveEditor();
java类中如何取得文件路径
vb 中现存文件的生成时间取得方法
在WIN2K中,注册表文件的路径?
VFP中怎样获取文件的路径?
vc++从文本框取得数值(注意不是字符串)的方法
取得草木灰的方法?
从QQ硬盘下载的文件默认路径是?
delphi7 中数据库使用相对路径的方法
3DMax的插件装在什么路径下面,如何在3D中调用
怎样设置JCreator Pro中,默认的文件保存路径~~??
在MFC中如何获得打开文件的路径
vb中怎么调出保存文件的路径
boot.ini文件在2000中C盘的路径#@!#@#
boot.ini文件在2000中C盘的路径#@!#@#
VB中关于文件路径的问题,VB高手进
asp怎么得到新闻中上传的文件路径
AE中如何修改所使用的文件路径
这样的文件路径
jsp的文件路径?
请教:如何实现鼠标向窗口内拖入一个文件,程序获得文件路径的方法
中国近几年来取得的成就
火影忍者3 中物品取得方法
最快的方法取得会计证
仙三中琥珀的取得方法?