小哈兒的 學習日記

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

          2007年5月24日

              今天調試一個bug,迷惑了很久。最后發現是關于首選項取值存值問題。
             這里ps為IPreferenceStore對象.

             ps.getString(XXX_KEY)是首選查找首選項 ,如果取出的值為空,如果有default值的話則執行ps.getDefault(XXX_KEY)。

             ps.setValue(XXX_KEY, "XXX")時首先和default中的XXX_KEY比較,如果不同的話才put進去,否則就刪除。這也是我今天這個bug的原因。修改辦法是用putValue函數來代替setValue.

          有什么說的不對的地方歡迎批評指正.

          posted @ 2007-08-28 22:17 dayue 閱讀(1118) | 評論 (0)編輯 收藏

          從插件中獲得絕對路徑:
                  
          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();
             }

          posted @ 2007-05-24 18:07 dayue 閱讀(355) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 河间市| 黄石市| 珠海市| 安顺市| 双牌县| 凤台县| 桃源县| 河南省| 永靖县| 永昌县| 任丘市| 鄱阳县| 泌阳县| 浠水县| 巴里| 云安县| 夹江县| 潼关县| 贵州省| 乌恰县| 永靖县| 沾益县| 利川市| 杭州市| 称多县| 加查县| 滨州市| 宜丰县| 屏边| 江安县| 阿城市| 通海县| 嘉定区| 怀集县| 新晃| 望江县| 兴宁市| 新龙县| 宁蒗| 黔西| 青龙|