本文介绍了有没有人在 IViewPart 中完全实现了 XText 编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我需要在 IViewPart 中实现一个完整的 XText 编辑器.我的大部分工作基于 XText 表单集成项目.不幸的是,这不是 XText 编辑器上的完整实现,我想知道是否有人知道更好的起点.. 甚至完整的实现:-)

Basically I need to implement a full XText editor in an IViewPart. I have most of it working based on the XText Forms Integration project. Unfortunately, this is not a full implementation on an XText editor, and I wondered if anybody are aware of better starting points.. or even complete implementations :-)

推荐答案

从 2.2 开始就有可能(见 此线程).这段代码对我有用:

It is possible since 2.2 (see this thread).This code worked for me:

IEditedResourceProvider resourceProvider = new IEditedResourceProvider() {

        @Override
        public XtextResource createResource() {
            try {
                MyDslQueryStandaloneSetup.doSetup();
                ResourceSet resourceSet = new ResourceSetImpl();
                Resource resource = resourceSet.createResource(URI.createURI("somefile.MyDsl"));

                return (XtextResource) resource;
            } catch (Exception e) {
                return null;
            }
        }
    };

    MyDslActivator activator = MyDslActivator.getInstance();
    Injector injector = activator
            .getInjector(MyDslActivator.QUERYNAME);
    EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class);
    handle = factory.newEditor(resourceProvider).withParent(
            parent);

    // keep the partialEditor as instance var to read / write the edited text
    partialEditor = handle.createPartialEditor(true);

这篇关于有没有人在 IViewPart 中完全实现了 XText 编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-30 09:41