对话框中的Xtext DSL嵌入式编辑器 [英] Xtext DSL embedded editor in a dialog

查看:130
本文介绍了对话框中的Xtext DSL嵌入式编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是xtext的新手,我使用xtext创建了DSL,并且生成了工件,从而生成了具有许多功能(如内容辅助和语法着色)的编辑器,现在的问题是我想将编辑器嵌入其中一个对话框。


为了使用EmbeddedEditor实现此即时消息,我能够获得嵌入式编辑器并将其放置在对话框中,但是嵌入式编辑器未显示文件的内容。 / p>

文件C:/Eclipse_Work/workspace/runtime_workspace/apa/ex.mydsl包含:

  import com .ex.test; 
实体{
元素a;
}

对话框的createcontrol()中的代码为:


< pre class = lang-java prettyprint-override> IEditedResourceProvider resourceProvider = new IEditedResourceProvider(){

@Override
public XtextResource createResource(){
尝试{

资源resource = resourceSet.createResource(URI.createURI( C:/Eclipse_Work/workspace/runtime_workspace/apa/ex.mydsl)));
XtextResource resource2 =(XtextResource)资源;

返回(XtextResource)资源;
} catch(异常e){
返回null;
}
}
};

MyDslActivator激活器= MyDslActivator.getInstance();
注入器注入器=激活器
.getInjector(MyDslActivator.COM_APAMA_STUDIO_QUERY_EXT_MYDSL);

@ SuppressWarnings( restriction)
EmbeddedEditorFactory factory = jector.getInstance(EmbeddedEditorFactory.class);
EmbeddedEditor handle = factory.newEditor(resourceProvider).withParent(
Composite);

EmbeddedEditorModelAccess部分编辑器= handle.createPartialEditor();


handle.getViewer()。getControl()。setLayoutData(new GridData(GridData.FILL,GridData.FILL,true,true,2,0));

当我运行项目时,对话框打开并显示一个编辑器区域,但不显示ex.mydsl中存在的代码,


请告诉我如何在嵌入式编辑器中显示代码

解决方案

您必须将编辑器的初始内容指定为editablePart 参数javadoc / 2.4 / org / eclipse / xtext / ui / editor / embedded / EmbeddedEditor.html#createPartialEditor%28java.lang.String,%20java.lang.String,%20java.lang.String,%20boolean%29 rel = nofollow> createPartialEditor(字符串前缀,字符串editablePart,字符串后缀,布尔insertLineBreaks) 。要获取您的 XtextResource 的内容作为文本,请保存 ByteArrayOutputStream ,然后使用 toString将其转换为字符串。


I am new to xtext, and i have created a DSL using xtext and i have generated the artifacts, which has generated the editor which has many features like content assist and syntax coloring now the problem is i want to embed the editor inside a dialog.

For achieving this im using EmbeddedEditor, i am able to get the embedded editor and place it in the dialog, but the embedded editor is not displaying the contents of the file.

The file C:/Eclipse_Work/workspace/runtime_workspace/apa/ex.mydsl contains:

import com.ex.test;
entity{
 element a;
}

The code in the createcontrol() of dialog is :

    IEditedResourceProvider resourceProvider=new IEditedResourceProvider() {
        
        @Override
        public XtextResource createResource() {
            try {

                Resource resource = resourceSet.createResource(URI.createURI("C:/Eclipse_Work/workspace/runtime_workspace/apa/ex.mydsl"));
                XtextResource resource2=(XtextResource)resource;
                
                return (XtextResource) resource;
            } catch (Exception e) {
                return null;
            }
        }
    };
    
    MyDslActivator activator = MyDslActivator.getInstance();
    Injector injector = activator
            .getInjector(MyDslActivator.COM_APAMA_STUDIO_QUERY_EXT_MYDSL);
    
    @SuppressWarnings("restriction")
    EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class);
   EmbeddedEditor handle= factory.newEditor(resourceProvider).withParent(
            composite);
   
   EmbeddedEditorModelAccess partialEditor= handle.createPartialEditor();

   
   handle.getViewer().getControl().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 0));  

When i run the project the dialog opens with a editor area but it is not displaying the code present in ex.mydsl, the editor is empty.

Please tell me how to show the code in the embedded editor

解决方案

You have to specify the editor's initial contents as the editablePart parameter of createPartialEditor(String prefix, String editablePart, String suffix, boolean insertLineBreaks). To obtain your XtextResource's contents as text, save it to a ByteArrayOutputStream, then convert it to a string using toString.

这篇关于对话框中的Xtext DSL嵌入式编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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