Eclipse自然特定项目属性 [英] Eclipse Nature-specific Project Properties

查看:137
本文介绍了Eclipse自然特定项目属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有自定义项目性质的Eclipse插件。自然本身工作正常。我需要实现项目特定的属性页面,允许用户自定义特定于这种属性的设置;到目前为止,我一直没有成功,并且会提供任何帮助。我设想这是类似于Java性质允许一个人设置项目特定的编译器选项,格式化程序设置等。



项目设置存储至关重要在项目本身中,类似于Java设置如何存储在(project root)/。settings / org.eclipse.jdt。*。prefs 中。这些需要在该项目的源代码控制中,所以整个团队都遵守相同的标准。



这是我到目前为止在plugin.xml中的: / p>

 < extension point =org.eclipse.ui.propertyPages> 
< page id =test.MyOverlayPage
name =%Key.PropertyPage
class =test.MyOverlayPage>
< enabledWhen>
< instanceof value =org.eclipse.core.resources.IProject/>
< / enabledWhen>
< / page>
< / extension>

这显然不会以Java设置的方式限制属性页,但是目前这个没有出现任何项目,更不用说具有自定义性质的项目。



我发现以下问题没有解决我的具体问题:



为项目资源库eclipse插件创建自己的属性页面





我还发现这个Eclipse帮助页面严重缺乏在细节方面,我根本就无法得到这样的工作:



http:// he lp.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresInt_properties.htm

解决方案

Java属性页面使用这个:

 < enabledWhen& ; 
< adapt type =org.eclipse.core.resources.IProject>
< test property =org.eclipse.core.resources.projectNature
value =org.eclipse.jdt.core.javanature/>
< / adapt>
< / enabledWhen>

这使用适应而不是 instanceof ,因为视图中的UI对象通常不是项目(或其他资源)的实例。相反,他们使用 IAdapterManager 将(适应)从UI类转换为工作空间模型类。



code> test 元素添加了项目性质的测试,这里是针对Java性质标识,但可以替换您的自然ID。



要保存项目中的偏好设置 .settings 使用如下方式:

  IProject project = ...从选择或某事获取项目

IScopeContext context = new ProjectScope(project);

首选项projectPreferences = context.getNode(your nature id);

projectPreferences.put(key,value);

projectPreferences.flush();


I am working on an Eclipse plugin with a custom project nature. The nature itself works fine. I need to implement a project-specific properties page that allows the user to customize settings specific to that nature; thus far, I have been unsuccessful and would apppreciate any help. I envision this to be similar to how the Java nature allows one to set project-specific compiler options, formatter settings, etc.

It is crucial that the project settings are stored in the project itself, similar to how Java settings are stored in (project root)/.settings/org.eclipse.jdt.*.prefs. These need to be in source control for that project so the whole team is beholden to the same standards.

Here is what I have so far in the plugin.xml:

  <extension point="org.eclipse.ui.propertyPages">
    <page id="test.MyOverlayPage"
          name="%Key.PropertyPage"
          class="test.MyOverlayPage">
      <enabledWhen>
        <instanceof value="org.eclipse.core.resources.IProject"/>
      </enabledWhen>
    </page>
  </extension>

This obviously does not restrict the property page by nature the way the Java settings are, but currently this does not show up for any project, let alone ones with the custom nature.

I found the following questions which do not address my specific concern:

Create our own property page for project explorer eclipse plugin

Eclipse: Storing info in .project file

I also found this Eclipse help page which is severely lacking in details and I have not been able to get this working based on it:

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresInt_properties.htm

解决方案

The Java property pages use this:

<enabledWhen>
    <adapt type="org.eclipse.core.resources.IProject">
        <test property="org.eclipse.core.resources.projectNature" 
              value="org.eclipse.jdt.core.javanature"/>
    </adapt>         
</enabledWhen>

This uses adapt instead of instanceof because UI objects in a view are often not instances of projects (or other resources). Instead they use the IAdapterManager to convert (adapt) from the UI class to the workspace model class.

The test element adds a test on the project nature, here it is for the Java nature id but you can substitute your nature id.

To save preferences in the project .settings use something like:

IProject project =  ... get project from selection or something

IScopeContext context = new ProjectScope(project);

Preferences projectPreferences = context.getNode("your nature id");

projectPreferences.put(key, value);

projectPreferences.flush();

这篇关于Eclipse自然特定项目属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆