小哈儿的 学习日记

像疯子一样去战斗!
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 阅读(1098) | 评论 (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 阅读(337) | 评论 (0)编辑 收藏