如何在 Eclipse 属性页上包含 Xtext 生成的编辑器?

发布于 2024-12-01 14:38:34 字数 2026 浏览 4 评论 0原文

我试图在 Eclipse RCP 应用程序的属性页上包含一个 DSL 的文本编辑器,它是我使用 Xtext 生成的。

例如,我从一个简单的 Xtext 语法开始:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
    greetings+=Greeting*;

Greeting:
    'Hello' name=ID '!';

并从中生成文本编辑器。然后,我在一个新的插件项目中创建一个属性页:

package com.example.plugin.propertypage.properties;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.dialogs.PropertyPage;

public class SamplePropertyPage extends PropertyPage {

    public SamplePropertyPage() {
        super();
    }

    protected Control createContents(Composite parent) {
        Composite composite = new Composite(parent, SWT.NONE);
        return composite;
    }

    protected void performDefaults() {
        super.performDefaults();
    }

    public boolean performOk() {
        return true;
    }

}

对于 org.eclipse.core.resources.IFile 的每个实例,(空)属性页将显示在属性对话框中:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         point="org.eclipse.ui.propertyPages">
      <page
            name="Sample Page"
            nameFilter="*.*"
            class="com.example.plugin.propertypage.properties.SamplePropertyPage"
            id="com.example.plugin.propertypage.properties.samplePropertyPage">
         <enabledWhen>
            <instanceof
                  value="org.eclipse.core.resources.IFile">
            </instanceof>
         </enabledWhen>
      </page>
   </extension>

</plugin>

如何使生成的编辑器出现在属性页上?

在我的研究过程中,我查看了 Xtext GMF 集成示例,该示例随 Xtext 和 Xtext 用户指南中引用。此示例演示如何创建弹出 Xtext 编辑器。这个例子可能包含一些有价值的信息,但我无法弄清楚如何适应我的目的。

任何帮助将不胜感激。谢谢。

I'm trying to include a textual editor for my DSL, which I generated using Xtext, on a property page within an Eclipse RCP application.

For example, I start with a simple Xtext grammar:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
    greetings+=Greeting*;

Greeting:
    'Hello' name=ID '!';

and generate the textual editor from it. Then, I create a property page wihtin a new plug-in project:

package com.example.plugin.propertypage.properties;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.dialogs.PropertyPage;

public class SamplePropertyPage extends PropertyPage {

    public SamplePropertyPage() {
        super();
    }

    protected Control createContents(Composite parent) {
        Composite composite = new Composite(parent, SWT.NONE);
        return composite;
    }

    protected void performDefaults() {
        super.performDefaults();
    }

    public boolean performOk() {
        return true;
    }

}

The (empty) property page will be shown in the properties dialog for every instance of org.eclipse.core.resources.IFile:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         point="org.eclipse.ui.propertyPages">
      <page
            name="Sample Page"
            nameFilter="*.*"
            class="com.example.plugin.propertypage.properties.SamplePropertyPage"
            id="com.example.plugin.propertypage.properties.samplePropertyPage">
         <enabledWhen>
            <instanceof
                  value="org.eclipse.core.resources.IFile">
            </instanceof>
         </enabledWhen>
      </page>
   </extension>

</plugin>

How can I make the generated editor appear on the property page?

During my research, I had a look at the Xtext GMF Integration Example which is shipped with Xtext and referenced in the Xtext User Guide. This example shows how to create a popup Xtext editor. This example may contain some valuable information, but I was not able to figure out how to adapt this for my purposes.

Any help would be appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文