小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

從插件/RCP中取得文件路徑的方法 中國Eclipse社區(qū)

 jinzq 2007-01-18
從插件/RCP中取得文件路徑的方法

作者:hopeshared
引用地址:http://www./hopeshared/archive/2005/12/20/24798.html

最近社區(qū)里問這個(gè)問題的人特別多,所以在這里將自己用到的幾個(gè)方法寫出來。假如以后還有其他的方法,會(huì)進(jìn)行更新。

從插件中獲得絕對路徑:
    AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());


通過文件得到Project:

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


通過文件得到全路徑:

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



得到整個(gè)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();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
得到項(xiàng)目的絕對路徑:

FileLocator.toFileURL(
               Platform.getBundle(Application.PLUGIN_ID).getEntry(""))
               .getPath()

///////////////////////////////////////////////////////////////////////////////////////////////////////////
從插件中獲得絕對路徑:
  AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());

getStateLocation() 報(bào)錯(cuò)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());
這個(gè)方法不錯(cuò),我花了一個(gè)下午看源代碼找到的。
如果你的RCP工程沒有發(fā)布,得到的是eclipse的路徑。如果你的RCP工程已經(jīng)發(fā)布(假如在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();

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多