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

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

问题描述

我正在开发一个具有自定义项目性质的 Eclipse 插件.自然本身运作良好.我需要实现一个特定于项目的属性页面,该页面允许用户自定义特定于该性质的设置;到目前为止,我一直没有成功,并会感谢任何帮助.我设想这类似于 Java 的特性允许设置特定于项目的编译器选项、格式化程序设置等.

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.

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

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.

这是我目前在 plugin.xml 中的内容:

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>

这显然不会像 Java 设置那样从本质上限制属性页,但目前这不会出现在任何项目中,更不用说具有自定义性质的项目了.

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:

为项目资源管理器eclipse创建我们自己的属性页插件

Eclipse:将信息存储在 .project 文件中

我还发现了这个 Eclipse 帮助页面,它严重缺乏细节,我无法根据它来完成这项工作:

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

推荐答案

Java 属性页使用这个:

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>

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

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.

test 元素添加了对项目性质的测试,这里用于 Java 性质 id,但您可以替换您的性质 id.

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.

要在项目 .settings 中保存首选项,请使用以下内容:

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天全站免登陆