Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has anybody fully implemented an XText editor in an IViewPart

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 :-)

like image 266
Tonny Madsen Avatar asked Jun 23 '11 20:06

Tonny Madsen


1 Answers

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);
like image 139
Tobias Avatar answered Sep 26 '22 10:09

Tobias