小哈兒的 學習日記

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

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

          Posted on 2007-05-24 18:07 dayue 閱讀(356) 評論(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();
             }
          主站蜘蛛池模板: 康马县| 沁阳市| 秦安县| 汉寿县| 枣阳市| 公主岭市| 兴安盟| 鲜城| 章丘市| 牟定县| 大兴区| 田东县| 内丘县| 当阳市| 贞丰县| 阳信县| 弥渡县| 大英县| 丰宁| 门头沟区| 宣武区| 即墨市| 万荣县| 陕西省| 安多县| 华池县| 泾阳县| 厦门市| 精河县| 辉县市| 通河县| 九寨沟县| 紫金县| 高邑县| 福贡县| 兴隆县| 滁州市| 遂溪县| 井研县| 屯门区| 来安县|