小哈兒的 學習日記

          像瘋子一樣去戰斗!
          posts - 13, comments - 0, trackbacks - 0, articles - 0

          [轉]eclipse插件中取得路徑的方法

          Posted on 2007-05-24 18:07 dayue 閱讀(355) 評論(0)  編輯  收藏 所屬分類: eclipse
          從插件中獲得絕對路徑:
                  
          TestPlugin.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();
             }
          主站蜘蛛池模板: 和龙市| 申扎县| 敖汉旗| 泗阳县| 钟祥市| 呼伦贝尔市| 巴楚县| 宜章县| 邢台县| 嘉定区| 稻城县| 拉萨市| 霸州市| 阜宁县| 河南省| 江门市| 通山县| 巫山县| 新密市| 西乌珠穆沁旗| 七台河市| 长子县| 姚安县| 当阳市| 桐乡市| 庆阳市| 南丰县| 疏附县| 巨野县| 祁连县| 新建县| 年辖:市辖区| 康马县| 金寨县| 永顺县| 新营市| 藁城市| 松原市| 厦门市| 枞阳县| 邹平县|